initiative_core/world/place/location/geographical/
beach.rs1use crate::utils::pluralize;
2use crate::world::place::PlaceData;
3use crate::world::{word, word::ListGenerator, Demographics};
4use rand::prelude::*;
5
6pub fn generate(place: &mut PlaceData, rng: &mut impl Rng, _demographics: &Demographics) {
7 place.name.replace_with(|_| name(rng));
8}
9
10fn name(rng: &mut impl Rng) -> String {
11 match rng.gen_range(0..=5) {
12 0 => format!("{} {}", thing(rng), beach_synonym(rng)),
13 1 => format!("The {} {}", placement(rng), beach_synonym(rng)),
14 2 => format!("{} {}", word::cardinal_direction(rng), beach_synonym(rng)),
15 3 => format!("{} {}", word::adjective(rng), beach_synonym(rng)),
16 4 => format!(
17 "{} {} {}",
18 word::adjective(rng),
19 thing(rng),
20 beach_synonym(rng)
21 ),
22 5 => {
23 let (profession, s) = pluralize(word::profession(rng));
24 format!("{}{} {}", profession, s, beach_synonym(rng))
25 }
26 _ => unreachable!(),
27 }
28}
29
30fn thing(rng: &mut impl Rng) -> &'static str {
31 match rng.gen_range(0..=10) {
32 0 => word::land_animal(rng),
33 1..=2 => word::coastal_animal(rng),
34 3 => word::enemy(rng),
35 4 => word::food(rng),
36 5 => word::profession(rng),
37 6 => word::symbol(rng),
38 7..=10 => word::gem(rng),
39 _ => unreachable!(),
40 }
41}
42
43#[rustfmt::skip]
44fn beach_synonym(rng: &mut impl Rng) -> &'static str {
45 ListGenerator(&[
46 "Bank", "Beach", "Berm", "Coast", "Cove", "Embankment", "Landing", "Point", "Sands",
47 "Shore", "Shoreline", "Strand", "Waterfront",
48 ]).gen(rng)
49}
50
51#[rustfmt::skip]
52fn placement(rng: &mut impl Rng) -> &'static str {
53 ListGenerator(&["First", "Last"]).gen(rng)
54}
55
56#[cfg(test)]
57mod test {
58 use super::*;
59
60 #[test]
61 fn name_test() {
62 let mut rng = SmallRng::seed_from_u64(0);
63
64 assert_eq!(
65 [
66 "East Embankment",
67 "The Last Bank",
68 "Carpenters Shoreline",
69 "Lost Otter Strand",
70 "Amber Cove",
71 "Coopers Cove",
72 "The Last Embankment",
73 "Quartz Cove",
74 "South Cove",
75 "West Sands",
76 "Herring Shore",
77 "Enchanted Herring Waterfront",
78 "Lucky Sands",
79 "Otter Sands",
80 "Citrine Strand",
81 "Wasted Emerald Embankment",
82 "Green Waterfront",
83 "The Last Strand",
84 "Hallowed Beryl Coast",
85 "Thirsty Opal Shore"
86 ]
87 .iter()
88 .map(|s| s.to_string())
89 .collect::<Vec<_>>(),
90 (0..20).map(|_| name(&mut rng)).collect::<Vec<String>>(),
91 );
92 }
93}