veloren_common/comp/body/
biped_small.rs

1use common_base::{enum_iter, struct_iter};
2use rand::{prelude::IndexedRandom, 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 = 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::RngExt, &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::BipedSmall(body) }
30}
31
32enum_iter! {
33    ~const_array(ALL)
34    #[derive(
35        Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
36    #[repr(u32)]
37    pub enum Species {
38        Gnome = 0,
39        Sahagin = 1,
40        Adlet = 2,
41        Gnarling = 3,
42        Mandragora = 4,
43        Kappa = 5,
44        Cactid = 6,
45        Gnoll = 7,
46        Haniwa = 8,
47        Myrmidon = 9,
48        Husk = 10,
49        Boreal = 11,
50        Bushly = 12,
51        Irrwurz = 13,
52        IronDwarf = 14,
53        Flamekeeper = 15,
54        ShamanicSpirit = 16,
55        Jiangshi = 17,
56        TreasureEgg = 18,
57        GnarlingChieftain = 19,
58        BloodmoonHeiress = 20,
59        Bloodservant = 21,
60        Harlequin = 22,
61        GoblinThug = 23,
62        GoblinChucker = 24,
63        GoblinRuffian = 25,
64        GreenLegoom = 26,
65        OchreLegoom = 27,
66        PurpleLegoom = 28,
67        RedLegoom = 29,
68        Ashen = 30,
69        UmberLegoom = 31,
70    }
71}
72
73/// Data representing per-species generic data.
74#[derive(Clone, Debug, Deserialize, Serialize)]
75pub struct AllSpecies<SpeciesMeta> {
76    pub gnome: SpeciesMeta,
77    pub sahagin: SpeciesMeta,
78    pub adlet: SpeciesMeta,
79    pub gnarling: SpeciesMeta,
80    pub mandragora: SpeciesMeta,
81    pub kappa: SpeciesMeta,
82    pub cactid: SpeciesMeta,
83    pub gnoll: SpeciesMeta,
84    pub haniwa: SpeciesMeta,
85    pub myrmidon: SpeciesMeta,
86    pub husk: SpeciesMeta,
87    pub boreal: SpeciesMeta,
88    pub bushly: SpeciesMeta,
89    pub irrwurz: SpeciesMeta,
90    pub iron_dwarf: SpeciesMeta,
91    pub flamekeeper: SpeciesMeta,
92    pub shamanic_spirit: SpeciesMeta,
93    pub jiangshi: SpeciesMeta,
94    pub treasure_egg: SpeciesMeta,
95    pub gnarling_chieftain: SpeciesMeta,
96    pub bloodmoon_heiress: SpeciesMeta,
97    pub bloodservant: SpeciesMeta,
98    pub harlequin: SpeciesMeta,
99    pub goblin_thug: SpeciesMeta,
100    pub goblin_chucker: SpeciesMeta,
101    pub goblin_ruffian: SpeciesMeta,
102    pub green_legoom: SpeciesMeta,
103    pub ochre_legoom: SpeciesMeta,
104    pub purple_legoom: SpeciesMeta,
105    pub red_legoom: SpeciesMeta,
106    pub ashen: SpeciesMeta,
107    pub umber_legoom: SpeciesMeta,
108}
109
110impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
111    type Output = SpeciesMeta;
112
113    #[inline]
114    fn index(&self, &index: &'a Species) -> &Self::Output {
115        match index {
116            Species::Gnome => &self.gnome,
117            Species::Sahagin => &self.sahagin,
118            Species::Adlet => &self.adlet,
119            Species::Gnarling => &self.gnarling,
120            Species::Mandragora => &self.mandragora,
121            Species::Kappa => &self.kappa,
122            Species::Cactid => &self.cactid,
123            Species::Gnoll => &self.gnoll,
124            Species::Haniwa => &self.haniwa,
125            Species::Myrmidon => &self.myrmidon,
126            Species::Husk => &self.husk,
127            Species::Boreal => &self.boreal,
128            Species::Bushly => &self.bushly,
129            Species::Irrwurz => &self.irrwurz,
130            Species::IronDwarf => &self.iron_dwarf,
131            Species::Flamekeeper => &self.flamekeeper,
132            Species::ShamanicSpirit => &self.shamanic_spirit,
133            Species::Jiangshi => &self.jiangshi,
134            Species::TreasureEgg => &self.treasure_egg,
135            Species::GnarlingChieftain => &self.gnarling_chieftain,
136            Species::BloodmoonHeiress => &self.bloodmoon_heiress,
137            Species::Bloodservant => &self.bloodservant,
138            Species::Harlequin => &self.harlequin,
139            Species::GoblinThug => &self.goblin_thug,
140            Species::GoblinChucker => &self.goblin_chucker,
141            Species::GoblinRuffian => &self.goblin_ruffian,
142            Species::GreenLegoom => &self.green_legoom,
143            Species::OchreLegoom => &self.ochre_legoom,
144            Species::PurpleLegoom => &self.purple_legoom,
145            Species::RedLegoom => &self.red_legoom,
146            Species::Ashen => &self.ashen,
147            Species::UmberLegoom => &self.umber_legoom,
148        }
149    }
150}
151
152pub const ALL_SPECIES: [Species; Species::NUM_KINDS] = Species::ALL;
153
154impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
155    type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;
156    type Item = Species;
157
158    fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
159}
160
161enum_iter! {
162    ~const_array(ALL)
163    #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, EnumString, Display)]
164    #[repr(u32)]
165    pub enum BodyType {
166        Female = 0,
167        Male = 1,
168    }
169}
170pub const ALL_BODY_TYPES: [BodyType; BodyType::NUM_KINDS] = BodyType::ALL;