MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / my_unit_mut

Method my_unit_mut

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

Gets a mutable version of 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.

(&mut self, id: UnitID)

Source from the content-addressed store, hash-verified

796 /// * NoSuchUnit - the unit does not exist (inside the vision range).
797 /// * TeamNotAllowed - the unit is not on the current player's team.
798 fn my_unit_mut(&mut self, id: UnitID) -> Result<&mut Unit, GameError> {
799 if self.my_unit(id)?.team() == self.team() {
800 if self.my_planet().units.contains_key(&id) {
801 Ok(self.my_planet_mut().units.get_mut(&id).expect("key exists"))
802 } else if self.my_team().units_in_space.contains_key(&id) {
803 Ok(self.my_team_mut().units_in_space.get_mut(&id).expect("key exists"))
804 } else {
805 Err(GameError::NoSuchUnit)?
806 }
807 } else {
808 Err(GameError::TeamNotAllowed)?
809 }
810 }
811
812 /// Gets this unit from space or the current planet.
813 ///

Callers 15

move_toMethod · 0.80
attackMethod · 0.80
harvestMethod · 0.80
blueprintMethod · 0.80
buildMethod · 0.80
repairMethod · 0.80
replicateMethod · 0.80
javelinMethod · 0.80
begin_snipeMethod · 0.80
blinkMethod · 0.80
healMethod · 0.80
overchargeMethod · 0.80

Calls 6

my_unitMethod · 0.80
my_planetMethod · 0.80
my_planet_mutMethod · 0.80
my_teamMethod · 0.80
my_team_mutMethod · 0.80
teamMethod · 0.45

Tested by

no test coverage detected