diff options
| author | troido <troido@protonmail.com> | 2020-03-03 19:11:32 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-03 19:11:32 +0100 |
| commit | f844ed18e29465177a339f244800fb7a2e77daa9 (patch) | |
| tree | c3445f869eb072a35162e008609cc1dc75c427fb /src/systems | |
| parent | 986c82723cf9a4adada02287309999f4ebbf94e3 (diff) | |
factions now work
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/controlai.rs | 9 | ||||
| -rw-r--r-- | src/systems/fight.rs | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/systems/controlai.rs b/src/systems/controlai.rs index debe716..ab72f77 100644 --- a/src/systems/controlai.rs +++ b/src/systems/controlai.rs @@ -11,7 +11,7 @@ use specs::{ }; use crate::{ - components::{Controller, ControlCooldown, Fighter, MonsterAI, Home, Health, Position}, + components::{Controller, ControlCooldown, Fighter, MonsterAI, Home, Health, Position, Faction}, controls::{Control, Direction::{self, North, South, East, West}}, Pos }; @@ -27,9 +27,10 @@ impl <'a> System<'a> for ControlAI { ReadStorage<'a, Fighter>, ReadStorage<'a, Home>, ReadStorage<'a, Health>, - ReadStorage<'a, Position> + ReadStorage<'a, Position>, + ReadStorage<'a, Faction> ); - fn run(&mut self, (entities, mut controllers, cooldowns, ais, fighters, homes, healths, positions): Self::SystemData) { + fn run(&mut self, (entities, mut controllers, cooldowns, ais, fighters, homes, healths, positions, factions): Self::SystemData) { for (entity, ai, position, ()) in (&entities, &ais, &positions, !&cooldowns).join() { if let Some(fighter) = fighters.get(entity) { @@ -37,7 +38,7 @@ impl <'a> System<'a> for ControlAI { let mut closest = None; let mut closest_position = None; for (target, target_position, _) in (&entities, &positions, &healths).join() { - if target == entity { + if target == entity || !Faction::is_enemy_entity(&factions, entity, target) { continue; } let distance = position.pos.distance_to(target_position.pos); diff --git a/src/systems/fight.rs b/src/systems/fight.rs index 00aeb3e..47b5811 100644 --- a/src/systems/fight.rs +++ b/src/systems/fight.rs @@ -17,7 +17,8 @@ use crate::components::{ Fighter, Health, ControlCooldown, - Autofight + Autofight, + Faction }; use crate::controls::{Control}; @@ -36,17 +37,18 @@ impl <'a> System<'a> for Fight { ReadStorage<'a, Fighter>, ReadStorage<'a, Health>, WriteStorage<'a, ControlCooldown>, - WriteStorage<'a, Autofight> + WriteStorage<'a, Autofight>, + ReadStorage<'a, Faction> ); - fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters, factions): Self::SystemData) { for (entity, controller, position, fighter) in (&entities, &controllers, &positions, &fighters).join(){ let mut target = None; match &controller.control { Control::Attack(directions) => { 'targets: for direction in directions { for ent in ground.cells.get(&(position.pos + direction.to_position())).unwrap_or(&HashSet::new()) { - if healths.contains(*ent) && *ent != entity { + if healths.contains(*ent) && *ent != entity && Faction::is_enemy_entity(&factions, entity, *ent) { target = Some(*ent); break 'targets; } |
