mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Allowed specifying that rtsim entities spawn at a particular site.
This commit is contained in:
parent
8d377d6cf2
commit
311fb251c1
@ -468,7 +468,7 @@ impl Server {
|
||||
|
||||
// Initiate real-time world simulation
|
||||
#[cfg(feature = "worldgen")]
|
||||
rtsim::init(&mut state, &world);
|
||||
rtsim::init(&mut state, &world, index.as_index_ref());
|
||||
#[cfg(not(feature = "worldgen"))]
|
||||
rtsim::init(&mut state);
|
||||
|
||||
|
@ -441,6 +441,7 @@ impl Entity {
|
||||
Travel::Lost
|
||||
}
|
||||
},
|
||||
Travel::Idle => Travel::Idle,
|
||||
};
|
||||
|
||||
// Forget old memories
|
||||
@ -482,6 +483,8 @@ enum Travel {
|
||||
progress: usize,
|
||||
reversed: bool,
|
||||
},
|
||||
// For testing purposes
|
||||
Idle,
|
||||
}
|
||||
|
||||
impl Default for Travel {
|
||||
@ -498,6 +501,16 @@ pub struct 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 forget_enemy(&mut self, to_forget: &str) {
|
||||
|
@ -20,7 +20,7 @@ use slab::Slab;
|
||||
use specs::{DispatcherBuilder, WorldExt};
|
||||
use vek::*;
|
||||
|
||||
pub use self::entity::Entity;
|
||||
pub use self::entity::{Entity, Brain};
|
||||
|
||||
pub struct RtSim {
|
||||
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")]
|
||||
let mut rtsim = RtSim::new(world.sim().get_size());
|
||||
#[cfg(not(feature = "worldgen"))]
|
||||
@ -113,22 +113,49 @@ pub fn init(state: &mut State, #[cfg(feature = "worldgen")] world: &world::World
|
||||
// TODO: Determine number of rtsim entities based on things like initial site
|
||||
// populations rather than world size
|
||||
#[cfg(feature = "worldgen")]
|
||||
for _ in 0..world.sim().get_size().product() / 400 {
|
||||
let pos = rtsim
|
||||
.chunks
|
||||
.size()
|
||||
.map2(TerrainChunk::RECT_SIZE, |sz, chunk_sz| {
|
||||
thread_rng().gen_range(0..sz * chunk_sz) as i32
|
||||
});
|
||||
{
|
||||
for _ in 0..world.sim().get_size().product() / 400 {
|
||||
let pos = rtsim
|
||||
.chunks
|
||||
.size()
|
||||
.map2(TerrainChunk::RECT_SIZE, |sz, chunk_sz| {
|
||||
thread_rng().gen_range(0..sz * chunk_sz) as i32
|
||||
});
|
||||
|
||||
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: Default::default(),
|
||||
});
|
||||
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: 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);
|
||||
|
Loading…
Reference in New Issue
Block a user