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)
| 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 | /// |
no test coverage detected