ancestries
This commit is contained in:
parent
c8b28a9abd
commit
3050219494
11 changed files with 274 additions and 110 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{raws::Reaction, Faction, Map, Position, TakingTurn, WantsToMelee};
|
||||
use crate::{raws::Reaction, Faction, HasAncestry, Map, Position, TakingTurn, WantsToMelee};
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct AdjacentAI {}
|
||||
|
|
@ -8,6 +8,7 @@ impl<'a> System<'a> for AdjacentAI {
|
|||
type SystemData = (
|
||||
WriteStorage<'a, TakingTurn>,
|
||||
ReadStorage<'a, Faction>,
|
||||
ReadStorage<'a, HasAncestry>,
|
||||
ReadStorage<'a, Position>,
|
||||
ReadExpect<'a, Map>,
|
||||
WriteStorage<'a, WantsToMelee>,
|
||||
|
|
@ -16,7 +17,7 @@ impl<'a> System<'a> for AdjacentAI {
|
|||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (mut turns, factions, positions, map, mut want_melee, entities, player) = data;
|
||||
let (mut turns, factions, ancestries, positions, map, mut want_melee, entities, player) = data;
|
||||
|
||||
let mut turn_done: Vec<Entity> = Vec::new();
|
||||
for (entity, _turn, my_faction, pos) in (&entities, &turns, &factions, &positions).join() {
|
||||
|
|
@ -27,28 +28,28 @@ impl<'a> System<'a> for AdjacentAI {
|
|||
let h = map.height;
|
||||
// Add possible reactions to adjacents for each direction
|
||||
if pos.x > 0 {
|
||||
evaluate(idx - 1, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, idx - 1, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.x < w - 1 {
|
||||
evaluate(idx + 1, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, idx + 1, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.y > 0 {
|
||||
evaluate(idx - w as usize, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, idx - w as usize, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.y < h - 1 {
|
||||
evaluate(idx + w as usize, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, idx + w as usize, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.y > 0 && pos.x > 0 {
|
||||
evaluate((idx - w as usize) - 1, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, (idx - w as usize) - 1, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.y > 0 && pos.x < w - 1 {
|
||||
evaluate((idx - w as usize) + 1, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, (idx - w as usize) + 1, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.y < h - 1 && pos.x > 0 {
|
||||
evaluate((idx + w as usize) - 1, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, (idx + w as usize) - 1, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
if pos.y < h - 1 && pos.x < w - 1 {
|
||||
evaluate((idx + w as usize) + 1, &factions, &my_faction.name, &mut reactions);
|
||||
evaluate(entity, (idx + w as usize) + 1, &ancestries, &factions, &my_faction.name, &mut reactions);
|
||||
}
|
||||
|
||||
let mut done = false;
|
||||
|
|
@ -73,13 +74,31 @@ impl<'a> System<'a> for AdjacentAI {
|
|||
}
|
||||
|
||||
/// Evaluates all possible reactions between this faction and all entities on a given tile idx.
|
||||
fn evaluate(idx: usize, factions: &ReadStorage<Faction>, this_faction: &str, reactions: &mut Vec<(Entity, Reaction)>) {
|
||||
fn evaluate(
|
||||
entity: Entity,
|
||||
idx: usize,
|
||||
ancestries: &ReadStorage<HasAncestry>,
|
||||
factions: &ReadStorage<Faction>,
|
||||
this_faction: &str,
|
||||
reactions: &mut Vec<(Entity, Reaction)>,
|
||||
) {
|
||||
crate::spatial::for_each_tile_content(idx, |other_entity| {
|
||||
if let Some(faction) = factions.get(other_entity) {
|
||||
reactions.push((
|
||||
other_entity,
|
||||
crate::raws::faction_reaction(this_faction, &faction.name, &crate::raws::RAWS.lock().unwrap()),
|
||||
));
|
||||
let mut shared_ancestry = false;
|
||||
if let Some(this_ancestry) = ancestries.get(entity) {
|
||||
if let Some(other_ancestry) = ancestries.get(other_entity) {
|
||||
if this_ancestry.name == other_ancestry.name {
|
||||
reactions.push((other_entity, Reaction::Ignore));
|
||||
shared_ancestry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if !shared_ancestry {
|
||||
if let Some(faction) = factions.get(other_entity) {
|
||||
reactions.push((
|
||||
other_entity,
|
||||
crate::raws::faction_reaction(this_faction, &faction.name, &crate::raws::RAWS.lock().unwrap()),
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue