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:
@ -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);
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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,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
|
// 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 {
|
{
|
||||||
let pos = rtsim
|
for _ in 0..world.sim().get_size().product() / 400 {
|
||||||
.chunks
|
let pos = rtsim
|
||||||
.size()
|
.chunks
|
||||||
.map2(TerrainChunk::RECT_SIZE, |sz, chunk_sz| {
|
.size()
|
||||||
thread_rng().gen_range(0..sz * chunk_sz) as i32
|
.map2(TerrainChunk::RECT_SIZE, |sz, chunk_sz| {
|
||||||
});
|
thread_rng().gen_range(0..sz * chunk_sz) as i32
|
||||||
|
});
|
||||||
|
|
||||||
rtsim.entities.insert(Entity {
|
rtsim.entities.insert(Entity {
|
||||||
is_loaded: false,
|
is_loaded: false,
|
||||||
pos: Vec3::from(pos.map(|e| e as f32)),
|
pos: Vec3::from(pos.map(|e| e as f32)),
|
||||||
seed: thread_rng().gen(),
|
seed: thread_rng().gen(),
|
||||||
controller: RtSimController::default(),
|
controller: RtSimController::default(),
|
||||||
last_time_ticked: 0.0,
|
last_time_ticked: 0.0,
|
||||||
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);
|
||||||
|
Reference in New Issue
Block a user