From 81974edb3386b2097ca876bffdf95fb64a901267 Mon Sep 17 00:00:00 2001 From: Owen McCormick Date: Thu, 11 Feb 2021 13:50:56 -0800 Subject: [PATCH 1/5] Replaced individual movement system components --- src/components.rs | 13 +++-- src/states/default.rs | 9 +--- src/systems/elephant_spawner.rs | 4 +- src/systems/leader1_simple_movement.rs | 68 +++++++++++++------------ src/systems/leader2_simple_movement.rs | 66 +++++++++++++----------- src/systems/mod.rs | 8 +-- src/systems/simple_movement.rs | 70 +++++++++++++------------- src/systems/spawn_creep.rs | 4 +- src/systems/spawn_leader.rs | 24 ++++----- 9 files changed, 138 insertions(+), 128 deletions(-) diff --git a/src/components.rs b/src/components.rs index 6002dd1..c4026e7 100644 --- a/src/components.rs +++ b/src/components.rs @@ -31,11 +31,14 @@ pub struct Leader(pub u8); /// Adds a name to an entity. pub struct Name(pub String); /// Allows this entity to move to the closest enemy entity. -pub struct SimpleMovement; -/// Allows this entity to move to the closest enemy entity. -pub struct Leader1SimpleMovement; -/// Allows this entity to move a given distance away from the closest enemy entity. -pub struct Leader2SimpleMovement; +pub enum MovementSystems { + /// Standard movement + SimpleMovement, + /// Melee leader movement + Leader1SimpleMovement, + /// Ranged leader movement + Leader2SimpleMovement, +} /// Makes this entity run back to its team's `Core` when low in health. pub struct FleeToBase(pub f64); /// Added on entities which temporarily cannot move. diff --git a/src/states/default.rs b/src/states/default.rs index 040d289..8a34e79 100644 --- a/src/states/default.rs +++ b/src/states/default.rs @@ -5,12 +5,7 @@ pub struct DefaultState; #[allow(unused_variables)] impl minigene::State for DefaultState { - fn update( - &mut self, - world: &mut World, - dispatcher: &mut Dispatcher, - ctx: &mut BTerm, - ) -> Trans { + fn update(&mut self, world: &mut World, dispatcher: &mut Dispatcher, ctx: &mut BTerm) -> Trans { #[cfg(not(feature = "headless"))] { ctx.set_active_console(0); @@ -56,5 +51,5 @@ impl minigene::State for DefaultState { } Trans::None - } + } } diff --git a/src/systems/elephant_spawner.rs b/src/systems/elephant_spawner.rs index 9aa5b5b..fb6c7d7 100644 --- a/src/systems/elephant_spawner.rs +++ b/src/systems/elephant_spawner.rs @@ -6,7 +6,7 @@ pub fn elephant_spawner_system( stat_def: &StatDefinitions, teams: &mut Components, proximity_attacks: &mut Components, - simple_movements: &mut Components, + simple_movements: &mut Components, stats: &mut Components>, positions: &mut Components, entities: &mut Entities, @@ -22,7 +22,7 @@ pub fn elephant_spawner_system( let elephant = entities.create(); positions.insert(elephant, pos.clone()); companions.insert(ev.0, Companion::Elephant(elephant)); - simple_movements.insert(elephant, SimpleMovement); + simple_movements.insert(elephant, MovementSystems::SimpleMovement); teams.insert(elephant, team); stats.insert(elephant, stat_def.to_statset()); proximity_attacks.insert(elephant, ProximityAttack::new(CREEP_ATTACK_RADIUS)); diff --git a/src/systems/leader1_simple_movement.rs b/src/systems/leader1_simple_movement.rs index 04bc40b..7616000 100644 --- a/src/systems/leader1_simple_movement.rs +++ b/src/systems/leader1_simple_movement.rs @@ -3,7 +3,7 @@ use crate::*; /// Moves melee leaders on the map. pub fn leader1_simple_movement_system( entities: &Entities, - simple_movements: &Components, + simple_movements: &Components, teams: &Components, is_caught: &Components, stats: &Components>, @@ -20,22 +20,26 @@ pub fn leader1_simple_movement_system( let leader_team = leader_team.unwrap(); let caught = caught.unwrap(); if caught.0 { - for (e, _, team, pos) in join!(&entities && &simple_movements && &teams && &positions) { - let e = e.unwrap(); - let team = team.unwrap(); - let pos = pos.unwrap(); - // find closest leader in other team - // TODO: optimize - let mut vec = join!(&teams && &positions && &stats && &leaders) - .filter(|(t, _, _, _)| *t.unwrap() != *team) - .map(|(_, p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) - .collect::>(); - vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); - let closest = vec.into_iter().next().map(|(_d, p)| p); - if let Some(c) = closest { - targets.insert(e, AiDestination::new(c.clone())).unwrap(); - } else { - targets.remove(e); + for (e, movement, team, pos) in + join!(&entities && &simple_movements && &teams && &positions) + { + if let MovementSystems::Leader1SimpleMovement = movement.unwrap() { + let e = e.unwrap(); + let team = team.unwrap(); + let pos = pos.unwrap(); + // find closest leader in other team + // TODO: optimize + let mut vec = join!(&teams && &positions && &stats && &leaders) + .filter(|(t, _, _, _)| *t.unwrap() != *team) + .map(|(_, p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) + .collect::>(); + vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); + let closest = vec.into_iter().next().map(|(_d, p)| p); + if let Some(c) = closest { + targets.insert(e, AiDestination::new(c.clone())).unwrap(); + } else { + targets.remove(e); + } } } } else { @@ -57,20 +61,22 @@ pub fn leader1_simple_movement_system( } } } else { - for (e, _, pos) in join!(&entities && &simple_movements && &positions) { - let e = e.unwrap(); - let pos = pos.unwrap(); - // find closest creep - // TODO: optimize - let mut vec = join!(&positions && &stats && &creeps) - .map(|(p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) - .collect::>(); - vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); - let closest = vec.into_iter().next().map(|(_d, p)| p); - if let Some(c) = closest { - targets.insert(e, AiDestination::new(c.clone())).unwrap(); - } else { - targets.remove(e); + for (e, movement, pos) in join!(&entities && &simple_movements && &positions) { + if let MovementSystems::Leader1SimpleMovement = movement.unwrap() { + let e = e.unwrap(); + let pos = pos.unwrap(); + // find closest creep + // TODO: optimize + let mut vec = join!(&positions && &stats && &creeps) + .map(|(p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) + .collect::>(); + vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); + let closest = vec.into_iter().next().map(|(_d, p)| p); + if let Some(c) = closest { + targets.insert(e, AiDestination::new(c.clone())).unwrap(); + } else { + targets.remove(e); + } } } } diff --git a/src/systems/leader2_simple_movement.rs b/src/systems/leader2_simple_movement.rs index c7d81c7..3532c6f 100644 --- a/src/systems/leader2_simple_movement.rs +++ b/src/systems/leader2_simple_movement.rs @@ -3,7 +3,7 @@ use crate::*; /// Moves ranged leaders on the map. pub fn leader2_simple_movement_system( entities: &Entities, - simple_movements: &Components, + simple_movements: &Components, teams: &Components, is_caught: &Components, stats: &Components>, @@ -19,22 +19,26 @@ pub fn leader2_simple_movement_system( let leader_team = leader_team.unwrap(); let caught = caught.unwrap(); if caught.0 { - for (e, _, team, pos) in join!(&entities && &simple_movements && &teams && &positions) { - let e = e.unwrap(); - let team = team.unwrap(); - let pos = pos.unwrap(); - // find closest leader in other team - // TODO: optimize - let mut vec = join!(&teams && &positions && &stats && &leaders) - .filter(|(t, _, _, _)| *t.unwrap() != *team) - .map(|(_, p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) - .collect::>(); - vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); - let closest = vec.into_iter().next().map(|(_d, p)| p); - if let Some(c) = closest { - targets.insert(e, AiDestination::new(c.clone())).unwrap(); - } else { - targets.remove(e); + for (e, movement, team, pos) in + join!(&entities && &simple_movements && &teams && &positions) + { + if let MovementSystems::Leader2SimpleMovement = movement.unwrap() { + let e = e.unwrap(); + let team = team.unwrap(); + let pos = pos.unwrap(); + // find closest leader in other team + // TODO: optimize + let mut vec = join!(&teams && &positions && &stats && &leaders) + .filter(|(t, _, _, _)| *t.unwrap() != *team) + .map(|(_, p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) + .collect::>(); + vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); + let closest = vec.into_iter().next().map(|(_d, p)| p); + if let Some(c) = closest { + targets.insert(e, AiDestination::new(c.clone())).unwrap(); + } else { + targets.remove(e); + } } } } else { @@ -56,24 +60,26 @@ pub fn leader2_simple_movement_system( } } } else { - for (e, _, team, pos) in + for (e, movement, team, pos) in join!(&entities && &simple_movements && &teams && &positions) { - let e = e.unwrap(); - let pos = pos.unwrap(); - let team = team.unwrap(); - // find closest enemy - let closest = find_closest_in_other_team( - team, pos, &teams, &positions, &stats, &entities, - ); - if dist(&closest.unwrap().1, pos) > RANGED_LEADER_ATTACK_RADIUS { - if let Some((_, c)) = closest { - targets.insert(e, AiDestination::new(c.clone())).unwrap(); + if let MovementSystems::Leader2SimpleMovement = movement.unwrap() { + let e = e.unwrap(); + let pos = pos.unwrap(); + let team = team.unwrap(); + // find closest enemy + let closest = find_closest_in_other_team( + team, pos, &teams, &positions, &stats, &entities, + ); + if dist(&closest.unwrap().1, pos) > RANGED_LEADER_ATTACK_RADIUS { + if let Some((_, c)) = closest { + targets.insert(e, AiDestination::new(c.clone())).unwrap(); + } else { + targets.remove(e); + } } else { targets.remove(e); } - } else { - targets.remove(e); } } } diff --git a/src/systems/mod.rs b/src/systems/mod.rs index d1a895f..eb49a66 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -4,10 +4,10 @@ mod air_corrosion; mod aoe_damage; mod back_endurance; mod battle_hunger; -mod elephant_spawner; mod creep_spawner; mod damage_entity; mod dark_presence; +mod elephant_spawner; mod fog_of_vision; mod game_stats_updater; mod handle_action_points; @@ -36,8 +36,8 @@ mod tower_projectile; mod transfer_gold; mod update_collision_resource; mod update_enemies_around_stat; -mod update_mouse_events; mod update_leaders_around_stat; +mod update_mouse_events; mod update_win_condition; pub use self::additional_attack::*; pub use self::additional_defense::*; @@ -45,10 +45,10 @@ pub use self::air_corrosion::*; pub use self::aoe_damage::*; pub use self::back_endurance::*; pub use self::battle_hunger::*; -pub use self::elephant_spawner::*; pub use self::creep_spawner::*; pub use self::damage_entity::*; pub use self::dark_presence::*; +pub use self::elephant_spawner::*; pub use self::fog_of_vision::*; pub use self::game_stats_updater::*; pub use self::handle_action_points::*; @@ -78,6 +78,6 @@ pub use self::tower_projectile::*; pub use self::transfer_gold::*; pub use self::update_collision_resource::*; pub use self::update_enemies_around_stat::*; -pub use self::update_mouse_events::*; pub use self::update_leaders_around_stat::*; +pub use self::update_mouse_events::*; pub use self::update_win_condition::*; diff --git a/src/systems/simple_movement.rs b/src/systems/simple_movement.rs index 9f897ee..2cc6456 100644 --- a/src/systems/simple_movement.rs +++ b/src/systems/simple_movement.rs @@ -3,49 +3,51 @@ use crate::*; /// Moves the entity towards the closest enemy, provided we have enough action points to do so. pub fn simple_movement_system( entities: &Entities, - simple_movements: &Components, + simple_movements: &Components, teams: &Components, positions: &Components, stats: &mut Components>, targets: &mut Components, paths: &mut Components, ) -> SystemResult { - for (e, _, team, pos) in join!(&entities && &simple_movements && &teams && &positions) { - // find closest in other team - // TODO: optimize - // TODO: fix assumption that if you have a movement and team you have stats - if stats - .get(e.unwrap()) - .unwrap() - .stats - .get(&Stats::ActionPoints) - .unwrap() - .value - >= ACTION_POINT_MOVE_COST - { - let closest = find_closest_in_other_team( - team.unwrap(), - pos.unwrap(), - &teams, - &positions, - &stats, - &entities, - ); - if let Some((_, c)) = closest { - stats - .get_mut(e.unwrap()) - .unwrap() - .stats - .get_mut(&Stats::ActionPoints) - .unwrap() - .value -= ACTION_POINT_MOVE_COST; - targets.insert(e.unwrap(), AiDestination::new(c.clone())); + for (e, movement, team, pos) in join!(&entities && &simple_movements && &teams && &positions) { + if let MovementSystems::SimpleMovement = movement.unwrap() { + // find closest in other team + // TODO: optimize + // TODO: fix assumption that if you have a movement and team you have stats + if stats + .get(e.unwrap()) + .unwrap() + .stats + .get(&Stats::ActionPoints) + .unwrap() + .value + >= ACTION_POINT_MOVE_COST + { + let closest = find_closest_in_other_team( + team.unwrap(), + pos.unwrap(), + &teams, + &positions, + &stats, + &entities, + ); + if let Some((_, c)) = closest { + stats + .get_mut(e.unwrap()) + .unwrap() + .stats + .get_mut(&Stats::ActionPoints) + .unwrap() + .value -= ACTION_POINT_MOVE_COST; + targets.insert(e.unwrap(), AiDestination::new(c.clone())); + } else { + targets.remove(e.unwrap()); + } } else { targets.remove(e.unwrap()); + paths.remove(e.unwrap()); } - } else { - targets.remove(e.unwrap()); - paths.remove(e.unwrap()); } } Ok(()) diff --git a/src/systems/spawn_creep.rs b/src/systems/spawn_creep.rs index fd0c2b2..6141f84 100644 --- a/src/systems/spawn_creep.rs +++ b/src/systems/spawn_creep.rs @@ -7,7 +7,7 @@ pub fn spawn_creep_system( entities: &mut Entities, positions: &mut Components, creeps: &mut Components, - simple_movements: &mut Components, + simple_movements: &mut Components, proximity_attacks: &mut Components, stats: &mut Components>, teams: &mut Components, @@ -20,7 +20,7 @@ pub fn spawn_creep_system( let creep = entities.create(); positions.insert(creep, pos.clone()); creeps.insert(creep, Creep); - simple_movements.insert(creep, SimpleMovement); + simple_movements.insert(creep, MovementSystems::SimpleMovement); teams.insert(creep, *team); stats.insert(creep, stat_def.to_statset()); proximity_attacks.insert(creep, ProximityAttack::new(CREEP_ATTACK_RADIUS)); diff --git a/src/systems/spawn_leader.rs b/src/systems/spawn_leader.rs index 0202ae6..a05f091 100644 --- a/src/systems/spawn_leader.rs +++ b/src/systems/spawn_leader.rs @@ -12,10 +12,8 @@ pub fn spawn_leader_system( // retreats: &mut Components, // is_caught: &mut Components, spell_steals: &mut Components, - simple_movements: &mut Components, + simple_movements: &mut Components, proximity_attacks: &mut Components, - // leader1_simple_movements: &mut Components, - // leader2_simple_movements: &mut Components, // leader1_proximity_attacks: &mut Components, stats: &mut Components>, teams: &mut Components, @@ -80,7 +78,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(6)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -99,7 +97,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(5)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -118,7 +116,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(55)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -137,7 +135,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(4)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -156,7 +154,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(8)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -175,7 +173,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(16)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -194,7 +192,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(7)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -213,7 +211,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(7)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -233,7 +231,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(19)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable @@ -252,7 +250,7 @@ pub fn spawn_leader_system( }, ); sprite_indices.insert(leader, SpriteIndex(14)); - simple_movements.insert(leader, SimpleMovement); + simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable From fcc01a05c018a5964d72e10105b616a87d96de46 Mon Sep 17 00:00:00 2001 From: Owen McCormick Date: Thu, 11 Feb 2021 14:18:08 -0800 Subject: [PATCH 2/5] Replaced separate components for proximity attacks --- src/components.rs | 14 +++---- src/systems/elephant_spawner.rs | 4 +- src/systems/leader1_proximity_attack.rs | 54 ++++++++++++++----------- src/systems/proximity_attack.rs | 30 +++++++------- src/systems/spawn_creep.rs | 4 +- src/systems/spawn_leader.rs | 23 +++++------ 6 files changed, 66 insertions(+), 63 deletions(-) diff --git a/src/components.rs b/src/components.rs index c4026e7..cc518bb 100644 --- a/src/components.rs +++ b/src/components.rs @@ -4,15 +4,11 @@ use crate::*; pub struct Tower; /// Allows this entity to attack other entities in proximity to it. #[derive(new)] -pub struct ProximityAttack { - /// The radius at which we can attack. - pub radius: f32, -} -/// Allows this leader to attack other entities in proximity to it. -#[derive(new)] -pub struct Leader1ProximityAttack { - /// The radius at which we can attack. - pub radius: f32, +pub enum ProximityAttackSystems { + /// Standard proximity attack + SimpleProximityAttack(f32), + /// Leader proximity attack + Leader1ProximityAttack(f32), } /// Identifies which type is the companion #[derive(PartialEq, Eq, Copy, Clone, Debug)] diff --git a/src/systems/elephant_spawner.rs b/src/systems/elephant_spawner.rs index fb6c7d7..27bbc36 100644 --- a/src/systems/elephant_spawner.rs +++ b/src/systems/elephant_spawner.rs @@ -5,7 +5,7 @@ pub fn elephant_spawner_system( events: &Vec>, stat_def: &StatDefinitions, teams: &mut Components, - proximity_attacks: &mut Components, + proximity_attacks: &mut Components, simple_movements: &mut Components, stats: &mut Components>, positions: &mut Components, @@ -25,7 +25,7 @@ pub fn elephant_spawner_system( simple_movements.insert(elephant, MovementSystems::SimpleMovement); teams.insert(elephant, team); stats.insert(elephant, stat_def.to_statset()); - proximity_attacks.insert(elephant, ProximityAttack::new(CREEP_ATTACK_RADIUS)); + proximity_attacks.insert(elephant, ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS)); let bg = if team == Team::Me { RGBA::named(GREEN) } else { diff --git a/src/systems/leader1_proximity_attack.rs b/src/systems/leader1_proximity_attack.rs index 6763bf6..74ca672 100644 --- a/src/systems/leader1_proximity_attack.rs +++ b/src/systems/leader1_proximity_attack.rs @@ -5,7 +5,7 @@ use rand::Rng; /// Attacks entities that are close to this leader. pub fn leader1_proximity_attack_system( entities: &Entities, - proximity_attacks: &Components, + proximity_attacks: &Components, leaders: &Components, teams: &Components, positions: &Components, @@ -15,37 +15,43 @@ pub fn leader1_proximity_attack_system( ) -> SystemResult { let mut v = vec![]; let mut rng = thread_rng(); - for (e, _proximity, stat, pos, team) in + for (e, proximity, stat, pos, team) in join!(&entities && &proximity_attacks && &stats && &positions && &teams) { - let closest = find_closest_in_other_team( - team.unwrap(), - pos.unwrap(), - &teams, - &positions, - &stats, - &entities, - ); - if let Some((target, _)) = closest { - let damage = stat.unwrap().stats.get(&Stats::Attack).unwrap().value; - v.push((e.unwrap().clone(), target.clone(), damage)); + if let ProximityAttackSystems::Leader1ProximityAttack(radius) = proximity.unwrap() { + let closest = find_closest_in_other_team( + team.unwrap(), + pos.unwrap(), + &teams, + &positions, + &stats, + &entities, + ); + if let Some((target, p)) = closest { + if dist(&p, pos.unwrap()) <= *radius { + let damage = stat.unwrap().stats.get(&Stats::Attack).unwrap().value; + v.push((e.unwrap().clone(), target.clone(), damage)); + } + } } } // 5% chance of getting caught if leaders are in range of each other for (proximity, pos, team, _, mut caught) in join!(&proximity_attacks && &positions && &teams && &leaders && &mut is_caught) { - let mut vec = join!(&entities && &teams && &positions && &stats && &leaders) - .filter(|(_e, t, _, _, _)| *t.unwrap() != *team.unwrap()) - .map(|(e, _, p, _, _)| (dist(pos.unwrap(), p.unwrap()), e.unwrap())) - .filter(|(d, _)| *d < proximity.unwrap().radius) - .collect::>(); - vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); - let closest = vec.into_iter().next().map(|(_d, p)| p); - if let Some(_) = closest { - // 5% chance of leaders getting caught - if rng.gen_range(1, 21) == 1 { - caught.as_mut().unwrap().0 = true; + if let ProximityAttackSystems::Leader1ProximityAttack(radius) = proximity.unwrap() { + let mut vec = join!(&entities && &teams && &positions && &stats && &leaders) + .filter(|(_e, t, _, _, _)| *t.unwrap() != *team.unwrap()) + .map(|(e, _, p, _, _)| (dist(pos.unwrap(), p.unwrap()), e.unwrap())) + .filter(|(d, _)| *d < *radius) + .collect::>(); + vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); + let closest = vec.into_iter().next().map(|(_d, p)| p); + if let Some(_) = closest { + // 5% chance of leaders getting caught + if rng.gen_range(1, 21) == 1 { + caught.as_mut().unwrap().0 = true; + } } } } diff --git a/src/systems/proximity_attack.rs b/src/systems/proximity_attack.rs index 793e8cb..86dbc52 100644 --- a/src/systems/proximity_attack.rs +++ b/src/systems/proximity_attack.rs @@ -3,28 +3,30 @@ use crate::*; /// Attacks entities that are in close proximity with this entity. pub fn proximity_attack_system( entities: &Entities, - proximity_attacks: &Components, + proximity_attacks: &Components, teams: &Components, positions: &Components, stats: &mut Components>, game_events: &mut Vec, ) -> SystemResult { let mut v = vec![]; - for (e, _proximity, stat, pos, team) in + for (e, proximity, stat, pos, team) in join!(&entities && &proximity_attacks && &stats && &positions && &teams) { - let closest = find_closest_in_other_team( - team.unwrap(), - pos.unwrap(), - &teams, - &positions, - &stats, - &entities, - ); - if let Some((target, p)) = closest { - if dist(&p, pos.unwrap()) <= CREEP_ATTACK_RADIUS { - let damage = stat.unwrap().stats.get(&Stats::Attack).unwrap().value; - v.push((e.unwrap().clone(), target.clone(), damage)); + if let ProximityAttackSystems::SimpleProximityAttack(radius) = proximity.unwrap() { + let closest = find_closest_in_other_team( + team.unwrap(), + pos.unwrap(), + &teams, + &positions, + &stats, + &entities, + ); + if let Some((target, p)) = closest { + if dist(&p, pos.unwrap()) <= *radius { + let damage = stat.unwrap().stats.get(&Stats::Attack).unwrap().value; + v.push((e.unwrap().clone(), target.clone(), damage)); + } } } } diff --git a/src/systems/spawn_creep.rs b/src/systems/spawn_creep.rs index 6141f84..a5734ca 100644 --- a/src/systems/spawn_creep.rs +++ b/src/systems/spawn_creep.rs @@ -8,7 +8,7 @@ pub fn spawn_creep_system( positions: &mut Components, creeps: &mut Components, simple_movements: &mut Components, - proximity_attacks: &mut Components, + proximity_attacks: &mut Components, stats: &mut Components>, teams: &mut Components, sprites: &mut Components, @@ -23,7 +23,7 @@ pub fn spawn_creep_system( simple_movements.insert(creep, MovementSystems::SimpleMovement); teams.insert(creep, *team); stats.insert(creep, stat_def.to_statset()); - proximity_attacks.insert(creep, ProximityAttack::new(CREEP_ATTACK_RADIUS)); + proximity_attacks.insert(creep, ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS)); let bg = if *team == Team::Me { sights.insert(creep, LineOfSight::new(5)); RGBA::named(GREEN) diff --git a/src/systems/spawn_leader.rs b/src/systems/spawn_leader.rs index a05f091..1519822 100644 --- a/src/systems/spawn_leader.rs +++ b/src/systems/spawn_leader.rs @@ -13,8 +13,7 @@ pub fn spawn_leader_system( // is_caught: &mut Components, spell_steals: &mut Components, simple_movements: &mut Components, - proximity_attacks: &mut Components, - // leader1_proximity_attacks: &mut Components, + proximity_attacks: &mut Components, stats: &mut Components>, teams: &mut Components, sprites: &mut Components, @@ -80,7 +79,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(6)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttacks::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -99,7 +98,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(5)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -118,7 +117,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(55)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -137,7 +136,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(4)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -156,7 +155,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(8)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -175,7 +174,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(16)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -194,7 +193,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(7)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -213,7 +212,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(7)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -233,7 +232,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(19)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -252,7 +251,7 @@ pub fn spawn_leader_system( sprite_indices.insert(leader, SpriteIndex(14)); simple_movements.insert(leader, MovementSystems::SimpleMovement); proximity_attacks - .insert(leader, ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); + .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); From 828bc8a9633591096eb3a40dc2328dc42f870d5a Mon Sep 17 00:00:00 2001 From: Owen McCormick Date: Thu, 11 Feb 2021 14:22:15 -0800 Subject: [PATCH 3/5] Updated documentation --- doc/create_leader.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/create_leader.md b/doc/create_leader.md index aa2f657..d8e7446 100644 --- a/doc/create_leader.md +++ b/doc/create_leader.md @@ -41,8 +41,8 @@ They have: - `Sprite`: A letter and color for drawing in the terminal - `SpriteIndex`: A number pointing to the 2d sprite in the spritesheet used by the game. There are 10 sprites per row and 10 rows, for a total of 100 sprites. - `Team`: Indicates which team the entity is on. Used by AI to determine which entity to attack or follow. -- `SimpleMovement`: A marker component indicating that this entity should be moved by the SimpleMovementSystem (shared by creeps and leaders). -- `ProximityAttack`: A marker component indicating that this entity should attack nearby opponents. +- `MovementSystems`: A marker component indicating that this entity should be moved by the particular movement system specified by the enum variant. +- `ProximityAttackSystems`: A marker component indicating that this entity should attack nearby opponents following the particular proximity attack system specified by the enum variant. - `Inventory`: An inventory of the items this leader has. This can easily be cloned from the default inventory (default_inventory). - `SkillSet`: The skillset we defined earlier for this leader. - `AiPath`: The path that this entity will follow while moving. This is used by the AI systems to move the entities around. From 3edf446f8090dfac83d25d7cde15f828d4bdebf2 Mon Sep 17 00:00:00 2001 From: Owen McCormick Date: Thu, 11 Feb 2021 14:22:41 -0800 Subject: [PATCH 4/5] cargo fmt --- src/systems/elephant_spawner.rs | 5 ++- src/systems/spawn_creep.rs | 5 ++- src/systems/spawn_leader.rs | 60 ++++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/systems/elephant_spawner.rs b/src/systems/elephant_spawner.rs index 27bbc36..8c980e7 100644 --- a/src/systems/elephant_spawner.rs +++ b/src/systems/elephant_spawner.rs @@ -25,7 +25,10 @@ pub fn elephant_spawner_system( simple_movements.insert(elephant, MovementSystems::SimpleMovement); teams.insert(elephant, team); stats.insert(elephant, stat_def.to_statset()); - proximity_attacks.insert(elephant, ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS)); + proximity_attacks.insert( + elephant, + ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS), + ); let bg = if team == Team::Me { RGBA::named(GREEN) } else { diff --git a/src/systems/spawn_creep.rs b/src/systems/spawn_creep.rs index a5734ca..72c61be 100644 --- a/src/systems/spawn_creep.rs +++ b/src/systems/spawn_creep.rs @@ -23,7 +23,10 @@ pub fn spawn_creep_system( simple_movements.insert(creep, MovementSystems::SimpleMovement); teams.insert(creep, *team); stats.insert(creep, stat_def.to_statset()); - proximity_attacks.insert(creep, ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS)); + proximity_attacks.insert( + creep, + ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS), + ); let bg = if *team == Team::Me { sights.insert(creep, LineOfSight::new(5)); RGBA::named(GREEN) diff --git a/src/systems/spawn_leader.rs b/src/systems/spawn_leader.rs index 1519822..ac133b9 100644 --- a/src/systems/spawn_leader.rs +++ b/src/systems/spawn_leader.rs @@ -78,8 +78,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(6)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttacks::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -97,8 +99,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(5)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -116,8 +120,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(55)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -135,8 +141,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(4)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -154,8 +162,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(8)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -173,8 +183,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(16)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); @@ -192,8 +204,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(7)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -211,8 +225,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(7)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -231,8 +247,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(19)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(RANGED_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader2_simple_movements.insert(leader, Leader2SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(RANGED_LEADER_ATTACK_RADIUS)); @@ -250,8 +268,10 @@ pub fn spawn_leader_system( ); sprite_indices.insert(leader, SpriteIndex(14)); simple_movements.insert(leader, MovementSystems::SimpleMovement); - proximity_attacks - .insert(leader, ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS)); + proximity_attacks.insert( + leader, + ProximityAttackSystems::SimpleProximityAttack(MELEE_LEADER_ATTACK_RADIUS), + ); // TODO: Add higher threshold for retreating and re-enable // leader1_simple_movements.insert(leader, Leader1SimpleMovement); // leader1_proximity_attacks.insert(leader, Leader1ProximityAttack::new(MELEE_LEADER_ATTACK_RADIUS)); From ae2c7d4b64cf3d7715a5307e4125098f0150f479 Mon Sep 17 00:00:00 2001 From: Owen McCormick Date: Thu, 11 Feb 2021 18:51:03 -0800 Subject: [PATCH 5/5] Internally renamed creeps to pawns --- assets/skill_defs.yaml | 2 +- src/components.rs | 8 ++--- src/events.rs | 4 +-- src/main.rs | 20 ++++++------- src/systems/elephant_spawner.rs | 2 +- src/systems/leader1_simple_movement.rs | 6 ++-- src/systems/mod.rs | 8 ++--- src/systems/nature_summon.rs | 4 +-- .../{creep_spawner.rs => pawn_spawner.rs} | 8 ++--- src/systems/{spawn_creep.rs => spawn_pawn.rs} | 30 +++++++++---------- 10 files changed, 46 insertions(+), 46 deletions(-) rename src/systems/{creep_spawner.rs => pawn_spawner.rs} (74%) rename src/systems/{spawn_creep.rs => spawn_pawn.rs} (57%) diff --git a/assets/skill_defs.yaml b/assets/skill_defs.yaml index d55692c..65cc9e0 100644 --- a/assets/skill_defs.yaml +++ b/assets/skill_defs.yaml @@ -45,7 +45,7 @@ defs: key: NatureSummon name: NatureSummon friendly_name: nature_summon - description: Spawn a treant creep every 6s. + description: Spawn a treant pawn every 6s. cooldown: 6.0 passive: true conditions: [] diff --git a/src/components.rs b/src/components.rs index cc518bb..6d6a0ca 100644 --- a/src/components.rs +++ b/src/components.rs @@ -41,10 +41,10 @@ pub struct FleeToBase(pub f64); pub struct IsCaught(pub bool); /// Tracks whether or not Spell Steal has been used for heroes with that ability. pub struct SpellSteal(pub bool); -/// Tags a creep. -pub struct Creep; -/// Tags a creep spawner. Contains the delay in ticks between spawns. -pub struct CreepSpawner(pub u32, pub u32); +/// Tags a pawn. +pub struct Pawn; +/// Tags a pawn spawner. Contains the delay in ticks between spawns. +pub struct PawnSpawner(pub u32, pub u32); /// Tags a base. pub struct Base; /// Identifies mouse selectable entities diff --git a/src/events.rs b/src/events.rs index 8b3f275..4874340 100644 --- a/src/events.rs +++ b/src/events.rs @@ -31,8 +31,8 @@ pub enum GameEvent { TransferedGold(Entity, f64), /// A leader died. LeaderDied(u8), - /// Spawn a creep at the specified position in the specified team. - SpawnCreep(Point, Team), + /// Spawn a pawn at the specified position in the specified team. + SpawnPawn(Point, Team), /// Spawns a leader using the `TeamLeaders`' index and a position. SpawnLeader(Point, u8), /// Set additional attack for an entity. diff --git a/src/main.rs b/src/main.rs index 245bddf..05e1445 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,8 @@ const PLAY_WIDTH: u32 = 81; const PLAY_HEIGHT: u32 = 50; const SCREEN_WIDTH: u32 = 100; const SCREEN_HEIGHT: u32 = 50; -const CREEP_SPAWN_TICKS: u32 = 125; -const CREEP_ATTACK_RADIUS: f32 = 2.1; +const PAWN_SPAWN_TICKS: u32 = 125; +const PAWN_ATTACK_RADIUS: f32 = 2.1; const MELEE_LEADER_ATTACK_RADIUS: f32 = 2.1; const RANGED_LEADER_ATTACK_RADIUS: f32 = 21.0; const AOE_RADIUS: f32 = 4.0; @@ -218,7 +218,7 @@ fn main() -> BError { update_mouse_events_system, update_collision_resource_system, handle_action_points_system, - creep_spawner_system, + pawn_spawner_system, simple_movement_system, ai_pathing_system, ai_movement_system, @@ -259,7 +259,7 @@ fn main() -> BError { leader_teleport_system, root_system, respawn_leader_driver, - spawn_creep_system, + spawn_pawn_system, spawn_leader_system, game_stats_updater_system, ); @@ -313,7 +313,7 @@ fn main() -> BError { /*register!(world, MultiSprite, Sprite, Team, Barrack, Tower, Core, Leader, Name, SpriteIndex, StatSet, EffectorSet, SkillSet, Inventory, Point, SimpleMovement, - AiPath, AiDestination, Creep, Player, CollisionMap, CreepSpawner, Collision, + AiPath, AiDestination, Pawn, Player, CollisionMap, PawnSpawner, Collision, ProximityAttack, TowerProjectile, GotoStraight, GotoEntity,);*/ // TODO reenable @@ -403,12 +403,12 @@ fn main() -> BError { Barrack, default_stats.clone(), ); - // Creep spawners + // Pawn spawners centity!( world, Point::new(x, y + 1), - CreepSpawner(0, CREEP_SPAWN_TICKS), - //CreepSpawner(0, 2)) + PawnSpawner(0, PAWN_SPAWN_TICKS), + //PawnSpawner(0, 2)) Team::Other, ); } @@ -430,11 +430,11 @@ fn main() -> BError { default_stats.clone(), LineOfSight::new(15), ); - // Creep spawners + // Pawn spawners centity!( world, Point::new(x, y - 1), - CreepSpawner(0, CREEP_SPAWN_TICKS), + PawnSpawner(0, PAWN_SPAWN_TICKS), Team::Me, LineOfSight::new(15), ); diff --git a/src/systems/elephant_spawner.rs b/src/systems/elephant_spawner.rs index 8c980e7..a2403a2 100644 --- a/src/systems/elephant_spawner.rs +++ b/src/systems/elephant_spawner.rs @@ -27,7 +27,7 @@ pub fn elephant_spawner_system( stats.insert(elephant, stat_def.to_statset()); proximity_attacks.insert( elephant, - ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS), + ProximityAttackSystems::SimpleProximityAttack(PAWN_ATTACK_RADIUS), ); let bg = if team == Team::Me { RGBA::named(GREEN) diff --git a/src/systems/leader1_simple_movement.rs b/src/systems/leader1_simple_movement.rs index 7616000..69dc10c 100644 --- a/src/systems/leader1_simple_movement.rs +++ b/src/systems/leader1_simple_movement.rs @@ -7,7 +7,7 @@ pub fn leader1_simple_movement_system( teams: &Components, is_caught: &Components, stats: &Components>, - creeps: &Components, + pawns: &Components, leaders: &Components, retreats: &Components, cores: &Components, @@ -65,9 +65,9 @@ pub fn leader1_simple_movement_system( if let MovementSystems::Leader1SimpleMovement = movement.unwrap() { let e = e.unwrap(); let pos = pos.unwrap(); - // find closest creep + // find closest pawn // TODO: optimize - let mut vec = join!(&positions && &stats && &creeps) + let mut vec = join!(&positions && &stats && &pawns) .map(|(p, _, _)| (dist(pos, p.unwrap()), p.unwrap().clone())) .collect::>(); vec.sort_by(|e1, e2| e1.0.partial_cmp(&e2.0).unwrap()); diff --git a/src/systems/mod.rs b/src/systems/mod.rs index eb49a66..fcf3dcf 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -4,7 +4,6 @@ mod air_corrosion; mod aoe_damage; mod back_endurance; mod battle_hunger; -mod creep_spawner; mod damage_entity; mod dark_presence; mod elephant_spawner; @@ -18,14 +17,15 @@ mod leader2_simple_movement; mod leader_respawn_driver; mod leader_teleport; mod nature_summon; +mod pawn_spawner; mod proximity_attack; mod return_damage; mod root; mod savagery; mod select_leader; mod simple_movement; -mod spawn_creep; mod spawn_leader; +mod spawn_pawn; mod spell_steal; mod steal_soul; mod telekinesis; @@ -45,7 +45,6 @@ pub use self::air_corrosion::*; pub use self::aoe_damage::*; pub use self::back_endurance::*; pub use self::battle_hunger::*; -pub use self::creep_spawner::*; pub use self::damage_entity::*; pub use self::dark_presence::*; pub use self::elephant_spawner::*; @@ -59,6 +58,7 @@ pub use self::leader2_simple_movement::*; pub use self::leader_respawn_driver::*; pub use self::leader_teleport::*; pub use self::nature_summon::*; +pub use self::pawn_spawner::*; pub use self::proximity_attack::*; pub use self::return_damage::*; pub use self::root::*; @@ -66,8 +66,8 @@ pub use self::savagery::*; pub use self::select_leader::*; pub use self::simple_movement::*; pub use self::simple_movement::*; -pub use self::spawn_creep::*; pub use self::spawn_leader::*; +pub use self::spawn_pawn::*; pub use self::spell_steal::*; pub use self::steal_soul::*; pub use self::telekinesis::*; diff --git a/src/systems/nature_summon.rs b/src/systems/nature_summon.rs index 2080a71..6474c5f 100644 --- a/src/systems/nature_summon.rs +++ b/src/systems/nature_summon.rs @@ -12,8 +12,8 @@ pub fn nature_summon_system( let pos = positions.get(ev.0).unwrap(); let team = teams.get(ev.0).unwrap(); - //@TODO: spawn an actual treant creep - game_events.push(GameEvent::SpawnCreep(*pos, *team)); + //@TODO: spawn an actual treant pawn + game_events.push(GameEvent::SpawnPawn(*pos, *team)); } } Ok(()) diff --git a/src/systems/creep_spawner.rs b/src/systems/pawn_spawner.rs similarity index 74% rename from src/systems/creep_spawner.rs rename to src/systems/pawn_spawner.rs index b98b6ee..552be80 100644 --- a/src/systems/creep_spawner.rs +++ b/src/systems/pawn_spawner.rs @@ -1,9 +1,9 @@ use crate::*; -/// Periodically generates events to spawn creeps. -pub fn creep_spawner_system( +/// Periodically generates events to spawn pawns. +pub fn pawn_spawner_system( positions: &mut Components, - spawners: &mut Components, + spawners: &mut Components, teams: &mut Components, game_events: &mut Vec, ) -> SystemResult { @@ -12,7 +12,7 @@ pub fn creep_spawner_system( if spawner.0 == 0 { spawner.0 = spawner.1; // spawn - game_events.push(GameEvent::SpawnCreep( + game_events.push(GameEvent::SpawnPawn( pos.unwrap().clone(), team.unwrap().clone(), )); diff --git a/src/systems/spawn_creep.rs b/src/systems/spawn_pawn.rs similarity index 57% rename from src/systems/spawn_creep.rs rename to src/systems/spawn_pawn.rs index 72c61be..200e926 100644 --- a/src/systems/spawn_creep.rs +++ b/src/systems/spawn_pawn.rs @@ -1,12 +1,12 @@ use crate::*; -/// Spawns a creep using the provided event. -pub fn spawn_creep_system( +/// Spawns a pawn using the provided event. +pub fn spawn_pawn_system( game_events: &Vec, stat_def: &StatDefinitions, entities: &mut Entities, positions: &mut Components, - creeps: &mut Components, + pawns: &mut Components, simple_movements: &mut Components, proximity_attacks: &mut Components, stats: &mut Components>, @@ -16,32 +16,32 @@ pub fn spawn_creep_system( sights: &mut Components, ) -> SystemResult { for ev in game_events.iter() { - if let GameEvent::SpawnCreep(pos, team) = ev { - let creep = entities.create(); - positions.insert(creep, pos.clone()); - creeps.insert(creep, Creep); - simple_movements.insert(creep, MovementSystems::SimpleMovement); - teams.insert(creep, *team); - stats.insert(creep, stat_def.to_statset()); + if let GameEvent::SpawnPawn(pos, team) = ev { + let pawn = entities.create(); + positions.insert(pawn, pos.clone()); + pawns.insert(pawn, Pawn); + simple_movements.insert(pawn, MovementSystems::SimpleMovement); + teams.insert(pawn, *team); + stats.insert(pawn, stat_def.to_statset()); proximity_attacks.insert( - creep, - ProximityAttackSystems::SimpleProximityAttack(CREEP_ATTACK_RADIUS), + pawn, + ProximityAttackSystems::SimpleProximityAttack(PAWN_ATTACK_RADIUS), ); let bg = if *team == Team::Me { - sights.insert(creep, LineOfSight::new(5)); + sights.insert(pawn, LineOfSight::new(5)); RGBA::named(GREEN) } else { RGBA::named(RED) }; sprites.insert( - creep, + pawn, Sprite { glyph: to_cp437('c'), fg: RGBA::named(YELLOW), bg, }, ); - sprite_indices.insert(creep, SpriteIndex(9)); + sprite_indices.insert(pawn, SpriteIndex(9)); } } Ok(())