From 8e2ca9cdecf5120428a9b41e04ba3a0b607be29a Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 18 Sep 2021 16:24:56 +0100 Subject: [PATCH] Added rtsim villagers to site2 towns --- common/src/store.rs | 4 ++-- server/src/rtsim/entity.rs | 18 ++++++++++++++++++ server/src/rtsim/mod.rs | 20 ++++++++++++++++++++ world/src/civ/mod.rs | 2 +- world/src/site2/mod.rs | 2 +- world/src/site2/plot.rs | 2 ++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/common/src/store.rs b/common/src/store.rs index 42c370bd52..7c03577d7d 100644 --- a/common/src/store.rs +++ b/common/src/store.rs @@ -59,9 +59,9 @@ impl Store { (0..self.items.len()).map(|i| Id(i as u64, PhantomData)) } - pub fn values(&self) -> impl Iterator { self.items.iter() } + pub fn values(&self) -> impl ExactSizeIterator { self.items.iter() } - pub fn values_mut(&mut self) -> impl Iterator { self.items.iter_mut() } + pub fn values_mut(&mut self) -> impl ExactSizeIterator { self.items.iter_mut() } pub fn iter(&self) -> impl Iterator, &T)> { self.ids().zip(self.values()) } diff --git a/server/src/rtsim/entity.rs b/server/src/rtsim/entity.rs index d10a2faf2d..d72484f4de 100644 --- a/server/src/rtsim/entity.rs +++ b/server/src/rtsim/entity.rs @@ -30,6 +30,7 @@ pub struct Entity { pub enum RtSimEntityKind { Random, Cultist, + Villager, } const BIRD_LARGE_ROSTER: &[comp::bird_large::Species] = &[ @@ -84,6 +85,12 @@ impl Entity { .unwrap(); comp::humanoid::Body::random_with(&mut self.rng(PERM_BODY), &species).into() }, + RtSimEntityKind::Villager => { + let species = *(&comp::humanoid::ALL_SPECIES) + .choose(&mut self.rng(PERM_SPECIES)) + .unwrap(); + comp::humanoid::Body::random_with(&mut self.rng(PERM_BODY), &species).into() + }, } } @@ -657,6 +664,16 @@ impl Brain { } } + pub fn villager(home_id: Id) -> Self { + Self { + begin: None, + tgt: None, + route: Travel::Idle, + last_visited: None, + memories: Vec::new(), + } + } + pub fn add_memory(&mut self, memory: Memory) { self.memories.push(memory); } pub fn forget_enemy(&mut self, to_forget: &str) { @@ -715,6 +732,7 @@ fn humanoid_config(kind: RtSimEntityKind) -> &'static str { match kind { RtSimEntityKind::Cultist => "common.entity.dungeon.tier-5.cultist", RtSimEntityKind::Random => "common.entity.world.traveler", + RtSimEntityKind::Villager => "common.loadout.village.villager", } } diff --git a/server/src/rtsim/mod.rs b/server/src/rtsim/mod.rs index 192fb9ef76..bf2a4f6d0a 100644 --- a/server/src/rtsim/mod.rs +++ b/server/src/rtsim/mod.rs @@ -198,6 +198,26 @@ pub fn init( }, _ => {}, }, + SiteKind::Refactor(site2) => { + for _ in 0..(site.economy.pop as usize).min(site2.plots().len() * 3) { + rtsim.entities.insert(Entity { + is_loaded: false, + pos: site2 + .plots() + .choose(&mut thread_rng()) + .map_or(site.get_origin(), |plot| { + site2.tile_center_wpos(plot.root_tile()) + }) + .with_z(0) + .map(|e| e as f32), + seed: thread_rng().gen(), + controller: RtSimController::default(), + last_time_ticked: 0.0, + kind: RtSimEntityKind::Villager, + brain: Brain::villager(site_id), + }); + } + }, _ => {}, } } diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index a0102a9e06..b2ceafa8af 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -108,7 +108,7 @@ impl Civs { attempt(5, || { let (kind, size) = match ctx.rng.gen_range(0..64) { 0..=4 => (SiteKind::Castle, 3), - // 5..=28 => (SiteKind::Refactor, 6), + 5..=28 => (SiteKind::Refactor, 6), 29..=31 => (SiteKind::Tree, 4), _ => (SiteKind::Dungeon, 0), }; diff --git a/world/src/site2/mod.rs b/world/src/site2/mod.rs index eda9a6a6ef..ed291da263 100644 --- a/world/src/site2/mod.rs +++ b/world/src/site2/mod.rs @@ -77,7 +77,7 @@ impl Site { pub fn plot(&self, id: Id) -> &Plot { &self.plots[id] } - pub fn plots(&self) -> impl Iterator + '_ { self.plots.values() } + pub fn plots(&self) -> impl ExactSizeIterator + '_ { self.plots.values() } pub fn create_plot(&mut self, plot: Plot) -> Id { self.plots.insert(plot) } diff --git a/world/src/site2/plot.rs b/world/src/site2/plot.rs index ff753f9070..ac7da8edff 100644 --- a/world/src/site2/plot.rs +++ b/world/src/site2/plot.rs @@ -26,6 +26,8 @@ impl Plot { } pub fn kind(&self) -> &PlotKind { &self.kind } + + pub fn root_tile(&self) -> Vec2 { self.root_tile } } pub enum PlotKind {