veloren_common/comp/body/
biped_small.rs1use 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::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 }
69}
70
71#[derive(Clone, Debug, Deserialize, Serialize)]
73pub struct AllSpecies<SpeciesMeta> {
74 pub gnome: SpeciesMeta,
75 pub sahagin: SpeciesMeta,
76 pub adlet: SpeciesMeta,
77 pub gnarling: SpeciesMeta,
78 pub mandragora: SpeciesMeta,
79 pub kappa: SpeciesMeta,
80 pub cactid: SpeciesMeta,
81 pub gnoll: SpeciesMeta,
82 pub haniwa: SpeciesMeta,
83 pub myrmidon: SpeciesMeta,
84 pub husk: SpeciesMeta,
85 pub boreal: SpeciesMeta,
86 pub bushly: SpeciesMeta,
87 pub irrwurz: SpeciesMeta,
88 pub iron_dwarf: SpeciesMeta,
89 pub flamekeeper: SpeciesMeta,
90 pub shamanic_spirit: SpeciesMeta,
91 pub jiangshi: SpeciesMeta,
92 pub treasure_egg: SpeciesMeta,
93 pub gnarling_chieftain: SpeciesMeta,
94 pub bloodmoon_heiress: SpeciesMeta,
95 pub bloodservant: SpeciesMeta,
96 pub harlequin: SpeciesMeta,
97 pub goblin_thug: SpeciesMeta,
98 pub goblin_chucker: SpeciesMeta,
99 pub goblin_ruffian: SpeciesMeta,
100 pub green_legoom: SpeciesMeta,
101 pub ochre_legoom: SpeciesMeta,
102 pub purple_legoom: SpeciesMeta,
103 pub red_legoom: SpeciesMeta,
104}
105
106impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
107 type Output = SpeciesMeta;
108
109 #[inline]
110 fn index(&self, &index: &'a Species) -> &Self::Output {
111 match index {
112 Species::Gnome => &self.gnome,
113 Species::Sahagin => &self.sahagin,
114 Species::Adlet => &self.adlet,
115 Species::Gnarling => &self.gnarling,
116 Species::Mandragora => &self.mandragora,
117 Species::Kappa => &self.kappa,
118 Species::Cactid => &self.cactid,
119 Species::Gnoll => &self.gnoll,
120 Species::Haniwa => &self.haniwa,
121 Species::Myrmidon => &self.myrmidon,
122 Species::Husk => &self.husk,
123 Species::Boreal => &self.boreal,
124 Species::Bushly => &self.bushly,
125 Species::Irrwurz => &self.irrwurz,
126 Species::IronDwarf => &self.iron_dwarf,
127 Species::Flamekeeper => &self.flamekeeper,
128 Species::ShamanicSpirit => &self.shamanic_spirit,
129 Species::Jiangshi => &self.jiangshi,
130 Species::TreasureEgg => &self.treasure_egg,
131 Species::GnarlingChieftain => &self.gnarling_chieftain,
132 Species::BloodmoonHeiress => &self.bloodmoon_heiress,
133 Species::Bloodservant => &self.bloodservant,
134 Species::Harlequin => &self.harlequin,
135 Species::GoblinThug => &self.goblin_thug,
136 Species::GoblinChucker => &self.goblin_chucker,
137 Species::GoblinRuffian => &self.goblin_ruffian,
138 Species::GreenLegoom => &self.green_legoom,
139 Species::OchreLegoom => &self.ochre_legoom,
140 Species::PurpleLegoom => &self.purple_legoom,
141 Species::RedLegoom => &self.red_legoom,
142 }
143 }
144}
145
146pub const ALL_SPECIES: [Species; Species::NUM_KINDS] = Species::ALL;
147
148impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
149 type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;
150 type Item = Species;
151
152 fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
153}
154
155enum_iter! {
156 ~const_array(ALL)
157 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, EnumString, Display)]
158 #[repr(u32)]
159 pub enum BodyType {
160 Female = 0,
161 Male = 1,
162 }
163}
164pub const ALL_BODY_TYPES: [BodyType; BodyType::NUM_KINDS] = BodyType::ALL;