1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use super::{Age, Gender, Generate, GenerateSimple};
use rand::prelude::*;

pub struct Ethnicity;

impl GenerateSimple for Ethnicity {
    fn syllable_fname_count_f() -> &'static [(u8, usize)] {
        &[(2, 11), (3, 7), (4, 1)]
    }

    #[rustfmt::skip]
    fn syllable_fname_first_f() -> &'static [(&'static str, usize)] {
        &[
            ("Alfi", 1), ("Bry", 1), ("Ha", 1), ("He", 1), ("Ka", 1), ("Lo", 1), ("Mac", 1),
            ("Nar", 1), ("Nee", 1), ("Ny", 1), ("Ora", 1), ("Rae", 1), ("Sfe", 1), ("Syl", 1),
            ("Te", 1), ("Va", 1), ("Xal", 1),
        ]
    }

    #[rustfmt::skip]
    fn syllable_fname_last_f() -> &'static [(&'static str, usize)] {
        &[
            ("na", 2), ("ra", 2), ("fer", 1), ("la", 1), ("lar", 1), ("leen", 1), ("lia", 1),
            ("lis", 1), ("nosh", 1), ("sa", 1), ("seis", 1), ("shka", 1), ("cath", 1), ("vyre", 1),
            ("del", 1),
        ]
    }

    fn syllable_fname_count_m() -> &'static [(u8, usize)] {
        &[(2, 18), (3, 2)]
    }

    #[rustfmt::skip]
    fn syllable_fname_first_m() -> &'static [(&'static str, usize)] {
        &[
            ("Bil", 1), ("Da", 1), ("Go", 1), ("Haer'", 1), ("Her", 1), ("Ia", 1), ("Ka", 1),
            ("Kad", 1), ("Ma", 1), ("Mor", 1), ("No", 1), ("Pyn", 1), ("Ral", 1), ("Squid", 1),
            ("Va", 1), ("Vi", 1), ("Zev", 1),
        ]
    }

    #[rustfmt::skip]
    fn syllable_fname_last_m() -> &'static [(&'static str, usize)] {
        &[
            ("roth", 2), ("dai", 1), ("dly", 1), ("dos", 1), ("kos", 1), ("len", 1), ("lio", 1),
            ("lis", 1), ("lor", 1), ("mam", 1), ("mays", 1), ("non", 1), ("rim", 1), ("tuor", 1),
            ("chorn", 1), ("zgo", 1),
        ]
    }

    fn syllable_fname_count() -> &'static [(u8, usize)] {
        &[(2, 31), (3, 10), (4, 1)]
    }

    #[rustfmt::skip]
    fn syllable_fname_first() -> &'static [(&'static str, usize)] {
        &[
            ("Va", 2), ("Ka", 2), ("Bry", 1), ("Da", 1), ("Go", 1), ("Ha", 1), ("Haer'", 1),
            ("He", 1), ("Her", 1), ("Ia", 1), ("Jer", 1), ("Kad", 1), ("Lo", 1), ("Ma", 1),
            ("Mac", 1), ("Mor", 1), ("Nar", 1), ("Nee", 1), ("No", 1), ("Ny", 1), ("Ora", 1),
            ("Par", 1), ("Pyn", 1), ("Rae", 1), ("Ral", 1), ("Sfe", 1), ("Squid", 1), ("Syl", 1),
            ("Te", 1), ("Vi", 1), ("Xal", 1), ("Alfi", 1), ("Zev", 1), ("Bil", 1),
        ]
    }

    #[rustfmt::skip]
    fn syllable_fname_last() -> &'static [(&'static str, usize)] {
        &[
            ("lis", 2), ("roth", 2), ("na", 2), ("ra", 2), ("del", 1), ("der", 1), ("dly", 1),
            ("dos", 1), ("fer", 1), ("kos", 1), ("la", 1), ("lar", 1), ("leen", 1), ("len", 1),
            ("lia", 1), ("lio", 1), ("lor", 1), ("mam", 1), ("mays", 1), ("non", 1), ("nosh", 1),
            ("rim", 1), ("sa", 1), ("seis", 1), ("shka", 1), ("tuor", 1), ("vyre", 1), ("bid", 1),
            ("zgo", 1), ("cath", 1), ("chorn", 1), ("dai", 1),
        ]
    }

    #[rustfmt::skip]
    fn syllable_fname_middle() -> &'static [(&'static str, usize)] {
        &[
            ("ra", 2), ("vi", 2), ("lia", 1), ("man", 1), ("mes", 1), ("Da", 1), ("phe", 1),
            ("ris", 1), ("ni", 1), ("dan", 1),
        ]
    }

    fn syllable_lname_count() -> &'static [(u8, usize)] {
        &[(2, 14), (3, 3)]
    }

    #[rustfmt::skip]
    fn syllable_lname_first() -> &'static [(&'static str, usize)] {
        &[
            ("Aleg", 1), ("de", 1), ("Gul", 1), ("Imp", 1), ("Ka", 1), ("Rii", 1), ("Sa", 1),
            ("Sha", 1), ("Vroc", 1),
        ]
    }

    #[rustfmt::skip]
    fn syllable_lname_middle() -> &'static [(&'static str, usize)] {
        &[
            ("dow", 1), ("kis", 1), ("vi", 1),
        ]
    }

    #[rustfmt::skip]
    fn syllable_lname_last() -> &'static [(&'static str, usize)] {
        &[
            ("breath", 1), ("kas", 1), ("kith", 1), ("kwing", 1), ("maern", 1), ("ni", 1),
            ("tos", 1), ("Vore", 1), ("zar", 1),
        ]
    }

    fn compound_word_probability() -> f64 {
        0.
    }

    fn word_lname_first() -> &'static [(&'static str, usize)] {
        &[]
    }

    fn word_lname_last() -> &'static [(&'static str, usize)] {
        &[]
    }
}

