cleanup and bugfixes
This commit is contained in:
parent
d439ff6d3f
commit
2ba7cfad8d
7 changed files with 20 additions and 24 deletions
|
|
@ -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<Faction>,
|
||||
this_faction: &str,
|
||||
reactions: &mut Vec<(Entity, Reaction)>,
|
||||
) {
|
||||
fn evaluate(idx: usize, factions: &ReadStorage<Faction>, 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((
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Faction>,
|
||||
this_faction: &str,
|
||||
reactions: &mut Vec<(usize, Reaction, Entity)>,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ impl MasterDungeonMap {
|
|||
/// Gets a map by ID from the MasterDungeonMap
|
||||
pub fn get_map(&self, id: i32) -> Option<Map> {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue