veloren_common/comp/body/
biped_large.rs

1use common_base::{enum_iter, struct_iter};
2use common_i18n::Content;
3use rand::{seq::SliceRandom, thread_rng};
4use serde::{Deserialize, Serialize};
5
6struct_iter! {
7    #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
8    pub struct Body {
9        pub species: Species,
10        pub body_type: BodyType,
11    }
12}
13
14impl Body {
15    pub fn random() -> Self {
16        let mut rng = thread_rng();
17        let species = *ALL_SPECIES.choose(&mut rng).unwrap();
18        Self::random_with(&mut rng, &species)
19    }
20
21    #[inline]
22    pub fn random_with(rng: &mut impl rand::Rng, &species: &Species) -> Self {
23        let body_type = *ALL_BODY_TYPES.choose(rng).unwrap();
24        Self { species, body_type }
25    }
26
27    /// Should be only used with npc-tell_monster.
28    ///
29    /// If you want to use for displaying names in HUD, add new strings.
30    /// If you want to use for anything else, add new strings.
31    pub fn localize_npc(&self) -> Option<Content> {
32        let key = match &self.species {
33            Species::Ogre => match self.body_type {
34                BodyType::Male => "body-npc-speech-biped_large-ogre-male",
35                BodyType::Female => "body-npc-speech-biped_large-ogre-female",
36            },
37            Species::Cyclops => "body-npc-speech-biped_large-cyclops",
38            Species::Wendigo => "body-npc-speech-biped_large-wendigo",
39            Species::Werewolf => "body-npc-speech-biped_large-werewolf",
40            Species::Cavetroll => "body-npc-speech-biped_large-cave_troll",
41            Species::Mountaintroll => "body-npc-speech-biped_large-mountain_troll",
42            Species::Swamptroll => "body-npc-speech-biped_large-swamp_troll",
43            Species::Blueoni => "body-npc-speech-biped_large-blue_oni",
44            Species::Redoni => "body-npc-speech-biped_large-red_oni",
45            Species::Tursus => "body-npc-speech-biped_large-tursus",
46            Species::Dullahan => "body-npc-speech-biped_large-dullahan",
47            Species::Occultsaurok => "body-npc-speech-biped_large-occult_saurok",
48            Species::Mightysaurok => "body-npc-speech-biped_large-mighty_saurok",
49            Species::Slysaurok => "body-npc-speech-biped_large-sly_saurok",
50            Species::Mindflayer => "body-npc-speech-biped_large-mindflayer",
51            Species::Minotaur => "body-npc-speech-biped_large-minotaur",
52            Species::Tidalwarrior => "body-npc-speech-biped_large-tidal_warrior",
53            Species::Yeti => "body-npc-speech-biped_large-yeti",
54            Species::Harvester => "body-npc-speech-biped_large-harvester",
55            Species::Cultistwarlord => "body-npc-speech-biped_large-cultist_warlord",
56            Species::Cultistwarlock => "body-npc-speech-biped_large-cultist_warlock",
57            Species::Huskbrute => "body-npc-speech-biped_large-husk_brute",
58            Species::Gigasfrost => "body-npc-speech-biped_large-gigas_frost",
59            Species::AdletElder => "body-npc-speech-biped_large-adlet_elder",
60            Species::SeaBishop => "body-npc-speech-biped_large-sea_bishop",
61            Species::HaniwaGeneral => "body-npc-speech-biped_large-haniwa_general",
62            Species::TerracottaBesieger => "body-npc-speech-biped_large-terracotta_besieger",
63            Species::TerracottaDemolisher => "body-npc-speech-biped_large-terracotta_demolisher",
64            Species::TerracottaPunisher => "body-npc-speech-biped_large-terracotta_punisher",
65            Species::TerracottaPursuer => "body-npc-speech-biped_large-terracotta_pursuer",
66            Species::Cursekeeper => "body-npc-speech-biped_large-cursekeeper",
67            Species::Forgemaster => "body-npc-speech-biped_large-forgemaster",
68            Species::Strigoi => "body-npc-speech-biped_large-strigoi",
69            Species::Executioner => "body-npc-speech-biped_large-executioner",
70        };
71
72        Some(Content::localized(key))
73    }
74}
75
76impl From<Body> for super::Body {
77    fn from(body: Body) -> Self { super::Body::BipedLarge(body) }
78}
79
80enum_iter! {
81    ~const_array(ALL)
82    #[derive(
83        Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
84    #[repr(u32)]
85    pub enum Species {
86        Ogre = 0,
87        Cyclops = 1,
88        Wendigo = 2,
89        Cavetroll = 3,
90        Mountaintroll = 4,
91        Swamptroll = 5,
92        Dullahan = 6,
93        Werewolf = 7,
94        Occultsaurok = 8,
95        Mightysaurok = 9,
96        Slysaurok = 10,
97        Mindflayer = 11,
98        Minotaur = 12,
99        Tidalwarrior = 13,
100        Yeti = 14,
101        Harvester = 15,
102        Blueoni = 16,
103        Redoni = 17,
104        Cultistwarlord = 18,
105        Cultistwarlock = 19,
106        Huskbrute = 20,
107        Tursus = 21,
108        Gigasfrost = 22,
109        AdletElder = 23,
110        SeaBishop = 24,
111        HaniwaGeneral = 25,
112        TerracottaBesieger = 26,
113        TerracottaDemolisher = 27,
114        TerracottaPunisher = 28,
115        TerracottaPursuer = 29,
116        Cursekeeper = 30,
117        Forgemaster = 31,
118        Strigoi = 32,
119        Executioner = 33,
120    }
121}
122
123/// Data representing per-species generic data.
124#[derive(Clone, Debug, Deserialize, Serialize)]
125pub struct AllSpecies<SpeciesMeta> {
126    pub ogre: SpeciesMeta,
127    pub cyclops: SpeciesMeta,
128    pub wendigo: SpeciesMeta,
129    pub troll_cave: SpeciesMeta,
130    pub troll_mountain: SpeciesMeta,
131    pub troll_swamp: SpeciesMeta,
132    pub dullahan: SpeciesMeta,
133    pub werewolf: SpeciesMeta,
134    pub saurok_occult: SpeciesMeta,
135    pub saurok_mighty: SpeciesMeta,
136    pub saurok_sly: SpeciesMeta,
137    pub mindflayer: SpeciesMeta,
138    pub minotaur: SpeciesMeta,
139    pub tidalwarrior: SpeciesMeta,
140    pub yeti: SpeciesMeta,
141    pub harvester: SpeciesMeta,
142    pub oni_blue: SpeciesMeta,
143    pub oni_red: SpeciesMeta,
144    pub cultist_warlord: SpeciesMeta,
145    pub cultist_warlock: SpeciesMeta,
146    pub husk_brute: SpeciesMeta,
147    pub tursus: SpeciesMeta,
148    pub gigas_frost: SpeciesMeta,
149    pub adlet_elder: SpeciesMeta,
150    pub sea_bishop: SpeciesMeta,
151    pub haniwa_general: SpeciesMeta,
152    pub terracotta_besieger: SpeciesMeta,
153    pub terracotta_demolisher: SpeciesMeta,
154    pub terracotta_punisher: SpeciesMeta,
155    pub terracotta_pursuer: SpeciesMeta,
156    pub cursekeeper: SpeciesMeta,
157    pub forgemaster: SpeciesMeta,
158    pub strigoi: SpeciesMeta,
159    pub executioner: SpeciesMeta,
160}
161
162impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
163    type Output = SpeciesMeta;
164
165    #[inline]
166    fn index(&self, &index: &'a Species) -> &Self::Output {
167        match index {
168            Species::Ogre => &self.ogre,
169            Species::Cyclops => &self.cyclops,
170            Species::Wendigo => &self.wendigo,
171            Species::Cavetroll => &self.troll_cave,
172            Species::Mountaintroll => &self.troll_mountain,
173            Species::Swamptroll => &self.troll_swamp,
174            Species::Dullahan => &self.dullahan,
175            Species::Werewolf => &self.werewolf,
176            Species::Occultsaurok => &self.saurok_occult,
177            Species::Mightysaurok => &self.saurok_mighty,
178            Species::Slysaurok => &self.saurok_sly,
179            Species::Mindflayer => &self.mindflayer,
180            Species::Minotaur => &self.minotaur,
181            Species::Tidalwarrior => &self.tidalwarrior,
182            Species::Yeti => &self.yeti,
183            Species::Harvester => &self.harvester,
184            Species::Blueoni => &self.oni_blue,
185            Species::Redoni => &self.oni_red,
186            Species::Cultistwarlord => &self.cultist_warlord,
187            Species::Cultistwarlock => &self.cultist_warlock,
188            Species::Huskbrute => &self.husk_brute,
189            Species::Tursus => &self.tursus,
190            Species::Gigasfrost => &self.gigas_frost,
191            Species::AdletElder => &self.adlet_elder,
192            Species::SeaBishop => &self.sea_bishop,
193            Species::HaniwaGeneral => &self.haniwa_general,
194            Species::TerracottaBesieger => &self.terracotta_besieger,
195            Species::TerracottaDemolisher => &self.terracotta_demolisher,
196            Species::TerracottaPunisher => &self.terracotta_punisher,
197            Species::TerracottaPursuer => &self.terracotta_pursuer,
198            Species::Cursekeeper => &self.cursekeeper,
199            Species::Forgemaster => &self.forgemaster,
200            Species::Strigoi => &self.strigoi,
201            Species::Executioner => &self.executioner,
202        }
203    }
204}
205
206pub const ALL_SPECIES: [Species; Species::NUM_KINDS] = Species::ALL;
207
208impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
209    type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;
210    type Item = Species;
211
212    fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
213}
214
215enum_iter! {
216    ~const_array(ALL)
217    #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
218    #[repr(u32)]
219    pub enum BodyType {
220        Female = 0,
221        Male = 1,
222    }
223}
224pub const ALL_BODY_TYPES: [BodyType; BodyType::NUM_KINDS] = BodyType::ALL;