From 2b5824035f9e30337a1d764c9bb447c7c6e9a2a6 Mon Sep 17 00:00:00 2001 From: Ted Milker Date: Sat, 6 Nov 2021 17:41:32 -0500 Subject: [PATCH] Filter out multiple enemy messages moving to the same location --- WinningAndLosing/gauntlet/src/systems/mod.rs | 3 +++ .../gauntlet/src/systems/movement_filter.rs | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 WinningAndLosing/gauntlet/src/systems/movement_filter.rs diff --git a/WinningAndLosing/gauntlet/src/systems/mod.rs b/WinningAndLosing/gauntlet/src/systems/mod.rs index 1222bf2..5850038 100644 --- a/WinningAndLosing/gauntlet/src/systems/mod.rs +++ b/WinningAndLosing/gauntlet/src/systems/mod.rs @@ -7,6 +7,7 @@ mod random_move; mod chasing; mod end_turn; mod movement; +mod movement_filter; mod hud; mod tooltips; mod combat; @@ -42,6 +43,8 @@ pub fn build_monster_scheduler() -> Schedule { .flush() .add_system(combat::combat_system()) .flush() + .add_system(movement_filter::movement_filter_system()) + .flush() .add_system(movement::movement_system()) .flush() .add_system(map_render::map_render_system()) diff --git a/WinningAndLosing/gauntlet/src/systems/movement_filter.rs b/WinningAndLosing/gauntlet/src/systems/movement_filter.rs new file mode 100644 index 0000000..63c8eb4 --- /dev/null +++ b/WinningAndLosing/gauntlet/src/systems/movement_filter.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; + +#[system] +#[read_component(WantsToMove)] +pub fn movement_filter( + ecs: &mut SubWorld, + commands: &mut CommandBuffer) { + + let mut moves = <(Entity, &WantsToMove)>::query(); + let mut pos_seen: Vec = Vec::new(); + + moves.iter(ecs).for_each(|(entity, want_move)| { + if pos_seen.contains(&want_move.destination) { + commands.remove(*entity); + } + else { + pos_seen.push(want_move.destination); + } + }); +} \ No newline at end of file