impl Generate for Ethnicity {
    fn gen_name(rng: &mut impl Rng, _age: &Age, gender: &Gender) -> String {
        format!(
            "{} {}",
            Self::gen_fname_simple(rng, gender),
            Self::gen_lname_simple(rng),
        )
    }
}

#[cfg(test)]
mod test_generate_for_ethnicity {
    use super::*;
    use crate::world::npc::ethnicity::{regenerate, Ethnicity};
    use crate::world::npc::NpcData;

    #[test]
    fn gen_name_test() {
        let mut rng = SmallRng::seed_from_u64(0);
        let adult = Age::Adult;
        let m = Gender::Masculine;
        let f = Gender::Feminine;
        let t = Gender::NonBinaryThey;

        assert_eq!(
            [
                "Vidandos Shatos",
                "Hevivyre Alegkwing",
                "Bilmays Katos",
                "Narra demaern",
                "Matuor Shazar",
                "Norislor Gulkwing",
                "Tefer Shavitos",
                "Orara deVore",
                "Zevlia Sazar",
                "Goroth Alegtos",
            ],
            [
                gen_name(&mut rng, &Age::Infant, &m),
                gen_name(&mut rng, &Age::Child, &f),
                gen_name(&mut rng, &Age::Adolescent, &m),
                gen_name(&mut rng, &Age::YoungAdult, &f),
                gen_name(&mut rng, &adult, &m),
                gen_name(&mut rng, &adult, &m),
                gen_name(&mut rng, &adult, &f),
                gen_name(&mut rng, &adult, &f),
                gen_name(&mut rng, &adult, &t),
                gen_name(&mut rng, &adult, &t),
            ],
        );
    }

    fn gen_name(rng: &mut impl Rng, age: &Age, gender: &Gender) -> String {
        let mut npc = NpcData::default();
        npc.gender.replace(*gender);
        npc.age.replace(*age);
        npc.ethnicity.replace(Ethnicity::Tiefling);
        regenerate(rng, &mut npc);
        format!("{}", npc.name)
    }
}