initiative_core/world/place/building/business/
theater.rs

1use crate::world::place::PlaceData;
2use crate::world::{word, Demographics};
3use rand::prelude::*;
4
5pub fn generate(place: &mut PlaceData, rng: &mut impl Rng, _demographics: &Demographics) {
6    place.name.replace_with(|_| name(rng));
7}
8
9fn name(rng: &mut impl Rng) -> String {
10    match rng.gen_range(0..7) {
11        0..=2 => format!("The {}", thing(rng)),
12        3..=5 => format!("{} {}", thing(rng), theater_synonym(rng)),
13        6 => format!(
14            "{} {} {}",
15            word::adjective(rng),
16            thing(rng),
17            theater_synonym(rng)
18        ),
19        _ => unreachable!(),
20    }
21}
22
23fn thing(rng: &mut impl Rng) -> &'static str {
24    match rng.gen_range(0..6) {
25        0 => word::animal(rng),
26        1..=2 => word::symbol(rng),
27        3..=4 => word::gem(rng),
28        5 => word::person(rng),
29        _ => unreachable!(),
30    }
31}
32
33fn theater_synonym(rng: &mut impl Rng) -> &'static str {
34    #[rustfmt::skip]
35    const THEATER_SYNONYMS: &[&str] = &[
36        "Theater", "Opera House", "Ampitheater", "Hall", "Playhouse",
37    ];
38    THEATER_SYNONYMS[rng.gen_range(0..THEATER_SYNONYMS.len())]
39}
40
41#[cfg(test)]
42mod test {
43    use super::*;
44
45    #[test]
46    fn name_test() {
47        let mut rng = SmallRng::seed_from_u64(0);
48
49        assert_eq!(
50            [
51                "Lance Playhouse",
52                "Lucky Helmet Playhouse",
53                "The Mermaid",
54                "The Opal",
55                "Sun Playhouse",
56                "Bronze Steeple Theater",
57                "The Sibling",
58                "Anchor Hall",
59                "Book Ampitheater",
60                "Foil Ampitheater",
61                "Deer Ampitheater",
62                "Amber Theater",
63                "The Otter",
64                "Ancestor Hall",
65                "Diamond Opera House",
66                "Green Sapphire Playhouse",
67                "The Rook",
68                "Purple Opal Theater",
69                "Feather Playhouse",
70                "Phalactary Ampitheater"
71            ]
72            .iter()
73            .map(|s| s.to_string())
74            .collect::<Vec<_>>(),
75            (0..20).map(|_| name(&mut rng)).collect::<Vec<String>>(),
76        );
77    }
78}