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

Method replicate

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

Replicates a worker in the given direction. Subtracts the cost of the worker from 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 is not ready to replicate again. InsufficientKarbonite - your team does not have enoug

(&mut self, worker_id: UnitID, direction: Direction)

Source from the content-addressed store, hash-verified

1452 /// * LocationNotEmpty - the location in the target direction is already
1453 /// occupied.
1454 pub fn replicate(&mut self, worker_id: UnitID, direction: Direction)
1455 -> Result<(), GameError> {
1456 self.ok_if_can_replicate(worker_id, direction)?;
1457 self.my_unit_mut(worker_id)?.worker_act();
1458 self.my_unit_mut(worker_id)?.replicate();
1459 let (team, location) = {
1460 let worker = self.my_unit(worker_id)?;
1461 (worker.team(), worker.location().map_location()?.add(direction))
1462 };
1463 self.create_unit(team, location, UnitType::Worker)?;
1464 self.my_team_mut().karbonite -= UnitType::Worker.replicate_cost()?;
1465 Ok(())
1466 }
1467
1468 // ************************************************************************
1469 // *************************** KNIGHT METHODS *****************************

Callers 1

applyMethod · 0.45

Calls 11

ok_if_can_replicateMethod · 0.80
worker_actMethod · 0.80
my_unit_mutMethod · 0.80
my_unitMethod · 0.80
map_locationMethod · 0.80
locationMethod · 0.80
create_unitMethod · 0.80
my_team_mutMethod · 0.80
replicate_costMethod · 0.80
teamMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected