Harvests up to the worker's harvest amount of karbonite from the given location, adding it to the team's resource pool. NoSuchUnit - the worker does not exist (within the vision range). TeamNotAllowed - the worker is not on the current player's team. InappropriateUnitType - the unit is not a worker. Overheated - the worker has already performed an action this turn. UnitNotOnMap - the worker is no
(&mut self, worker_id: UnitID, direction: Direction)
| 1237 | /// * LocationNotVisible - the location is not in the vision range. |
| 1238 | /// * KarboniteDepositEmpty - the location described contains no Karbonite. |
| 1239 | pub fn harvest(&mut self, worker_id: UnitID, direction: Direction) |
| 1240 | -> Result<(), GameError> { |
| 1241 | self.ok_if_can_harvest(worker_id, direction)?; |
| 1242 | let (harvest_loc, harvest_amount) = { |
| 1243 | let worker = self.my_unit_mut(worker_id).unwrap(); |
| 1244 | worker.worker_act(); |
| 1245 | (worker.location().map_location().unwrap().add(direction), |
| 1246 | worker.worker_harvest_amount().unwrap()) |
| 1247 | }; |
| 1248 | let amount_mined = cmp::min(self.karbonite_at(harvest_loc).unwrap(), harvest_amount); |
| 1249 | self.my_team_mut().karbonite += amount_mined; |
| 1250 | self.my_planet_mut().karbonite[harvest_loc.y as usize][harvest_loc.x as usize] -= amount_mined; |
| 1251 | let new_amount = self.karbonite_at(harvest_loc).unwrap(); |
| 1252 | self.viewer_changes.push(ViewerDelta::KarboniteChanged { |
| 1253 | location: harvest_loc, |
| 1254 | new_amount: new_amount, |
| 1255 | }); |
| 1256 | Ok(()) |
| 1257 | } |
| 1258 | |
| 1259 | fn ok_if_can_blueprint(&self, worker_id: UnitID, unit_type: UnitType, |
| 1260 | direction: Direction) -> Result<(), GameError> { |
no test coverage detected