diff --git a/core/src/world/place/building/business/mod.rs b/core/src/world/place/building/business/mod.rs index 9f33d781..667065ee 100644 --- a/core/src/world/place/building/business/mod.rs +++ b/core/src/world/place/building/business/mod.rs @@ -1,4 +1,5 @@ mod inn; +mod theater; use super::BuildingType; use crate::world::place::{Place, PlaceType}; @@ -112,6 +113,7 @@ pub fn generate(place: &mut Place, rng: &mut impl Rng, demographics: &Demographi #[allow(clippy::single_match)] match subtype { BusinessType::Inn => inn::generate(place, rng, demographics), + BusinessType::Theater => theater::generate(place, rng, demographics), _ => {} } } diff --git a/core/src/world/place/building/business/theater.rs b/core/src/world/place/building/business/theater.rs new file mode 100644 index 00000000..eb7130cd --- /dev/null +++ b/core/src/world/place/building/business/theater.rs @@ -0,0 +1,77 @@ +use crate::world::{word, Demographics, Place}; +use rand::prelude::*; + +pub fn generate(place: &mut Place, rng: &mut impl Rng, _demographics: &Demographics) { + place.name.replace_with(|_| name(rng)); +} + +fn name(rng: &mut impl Rng) -> String { + match rng.gen_range(0..7) { + 0..=2 => format!("The {}", thing(rng)), + 3..=5 => format!("{} {}", thing(rng), theater_synonym(rng)), + 6 => format!( + "{} {} {}", + word::adjective(rng), + thing(rng), + theater_synonym(rng) + ), + _ => unreachable!(), + } +} + +fn thing(rng: &mut impl Rng) -> &'static str { + match rng.gen_range(0..6) { + 0 => word::animal(rng), + 1..=2 => word::symbol(rng), + 3..=4 => word::gem(rng), + 5 => word::person(rng), + _ => unreachable!(), + } +} + +fn theater_synonym(rng: &mut impl Rng) -> &'static str { + #[rustfmt::skip] + const THEATER_SYNONYMS: &[&str] = &[ + "Theater", "Opera House", "Ampitheater", "Hall", "Playhouse", + ]; + THEATER_SYNONYMS[rng.gen_range(0..THEATER_SYNONYMS.len())] +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn name_test() { + let mut rng = SmallRng::seed_from_u64(0); + + assert_eq!( + [ + "Lance Playhouse", + "Lucky Helmet Playhouse", + "The Mermaid", + "The Opal", + "Sun Playhouse", + "Bronze Steeple Theater", + "The Sibling", + "Anchor Hall", + "Book Ampitheater", + "Foil Ampitheater", + "Deer Ampitheater", + "Amber Theater", + "The Otter", + "Ancestor Hall", + "Diamond Opera House", + "Green Sapphire Playhouse", + "The Rook", + "Purple Opal Theater", + "Feather Playhouse", + "Phalactary Ampitheater" + ] + .iter() + .map(|s| s.to_string()) + .collect::>(), + (0..20).map(|_| name(&mut rng)).collect::>(), + ); + } +} diff --git a/data/changelog.md b/data/changelog.md index 62ddbd6e..daa470a8 100644 --- a/data/changelog.md +++ b/data/changelog.md @@ -1,3 +1,4 @@ +* **Enhancement:** Name generator now works for `theater`. @azylko * **Bug:** Fixed a positioning issue with the autocomplete popup. @MikkelPaulson * **Enhancement:** Name generator now works for `canyon`. @chrisrenfrow * **Bug:** Fixed an edge case where unsaved journal entries might not be