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)
| 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. |