summaryrefslogtreecommitdiff
path: root/src/systems/spawncheck.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-10-03 15:20:52 +0200
committertroido <troido@protonmail.com>2020-10-03 15:20:52 +0200
commitfa5ddaa570473ece02e0a3bfb35702211d21ce12 (patch)
tree501498c9db9d7d2c985f86272b3405c98301556f /src/systems/spawncheck.rs
parent5af83beb6f10023cef7eba192a0b190518fe967b (diff)
added dense grass; home is now part of monsterAI component
Diffstat (limited to 'src/systems/spawncheck.rs')
-rw-r--r--src/systems/spawncheck.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/systems/spawncheck.rs b/src/systems/spawncheck.rs
new file mode 100644
index 0000000..52ff38e
--- /dev/null
+++ b/src/systems/spawncheck.rs
@@ -0,0 +1,39 @@
+
+use std::collections::HashSet;
+use specs::{
+ WriteStorage,
+ ReadStorage,
+ Entities,
+ System,
+ Join,
+ Read
+};
+
+use crate::{
+ components::{Removed, Requirements, New, Position, Flag, Flags},
+ resources::{Ground, RoomFlags}
+};
+
+
+pub struct SpawnCheck;
+impl <'a> System<'a> for SpawnCheck {
+ type SystemData = (
+ Entities<'a>,
+ ReadStorage<'a, Requirements>,
+ ReadStorage<'a, New>,
+ WriteStorage<'a, Removed>,
+ Read<'a, Ground>,
+ Read<'a, RoomFlags>,
+ ReadStorage<'a, Position>,
+ ReadStorage<'a, Flags>
+ );
+ fn run(&mut self, (entities, requirements, new, mut removeds, ground, roomflags, positions, flags): Self::SystemData) {
+ for (entity, requirements, _new, position) in (&entities, &requirements, &new, &positions).join() {
+ let ground_flags: HashSet<Flag> = ground.flags_on(position.pos, &flags).union(&roomflags.0).cloned().collect();
+ if !(requirements.required_flags.is_subset(&ground_flags) && requirements.blocking_flags.is_disjoint(&ground_flags)){
+ removeds.insert(entity, Removed).unwrap();
+ }
+ }
+ }
+}
+