initiative_core/world/place/building/business/
inn.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..6) {
12 0 => format!("The {}", thing(rng)),
13 1 => {
14 let (profession, s) = pluralize(word::profession(rng));
15 format!("{}{} Arms", profession, s)
16 }
17 2..=3 => {
18 let (thing1, thing2) = thing_thing(rng);
19 format!("{} and {}", thing1, thing2)
20 }
21 4 => format!("The {} {}", word::adjective(rng), thing(rng)),
22 5 => {
23 let (thing, s) = pluralize(thing(rng));
24 format!("{} {}{}", number(rng), thing, s)
25 }
26 _ => unreachable!(),
27 }
28}
29
30fn thing(rng: &mut impl Rng) -> &'static str {
31 match rng.gen_range(0..5) {
32 0 => word::animal(rng),
33 1 => word::enemy(rng),
34 2 => word::food(rng),
35 3 => word::profession(rng),
36 4 => word::symbol(rng),
37 _ => unreachable!(),
38 }
39}
40
41fn thing_thing(rng: &mut impl Rng) -> (&'static str, &'static str) {
42 let (thing1, thing2) = if rng.gen_bool(0.5) {
44 match rng.gen_range(0..5) {
45 0 => (word::animal(rng), word::animal(rng)),
46 1 => (word::enemy(rng), word::enemy(rng)),
47 2 => (word::food(rng), word::food(rng)),
48 3 => (word::profession(rng), word::profession(rng)),
49 4 => (word::symbol(rng), word::symbol(rng)),
50 _ => unreachable!(),
51 }
52 } else {
53 (thing(rng), thing(rng))
54 };
55
56 if thing1 == thing2
60 || rng.gen_bool(0.5)
61 && thing1
62 .chars()
63 .next()
64 .map(|c| !thing2.starts_with(c))
65 .unwrap_or(false)
66 {
67 thing_thing(rng)
68 } else {
69 (thing1, thing2)
70 }
71}
72
73#[rustfmt::skip]
74fn number(rng: &mut impl Rng) -> &'static str {
75 ListGenerator(&["Three", "Five", "Seven", "Ten"]).gen(rng)
76}
77
78#[cfg(test)]
79mod test {
80 use super::*;
81
82 #[test]
83 fn name_test() {
84 let mut rng = SmallRng::seed_from_u64(0);
85
86 assert_eq!(
87 [
88 "Mutton and Malt",
89 "Wizards Arms",
90 "The Column",
91 "Coopers Arms",
92 "The Orange Unicorn",
93 "Imp and Satyr",
94 "Otter and Rye",
95 "Seven Printers",
96 "Shovel and Crown",
97 "Seven Porters",
98 "The Bread",
99 "Mace and Phalactary",
100 "Three Kegs",
101 "Blacksmiths Arms",
102 "Ten Beggars",
103 "Bandit and Hydra",
104 "The Burgundy Potatoes",
105 "The Green Cooper",
106 "The Giant",
107 "The Lucky Wheel"
108 ]
109 .iter()
110 .map(|s| s.to_string())
111 .collect::<Vec<_>>(),
112 (0..20).map(|_| name(&mut rng)).collect::<Vec<String>>(),
113 );
114 }
115}