MCPcopy Index your code
hub / github.com/battlecode/battlecode-2018 / harvest

Method harvest

battlecode-engine/src/world.rs:1239–1257  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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> {

Callers 1

applyMethod · 0.45

Calls 10

ok_if_can_harvestMethod · 0.80
my_unit_mutMethod · 0.80
worker_actMethod · 0.80
map_locationMethod · 0.80
locationMethod · 0.80
worker_harvest_amountMethod · 0.80
my_team_mutMethod · 0.80
my_planet_mutMethod · 0.80
addMethod · 0.45
karbonite_atMethod · 0.45

Tested by

no test coverage detected