From 9e26c41aad2f1f2dc824eee0a958062e44a2aa85 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 21 Aug 2023 10:40:30 +0100 Subject: [PATCH] adds mob ancestries, converts everything over to get_reactions() --- raws/ancestries.json | 10 +++---- raws/mobs.json | 20 ++++++------- src/ai/adjacent_ai_system.rs | 2 +- src/ai/visible_ai_system.rs | 56 ++++++++++++------------------------ src/raws/rawmaster.rs | 6 +++- 5 files changed, 40 insertions(+), 54 deletions(-) diff --git a/raws/ancestries.json b/raws/ancestries.json index 41c837e..932e488 100644 --- a/raws/ancestries.json +++ b/raws/ancestries.json @@ -1,22 +1,22 @@ [ { "id": "human", - "allied": [] + "allies": [] }, { "id": "elf", - "allied": [] + "allies": [] }, { "id": "dwarf", - "allied": ["gnome"] + "allies": ["gnome"] }, { "id": "gnome", - "allied": ["dwarf"] + "allies": ["dwarf"] }, { "id": "catfolk", - "allied": [] + "allies": [] } ] diff --git a/raws/mobs.json b/raws/mobs.json index 8e3fca6..5819010 100644 --- a/raws/mobs.json +++ b/raws/mobs.json @@ -3,7 +3,7 @@ "id": "npc_barkeep", "name": "barkeep", "renderable": { "glyph": "@", "fg": "#EE82EE", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL"], + "flags": ["NEUTRAL", "IS_HUMAN"], "vision_range": 4, "quips": ["Drink?", "Something to eat?", "Don't go out on an empty stomach."] }, @@ -11,7 +11,7 @@ "id": "npc_townsperson", "name": "townsperson", "renderable": { "glyph": "@", "fg": "#9fa86c", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL", "RANDOM_PATH"], + "flags": ["NEUTRAL", "RANDOM_PATH", "IS_HUMAN"], "vision_range": 4, "quips": ["Hello!", "Good morning.", ""] }, @@ -19,7 +19,7 @@ "id": "npc_drunk", "name": "drunk", "renderable": { "glyph": "@", "fg": "#a0a83c", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL"], + "flags": ["NEUTRAL", "IS_HUMAN"], "vision_range": 4, "quips": ["Hic!", "H-Hic'.", "Get me 'nother, would you?"] }, @@ -27,7 +27,7 @@ "id": "npc_fisher", "name": "fisher", "renderable": { "glyph": "@", "fg": "#3ca3a8", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL"], + "flags": ["NEUTRAL", "IS_HUMAN"], "vision_range": 4, "quips": ["Hey."] }, @@ -35,7 +35,7 @@ "id": "npc_dockworker", "name": "dock worker", "renderable": { "glyph": "@", "fg": "#68d8de", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL"], + "flags": ["NEUTRAL", "IS_HUMAN"], "vision_range": 4, "quips": ["No boat for a few days.", "Not much for us to do."] }, @@ -43,7 +43,7 @@ "id": "npc_priest", "name": "priest", "renderable": { "glyph": "@", "fg": "#FFFFFF", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL"], + "flags": ["NEUTRAL", "IS_HUMAN"], "vision_range": 4, "quips": ["Light's givings.", "", "Bless you."] }, @@ -51,7 +51,7 @@ "id": "npc_miner", "name": "miner", "renderable": { "glyph": "@", "fg": "#946123", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL"], + "flags": ["NEUTRAL", "IS_HUMAN"], "vision_range": 4, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d8" }], "quips": ["You're not borrowing my pick."] @@ -60,7 +60,7 @@ "id": "npc_guard", "name": "smalltown guard", "renderable": { "glyph": "@", "fg": "#034efc", "bg": "#000000", "order": 1 }, - "flags": ["NEUTRAL", "RANDOM_PATH"], + "flags": ["NEUTRAL", "RANDOM_PATH", "IS_HUMAN"], "level": 2, "vision_range": 4, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d8" }], @@ -205,7 +205,7 @@ "id": "gnome", "name": "gnome", "renderable": { "glyph": "G", "fg": "#AA5500", "bg": "#000000", "order": 1 }, - "flags": ["SMALL_GROUP"], + "flags": ["SMALL_GROUP", "IS_GNOME"], "level": 1, "speed": 6, "vision_range": 12, @@ -282,7 +282,7 @@ "id": "dwarf", "name": "dwarf", "renderable": { "glyph": "h", "fg": "#d61b1b", "bg": "#000000", "order": 1 }, - "flags": [], + "flags": ["IS_DWARF"], "level": 2, "bac": 10, "speed": 6, diff --git a/src/ai/adjacent_ai_system.rs b/src/ai/adjacent_ai_system.rs index 7588759..5a930ba 100644 --- a/src/ai/adjacent_ai_system.rs +++ b/src/ai/adjacent_ai_system.rs @@ -20,7 +20,7 @@ impl<'a> System<'a> for AdjacentAI { let (mut turns, factions, ancestries, positions, map, mut want_melee, entities, player) = data; let mut turn_done: Vec = Vec::new(); - for (entity, _turn, my_faction, pos) in (&entities, &turns, &factions, &positions).join() { + for (entity, _turn, pos) in (&entities, &turns, &positions).join() { if entity != *player { let mut reactions: Vec<(Entity, Reaction)> = Vec::new(); let idx = map.xy_idx(pos.x, pos.y); diff --git a/src/ai/visible_ai_system.rs b/src/ai/visible_ai_system.rs index 2140446..09c0972 100644 --- a/src/ai/visible_ai_system.rs +++ b/src/ai/visible_ai_system.rs @@ -42,7 +42,7 @@ impl<'a> System<'a> for VisibleAI { mut chasing, ) = data; - for (entity, _turn, faction, pos, viewshed) in (&entities, &turns, &factions, &positions, &viewsheds).join() { + for (entity, _turn, pos, viewshed) in (&entities, &turns, &positions, &viewsheds).join() { if entity == *player { continue; } @@ -53,7 +53,7 @@ impl<'a> System<'a> for VisibleAI { for visible_tile in viewshed.visible_tiles.iter() { let idx = map.xy_idx(visible_tile.x, visible_tile.y); if this_idx != idx { - evaluate(entity, idx, &ancestries, &factions, &faction.name, &mut reactions, None); + evaluate(entity, idx, &ancestries, &factions, &mut reactions, None); idxs.insert(idx); } } @@ -64,7 +64,7 @@ impl<'a> System<'a> for VisibleAI { // and it's not the idx we're standing on, then evaluate here w/ minds taken into // account. if this_idx != idx && idxs.contains(&idx) { - evaluate(entity, idx, &ancestries, &factions, &faction.name, &mut reactions, Some(&minds)); + evaluate(entity, idx, &ancestries, &factions, &mut reactions, Some(&minds)); } } } @@ -96,46 +96,28 @@ fn evaluate( idx: usize, ancestries: &ReadStorage, factions: &ReadStorage, - this_faction: &str, reactions: &mut Vec<(usize, Reaction, Entity)>, minds: Option<&ReadStorage>, ) { crate::spatial::for_each_tile_content(idx, |other_entity| { - 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((idx, Reaction::Ignore, other_entity)); - shared_ancestry = true; - } + let mut check = true; + if minds.is_some() { + if minds.unwrap().get(other_entity).is_none() { + check = false; } } - if !shared_ancestry { - // If minds are passed, we assume we're using telepathy here, - // so if the other entity is mindless, we skip it. - if minds.is_some() { - if minds.unwrap().get(other_entity).is_some() { - if let Some(faction) = factions.get(other_entity) { - reactions.push(( - idx, - crate::raws::faction_reaction( - this_faction, - &faction.name, - &crate::raws::RAWS.lock().unwrap(), - ), - other_entity, - )); - } - } - } else { - if let Some(faction) = factions.get(other_entity) { - reactions.push(( - idx, - crate::raws::faction_reaction(this_faction, &faction.name, &crate::raws::RAWS.lock().unwrap()), - other_entity, - )); - } - } + if check { + reactions.push(( + idx, + crate::raws::get_reactions( + entity, + other_entity, + &factions, + &ancestries, + &crate::raws::RAWS.lock().unwrap(), + ), + other_entity, + )); } }); } diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index b5c44ac..950562c 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -96,6 +96,9 @@ impl RawMaster { } self.faction_index.insert(faction.id.clone(), reactions); } + for ancestry in self.raws.ancestries.iter() { + self.ancestry_index.insert(ancestry.id.clone(), ancestry.allies.clone()); + } } } @@ -851,14 +854,15 @@ pub fn ancestry_reaction(this_ancestry: Ancestry, other_ancestry: Ancestry, raws } else { let this_ancestry = get_ancestry_string(this_ancestry); let other_ancestry = get_ancestry_string(other_ancestry); + console::log(format!("{:?}", this_ancestry)); if raws.ancestry_index.contains_key(this_ancestry) { let mine = &raws.ancestry_index[this_ancestry]; + console::log(format!("{:?}", mine)); if mine.contains(other_ancestry) { return Some(Reaction::Ignore); } } } - return None; }