aboutsummaryrefslogtreecommitdiff
path: root/src/state.rs
diff options
context:
space:
mode:
authorGuillaume Pasquet <dev@etenil.net>2020-01-02 17:28:15 +0000
committerGuillaume Pasquet <dev@etenil.net>2020-03-14 16:52:06 +0000
commit219e32ad793e66a3111465ef02f3eb677f70277d (patch)
treeffbfc495906fdb447074c1c1e3e4996432f83a14 /src/state.rs
parent9848a92fde2891177cc352064ae9e4ec1098277f (diff)
Fix for invisible enemies
- Don't double-count visibility - Set enemies visibility with LOS - Set dirty flag when enemies are revealed
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs25
1 files changed, 25 insertions, 0 deletions
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,