1use crate::{
2 comp::{Density, Mass},
3 consts::{AIR_DENSITY, IRON_DENSITY, WATER_DENSITY},
4};
5use common_base::enum_iter;
6use rand::{seq::SliceRandom, thread_rng};
7use serde::{Deserialize, Serialize};
8use vek::Vec3;
9
10enum_iter! {
11 ~const_array(ALL)
12 #[derive(
13 Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
14 )]
15 #[repr(u32)]
16 pub enum Body {
17 Arrow = 0,
18 Bomb = 1,
19 Scarecrow = 2,
20 Pumpkin = 3,
21 Campfire = 4,
22 BoltFire = 5,
23 ArrowSnake = 6,
24 CampfireLit = 7,
25 BoltFireBig = 8,
26 TrainingDummy = 9,
27 FireworkBlue = 10,
28 FireworkGreen = 11,
29 FireworkPurple = 12,
30 FireworkRed = 13,
31 FireworkWhite = 14,
32 FireworkYellow = 15,
33 MultiArrow = 16,
34 BoltNature = 17,
35 ToughMeat = 18,
36 BeastMeat = 19,
37 Crossbow = 20,
38 ArrowTurret = 21,
39 ClayRocket = 22,
40 HaniwaSentry = 23,
41 SeaLantern = 24,
42 Snowball = 25,
43 Tornado = 26,
44 Apple = 27,
45 Hive = 28,
46 Coconut = 29,
47 SpitPoison = 30,
48 BoltIcicle = 31,
49 Dart = 32,
50 GnarlingTotemRed = 33,
51 GnarlingTotemGreen = 34,
52 GnarlingTotemWhite = 35,
53 DagonBomb = 36,
54 BarrelOrgan = 37,
55 IceBomb = 38,
56 SpectralSwordSmall = 39,
57 SpectralSwordLarge = 40,
58 LaserBeam = 41,
59 AdletSpear = 42,
60 AdletTrap = 43,
61 Flamethrower = 44,
62 Mine = 45,
63 LightningBolt = 46,
64 SpearIcicle = 47,
65 Portal = 48,
66 PortalActive = 49,
67 FieryTornado = 50,
68 FireRainDrop = 51,
69 ArrowClay = 52,
70 GrenadeClay = 53,
71 Pebble = 54,
72 LaserBeamSmall = 55,
73 TerracottaStatue = 56,
74 TerracottaDemolisherBomb = 57,
75 BoltBesieger = 58,
76 SurpriseEgg = 59,
77 BubbleBomb = 60,
78 IronPikeBomb = 61,
79 Lavathrower = 62,
80 PoisonBall = 63,
81 StrigoiHead = 64,
82 HarlequinDagger = 65,
83 BloodBomb = 66,
84 MinotaurAxe = 67,
85 BorealTrap = 68,
86 Crux = 69,
87 }
88}
89
90impl Body {
91 pub fn random() -> Self {
92 let mut rng = thread_rng();
93 *ALL_OBJECTS.choose(&mut rng).unwrap()
94 }
95}
96
97pub const ALL_OBJECTS: [Body; Body::NUM_KINDS] = Body::ALL;
98
99impl From<Body> for super::Body {
100 fn from(body: Body) -> Self { super::Body::Object(body) }
101}
102
103impl Body {
104 pub fn to_string(self) -> &'static str {
105 match self {
106 Body::Arrow => "arrow",
107 Body::Bomb => "bomb",
108 Body::Scarecrow => "scarecrow",
109 Body::Pumpkin => "pumpkin",
110 Body::Campfire => "campfire",
111 Body::CampfireLit => "campfire_lit",
112 Body::BoltFire => "bolt_fire",
113 Body::BoltFireBig => "bolt_fire_big",
114 Body::ArrowSnake => "arrow_snake",
115 Body::TrainingDummy => "training_dummy",
116 Body::FireworkBlue => "firework_blue",
117 Body::FireworkGreen => "firework_green",
118 Body::FireworkPurple => "firework_purple",
119 Body::FireworkRed => "firework_red",
120 Body::FireworkWhite => "firework_white",
121 Body::FireworkYellow => "firework_yellow",
122 Body::MultiArrow => "multi_arrow",
123 Body::BoltNature => "bolt_nature",
124 Body::ToughMeat => "tough_meat",
125 Body::BeastMeat => "beast_meat",
126 Body::Crossbow => "crossbow",
127 Body::ArrowTurret => "arrow_turret",
128 Body::ClayRocket => "clay_rocket",
129 Body::HaniwaSentry => "haniwa_sentry",
130 Body::SeaLantern => "sea_lantern",
131 Body::Snowball => "snowball",
132 Body::Tornado => "tornado",
133 Body::Apple => "apple",
134 Body::Hive => "hive",
135 Body::Coconut => "coconut",
136 Body::SpitPoison => "spit_poison",
137 Body::BoltIcicle => "bolt_icicle",
138 Body::Dart => "dart",
139 Body::GnarlingTotemRed => "gnarling_totem_red",
140 Body::GnarlingTotemGreen => "gnarling_totem_green",
141 Body::GnarlingTotemWhite => "gnarling_totem_white",
142 Body::DagonBomb => "dagon_bomb",
143 Body::TerracottaDemolisherBomb => "terracotta_demolisher_bomb",
144 Body::BarrelOrgan => "barrel_organ",
145 Body::IceBomb => "ice_bomb",
146 Body::SpectralSwordSmall => "spectral_sword_small",
147 Body::SpectralSwordLarge => "spectral_sword_large",
148 Body::LaserBeam => "laser_beam",
149 Body::LaserBeamSmall => "laser_beam_small",
150 Body::AdletSpear => "adlet_spear",
151 Body::AdletTrap => "adlet_trap",
152 Body::Flamethrower => "flamethrower",
153 Body::Lavathrower => "lavathrower",
154 Body::Mine => "mine",
155 Body::LightningBolt => "lightning_bolt",
156 Body::SpearIcicle => "spear_icicle",
157 Body::Portal => "portal",
158 Body::PortalActive => "portal_active",
159 Body::FieryTornado => "fiery_tornado",
160 Body::FireRainDrop => "fire_rain_drop",
161 Body::ArrowClay => "arrow_clay",
162 Body::GrenadeClay => "grenade_clay",
163 Body::Pebble => "pebble",
164 Body::TerracottaStatue => "terracotta_statue",
165 Body::BoltBesieger => "besieger_bolt",
166 Body::SurpriseEgg => "surprise_egg",
167 Body::BubbleBomb => "bubble_bomb",
168 Body::IronPikeBomb => "iron_pike_bomb",
169 Body::PoisonBall => "poison_ball",
170 Body::StrigoiHead => "strigoi_head",
171 Body::HarlequinDagger => "harlequin_dagger",
172 Body::BloodBomb => "blood_bomb",
173 Body::MinotaurAxe => "minotaur_axe",
174 Body::BorealTrap => "boreal_trap",
175 Body::Crux => "crux",
176 }
177 }
178
179 pub fn density(&self) -> Density {
180 let density = match self {
181 Body::Arrow
182 | Body::ArrowSnake
183 | Body::ArrowTurret
184 | Body::MultiArrow
185 | Body::ArrowClay
186 | Body::BoltBesieger
187 | Body::Dart
188 | Body::DagonBomb
189 | Body::TerracottaDemolisherBomb
190 | Body::SpectralSwordSmall
191 | Body::SpectralSwordLarge
192 | Body::AdletSpear
193 | Body::HarlequinDagger
194 | Body::AdletTrap
195 | Body::Flamethrower
196 | Body::Lavathrower
197 | Body::BorealTrap
198 | Body::BloodBomb => 500.0,
199 Body::Bomb | Body::Mine | Body::SurpriseEgg => 2000.0, Body::Scarecrow => 900.0,
202 Body::TrainingDummy => 2000.0,
203 Body::Snowball => 0.9 * WATER_DENSITY,
204 Body::Pebble => 1000.0,
205 Body::Crux => AIR_DENSITY,
206 _ => 1.1 * WATER_DENSITY,
208 };
209
210 Density(density)
211 }
212
213 pub fn mass(&self) -> Mass {
214 let m = match self {
215 Body::Arrow | Body::ArrowSnake | Body::ArrowTurret | Body::MultiArrow | Body::Dart => {
217 0.003
218 },
219 Body::SpectralSwordSmall => 0.5,
220 Body::SpectralSwordLarge => 50.0,
221 Body::BoltFire
222 | Body::BoltFireBig
223 | Body::BoltNature
224 | Body::BoltIcicle
225 | Body::FireRainDrop
226 | Body::ArrowClay
227 | Body::Pebble
228 | Body::BubbleBomb
229 | Body::IronPikeBomb
230 | Body::BoltBesieger
231 | Body::PoisonBall => 1.0,
232 Body::SpitPoison => 100.0,
233 Body::Bomb
234 | Body::DagonBomb
235 | Body::SurpriseEgg
236 | Body::TerracottaDemolisherBomb
237 | Body::BloodBomb => {
238 0.5 * IRON_DENSITY * std::f32::consts::PI / 6.0 * self.dimensions().x.powi(3)
239 },
240 Body::Campfire | Body::CampfireLit | Body::BarrelOrgan | Body::TerracottaStatue => {
241 300.0
242 },
243 Body::Crossbow => 200.0,
244 Body::Flamethrower | Body::Lavathrower => 200.0,
245 Body::FireworkBlue
246 | Body::FireworkGreen
247 | Body::FireworkPurple
248 | Body::FireworkRed
249 | Body::FireworkWhite
250 | Body::FireworkYellow => 1.0,
251 Body::ToughMeat => 50.0,
252 Body::BeastMeat => 50.0,
253 Body::Pumpkin | Body::StrigoiHead => 10.0,
254 Body::Scarecrow => 50.0,
255 Body::TrainingDummy => 60.0,
256 Body::ClayRocket | Body::GrenadeClay => 50.0,
257 Body::HaniwaSentry => 300.0,
258 Body::SeaLantern => 1000.0,
259 Body::MinotaurAxe => 100000.0,
260 Body::Snowball => 7360.0, Body::Tornado | Body::FieryTornado => 50.0,
262 Body::Apple => 2.0,
263 Body::Hive => 2.0,
264 Body::Coconut => 2.0,
265 Body::GnarlingTotemRed | Body::GnarlingTotemGreen | Body::GnarlingTotemWhite => 100.0,
266 Body::IceBomb => 12298.0, Body::LaserBeam | Body::LaserBeamSmall => 80000.0,
268 Body::AdletSpear => 1.5,
269 Body::AdletTrap => 10.0,
270 Body::Mine => 100.0,
271 Body::HarlequinDagger => 1.5,
272 Body::BorealTrap => 10.0,
273 Body::LightningBolt | Body::SpearIcicle => 20000.0,
274 Body::Portal | Body::PortalActive => 10.0, Body::Crux => 100.0,
276 };
277
278 Mass(m)
279 }
280
281 pub fn dimensions(&self) -> Vec3<f32> {
282 match self {
283 Body::Arrow
284 | Body::ArrowSnake
285 | Body::MultiArrow
286 | Body::ArrowTurret
287 | Body::ArrowClay
288 | Body::BoltBesieger
289 | Body::Dart
290 | Body::HarlequinDagger
291 | Body::AdletSpear => Vec3::new(0.01, 0.8, 0.01),
292 Body::AdletTrap => Vec3::new(1.0, 0.6, 0.3),
293 Body::BoltFire | Body::PoisonBall => Vec3::new(0.1, 0.1, 0.1),
294 Body::SpectralSwordSmall => Vec3::new(0.2, 0.9, 0.1),
295 Body::SpectralSwordLarge => Vec3::new(0.2, 1.5, 0.1),
296 Body::Crossbow => Vec3::new(3.0, 3.0, 1.5),
297 Body::Flamethrower => Vec3::new(3.0, 3.0, 2.5),
298 Body::Lavathrower => Vec3::new(3.0, 3.0, 2.0),
299 Body::HaniwaSentry => Vec3::new(0.8, 0.8, 1.4),
300 Body::SeaLantern => Vec3::new(0.8, 0.8, 1.4),
301 Body::Snowball => Vec3::broadcast(2.5),
302 Body::Tornado | Body::FieryTornado => Vec3::new(2.0, 2.0, 3.4),
303 Body::TrainingDummy => Vec3::new(1.5, 1.5, 3.0),
304 Body::BorealTrap => Vec3::new(1.0, 0.6, 0.3),
305 Body::GnarlingTotemRed | Body::GnarlingTotemGreen | Body::GnarlingTotemWhite => {
306 Vec3::new(0.8, 0.8, 1.4)
307 },
308 Body::BarrelOrgan => Vec3::new(4.0, 2.0, 3.0),
309 Body::TerracottaStatue => Vec3::new(5.0, 5.0, 5.0),
310 Body::IceBomb => Vec3::broadcast(2.5),
311 Body::LaserBeam => Vec3::new(8.0, 8.0, 8.0),
312 Body::LaserBeamSmall => Vec3::new(1.0, 1.0, 1.0),
313 Body::Mine => Vec3::new(0.8, 0.8, 0.5),
314 Body::LightningBolt | Body::SpearIcicle => Vec3::new(1.0, 1.0, 1.0),
315 Body::FireRainDrop => Vec3::new(0.01, 0.01, 0.02),
316 Body::Pebble => Vec3::new(0.4, 0.4, 0.4),
317 Body::MinotaurAxe => Vec3::new(5.0, 5.0, 5.0),
318 Body::Crux => Vec3::new(2.0, 2.0, 2.0),
319 _ => Vec3::broadcast(0.5),
321 }
322 }
323}