LocationOffMap - the location is off the map. LocationNotVisible - the location is outside the vision range.
(&self, location: MapLocation)
| 552 | /// * LocationOffMap - the location is off the map. |
| 553 | /// * LocationNotVisible - the location is outside the vision range. |
| 554 | fn ok_if_can_sense_location(&self, location: MapLocation) -> Result<(), GameError> { |
| 555 | if self.planet() != location.planet { |
| 556 | return Err(GameError::LocationOffMap)?; |
| 557 | } |
| 558 | |
| 559 | if location.x < 0 || location.y < 0 { |
| 560 | return Err(GameError::LocationOffMap)?; |
| 561 | } |
| 562 | |
| 563 | let map = self.starting_map(location.planet); |
| 564 | if location.x >= map.width as i32 || location.y >= map.height as i32 { |
| 565 | return Err(GameError::LocationOffMap)?; |
| 566 | } |
| 567 | |
| 568 | let x = location.x as usize; |
| 569 | let y = location.y as usize; |
| 570 | if !self.my_planet().visible_locs[y][x] { |
| 571 | return Err(GameError::LocationNotVisible)?; |
| 572 | } |
| 573 | Ok(()) |
| 574 | } |
| 575 | |
| 576 | /// Whether the location is on the map and within the vision range. |
| 577 | pub fn can_sense_location(&self, location: MapLocation) -> bool { |
no test coverage detected