veloren_common/comp/body/
quadruped_medium.rs

1use common_base::{enum_iter, struct_iter};
2use rand::{seq::SliceRandom, thread_rng};
3use serde::{Deserialize, Serialize};
4use strum::{Display, EnumString};
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
28impl From<Body> for super::Body {
29    fn from(body: Body) -> Self { super::Body::QuadrupedMedium(body) }
30}
31
32// Renaming any enum entries here (re-ordering is fine) will require a
33// database migration to ensure pets correctly de-serialize on player login.
34enum_iter! {
35    ~const_array(ALL)
36    #[derive(
37        Copy,
38        Clone,
39        Debug,
40        Display,
41        EnumString,
42        PartialEq,
43        Eq,
44        PartialOrd,
45        Ord,
46        Hash,
47        Serialize,
48        Deserialize,
49    )]
50    #[repr(u32)]
51    pub enum Species {
52        Grolgar = 0,
53        Saber = 1,
54        Tiger = 2,
55        Tuskram = 3,
56        Lion = 6,
57        Tarasque = 7,
58        Wolf = 8,
59        Frostfang = 9,
60        Mouflon = 10,
61        Catoblepas = 11,
62        Bonerattler = 12,
63        Deer = 13,
64        Hirdrasil = 14,
65        Roshwalr = 15,
66        Donkey = 16,
67        Camel = 17,
68        Zebra = 18,
69        Antelope = 19,
70        Kelpie = 20,
71        Horse = 21,
72        Barghest = 22,
73        Cattle = 23,
74        Darkhound = 24,
75        Highland = 25,
76        Yak = 26,
77        Panda = 27,
78        Bear = 28,
79        Dreadhorn = 29,
80        Moose = 30,
81        Snowleopard = 31,
82        Mammoth = 32,
83        Ngoubou = 33,
84        Llama = 34,
85        Alpaca = 35,
86        Akhlut = 36,
87        Bristleback = 37,
88        ClaySteed = 38,
89    }
90}
91
92/// Data representing per-species generic data.
93#[derive(Clone, Debug, Deserialize, Serialize)]
94pub struct AllSpecies<SpeciesMeta> {
95    pub grolgar: SpeciesMeta,
96    pub saber: SpeciesMeta,
97    pub tiger: SpeciesMeta,
98    pub tuskram: SpeciesMeta,
99    pub lion: SpeciesMeta,
100    pub tarasque: SpeciesMeta,
101    pub wolf: SpeciesMeta,
102    pub frostfang: SpeciesMeta,
103    pub mouflon: SpeciesMeta,
104    pub catoblepas: SpeciesMeta,
105    pub bonerattler: SpeciesMeta,
106    pub deer: SpeciesMeta,
107    pub hirdrasil: SpeciesMeta,
108    pub roshwalr: SpeciesMeta,
109    pub donkey: SpeciesMeta,
110    pub camel: SpeciesMeta,
111    pub zebra: SpeciesMeta,
112    pub antelope: SpeciesMeta,
113    pub kelpie: SpeciesMeta,
114    pub horse: SpeciesMeta,
115    pub barghest: SpeciesMeta,
116    pub cattle: SpeciesMeta,
117    pub darkhound: SpeciesMeta,
118    pub highland: SpeciesMeta,
119    pub yak: SpeciesMeta,
120    pub panda: SpeciesMeta,
121    pub bear: SpeciesMeta,
122    pub dreadhorn: SpeciesMeta,
123    pub moose: SpeciesMeta,
124    pub snowleopard: SpeciesMeta,
125    pub mammoth: SpeciesMeta,
126    pub ngoubou: SpeciesMeta,
127    pub llama: SpeciesMeta,
128    pub alpaca: SpeciesMeta,
129    pub akhlut: SpeciesMeta,
130    pub bristleback: SpeciesMeta,
131    pub claysteed: SpeciesMeta,
132}
133
134impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
135    type Output = SpeciesMeta;
136
137    #[inline]
138    fn index(&self, &index: &'a Species) -> &Self::Output {
139        match index {
140            Species::Grolgar => &self.grolgar,
141            Species::Saber => &self.saber,
142            Species::Tiger => &self.tiger,
143            Species::Tuskram => &self.tuskram,
144            Species::Lion => &self.lion,
145            Species::Tarasque => &self.tarasque,
146            Species::Wolf => &self.wolf,
147            Species::Frostfang => &self.frostfang,
148            Species::Mouflon => &self.mouflon,
149            Species::Catoblepas => &self.catoblepas,
150            Species::Bonerattler => &self.bonerattler,
151            Species::Deer => &self.deer,
152            Species::Hirdrasil => &self.hirdrasil,
153            Species::Roshwalr => &self.roshwalr,
154            Species::Donkey => &self.donkey,
155            Species::Camel => &self.camel,
156            Species::Zebra => &self.zebra,
157            Species::Antelope => &self.antelope,
158            Species::Kelpie => &self.kelpie,
159            Species::Horse => &self.horse,
160            Species::Barghest => &self.barghest,
161            Species::Cattle => &self.cattle,
162            Species::Darkhound => &self.darkhound,
163            Species::Highland => &self.highland,
164            Species::Yak => &self.yak,
165            Species::Panda => &self.panda,
166            Species::Bear => &self.bear,
167            Species::Dreadhorn => &self.dreadhorn,
168            Species::Moose => &self.moose,
169            Species::Snowleopard => &self.snowleopard,
170            Species::Mammoth => &self.mammoth,
171            Species::Ngoubou => &self.ngoubou,
172            Species::Llama => &self.llama,
173            Species::Alpaca => &self.alpaca,
174            Species::Akhlut => &self.akhlut,
175            Species::Bristleback => &self.bristleback,
176            Species::ClaySteed => &self.claysteed,
177        }
178    }
179}
180
181pub const ALL_SPECIES: [Species; Species::NUM_KINDS] = Species::ALL;
182
183impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
184    type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;
185    type Item = Species;
186
187    fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
188}
189
190// Renaming any enum entries here (re-ordering is fine) will require a
191// database migration to ensure pets correctly de-serialize on player login.
192enum_iter! {
193    ~const_array(ALL)
194    #[derive(
195        Copy,
196        Clone,
197        Debug,
198        Display,
199        EnumString,
200        PartialEq,
201        Eq,
202        PartialOrd,
203        Ord,
204        Hash,
205        Serialize,
206        Deserialize,
207    )]
208    #[repr(u32)]
209    pub enum BodyType {
210        Female = 0,
211        Male = 1,
212    }
213}
214pub const ALL_BODY_TYPES: [BodyType; BodyType::NUM_KINDS] = BodyType::ALL;