From 219e32ad793e66a3111465ef02f3eb677f70277d Mon Sep 17 00:00:00 2001 From: Guillaume Pasquet <dev@etenil.net> Date: Thu, 2 Jan 2020 17:28:15 +0000 Subject: Fix for invisible enemies - Don't double-count visibility - Set enemies visibility with LOS - Set dirty flag when enemies are revealed --- src/state.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index 776f2bf..0badaf0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -46,6 +46,10 @@ impl State { &self.dungeon.levels[self.level] } + pub fn current_level_mut(&mut self) -> &mut Level { + &mut self.dungeon.levels[self.level] + } + fn can_step_on(tile: &Tile) -> bool { match tile.get_type() { TileType::Floor => true, @@ -55,6 +59,27 @@ impl State { } } + fn clear_los(&mut self) { + { + let grid = self.grid.as_mut().unwrap(); + grid.clear_fog_of_war(self.player.location(), PLAYER_SIGHT); + } + + for i in 0..self.current_level().entities.len() { + let loc = *self.current_level().entities[i].location(); + if self + .grid + .as_ref() + .unwrap() + .block_at(loc.0, loc.1) + .is_visible() + && !self.current_level().entities[i].is_visible() + { + self.current_level_mut().entities[i].visibility(true); + } + } + } + pub fn move_player(&mut self, dir: Movement) -> Result<(), String> { let grid = match &self.grid { Some(g) => g, -- cgit v1.2.3