diff --git a/server/src/rtsim/entity.rs b/server/src/rtsim/entity.rs index 643e209b02..0601216893 100644 --- a/server/src/rtsim/entity.rs +++ b/server/src/rtsim/entity.rs @@ -30,6 +30,7 @@ pub enum RtSimEntityKind { Wanderer, Cultist, Villager, + TownGuard, Merchant, Blacksmith, Chef, @@ -95,6 +96,7 @@ impl Entity { }, RtSimEntityKind::Cultist | RtSimEntityKind::Villager + | RtSimEntityKind::TownGuard | RtSimEntityKind::Chef | RtSimEntityKind::Alchemist | RtSimEntityKind::Blacksmith @@ -746,6 +748,16 @@ impl Brain { } } + pub fn town_guard(home_id: Id) -> Self { + Self { + begin: Some(home_id), + tgt: None, + route: Travel::Idle, + last_visited: None, + memories: Vec::new(), + } + } + pub fn begin_site(&self) -> Option> { self.begin } pub fn add_memory(&mut self, memory: Memory) { self.memories.push(memory); } @@ -820,6 +832,7 @@ fn humanoid_config(kind: RtSimEntityKind, rank: TravelerRank) -> &'static str { TravelerRank::Rank3 => "common.entity.world.traveler3", }, RtSimEntityKind::Villager => "common.entity.village.villager", + RtSimEntityKind::TownGuard => "common.entity.village.guard", RtSimEntityKind::Merchant => "common.entity.village.merchant", RtSimEntityKind::Blacksmith => "common.entity.village.blacksmith", RtSimEntityKind::Chef => "common.entity.village.chef", diff --git a/server/src/rtsim/mod.rs b/server/src/rtsim/mod.rs index c1e8974b63..0d6160a539 100644 --- a/server/src/rtsim/mod.rs +++ b/server/src/rtsim/mod.rs @@ -198,7 +198,8 @@ pub fn init( _ => {}, }, SiteKind::Refactor(site2) => { - for _ in 0..site.economy.pop.min(site2.plots().len() as f32 * 1.5) as usize { + // villagers + for _ in 0..site.economy.pop.min(site2.plots().len() as f32) as usize { rtsim.entities.insert(Entity { is_loaded: false, pos: site2 @@ -217,7 +218,32 @@ pub fn init( }); } - for _ in 0..(site2.plazas().len() as f32 * 1.5) as usize { + // guards + for _ in 0..site2.plazas().len() as usize { + rtsim.entities.insert(Entity { + is_loaded: false, + pos: site2 + .plazas() + .choose(&mut thread_rng()) + .map_or(site.get_origin(), |p| { + site2.tile_center_wpos(site2.plot(p).root_tile()) + + Vec2::new( + thread_rng().gen_range(-8..9), + thread_rng().gen_range(-8..9), + ) + }) + .with_z(0) + .map(|e| e as f32), + seed: thread_rng().gen(), + controller: RtSimController::default(), + last_time_ticked: 0.0, + kind: RtSimEntityKind::TownGuard, + brain: Brain::town_guard(site_id), + }); + } + + // merchants + for _ in 0..site2.plazas().len() as usize { rtsim.entities.insert(Entity { is_loaded: false, pos: site2 diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index 69257b78f9..88c943d2cc 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -1298,7 +1298,9 @@ impl SiteKind { impl Site { pub fn is_dungeon(&self) -> bool { matches!(self.kind, SiteKind::Dungeon) } - pub fn is_settlement(&self) -> bool { matches!(self.kind, SiteKind::Settlement) } + pub fn is_settlement(&self) -> bool { + matches!(self.kind, SiteKind::Settlement | SiteKind::Refactor) + } pub fn is_castle(&self) -> bool { matches!(self.kind, SiteKind::Castle) } }