Kill outcomes: falling hull, breakup or air detonation by weapon and target, recorded for replays (#97)
build / mod (push) Successful in 3m54s
build / mod (push) Successful in 3m54s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -168,8 +168,9 @@ pub struct Track {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum EventKind {
|
||||
/// A drone shot down: by which system (its index then), with a missile or the guns.
|
||||
Kill { drone: u32, kind: DroneKind, sam: u32, sam_kind: SamKind, sam_index: usize, missile: Option<u32> },
|
||||
/// A drone shot down: by which system (its index then), with a missile or the guns, and how it ended
|
||||
/// (rolled once, live; a replay reads it and never rolls).
|
||||
Kill { drone: u32, kind: DroneKind, sam: u32, sam_kind: SamKind, sam_index: usize, missile: Option<u32>, outcome: Outcome },
|
||||
/// A drone's warhead went off where it aimed: at an object, a system, or the land.
|
||||
Hit { drone: u32, kind: DroneKind, power: u32, object: Option<usize>, sam: Option<(SamKind, usize)> },
|
||||
/// A system destroyed.
|
||||
@@ -331,8 +332,8 @@ pub struct ReplayFire {
|
||||
/// The look of an interception by the drone's warhead: (fireball radius, ticks it burns, loudness).
|
||||
/// A bare decoy pops; a big warhead lights the sky. The same in the live raid and its replay.
|
||||
pub fn kill_look(kind: DroneKind) -> (f32, u32, f32) {
|
||||
let w = kind.spec().warhead.min(8) as f32;
|
||||
(3.5 * (0.85 + 0.12 * w), (8 + (w as u32) / 2) * 9, 1.0 + 0.06 * w)
|
||||
let (size, life, gain, _) = outcome::look(kind, Outcome::DisabledFalling);
|
||||
(size, life, gain)
|
||||
}
|
||||
|
||||
/// A blast's look for an event: (fireball radius, ticks it burns). The live blasts use the same.
|
||||
@@ -340,8 +341,8 @@ pub fn blast_spec(kind: EventKind) -> (f32, u32) {
|
||||
const SIZE: [f32; 5] = [2.5, 4.5, 7.0, 10.0, 13.0];
|
||||
const LIFE: [u32; 5] = [11, 11, 18, 22, 26];
|
||||
match kind {
|
||||
EventKind::Kill { kind, .. } => {
|
||||
let (size, life, _) = kill_look(kind);
|
||||
EventKind::Kill { kind, outcome, .. } => {
|
||||
let (size, life, _, _) = outcome::look(kind, outcome);
|
||||
(size, life)
|
||||
}
|
||||
EventKind::Hit { power, .. } | EventKind::Crash { power, .. } => {
|
||||
@@ -581,6 +582,7 @@ impl Sim {
|
||||
|
||||
/// Draws the recording's drones and interceptors as they were at `t`, as ghosts: ids from `base`.
|
||||
pub fn draw_ghosts(&self, rec: &Recording, t: f64, base: u32, out: &mut Out) {
|
||||
let base_id = base;
|
||||
for (k, tr) in rec.tracks.iter().enumerate() {
|
||||
let Some(pos) = tr.at(rec.origin, t) else { continue };
|
||||
let dir = tr.dir(rec.origin, t);
|
||||
@@ -660,6 +662,31 @@ impl Sim {
|
||||
out.particles("minecraft:large_smoke", f.at + DVec3::Y, 0.8, DVec3::new(0.0, 0.1, 0.0), 0.03, 1 + (smoke * 2.0) as u32);
|
||||
}
|
||||
}
|
||||
// The pieces a breakup or an air detonation threw off, from the recorded outcome (never a new roll): the same
|
||||
// pieces the live raid made, moved by the same flight, a pure function of the time.
|
||||
for (k, e) in rec.events.iter().enumerate() {
|
||||
let EventKind::Kill { drone, outcome, .. } = e.kind else { continue };
|
||||
let age = t - e.at as f64;
|
||||
if outcome == Outcome::DisabledFalling || !(0.0..outcome::PIECE_LIFE as f64).contains(&age) {
|
||||
continue;
|
||||
}
|
||||
let base = rec
|
||||
.track(drone)
|
||||
.and_then(|tr| Some((tr.at(rec.origin, e.at as f64)? - tr.at(rec.origin, e.at as f64 - STEP as f64)?) / STEP as f64))
|
||||
.unwrap_or(DVec3::ZERO);
|
||||
let seed = (k as u64).wrapping_mul(0x2545_f491_4f6c_dd1d) ^ e.at as u64;
|
||||
for (n, p) in outcome::pieces(seed, outcome, base).iter().enumerate() {
|
||||
if age as u32 >= p.life {
|
||||
continue;
|
||||
}
|
||||
let at = outcome::piece_at(e.pos, p, age as u32);
|
||||
let id = base_id + 0x0060_0000 + (k as u32 * 16 + n as u32) * PARTS;
|
||||
out.model(id, "airdef:debris", at, outcome::piece_rot(p, age as u32), p.scale, false);
|
||||
if p.burns && (age as u32) % 3 == 0 {
|
||||
out.particles("minecraft:large_smoke", at, 0.1, DVec3::new(0.0, 0.03, 0.0), 0.01, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Blasts: with the shader effects on, the post pass and the HD lights draw them from
|
||||
// `replay_blasts` (the same as the live ones); the models are the fallback without them.
|
||||
if self.shader {
|
||||
@@ -793,4 +820,46 @@ mod tests {
|
||||
assert_eq!(r.world_tick(50.0), Some(1040 + 10));
|
||||
assert_eq!(r.world_tick(70.0), Some(1100 + 10));
|
||||
}
|
||||
|
||||
// #97: the kill's outcome is a recorded fact: a replay draws the pieces of that outcome and rolls nothing;
|
||||
// an event without one (an old recording) is the plain fall it always was.
|
||||
#[test]
|
||||
fn a_replay_shows_the_recorded_outcome() {
|
||||
let mut sim = Sim::new(5);
|
||||
sim.rec = Some(Recording::new(1, &sim));
|
||||
let sam = sim.id();
|
||||
sim.sams.push(Sam::new(sam, SamKind::Patriot, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(0.0, 120.0, 300.0), DVec3::X, DVec3::new(900.0, 70.0, 0.0));
|
||||
let at = sim.drones[0].pos;
|
||||
let live = sim.shoot_down_by(0, sam, None, Impact::missile(MissileKind::M77n6, at, 6.0), &mut Out::default()).unwrap();
|
||||
let rec = sim.rec.take().unwrap();
|
||||
let recorded = rec.events.iter().find_map(|e| if let EventKind::Kill { outcome, .. } = e.kind { Some(outcome) } else { None });
|
||||
assert_eq!(recorded, Some(live), "the live outcome is what was recorded");
|
||||
let pieces = |rec: &Recording, t: f64| {
|
||||
let mut out = Out::default();
|
||||
sim.draw_ghosts(rec, t, 0x5000_0000, &mut out);
|
||||
out.models.iter().filter(|m| m.name == "airdef:debris").count()
|
||||
};
|
||||
let at_tick = rec.events[0].at as f64;
|
||||
// The same frame twice is the same (a pure function of the time), and the pieces are the outcome's.
|
||||
let mut forced = Recording { events: rec.events.clone(), ..Recording::blank(200) };
|
||||
for (outcome, want) in [(Outcome::AirDetonation, true), (Outcome::Breakup, true), (Outcome::DisabledFalling, false)] {
|
||||
if let EventKind::Kill { outcome: o, .. } = &mut forced.events[0].kind {
|
||||
*o = outcome;
|
||||
}
|
||||
assert_eq!(pieces(&forced, at_tick + 5.0), pieces(&forced, at_tick + 5.0));
|
||||
assert_eq!(pieces(&forced, at_tick + 5.0) > 0, want, "{outcome:?}");
|
||||
assert_eq!(pieces(&forced, at_tick + f64::from(outcome::PIECE_LIFE) + 1.0), 0, "the pieces are gone in time");
|
||||
}
|
||||
// Its flash and sound are the outcome's too.
|
||||
let spec = |o| {
|
||||
let mut e = rec.events[0];
|
||||
if let EventKind::Kill { outcome, .. } = &mut e.kind {
|
||||
*outcome = o;
|
||||
}
|
||||
blast_spec(e.kind)
|
||||
};
|
||||
assert!(spec(Outcome::AirDetonation).0 > spec(Outcome::DisabledFalling).0);
|
||||
assert_eq!(spec(Outcome::default()).0, kill_look(DroneKind::Shahed).0, "an old recording looks as it did");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user