veloren_common/comp/body/
theropod.rs1use rand::{seq::SliceRandom, thread_rng};
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
5pub struct Body {
6 pub species: Species,
7 pub body_type: BodyType,
8}
9
10impl Body {
11 pub fn random() -> Self {
12 let mut rng = thread_rng();
13 let species = *ALL_SPECIES.choose(&mut rng).unwrap();
14 Self::random_with(&mut rng, &species)
15 }
16
17 #[inline]
18 pub fn random_with(rng: &mut impl rand::Rng, &species: &Species) -> Self {
19 let body_type = *ALL_BODY_TYPES.choose(rng).unwrap();
20 Self { species, body_type }
21 }
22}
23
24impl From<Body> for super::Body {
25 fn from(body: Body) -> Self { super::Body::Theropod(body) }
26}
27
28#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
29#[repr(u32)]
30pub enum Species {
31 Archaeos = 0,
32 Odonto = 1,
33 Sandraptor = 2,
34 Snowraptor = 3,
35 Woodraptor = 4,
36 Sunlizard = 5,
37 Yale = 6,
38 Ntouka = 7,
39 Dodarock = 8,
40 Axebeak = 9,
41}
42
43#[derive(Clone, Debug, Serialize, Deserialize)]
45pub struct AllSpecies<SpeciesMeta> {
46 pub archaeos: SpeciesMeta,
47 pub odonto: SpeciesMeta,
48 pub raptor_sand: SpeciesMeta,
49 pub raptor_snow: SpeciesMeta,
50 pub raptor_wood: SpeciesMeta,
51 pub sunlizard: SpeciesMeta,
52 pub yale: SpeciesMeta,
53 pub dodarock: SpeciesMeta,
54 pub ntouka: SpeciesMeta,
55 pub axebeak: SpeciesMeta,
56}
57
58impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies<SpeciesMeta> {
59 type Output = SpeciesMeta;
60
61 #[inline]
62 fn index(&self, &index: &'a Species) -> &Self::Output {
63 match index {
64 Species::Archaeos => &self.archaeos,
65 Species::Odonto => &self.odonto,
66 Species::Sandraptor => &self.raptor_sand,
67 Species::Snowraptor => &self.raptor_snow,
68 Species::Woodraptor => &self.raptor_wood,
69 Species::Sunlizard => &self.sunlizard,
70 Species::Yale => &self.yale,
71 Species::Dodarock => &self.dodarock,
72 Species::Ntouka => &self.ntouka,
73 Species::Axebeak => &self.axebeak,
74 }
75 }
76}
77
78pub const ALL_SPECIES: [Species; 10] = [
79 Species::Archaeos,
80 Species::Odonto,
81 Species::Sandraptor,
82 Species::Snowraptor,
83 Species::Woodraptor,
84 Species::Sunlizard,
85 Species::Yale,
86 Species::Dodarock,
87 Species::Ntouka,
88 Species::Axebeak,
89];
90
91impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies<SpeciesMeta> {
92 type IntoIter = std::iter::Copied<std::slice::Iter<'static, Self::Item>>;
93 type Item = Species;
94
95 fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() }
96}
97
98#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
99#[repr(u32)]
100pub enum BodyType {
101 Female = 0,
102 Male = 1,
103}
104pub const ALL_BODY_TYPES: [BodyType; 2] = [BodyType::Female, BodyType::Male];