veloren/rtsim/src/gen/mod.rs

43 lines
1.2 KiB
Rust
Raw Normal View History

use crate::data::{Npcs, Npc, Data, Nature};
2022-05-16 19:11:49 +00:00
use hashbrown::HashMap;
use rand::prelude::*;
use world::{
site::SiteKind,
IndexRef,
World,
};
2022-05-16 19:11:49 +00:00
impl Data {
pub fn generate(index: IndexRef, world: &World) -> Self {
let mut seed = [0; 32];
seed.iter_mut().zip(&mut index.seed.to_le_bytes()).for_each(|(dst, src)| *dst = *src);
let mut rng = SmallRng::from_seed(seed);
let mut this = Self {
nature: Nature::generate(world),
npcs: Npcs { npcs: Default::default() },
};
for (site_id, site) in world
.civs()
.sites
.iter()
.filter_map(|(site_id, site)| site.site_tmp.map(|id| (site_id, &index.sites[id])))
{
match &site.kind {
SiteKind::Refactor(site2) => {
let wpos = site.get_origin()
.map(|e| e as f32 + 0.5)
.with_z(world.sim().get_alt_approx(site.get_origin()).unwrap_or(0.0));
// TODO: Better API
this.npcs.spawn(Npc::at(wpos));
println!("Spawned rtsim NPC at {:?}", wpos);
}
_ => {},
}
2022-05-16 19:11:49 +00:00
}
this
2022-05-16 19:11:49 +00:00
}
}