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

Method get_unit

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

Gets this unit from space or the current planet. NoSuchUnit - the unit does not exist.

(&self, id: UnitID)

Source from the content-addressed store, hash-verified

813 ///
814 /// * NoSuchUnit - the unit does not exist.
815 fn get_unit(&self, id: UnitID) -> Result<&Unit, GameError> {
816 if let Some(unit) = self.get_planet(Planet::Earth).units.get(&id) {
817 Ok(unit)
818 } else if let Some(unit) = self.get_planet(Planet::Mars).units.get(&id) {
819 Ok(unit)
820 } else if let Some(unit) = self.get_team(Team::Red).units_in_space.get(&id) {
821 Ok(unit)
822 } else if let Some(unit) = self.get_team(Team::Blue).units_in_space.get(&id) {
823 Ok(unit)
824 } else {
825 Err(GameError::NoSuchUnit)?
826 }
827 }
828
829 /// Gets a mutable version of this unit from space or the current planet.
830 ///

Callers 1

process_asteroidsMethod · 0.80

Calls 2

get_planetMethod · 0.80
get_teamMethod · 0.80

Tested by

no test coverage detected