diff options
| author | troido <troido@protonmail.com> | 2020-09-26 00:05:03 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-26 00:05:03 +0200 |
| commit | 345251f20401a71f7e7e00f4810b92af39ad4395 (patch) | |
| tree | 4f1f64a4f09e81fb98bb786865d5164048440321 /src/systems | |
| parent | 9e2aa0f98cb93ea79db023f1309e083e59192293 (diff) | |
use flags for the whole room instead of room permissions
the flags on a tile are the union of the flags from the entity on that tile and the room flags
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/useitem.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index 4927636..5a12b7e 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -1,4 +1,5 @@ +use std::collections::HashSet; use specs::{ Entities, @@ -18,9 +19,10 @@ use crate::{ AttackInbox, AttackMessage, AttackType, - Flags + Flags, + Flag }, - resources::{NewEntities, Ground, RoomPermissions}, + resources::{NewEntities, Ground, RoomFlags}, item::ItemAction::{None, Build, Eat, Equip}, controls::Control, }; @@ -37,17 +39,17 @@ impl <'a> System<'a> for Use { WriteStorage<'a, AttackInbox>, Write<'a, Ground>, ReadStorage<'a, Flags>, - Read<'a, RoomPermissions> + Read<'a, RoomFlags> ); - fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut ground, flags, roompermissions): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut ground, flags, roomflags): Self::SystemData) { for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){ if let Control::Use(rank) = &controller.control { if let Some(entry) = inventory.items.get_mut(*rank) { match &entry.item.action { Build(template, required_flags, blocking_flags) => { - let ground_flags = ground.flags_on(position.pos, &flags); - if roompermissions.build && required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){ + let ground_flags: HashSet<Flag> = ground.flags_on(position.pos, &flags).union(&roomflags.0).cloned().collect(); + if required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){ new.create(position.pos, &template).unwrap(); inventory.items.remove(*rank); } |
