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

Method my_unit

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

Gets this unit from space or the current planet. Checks that its team is the same as the current team. NoSuchUnit - the unit does not exist (inside the vision range). TeamNotAllowed - the unit is not on the current player's team.

(&self, id: UnitID)

Source from the content-addressed store, hash-verified

774 /// * NoSuchUnit - the unit does not exist (inside the vision range).
775 /// * TeamNotAllowed - the unit is not on the current player's team.
776 fn my_unit(&self, id: UnitID) -> Result<&Unit, GameError> {
777 let unit = {
778 if let Some(unit) = self.my_planet().units.get(&id) {
779 unit
780 } else if let Some(unit) = self.my_team().units_in_space.get(&id) {
781 unit
782 } else {
783 Err(GameError::NoSuchUnit)?
784 }
785 };
786 if unit.team() == self.team() {
787 Ok(unit)
788 } else {
789 Err(GameError::TeamNotAllowed)?
790 }
791 }
792
793 /// Gets a mutable version of this unit from space or the current planet.
794 /// Checks that its team is the same as the current team.

Callers 15

my_unit_mutMethod · 0.80
place_unitMethod · 0.80
remove_unitMethod · 0.80
destroy_unitMethod · 0.80
disintegrate_unitMethod · 0.80
ok_if_can_moveMethod · 0.80
ok_if_move_readyMethod · 0.80
move_robotMethod · 0.80
ok_if_can_attackMethod · 0.80
ok_if_attack_readyMethod · 0.80
attackMethod · 0.80
ok_if_can_harvestMethod · 0.80

Calls 3

my_planetMethod · 0.80
my_teamMethod · 0.80
teamMethod · 0.45

Tested by 2

test_unit_createFunction · 0.64
test_factory_productionFunction · 0.64