Skip to main content

ob_game/
dudes.rs

1//! Enemy ("dude") definitions. Values are OpenBlood's own tuning, chosen to play close
2//! to the original; animation sets are resolved from the SEQ names in BLOOD.RFF.
3
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum Attack {
6    /// Harmless (innocents).
7    None,
8    Melee {
9        damage: i32,
10        range: f64,
11    },
12    /// Instant bullets: damage per pellet, pellets, spread (fraction of unit vector).
13    Hitscan {
14        damage: i32,
15        pellets: i32,
16        spread: f64,
17        range: f64,
18    },
19    Projectile {
20        kind: ProjKind,
21        range: f64,
22    },
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum ProjKind {
27    Flare,
28    Fireball,
29    Napalm,
30    Tesla,
31    Bone,
32    Puke,
33    Tnt,
34    Leech,
35}
36
37#[derive(Debug, Clone, Copy)]
38pub struct DudeInfo {
39    pub seq_base: u32,
40    pub health: i32,
41    /// Movement speed in xy units per second.
42    pub speed: f64,
43    pub radius: f64,
44    pub height: f64,
45    pub flying: bool,
46    pub attack: Attack,
47    /// Seconds between attacks.
48    pub cooldown: f64,
49    /// Base ids of sound groups (spot, pain, die); 0 = none. Each group has 3 variants.
50    pub spot_sound: i32,
51    pub pain_sound: i32,
52    pub die_sound: i32,
53    pub attack_sound: i32,
54    /// Chance (0..1) that a hit interrupts the dude.
55    pub recoil_chance: f64,
56}
57
58/// Dude speeds below are relative values. The scale makes the E4M9 axe zombies close in at
59/// the ~1700 units/s measured in DOSBox recordings (frame-by-frame size matching against
60/// renders at known distances).
61const SPEED_SCALE: f64 = 1.5;
62
63const fn d(seq_base: u32, health: i32, speed: f64, radius: f64, attack: Attack) -> DudeInfo {
64    DudeInfo {
65        seq_base,
66        health,
67        speed: speed * SPEED_SCALE,
68        radius,
69        height: 0x3000 as f64,
70        flying: false,
71        attack,
72        cooldown: 1.2,
73        spot_sound: 0,
74        pain_sound: 0,
75        die_sound: 0,
76        attack_sound: 0,
77        recoil_chance: 0.5,
78    }
79}
80
81pub fn dude_info(t: i16) -> Option<DudeInfo> {
82    use Attack::*;
83    let melee = |damage, range| Melee { damage, range };
84    let mut i = match t {
85        201 => DudeInfo {
86            cooldown: 0.6,
87            spot_sound: 1003,
88            pain_sound: 1013,
89            die_sound: 1018,
90            attack_sound: 1031,
91            ..d(
92                4096,
93                40,
94                700.0,
95                64.0,
96                Hitscan {
97                    damage: 4,
98                    pellets: 1,
99                    spread: 0.04,
100                    range: 12000.0,
101                },
102            )
103        },
104        202 => DudeInfo {
105            cooldown: 1.4,
106            spot_sound: 1003,
107            pain_sound: 1013,
108            die_sound: 1018,
109            attack_sound: 411,
110            ..d(
111                4096,
112                40,
113                700.0,
114                64.0,
115                Hitscan {
116                    damage: 4,
117                    pellets: 7, // up to 28 per blast measured in DOSBox (E2M4 bar)
118                    spread: 0.08,
119                    range: 8000.0,
120                },
121            )
122        },
123        230 => DudeInfo {
124            spot_sound: 1003,
125            pain_sound: 1013,
126            die_sound: 1018,
127            attack_sound: 1031,
128            cooldown: 0.6,
129            ..d(
130                11520,
131                40,
132                0.0,
133                64.0,
134                Hitscan {
135                    damage: 4,
136                    pellets: 1,
137                    spread: 0.04,
138                    range: 12000.0,
139                },
140            )
141        },
142        246 => DudeInfo {
143            spot_sound: 1003,
144            pain_sound: 1013,
145            die_sound: 1018,
146            attack_sound: 411,
147            ..d(
148                11520,
149                40,
150                0.0,
151                64.0,
152                Hitscan {
153                    damage: 4,
154                    pellets: 7,
155                    spread: 0.08,
156                    range: 8000.0,
157                },
158            )
159        },
160        247 => DudeInfo {
161            spot_sound: 4003,
162            pain_sound: 4013,
163            die_sound: 4018,
164            attack_sound: 470,
165            ..d(
166                12800,
167                60,
168                700.0,
169                64.0,
170                Projectile {
171                    kind: ProjKind::Tesla,
172                    range: 10000.0,
173                },
174            )
175        },
176        248 => DudeInfo {
177            spot_sound: 4003,
178            pain_sound: 4013,
179            die_sound: 4018,
180            attack_sound: 455,
181            cooldown: 2.0,
182            ..d(
183                13056,
184                50,
185                700.0,
186                64.0,
187                Projectile {
188                    kind: ProjKind::Tnt,
189                    range: 6000.0,
190                },
191            )
192        },
193        249 => DudeInfo {
194            spot_sound: 4003,
195            pain_sound: 4013,
196            die_sound: 4018,
197            ..d(
198                13312,
199                60,
200                700.0,
201                64.0,
202                Hitscan {
203                    damage: 4,
204                    pellets: 6,
205                    spread: 0.08,
206                    range: 8000.0,
207                },
208            )
209        },
210        203 | 205 | 244 => DudeInfo {
211            spot_sound: 1103,
212            pain_sound: 1106,
213            die_sound: 1107,
214            attack_sound: 1101,
215            // Speed, damage and swing rate measured against the original (E4M9 start: hits at
216            // 4.2, 5.0, 5.6, 6.7, 7.5 s after the level appears; death 7.5 s on skill 2).
217            cooldown: 2.2,
218            ..d(4352, 60, 1150.0, 64.0, melee(18, 220.0))
219        },
220        204 => DudeInfo {
221            spot_sound: 1200,
222            pain_sound: 1202,
223            die_sound: 1204,
224            attack_sound: 1207,
225            recoil_chance: 0.3,
226            ..d(4608, 100, 450.0, 80.0, melee(16, 240.0))
227        },
228        206 | 208 => DudeInfo {
229            flying: true,
230            spot_sound: 1400,
231            pain_sound: 1402,
232            die_sound: 1403,
233            attack_sound: 1406,
234            ..d(4864, 110, 900.0, 64.0, melee(20, 260.0))
235        },
236        207 | 209 => DudeInfo {
237            flying: true,
238            spot_sound: 1450,
239            pain_sound: 1452,
240            die_sound: 1453,
241            attack_sound: 1457,
242            recoil_chance: 0.2,
243            ..d(
244                5120,
245                200,
246                800.0,
247                72.0,
248                Projectile {
249                    kind: ProjKind::Fireball,
250                    range: 9000.0,
251                },
252            )
253        },
254        210 => DudeInfo {
255            flying: true,
256            spot_sound: 1600,
257            pain_sound: 1602,
258            die_sound: 1603,
259            ..d(5376, 100, 900.0, 64.0, melee(20, 240.0))
260        },
261        211 => DudeInfo {
262            spot_sound: 1300,
263            pain_sound: 1302,
264            die_sound: 1303,
265            attack_sound: 1306,
266            ..d(5632, 70, 1200.0, 64.0, melee(14, 240.0))
267        },
268        212 => DudeInfo {
269            height: 0x1000 as f64,
270            spot_sound: 1900,
271            pain_sound: 1902,
272            die_sound: 1903,
273            ..d(5888, 10, 900.0, 32.0, melee(3, 160.0))
274        },
275        213 => DudeInfo {
276            height: 0x1000 as f64,
277            spot_sound: 1800,
278            pain_sound: 1802,
279            die_sound: 1803,
280            ..d(6144, 10, 1000.0, 32.0, melee(3, 160.0))
281        },
282        214 => DudeInfo {
283            height: 0x1000 as f64,
284            spot_sound: 1800,
285            pain_sound: 1802,
286            die_sound: 1803,
287            ..d(6400, 25, 1000.0, 32.0, melee(5, 160.0))
288        },
289        215 => DudeInfo {
290            height: 0x1400 as f64,
291            spot_sound: 1800,
292            pain_sound: 1802,
293            die_sound: 1803,
294            ..d(6656, 75, 1000.0, 48.0, melee(8, 180.0))
295        },
296        216 => DudeInfo {
297            height: 0x2000 as f64,
298            spot_sound: 1853,
299            pain_sound: 1851,
300            die_sound: 1850,
301            recoil_chance: 0.1,
302            ..d(6912, 300, 700.0, 96.0, melee(14, 260.0))
303        },
304        217 => DudeInfo {
305            spot_sound: 1700,
306            pain_sound: 1702,
307            die_sound: 1703,
308            ..d(7168, 70, 700.0, 64.0, melee(12, 220.0))
309        },
310        218 => DudeInfo {
311            flying: true,
312            spot_sound: 1500,
313            pain_sound: 1502,
314            die_sound: 1503,
315            ..d(7424, 30, 800.0, 48.0, melee(8, 200.0))
316        },
317        219 => DudeInfo {
318            flying: true,
319            height: 0x1000 as f64,
320            spot_sound: 2000,
321            pain_sound: 2002,
322            die_sound: 2003,
323            ..d(7680, 10, 1000.0, 32.0, melee(3, 160.0))
324        },
325        220 => DudeInfo {
326            height: 0x0c00 as f64,
327            spot_sound: 2100,
328            pain_sound: 2102,
329            die_sound: 2103,
330            ..d(7936, 5, 900.0, 24.0, melee(2, 140.0))
331        },
332        221 | 223 | 225 => DudeInfo {
333            spot_sound: 2201,
334            pain_sound: 2200,
335            die_sound: 2203,
336            recoil_chance: 0.0,
337            ..d(
338                8192 + 512 * ((t - 221) / 2) as u32,
339                50,
340                0.0,
341                48.0,
342                Projectile {
343                    kind: ProjKind::Puke,
344                    range: 8000.0,
345                },
346            )
347        },
348        222 | 224 | 226 => DudeInfo {
349            spot_sound: 2201,
350            pain_sound: 2200,
351            die_sound: 2203,
352            recoil_chance: 0.0,
353            ..d(8448 + 512 * ((t - 222) / 2) as u32, 50, 0.0, 48.0, melee(10, 280.0))
354        },
355        227 => DudeInfo {
356            spot_sound: 2300,
357            pain_sound: 2302,
358            die_sound: 2304,
359            attack_sound: 1309,
360            recoil_chance: 0.05,
361            ..d(
362                9728,
363                600,
364                700.0,
365                128.0,
366                Projectile {
367                    kind: ProjKind::Fireball,
368                    range: 10000.0,
369                },
370            )
371        },
372        228 => DudeInfo {
373            spot_sound: 2300,
374            pain_sound: 2302,
375            die_sound: 2304,
376            attack_sound: 1309,
377            recoil_chance: 0.05,
378            ..d(
379                9984,
380                300,
381                700.0,
382                128.0,
383                Projectile {
384                    kind: ProjKind::Fireball,
385                    range: 10000.0,
386                },
387            )
388        },
389        229 => DudeInfo {
390            spot_sound: 2360,
391            pain_sound: 2370,
392            die_sound: 2380,
393            recoil_chance: 0.0,
394            ..d(
395                10240,
396                2000,
397                400.0,
398                160.0,
399                Projectile {
400                    kind: ProjKind::Fireball,
401                    range: 12000.0,
402                },
403            )
404        },
405        245 => DudeInfo {
406            spot_sound: 7007,
407            pain_sound: 7007,
408            die_sound: 7008,
409            ..d(12544, 10, 600.0, 64.0, None)
410        },
411        250 => DudeInfo {
412            height: 0x1800 as f64,
413            ..d(13568, 10, 700.0, 32.0, melee(2, 160.0))
414        },
415        251 => DudeInfo {
416            recoil_chance: 0.1,
417            ..d(10496, 500, 800.0, 96.0, melee(30, 300.0))
418        },
419        _ => return Option::None,
420    };
421    if i.height == 0.0 {
422        i.height = 0x3000 as f64;
423    }
424    Some(i)
425}
426
427pub fn is_dude(t: i16) -> bool {
428    (200..=254).contains(&t) && !(231..=238).contains(&t)
429}
430
431#[cfg(test)]
432mod tests {
433    use super::*;
434
435    #[test]
436    fn table_covers_common_dudes() {
437        for t in [201, 202, 203, 204, 206, 207, 211, 213, 217, 219, 220, 227, 245] {
438            let i = dude_info(t).expect("missing dude");
439            assert!(i.health > 0 && i.seq_base >= 4096);
440        }
441        assert!(dude_info(231).is_none());
442        assert!(is_dude(201) && !is_dude(231));
443    }
444}