Added rtsim villagers to site2 towns

This commit is contained in:
Joshua Barretto 2021-09-18 16:24:56 +01:00
parent 08a3a1b1b8
commit 8e2ca9cdec
6 changed files with 44 additions and 4 deletions

View File

@ -59,9 +59,9 @@ impl<T> Store<T> {
(0..self.items.len()).map(|i| Id(i as u64, PhantomData))
}
pub fn values(&self) -> impl Iterator<Item = &T> { self.items.iter() }
pub fn values(&self) -> impl ExactSizeIterator<Item = &T> { self.items.iter() }
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T> { self.items.iter_mut() }
pub fn values_mut(&mut self) -> impl ExactSizeIterator<Item = &mut T> { self.items.iter_mut() }
pub fn iter(&self) -> impl Iterator<Item = (Id<T>, &T)> { self.ids().zip(self.values()) }

View File

@ -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<Site>) -> 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",
}
}

View File

@ -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),
});
}
},
_ => {},
}
}

View File

@ -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),
};

View File

@ -77,7 +77,7 @@ impl Site {
pub fn plot(&self, id: Id<Plot>) -> &Plot { &self.plots[id] }
pub fn plots(&self) -> impl Iterator<Item = &Plot> + '_ { self.plots.values() }
pub fn plots(&self) -> impl ExactSizeIterator<Item = &Plot> + '_ { self.plots.values() }
pub fn create_plot(&mut self, plot: Plot) -> Id<Plot> { self.plots.insert(plot) }

View File

@ -26,6 +26,8 @@ impl Plot {
}
pub fn kind(&self) -> &PlotKind { &self.kind }
pub fn root_tile(&self) -> Vec2<i32> { self.root_tile }
}
pub enum PlotKind {