diff --git a/src/ai/adjacent_ai_system.rs b/src/ai/adjacent_ai_system.rs index b06c58d..6014ade 100644 --- a/src/ai/adjacent_ai_system.rs +++ b/src/ai/adjacent_ai_system.rs @@ -27,29 +27,33 @@ impl<'a> System<'a> for AdjacentAI { let idx = map.xy_idx(pos.x, pos.y); let (w, h) = (map.width, map.height); // Evaluate adjacent squares, add possible reactions + let mut eval_idx: usize = idx; if pos.x > 0 { - evaluate(idx - 1, &map, &factions, &faction.name, &mut reactions); + eval_idx = idx - 1; } if pos.x < w - 1 { - evaluate(idx + 1, &map, &factions, &faction.name, &mut reactions); + eval_idx = idx + 1; } if pos.y > 0 { - evaluate(idx - w as usize, &map, &factions, &faction.name, &mut reactions); + eval_idx = idx - w as usize; } if pos.y < h - 1 { - evaluate(idx + w as usize, &map, &factions, &faction.name, &mut reactions); + eval_idx = idx + w as usize; } if pos.y > 0 && pos.x > 0 { - evaluate((idx - w as usize) - 1, &map, &factions, &faction.name, &mut reactions); + eval_idx = (idx - w as usize) - 1; } if pos.y > 0 && pos.x < w - 1 { - evaluate((idx - w as usize) + 1, &map, &factions, &faction.name, &mut reactions); + eval_idx = (idx - w as usize) + 1; } if pos.y < h - 1 && pos.x > 0 { - evaluate((idx + w as usize) - 1, &map, &factions, &faction.name, &mut reactions); + eval_idx = (idx + w as usize) - 1; } if pos.y < h - 1 && pos.x < w - 1 { - evaluate((idx + w as usize) + 1, &map, &factions, &faction.name, &mut reactions); + eval_idx = (idx + w as usize) + 1; + } + if eval_idx != idx { + evaluate(eval_idx, &factions, &faction.name, &mut reactions); } let mut done = false; for reaction in reactions.iter() { @@ -72,13 +76,7 @@ impl<'a> System<'a> for AdjacentAI { } /// Evaluates all possible reactions between this faction and all entities on a given tile idx. -fn evaluate( - idx: usize, - map: &Map, - factions: &ReadStorage, - this_faction: &str, - reactions: &mut Vec<(Entity, Reaction)>, -) { +fn evaluate(idx: usize, factions: &ReadStorage, this_faction: &str, reactions: &mut Vec<(Entity, Reaction)>) { crate::spatial::for_each_tile_content(idx, |other_entity| { if let Some(faction) = factions.get(other_entity) { reactions.push(( diff --git a/src/ai/default_move_system.rs b/src/ai/default_move_system.rs index deca1f1..f32f05f 100644 --- a/src/ai/default_move_system.rs +++ b/src/ai/default_move_system.rs @@ -85,7 +85,7 @@ impl<'a> System<'a> for DefaultAI { Movement::RandomWaypoint { path } => { if let Some(path) = path { // We have a path - follow it - let mut idx = map.xy_idx(pos.x, pos.y); + let idx = map.xy_idx(pos.x, pos.y); if path.len() > 1 { if !crate::spatial::is_blocked(path[1] as usize) { pos.x = path[1] as i32 % map.width; diff --git a/src/ai/visible_ai_system.rs b/src/ai/visible_ai_system.rs index 0d2b762..61863ee 100644 --- a/src/ai/visible_ai_system.rs +++ b/src/ai/visible_ai_system.rs @@ -50,7 +50,7 @@ impl<'a> System<'a> for VisibleAI { for visible_tile in viewshed.visible_tiles.iter() { let idx = map.xy_idx(visible_tile.x, visible_tile.y); if this_idx != idx { - evaluate(idx, &map, &factions, &faction.name, &mut reactions, None); + evaluate(idx, &factions, &faction.name, &mut reactions, None); idxs.insert(idx); } } @@ -61,7 +61,7 @@ impl<'a> System<'a> for VisibleAI { // and it's not the idx we're standing on, then evaluate here w/ minds taken into // account. if this_idx != idx && idxs.contains(&idx) { - evaluate(idx, &map, &factions, &faction.name, &mut reactions, Some(&minds)); + evaluate(idx, &factions, &faction.name, &mut reactions, Some(&minds)); } } } @@ -90,7 +90,6 @@ impl<'a> System<'a> for VisibleAI { fn evaluate( idx: usize, - map: &Map, factions: &ReadStorage, this_faction: &str, reactions: &mut Vec<(usize, Reaction, Entity)>, diff --git a/src/map/dungeon.rs b/src/map/dungeon.rs index 6e3e0e9..9c2d84d 100644 --- a/src/map/dungeon.rs +++ b/src/map/dungeon.rs @@ -50,7 +50,7 @@ impl MasterDungeonMap { /// Gets a map by ID from the MasterDungeonMap pub fn get_map(&self, id: i32) -> Option { if self.maps.contains_key(&id) { - let mut result = self.maps[&id].clone(); + let result = self.maps[&id].clone(); return Some(result); } else { return None; diff --git a/src/map/mod.rs b/src/map/mod.rs index b943988..e40e0e8 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -1,6 +1,5 @@ use rltk::{Algorithm2D, BaseMap, Point}; use serde::{Deserialize, Serialize}; -use specs::prelude::*; use std::collections::HashSet; pub mod colours; mod glyphs; diff --git a/src/map_indexing_system.rs b/src/map_indexing_system.rs index d4ddf44..90ea6ec 100644 --- a/src/map_indexing_system.rs +++ b/src/map_indexing_system.rs @@ -4,10 +4,10 @@ use specs::prelude::*; pub struct MapIndexingSystem {} impl<'a> System<'a> for MapIndexingSystem { - type SystemData = (WriteExpect<'a, Map>, ReadStorage<'a, Position>, ReadStorage<'a, BlocksTile>, Entities<'a>); + type SystemData = (ReadExpect<'a, Map>, ReadStorage<'a, Position>, ReadStorage<'a, BlocksTile>, Entities<'a>); fn run(&mut self, data: Self::SystemData) { - let (mut map, position, blockers, entities) = data; + let (map, position, blockers, entities) = data; spatial::clear(); spatial::populate_blocked_from_map(&*map); diff --git a/src/spatial/mod.rs b/src/spatial/mod.rs index 5708a8a..cbce0d8 100644 --- a/src/spatial/mod.rs +++ b/src/spatial/mod.rs @@ -141,7 +141,7 @@ pub fn move_entity(entity: Entity, moving_from: usize, moving_to: usize) { }); lock.tile_content[moving_to].iter().for_each(|(_, blocks)| { if *blocks { - from_blocked = true; + to_blocked = true; } }); lock.blocked[moving_from].1 = from_blocked;