diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index 0aa94174e9..fb990d9d95 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -6,7 +6,7 @@ use self::{Occupation::*, Stock::*}; use crate::{ config::CONFIG, sim::WorldSim, - site::{Castle, Dungeon, Settlement, Site as WorldSite}, + site::{namegen::NameGen, Castle, Dungeon, Settlement, Site as WorldSite}, util::{attempt, seed_expan, MapVec, CARDINALS, NEIGHBORS}, Index, }; @@ -38,6 +38,11 @@ const fn initial_civ_count(map_size_lg: MapSizeLg) -> u32 { (3 << (map_size_lg.vec().x + map_size_lg.vec().y)) >> 16 } +pub struct CaveInfo { + pub location: (Vec2, Vec2), + pub name: String, +} + #[allow(clippy::type_complexity)] // TODO: Pending review in #587 #[derive(Default)] pub struct Civs { @@ -56,7 +61,7 @@ pub struct Civs { >, pub sites: Store, - pub caves: Store>, + pub caves: Store, } // Change this to get rid of particularly horrid seeds @@ -293,10 +298,24 @@ impl Civs { chunk.spawn_rate = 0.0; } } - self.caves - .insert(path.first().unwrap().0 * TerrainChunkSize::RECT_SIZE.map(|e: u32| e as i32)); - self.caves - .insert(path.last().unwrap().0 * TerrainChunkSize::RECT_SIZE.map(|e: u32| e as i32)); + self.caves.insert(CaveInfo { + location: ( + path.first().unwrap().0 * TerrainChunkSize::RECT_SIZE.map(|e: u32| e as i32), + path.last().unwrap().0 * TerrainChunkSize::RECT_SIZE.map(|e: u32| e as i32), + ), + name: { + let name = NameGen::location(&mut ctx.rng).generate(); + match ctx.rng.gen_range(0, 7) { + 0 => format!("{} Hole", name), + 1 => format!("{} Cavern", name), + 2 => format!("{} Hollow", name), + 3 => format!("{} Tunnel", name), + 4 => format!("{} Mouth", name), + 5 => format!("{} Grotto", name), + _ => format!("{} Den", name), + } + }, + }); } pub fn place(&self, id: Id) -> &Place { self.places.get(id) } diff --git a/world/src/lib.rs b/world/src/lib.rs index 02bccbd529..c1fe4091d9 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -118,10 +118,20 @@ impl World { self.civs() .caves .iter() - .map(|(_, pos)| world_msg::SiteInfo { - name: None, + .map(|(_, info)| world_msg::SiteInfo { + name: Some(info.name.clone()), kind: world_msg::SiteKind::Cave, - wpos: *pos, + wpos: info.location.0, + }), + ) + .chain( + self.civs() + .caves + .iter() + .map(|(_, info)| world_msg::SiteInfo { + name: Some(info.name.clone()), + kind: world_msg::SiteKind::Cave, + wpos: info.location.1, }), ) .collect(), diff --git a/world/src/site/mod.rs b/world/src/site/mod.rs index cbe82647c3..da168c28f5 100644 --- a/world/src/site/mod.rs +++ b/world/src/site/mod.rs @@ -2,7 +2,7 @@ mod block_mask; mod castle; mod dungeon; pub mod economy; -mod namegen; +pub mod namegen; mod settlement; // Reexports