1use crate::{
2 comp::{Density, Mass, item::Reagent},
3 consts::{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 }
87}
88
89impl Body {
90 pub fn random() -> Self {
91 let mut rng = thread_rng();
92 *ALL_OBJECTS.choose(&mut rng).unwrap()
93 }
94}
95
96pub const ALL_OBJECTS: [Body; Body::NUM_KINDS] = Body::ALL;
97
98impl From<Body> for super::Body {
99 fn from(body: Body) -> Self { super::Body::Object(body) }
100}
101
102impl Body {
103 pub fn to_string(self) -> &'static str {
104 match self {
105 Body::Arrow => "arrow",
106 Body::Bomb => "bomb",
107 Body::Scarecrow => "scarecrow",
108 Body::Pumpkin => "pumpkin",
109 Body::Campfire => "campfire",
110 Body::CampfireLit => "campfire_lit",
111 Body::BoltFire => "bolt_fire",
112 Body::BoltFireBig => "bolt_fire_big",
113 Body::ArrowSnake => "arrow_snake",
114 Body::TrainingDummy => "training_dummy",
115 Body::FireworkBlue => "firework_blue",
116 Body::FireworkGreen => "firework_green",
117 Body::FireworkPurple => "firework_purple",
118 Body::FireworkRed => "firework_red",
119 Body::FireworkWhite => "firework_white",
120 Body::FireworkYellow => "firework_yellow",
121 Body::MultiArrow => "multi_arrow",
122 Body::BoltNature => "bolt_nature",
123 Body::ToughMeat => "tough_meat",
124 Body::BeastMeat => "beast_meat",
125 Body::Crossbow => "crossbow",
126 Body::ArrowTurret => "arrow_turret",
127 Body::ClayRocket => "clay_rocket",
128 Body::HaniwaSentry => "haniwa_sentry",
129 Body::SeaLantern => "sea_lantern",
130 Body::Snowball => "snowball",
131 Body::Tornado => "tornado",
132 Body::Apple => "apple",
133 Body::Hive => "hive",
134 Body::Coconut => "coconut",
135 Body::SpitPoison => "spit_poison",
136 Body::BoltIcicle => "bolt_icicle",
137 Body::Dart => "dart",
138 Body::GnarlingTotemRed => "gnarling_totem_red",
139 Body::GnarlingTotemGreen => "gnarling_totem_green",
140 Body::GnarlingTotemWhite => "gnarling_totem_white",
141 Body::DagonBomb => "dagon_bomb",
142 Body::TerracottaDemolisherBomb => "terracotta_demolisher_bomb",
143 Body::BarrelOrgan => "barrel_organ",
144 Body::IceBomb => "ice_bomb",
145 Body::SpectralSwordSmall => "spectral_sword_small",
146 Body::SpectralSwordLarge => "spectral_sword_large",
147 Body::LaserBeam => "laser_beam",
148 Body::LaserBeamSmall => "laser_beam_small",
149 Body::AdletSpear => "adlet_spear",
150 Body::AdletTrap => "adlet_trap",
151 Body::Flamethrower => "flamethrower",
152 Body::Lavathrower => "lavathrower",
153 Body::Mine => "mine",
154 Body::LightningBolt => "lightning_bolt",
155 Body::SpearIcicle => "spear_icicle",
156 Body::Portal => "portal",
157 Body::PortalActive => "portal_active",
158 Body::FieryTornado => "fiery_tornado",
159 Body::FireRainDrop => "fire_rain_drop",
160 Body::ArrowClay => "arrow_clay",
161 Body::GrenadeClay => "grenade_clay",
162 Body::Pebble => "pebble",
163 Body::TerracottaStatue => "terracotta_statue",
164 Body::BoltBesieger => "besieger_bolt",
165 Body::SurpriseEgg => "surprise_egg",
166 Body::BubbleBomb => "bubble_bomb",
167 Body::IronPikeBomb => "iron_pike_bomb",
168 Body::PoisonBall => "poison_ball",
169 Body::StrigoiHead => "strigoi_head",
170 Body::HarlequinDagger => "harlequin_dagger",
171 Body::BloodBomb => "blood_bomb",
172 Body::MinotaurAxe => "minotaur_axe",
173 Body::BorealTrap => "boreal_trap",
174 }
175 }
176
177 pub fn for_firework(reagent: Reagent) -> Body {
178 match reagent {
179 Reagent::Blue => Body::FireworkBlue,
180 Reagent::Green => Body::FireworkGreen,
181 Reagent::Purple => Body::FireworkPurple,
182 Reagent::Red => Body::FireworkRed,
183 Reagent::White => Body::FireworkWhite,
184 Reagent::Yellow => Body::FireworkYellow,
185 Reagent::Phoenix => Body::FireRainDrop,
186 }
187 }
188
189 pub fn density(&self) -> Density {
190 let density = match self {
191 Body::Arrow
192 | Body::ArrowSnake
193 | Body::ArrowTurret
194 | Body::MultiArrow
195 | Body::ArrowClay
196 | Body::BoltBesieger
197 | Body::Dart
198 | Body::DagonBomb
199 | Body::TerracottaDemolisherBomb
200 | Body::SpectralSwordSmall
201 | Body::SpectralSwordLarge
202 | Body::AdletSpear
203 | Body::HarlequinDagger
204 | Body::AdletTrap
205 | Body::Flamethrower
206 | Body::Lavathrower
207 | Body::BorealTrap
208 | Body::BloodBomb => 500.0,
209 Body::Bomb | Body::Mine | Body::SurpriseEgg => 2000.0, Body::Scarecrow => 900.0,
212 Body::TrainingDummy => 2000.0,
213 Body::Snowball => 0.9 * WATER_DENSITY,
214 Body::Pebble => 1000.0,
215 _ => 1.1 * WATER_DENSITY,
217 };
218
219 Density(density)
220 }
221
222 pub fn mass(&self) -> Mass {
223 let m = match self {
224 Body::Arrow | Body::ArrowSnake | Body::ArrowTurret | Body::MultiArrow | Body::Dart => {
226 0.003
227 },
228 Body::SpectralSwordSmall => 0.5,
229 Body::SpectralSwordLarge => 50.0,
230 Body::BoltFire
231 | Body::BoltFireBig
232 | Body::BoltNature
233 | Body::BoltIcicle
234 | Body::FireRainDrop
235 | Body::ArrowClay
236 | Body::Pebble
237 | Body::BubbleBomb
238 | Body::IronPikeBomb
239 | Body::BoltBesieger
240 | Body::PoisonBall => 1.0,
241 Body::SpitPoison => 100.0,
242 Body::Bomb
243 | Body::DagonBomb
244 | Body::SurpriseEgg
245 | Body::TerracottaDemolisherBomb
246 | Body::BloodBomb => {
247 0.5 * IRON_DENSITY * std::f32::consts::PI / 6.0 * self.dimensions().x.powi(3)
248 },
249 Body::Campfire | Body::CampfireLit | Body::BarrelOrgan | Body::TerracottaStatue => {
250 300.0
251 },
252 Body::Crossbow => 200.0,
253 Body::Flamethrower | Body::Lavathrower => 200.0,
254 Body::FireworkBlue
255 | Body::FireworkGreen
256 | Body::FireworkPurple
257 | Body::FireworkRed
258 | Body::FireworkWhite
259 | Body::FireworkYellow => 1.0,
260 Body::ToughMeat => 50.0,
261 Body::BeastMeat => 50.0,
262 Body::Pumpkin | Body::StrigoiHead => 10.0,
263 Body::Scarecrow => 50.0,
264 Body::TrainingDummy => 60.0,
265 Body::ClayRocket | Body::GrenadeClay => 50.0,
266 Body::HaniwaSentry => 300.0,
267 Body::SeaLantern => 1000.0,
268 Body::MinotaurAxe => 100000.0,
269 Body::Snowball => 7360.0, Body::Tornado | Body::FieryTornado => 50.0,
271 Body::Apple => 2.0,
272 Body::Hive => 2.0,
273 Body::Coconut => 2.0,
274 Body::GnarlingTotemRed | Body::GnarlingTotemGreen | Body::GnarlingTotemWhite => 100.0,
275 Body::IceBomb => 12298.0, Body::LaserBeam | Body::LaserBeamSmall => 80000.0,
277 Body::AdletSpear => 1.5,
278 Body::AdletTrap => 10.0,
279 Body::Mine => 100.0,
280 Body::HarlequinDagger => 1.5,
281 Body::BorealTrap => 10.0,
282 Body::LightningBolt | Body::SpearIcicle => 20000.0,
283 Body::Portal | Body::PortalActive => 10., };
285
286 Mass(m)
287 }
288
289 pub fn dimensions(&self) -> Vec3<f32> {
290 match self {
291 Body::Arrow
292 | Body::ArrowSnake
293 | Body::MultiArrow
294 | Body::ArrowTurret
295 | Body::ArrowClay
296 | Body::BoltBesieger
297 | Body::Dart
298 | Body::HarlequinDagger
299 | Body::AdletSpear => Vec3::new(0.01, 0.8, 0.01),
300 Body::AdletTrap => Vec3::new(1.0, 0.6, 0.3),
301 Body::BoltFire | Body::PoisonBall => Vec3::new(0.1, 0.1, 0.1),
302 Body::SpectralSwordSmall => Vec3::new(0.2, 0.9, 0.1),
303 Body::SpectralSwordLarge => Vec3::new(0.2, 1.5, 0.1),
304 Body::Crossbow => Vec3::new(3.0, 3.0, 1.5),
305 Body::Flamethrower => Vec3::new(3.0, 3.0, 2.5),
306 Body::Lavathrower => Vec3::new(3.0, 3.0, 2.0),
307 Body::HaniwaSentry => Vec3::new(0.8, 0.8, 1.4),
308 Body::SeaLantern => Vec3::new(0.8, 0.8, 1.4),
309 Body::Snowball => Vec3::broadcast(2.5),
310 Body::Tornado | Body::FieryTornado => Vec3::new(2.0, 2.0, 3.4),
311 Body::TrainingDummy => Vec3::new(1.5, 1.5, 3.0),
312 Body::BorealTrap => Vec3::new(1.0, 0.6, 0.3),
313 Body::GnarlingTotemRed | Body::GnarlingTotemGreen | Body::GnarlingTotemWhite => {
314 Vec3::new(0.8, 0.8, 1.4)
315 },
316 Body::BarrelOrgan => Vec3::new(4.0, 2.0, 3.0),
317 Body::TerracottaStatue => Vec3::new(5.0, 5.0, 5.0),
318 Body::IceBomb => Vec3::broadcast(2.5),
319 Body::LaserBeam => Vec3::new(8.0, 8.0, 8.0),
320 Body::LaserBeamSmall => Vec3::new(1.0, 1.0, 1.0),
321 Body::Mine => Vec3::new(0.8, 0.8, 0.5),
322 Body::LightningBolt | Body::SpearIcicle => Vec3::new(1.0, 1.0, 1.0),
323 Body::FireRainDrop => Vec3::new(0.01, 0.01, 0.02),
324 Body::Pebble => Vec3::new(0.4, 0.4, 0.4),
325 Body::MinotaurAxe => Vec3::new(5.0, 5.0, 5.0),
326 _ => Vec3::broadcast(0.5),
328 }
329 }
330}