From 2ff0118df0a1acae31debca0fca0a591dc5580a7 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 4 May 2023 10:13:02 +0100 Subject: [PATCH] More rtsim monsters --- assets/voxygen/i18n/en/body.ftl | 7 +++++ common/src/comp/body/biped_large.rs | 7 +++++ common/src/rtsim.rs | 3 +++ rtsim/src/gen/mod.rs | 40 +++++++++++++++++++---------- server/src/rtsim/tick.rs | 15 +++++++++-- 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/assets/voxygen/i18n/en/body.ftl b/assets/voxygen/i18n/en/body.ftl index 8f712a55f2..59daf5bc3b 100644 --- a/assets/voxygen/i18n/en/body.ftl +++ b/assets/voxygen/i18n/en/body.ftl @@ -1,4 +1,11 @@ body-generic = creature +body-biped_large-ogre = ogre body-biped_large-cyclops = cyclops body-biped_large-wendigo = wendigo 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 diff --git a/common/src/comp/body/biped_large.rs b/common/src/comp/body/biped_large.rs index 5cda9e3685..8179dc7c1a 100644 --- a/common/src/comp/body/biped_large.rs +++ b/common/src/comp/body/biped_large.rs @@ -26,9 +26,16 @@ impl Body { pub fn localize(&self) -> Content { Content::localized(match &self.species { + Species::Ogre => "body-biped_large-ogre", Species::Cyclops => "body-biped_large-cyclops", Species::Wendigo => "body-biped_large-wendigo", 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", }) } diff --git a/common/src/rtsim.rs b/common/src/rtsim.rs index 16964fedd1..6b737cd7e0 100644 --- a/common/src/rtsim.rs +++ b/common/src/rtsim.rs @@ -290,8 +290,11 @@ pub enum ChunkResource { // identifiers for the sake of rtsim persistence #[derive(Clone, Debug, Serialize, Deserialize)] pub enum Role { + #[serde(rename = "0")] Civilised(Option), + #[serde(rename = "1")] Wild, + #[serde(rename = "2")] Monster, } diff --git a/rtsim/src/gen/mod.rs b/rtsim/src/gen/mod.rs index 67adbddbb5..52541cbdd7 100644 --- a/rtsim/src/gen/mod.rs +++ b/rtsim/src/gen/mod.rs @@ -13,13 +13,13 @@ use common::{ grid::Grid, resources::TimeOfDay, rtsim::{Personality, Role, WorldSettings}, - terrain::{CoordinateConversions, TerrainChunkSize}, + terrain::{BiomeKind, CoordinateConversions, TerrainChunkSize}, vol::RectVolSize, }; use rand::prelude::*; use tracing::info; use vek::*; -use world::{site::SiteKind, site2::PlotKind, IndexRef, World}; +use world::{site::SiteKind, site2::PlotKind, IndexRef, World, CONFIG}; impl Data { pub fn generate(settings: &WorldSettings, world: &World, index: IndexRef) -> Self { @@ -224,21 +224,35 @@ impl Data { // Spawn monsters into the world for _ in 0..100 { // 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))) - .find(|pos| world.sim().get(*pos).map_or(false, |c| !c.is_underwater())) - .map(|pos| { + .find_map(|pos| Some((pos, world.sim().get(pos).filter(|c| !c.is_underwater())?))) + .map(|(pos, chunk)| { let wpos2d = pos.cpos_to_wpos_center(); - wpos2d - .map(|e| e as f32 + 0.5) - .with_z(world.sim().get_alt_approx(wpos2d).unwrap_or(0.0)) + ( + wpos2d + .map(|e| e as f32 + 0.5) + .with_z(world.sim().get_alt_approx(wpos2d).unwrap_or(0.0)), + chunk, + ) }) { - let species = match rng.gen_range(0..3) { - 0 => comp::body::biped_large::Species::Cyclops, - 1 => comp::body::biped_large::Species::Wendigo, - _ => comp::body::biped_large::Species::Werewolf, - }; + let biome = chunk.get_biome(); + let Some(species) = [ + Some(comp::body::biped_large::Species::Ogre), + 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( rng.gen(), diff --git a/server/src/rtsim/tick.rs b/server/src/rtsim/tick.rs index d2e5bfa4c0..5a2bab3fab 100644 --- a/server/src/rtsim/tick.rs +++ b/server/src/rtsim/tick.rs @@ -170,12 +170,23 @@ fn get_npc_entity_info(npc: &Npc, sites: &Sites, index: IndexRef) -> EntityInfo _ => unimplemented!(), }, 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::Wendigo => "common.entity.wild.aggressive.wendigo", 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" + }, + 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), }, - _ => unimplemented!(), + body => unimplemented!("rtsim spawning for {:?}", body), }; let entity_config = EntityConfig::from_asset_expect_owned(config_asset) .with_body(BodyBuilder::Exact(npc.body));