Allowed specifying that rtsim entities spawn at a particular site.

This commit is contained in:
Sam
2021-09-03 23:34:24 -04:00
parent 663fe0fdbc
commit 7983c75911
3 changed files with 58 additions and 18 deletions

View File

@ -468,7 +468,7 @@ impl Server {
// Initiate real-time world simulation // Initiate real-time world simulation
#[cfg(feature = "worldgen")] #[cfg(feature = "worldgen")]
rtsim::init(&mut state, &world); rtsim::init(&mut state, &world, index.as_index_ref());
#[cfg(not(feature = "worldgen"))] #[cfg(not(feature = "worldgen"))]
rtsim::init(&mut state); rtsim::init(&mut state);

View File

@ -441,6 +441,7 @@ impl Entity {
Travel::Lost Travel::Lost
} }
}, },
Travel::Idle => Travel::Idle,
}; };
// Forget old memories // Forget old memories
@ -482,6 +483,8 @@ enum Travel {
progress: usize, progress: usize,
reversed: bool, reversed: bool,
}, },
// For testing purposes
Idle,
} }
impl Default for Travel { impl Default for Travel {
@ -498,6 +501,16 @@ pub struct Brain {
} }
impl Brain { impl Brain {
pub fn idle() -> 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 add_memory(&mut self, memory: Memory) { self.memories.push(memory); }
pub fn forget_enemy(&mut self, to_forget: &str) { pub fn forget_enemy(&mut self, to_forget: &str) {

View File

@ -20,7 +20,7 @@ use slab::Slab;
use specs::{DispatcherBuilder, WorldExt}; use specs::{DispatcherBuilder, WorldExt};
use vek::*; use vek::*;
pub use self::entity::Entity; pub use self::entity::{Entity, Brain};
pub struct RtSim { pub struct RtSim {
tick: u64, tick: u64,
@ -104,7 +104,7 @@ pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) {
]); ]);
} }
pub fn init(state: &mut State, #[cfg(feature = "worldgen")] world: &world::World) { pub fn init(state: &mut State, #[cfg(feature = "worldgen")] world: &world::World, #[cfg(feature = "worldgen")] index: world::IndexRef) {
#[cfg(feature = "worldgen")] #[cfg(feature = "worldgen")]
let mut rtsim = RtSim::new(world.sim().get_size()); let mut rtsim = RtSim::new(world.sim().get_size());
#[cfg(not(feature = "worldgen"))] #[cfg(not(feature = "worldgen"))]
@ -113,6 +113,7 @@ pub fn init(state: &mut State, #[cfg(feature = "worldgen")] world: &world::World
// TODO: Determine number of rtsim entities based on things like initial site // TODO: Determine number of rtsim entities based on things like initial site
// populations rather than world size // populations rather than world size
#[cfg(feature = "worldgen")] #[cfg(feature = "worldgen")]
{
for _ in 0..world.sim().get_size().product() / 400 { for _ in 0..world.sim().get_size().product() / 400 {
let pos = rtsim let pos = rtsim
.chunks .chunks
@ -130,6 +131,32 @@ pub fn init(state: &mut State, #[cfg(feature = "worldgen")] world: &world::World
brain: Default::default(), brain: Default::default(),
}); });
} }
for site in world.civs().sites.iter().filter_map(|(_, site)| site.site_tmp.map(|id| &index.sites[id])) {
use world::site::SiteKind;
match &site.kind {
SiteKind::Dungeon(dungeon) => {
match dungeon.dungeon_difficulty() {
Some(5) => {
let pos = site.get_origin();
for _ in 0..25 {
rtsim.entities.insert(Entity {
is_loaded: false,
pos: Vec3::from(pos.map(|e| e as f32)),
seed: thread_rng().gen(),
controller: RtSimController::default(),
last_time_ticked: 0.0,
brain: Brain::idle(),
});
}
},
_ => {},
}
},
_ => {},
}
}
}
state.ecs_mut().insert(rtsim); state.ecs_mut().insert(rtsim);
state.ecs_mut().register::<RtSimEntity>(); state.ecs_mut().register::<RtSimEntity>();