ancestries
This commit is contained in:
parent
c8b28a9abd
commit
3050219494
11 changed files with 274 additions and 110 deletions
|
|
@ -11,9 +11,9 @@ mod spawn_table_structs;
|
|||
use spawn_table_structs::*;
|
||||
mod loot_table_structs;
|
||||
use loot_table_structs::*;
|
||||
mod faction_structs;
|
||||
use faction_structs::FactionData;
|
||||
pub use faction_structs::Reaction;
|
||||
mod reaction_structs;
|
||||
pub use reaction_structs::Reaction;
|
||||
use reaction_structs::{AncestryData, FactionData};
|
||||
use std::sync::Mutex;
|
||||
|
||||
lazy_static! {
|
||||
|
|
@ -28,6 +28,7 @@ pub struct Raws {
|
|||
pub spawn_tables: Vec<SpawnTable>,
|
||||
pub loot_tables: Vec<LootTable>,
|
||||
pub factions: Vec<FactionData>,
|
||||
pub ancestries: Vec<AncestryData>,
|
||||
}
|
||||
|
||||
rltk::embedded_resource!(RAW_ITEMS, "../../raws/items.json");
|
||||
|
|
@ -36,6 +37,7 @@ rltk::embedded_resource!(RAW_PROPS, "../../raws/props.json");
|
|||
rltk::embedded_resource!(RAW_SPAWN_TABLES, "../../raws/spawn_tables.json");
|
||||
rltk::embedded_resource!(RAW_LOOT_TABLES, "../../raws/loot_tables.json");
|
||||
rltk::embedded_resource!(RAW_FACTIONS, "../../raws/factions.json");
|
||||
rltk::embedded_resource!(RAW_ANCESTRIES, "../../raws/ancestries.json");
|
||||
|
||||
pub fn load_raws() {
|
||||
rltk::link_resource!(RAW_ITEMS, "../../raws/items.json");
|
||||
|
|
@ -44,6 +46,7 @@ pub fn load_raws() {
|
|||
rltk::link_resource!(RAW_SPAWN_TABLES, "../../raws/spawn_tables.json");
|
||||
rltk::link_resource!(RAW_LOOT_TABLES, "../../raws/loot_tables.json");
|
||||
rltk::link_resource!(RAW_FACTIONS, "../../raws/factions.json");
|
||||
rltk::link_resource!(RAW_ANCESTRIES, "../../raws/ancestries.json");
|
||||
|
||||
let decoded_raws = get_decoded_raws();
|
||||
RAWS.lock().unwrap().load(decoded_raws);
|
||||
|
|
@ -56,8 +59,9 @@ pub fn get_decoded_raws() -> Raws {
|
|||
let spawn_tables: Vec<SpawnTable> = ParseJson::parse_raws_into_vector("../../raws/spawn_tables.json".to_string());
|
||||
let loot_tables: Vec<LootTable> = ParseJson::parse_raws_into_vector("../../raws/loot_tables.json".to_string());
|
||||
let factions: Vec<FactionData> = ParseJson::parse_raws_into_vector("../../raws/factions.json".to_string());
|
||||
let ancestries: Vec<AncestryData> = ParseJson::parse_raws_into_vector("../../raws/ancestries.json".to_string());
|
||||
|
||||
return Raws { items, mobs, props, spawn_tables, loot_tables, factions };
|
||||
return Raws { items, mobs, props, spawn_tables, loot_tables, factions, ancestries };
|
||||
}
|
||||
|
||||
trait ParseJson {
|
||||
|
|
@ -74,4 +78,4 @@ macro_rules! impl_ParseJson {
|
|||
})*
|
||||
}
|
||||
}
|
||||
impl_ParseJson!(for Vec<Item>, Vec<Mob>, Vec<Prop>, Vec<SpawnTable>, Vec<LootTable>, Vec<FactionData>);
|
||||
impl_ParseJson!(for Vec<Item>, Vec<Mob>, Vec<Prop>, Vec<SpawnTable>, Vec<LootTable>, Vec<FactionData>, Vec<AncestryData>);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use super::{Raws, Reaction};
|
||||
use crate::components::*;
|
||||
use crate::gamesystem::*;
|
||||
use crate::gui::Ancestry;
|
||||
use crate::random_table::RandomTable;
|
||||
use crate::LOG_SPAWNING;
|
||||
use regex::Regex;
|
||||
|
|
@ -23,6 +24,7 @@ pub struct RawMaster {
|
|||
table_index: HashMap<String, usize>,
|
||||
loot_index: HashMap<String, usize>,
|
||||
faction_index: HashMap<String, HashMap<String, Reaction>>,
|
||||
ancestry_index: HashMap<String, HashSet<String>>,
|
||||
}
|
||||
|
||||
impl RawMaster {
|
||||
|
|
@ -35,6 +37,7 @@ impl RawMaster {
|
|||
spawn_tables: Vec::new(),
|
||||
loot_tables: Vec::new(),
|
||||
factions: Vec::new(),
|
||||
ancestries: Vec::new(),
|
||||
},
|
||||
item_index: HashMap::new(),
|
||||
mob_index: HashMap::new(),
|
||||
|
|
@ -42,6 +45,7 @@ impl RawMaster {
|
|||
table_index: HashMap::new(),
|
||||
loot_index: HashMap::new(),
|
||||
faction_index: HashMap::new(),
|
||||
ancestry_index: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -322,6 +326,21 @@ pub fn spawn_named_mob(
|
|||
eb = eb.with(Faction { name: "carnivore".to_string() });
|
||||
has_faction = true;
|
||||
}
|
||||
"IS_GNOME" => {
|
||||
eb = eb.with(HasAncestry { name: Ancestry::Gnome });
|
||||
}
|
||||
"IS_DWARF" => {
|
||||
eb = eb.with(HasAncestry { name: Ancestry::Dwarf });
|
||||
}
|
||||
"IS_HUMAN" => {
|
||||
eb = eb.with(HasAncestry { name: Ancestry::Human });
|
||||
}
|
||||
"IS_CATFOLK" => {
|
||||
eb = eb.with(HasAncestry { name: Ancestry::Catfolk });
|
||||
}
|
||||
"IS_Elf" => {
|
||||
eb = eb.with(HasAncestry { name: Ancestry::Elf });
|
||||
}
|
||||
"SMALL_GROUP" => {} // These flags are for region spawning,
|
||||
"LARGE_GROUP" => {} // and don't matter here (yet)?
|
||||
"MULTIATTACK" => {
|
||||
|
|
@ -825,3 +844,31 @@ pub fn faction_reaction(this_faction: &str, other_faction: &str, raws: &RawMaste
|
|||
}
|
||||
return Reaction::Ignore;
|
||||
}
|
||||
|
||||
pub fn ancestry_reaction(this_ancestry: Ancestry, other_ancestry: Ancestry, raws: &RawMaster) -> Option<Reaction> {
|
||||
if this_ancestry == other_ancestry {
|
||||
return Some(Reaction::Ignore);
|
||||
} else {
|
||||
let this_ancestry = get_ancestry_string(this_ancestry);
|
||||
let other_ancestry = get_ancestry_string(other_ancestry);
|
||||
if raws.ancestry_index.contains_key(this_ancestry) {
|
||||
let mine = &raws.ancestry_index[this_ancestry];
|
||||
if mine.contains(other_ancestry) {
|
||||
return Some(Reaction::Ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
fn get_ancestry_string(ancestry: Ancestry) -> &'static str {
|
||||
match ancestry {
|
||||
Ancestry::Human => return "human",
|
||||
Ancestry::Elf => return "elf",
|
||||
Ancestry::Dwarf => return "dwarf",
|
||||
Ancestry::Catfolk => return "catfolk",
|
||||
Ancestry::Gnome => return "gnome",
|
||||
Ancestry::NULL => return "NULL",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct FactionData {
|
||||
|
|
@ -7,6 +7,12 @@ pub struct FactionData {
|
|||
pub responses: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct AncestryData {
|
||||
pub id: String,
|
||||
pub allies: HashSet<String>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Copy, Clone)]
|
||||
pub enum Reaction {
|
||||
Ignore,
|
||||
Loading…
Add table
Add a link
Reference in a new issue