More rtsim monsters

This commit is contained in:
Joshua Barretto 2023-05-04 10:13:02 +01:00
parent 6fbd007cea
commit 2ff0118df0
5 changed files with 57 additions and 15 deletions

View File

@ -1,4 +1,11 @@
body-generic = creature body-generic = creature
body-biped_large-ogre = ogre
body-biped_large-cyclops = cyclops body-biped_large-cyclops = cyclops
body-biped_large-wendigo = wendigo body-biped_large-wendigo = wendigo
body-biped_large-werewolf = werewolf body-biped_large-werewolf = werewolf
body-biped_large-cave_troll = cave troll
body-biped_large-mountain_troll = mountain troll
body-biped_large-swamp_troll = swamp troll
body-biped_large-blue_oni = blue oni
body-biped_large-red_oni = red oni
body-biped_large-tursus = tursus

View File

@ -26,9 +26,16 @@ impl Body {
pub fn localize(&self) -> Content { pub fn localize(&self) -> Content {
Content::localized(match &self.species { Content::localized(match &self.species {
Species::Ogre => "body-biped_large-ogre",
Species::Cyclops => "body-biped_large-cyclops", Species::Cyclops => "body-biped_large-cyclops",
Species::Wendigo => "body-biped_large-wendigo", Species::Wendigo => "body-biped_large-wendigo",
Species::Werewolf => "body-biped_large-werewolf", Species::Werewolf => "body-biped_large-werewolf",
Species::Cavetroll => "body-biped_large-cave_troll",
Species::Mountaintroll => "body-biped_large-mountain_troll",
Species::Swamptroll => "body-biped_large-swamp_troll",
Species::Blueoni => "body-biped_large-blue_oni",
Species::Redoni => "body-biped_large-red_oni",
Species::Tursus => "body-biped_large-tursus",
_ => "body-generic", _ => "body-generic",
}) })
} }

View File

@ -290,8 +290,11 @@ pub enum ChunkResource {
// identifiers for the sake of rtsim persistence // identifiers for the sake of rtsim persistence
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Role { pub enum Role {
#[serde(rename = "0")]
Civilised(Option<Profession>), Civilised(Option<Profession>),
#[serde(rename = "1")]
Wild, Wild,
#[serde(rename = "2")]
Monster, Monster,
} }

View File

@ -13,13 +13,13 @@ use common::{
grid::Grid, grid::Grid,
resources::TimeOfDay, resources::TimeOfDay,
rtsim::{Personality, Role, WorldSettings}, rtsim::{Personality, Role, WorldSettings},
terrain::{CoordinateConversions, TerrainChunkSize}, terrain::{BiomeKind, CoordinateConversions, TerrainChunkSize},
vol::RectVolSize, vol::RectVolSize,
}; };
use rand::prelude::*; use rand::prelude::*;
use tracing::info; use tracing::info;
use vek::*; use vek::*;
use world::{site::SiteKind, site2::PlotKind, IndexRef, World}; use world::{site::SiteKind, site2::PlotKind, IndexRef, World, CONFIG};
impl Data { impl Data {
pub fn generate(settings: &WorldSettings, world: &World, index: IndexRef) -> Self { pub fn generate(settings: &WorldSettings, world: &World, index: IndexRef) -> Self {
@ -224,21 +224,35 @@ impl Data {
// Spawn monsters into the world // Spawn monsters into the world
for _ in 0..100 { for _ in 0..100 {
// Try a few times to find a location that's not underwater // Try a few times to find a location that's not underwater
if let Some(wpos) = (0..10) if let Some((wpos, chunk)) = (0..10)
.map(|_| world.sim().get_size().map(|sz| rng.gen_range(0..sz as i32))) .map(|_| world.sim().get_size().map(|sz| rng.gen_range(0..sz as i32)))
.find(|pos| world.sim().get(*pos).map_or(false, |c| !c.is_underwater())) .find_map(|pos| Some((pos, world.sim().get(pos).filter(|c| !c.is_underwater())?)))
.map(|pos| { .map(|(pos, chunk)| {
let wpos2d = pos.cpos_to_wpos_center(); let wpos2d = pos.cpos_to_wpos_center();
(
wpos2d wpos2d
.map(|e| e as f32 + 0.5) .map(|e| e as f32 + 0.5)
.with_z(world.sim().get_alt_approx(wpos2d).unwrap_or(0.0)) .with_z(world.sim().get_alt_approx(wpos2d).unwrap_or(0.0)),
chunk,
)
}) })
{ {
let species = match rng.gen_range(0..3) { let biome = chunk.get_biome();
0 => comp::body::biped_large::Species::Cyclops, let Some(species) = [
1 => comp::body::biped_large::Species::Wendigo, Some(comp::body::biped_large::Species::Ogre),
_ => comp::body::biped_large::Species::Werewolf, Some(comp::body::biped_large::Species::Cyclops),
}; Some(comp::body::biped_large::Species::Wendigo).filter(|_| biome == BiomeKind::Taiga),
Some(comp::body::biped_large::Species::Cavetroll),
Some(comp::body::biped_large::Species::Mountaintroll).filter(|_| biome == BiomeKind::Mountain),
Some(comp::body::biped_large::Species::Swamptroll).filter(|_| biome == BiomeKind::Swamp),
Some(comp::body::biped_large::Species::Blueoni),
Some(comp::body::biped_large::Species::Redoni),
Some(comp::body::biped_large::Species::Tursus).filter(|_| chunk.temp < CONFIG.snow_temp),
]
.into_iter()
.flatten()
.choose(&mut rng)
else { continue };
this.npcs.create_npc(Npc::new( this.npcs.create_npc(Npc::new(
rng.gen(), rng.gen(),

View File

@ -170,12 +170,23 @@ fn get_npc_entity_info(npc: &Npc, sites: &Sites, index: IndexRef) -> EntityInfo
_ => unimplemented!(), _ => unimplemented!(),
}, },
Body::BipedLarge(body) => match body.species { Body::BipedLarge(body) => match body.species {
comp::biped_large::Species::Ogre => "common.entity.wild.aggressive.ogre",
comp::biped_large::Species::Cyclops => "common.entity.wild.aggressive.cyclops", comp::biped_large::Species::Cyclops => "common.entity.wild.aggressive.cyclops",
comp::biped_large::Species::Wendigo => "common.entity.wild.aggressive.wendigo", comp::biped_large::Species::Wendigo => "common.entity.wild.aggressive.wendigo",
comp::biped_large::Species::Werewolf => "common.entity.wild.aggressive.werewolf", comp::biped_large::Species::Werewolf => "common.entity.wild.aggressive.werewolf",
_ => unimplemented!(), comp::biped_large::Species::Cavetroll => "common.entity.wild.aggressive.cave_troll",
comp::biped_large::Species::Mountaintroll => {
"common.entity.wild.aggressive.mountain_troll"
}, },
_ => unimplemented!(), comp::biped_large::Species::Swamptroll => {
"common.entity.wild.aggressive.swamp_troll"
},
comp::biped_large::Species::Blueoni => "common.entity.wild.aggressive.blue_oni",
comp::biped_large::Species::Redoni => "common.entity.wild.aggressive.red_oni",
comp::biped_large::Species::Tursus => "common.entity.wild.aggressive.tursus",
species => unimplemented!("rtsim spawning for {:?}", species),
},
body => unimplemented!("rtsim spawning for {:?}", body),
}; };
let entity_config = EntityConfig::from_asset_expect_owned(config_asset) let entity_config = EntityConfig::from_asset_expect_owned(config_asset)
.with_body(BodyBuilder::Exact(npc.body)); .with_body(BodyBuilder::Exact(npc.body));