Raid replays: recording, raid map, event clips, full replay, highlight reel
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ use std::collections::HashMap;
|
||||
|
||||
mod damage;
|
||||
mod raid;
|
||||
pub mod record;
|
||||
mod sight;
|
||||
pub use raid::{Approach, Aim, RaidOrder};
|
||||
|
||||
@@ -686,6 +687,15 @@ struct MissileSpec {
|
||||
}
|
||||
|
||||
impl MissileKind {
|
||||
/// The sound of its launch.
|
||||
pub fn launch_sound(self) -> &'static str {
|
||||
match self {
|
||||
MissileKind::Pac3 => "airdef:launch.patriot",
|
||||
MissileKind::M57e6 => "airdef:launch.pantsir",
|
||||
MissileKind::M48n6 => "airdef:launch.s400_eject",
|
||||
MissileKind::M77n6 => "airdef:launch.s500_eject",
|
||||
}
|
||||
}
|
||||
fn spec(self) -> &'static MissileSpec {
|
||||
match self {
|
||||
MissileKind::Pac3 => &MissileSpec {
|
||||
@@ -1112,6 +1122,10 @@ pub struct Sim {
|
||||
pub target_health: Vec<f64>,
|
||||
/// The raid in progress, for its report.
|
||||
wave: Option<raid::WaveStats>,
|
||||
/// The raid being recorded, the last ones recorded, and how many have been.
|
||||
rec: Option<record::Recording>,
|
||||
pub replays: Vec<record::Recording>,
|
||||
recordings: u32,
|
||||
}
|
||||
|
||||
/// Ids: objects get multiples of 16, their parts the low bits.
|
||||
@@ -1141,6 +1155,9 @@ impl Sim {
|
||||
queue: Vec::new(),
|
||||
target_health: Vec::new(),
|
||||
wave: None,
|
||||
rec: None,
|
||||
replays: Vec::new(),
|
||||
recordings: 0,
|
||||
}
|
||||
}
|
||||
pub fn id(&mut self) -> u32 {
|
||||
@@ -1240,6 +1257,7 @@ impl Sim {
|
||||
self.draw_targets(out);
|
||||
self.step_wrecks(out);
|
||||
self.report_wave(out);
|
||||
self.record();
|
||||
let now = self.tick;
|
||||
self.blasts.retain(|b| now - b.start < b.life as u64);
|
||||
}
|
||||
@@ -1252,6 +1270,9 @@ impl Sim {
|
||||
let mut removed: Vec<u32> = Vec::new();
|
||||
// Oreshnik pieces released this tick: kind, at, velocity, target.
|
||||
let mut released: Vec<(DroneKind, DVec3, DVec3, DVec3)> = Vec::new();
|
||||
// Warheads that reached their aim (for the replays): drone, kind, where, TNT; and splits.
|
||||
let mut impacts: Vec<(u32, DroneKind, DVec3, u32)> = Vec::new();
|
||||
let mut splits: Vec<(u32, DVec3)> = Vec::new();
|
||||
for d in &mut self.drones {
|
||||
d.age += 1;
|
||||
let spec = d.kind.spec();
|
||||
@@ -1295,6 +1316,7 @@ impl Sim {
|
||||
|| d.age > 4000;
|
||||
if hit {
|
||||
boom.push((d.pos, spec.warhead, false));
|
||||
impacts.push((d.id, d.kind, d.pos, spec.warhead));
|
||||
removed.push(d.id);
|
||||
self.hits += 1;
|
||||
continue;
|
||||
@@ -1318,6 +1340,7 @@ impl Sim {
|
||||
released.push((piece, d.pos + v.normalize_or_zero() * (i as f64 * 0.3), v, aim));
|
||||
}
|
||||
out.sound("airdef:boom.sonic", d.pos, 1.0, 0.7);
|
||||
splits.push((d.id, d.pos));
|
||||
// Its pieces count as launched instead of it.
|
||||
self.launched += 5;
|
||||
out.particles("minecraft:firework", d.pos, 1.5, DVec3::ZERO, 0.3, 40);
|
||||
@@ -1393,6 +1416,9 @@ impl Sim {
|
||||
let in_ground = below.is_some_and(|g| d.pos.y <= g + 0.2);
|
||||
if at_target || in_ground || d.age > 8000 {
|
||||
boom.push((d.pos, spec.warhead, spec.decoy));
|
||||
if !spec.decoy {
|
||||
impacts.push((d.id, d.kind, d.pos, spec.warhead));
|
||||
}
|
||||
removed.push(d.id);
|
||||
if !spec.decoy {
|
||||
self.hits += 1;
|
||||
@@ -1417,6 +1443,21 @@ impl Sim {
|
||||
out.sound(event, d.pos, 1.0, pitch);
|
||||
}
|
||||
}
|
||||
for (drone, pos) in splits {
|
||||
self.log(pos, record::EventKind::Split { drone });
|
||||
}
|
||||
for (drone, kind, pos, tnt) in impacts {
|
||||
let power = match tnt {
|
||||
0 => 0,
|
||||
1 | 2 => 1,
|
||||
3..=5 => 2,
|
||||
6 | 7 => 3,
|
||||
_ => 4,
|
||||
};
|
||||
let object = self.targets.iter().position(|t| t.distance(pos) < 16.0);
|
||||
let sam = self.sams.iter().enumerate().find(|(_, s)| s.alive() && s.pos.distance(pos) < 12.0).map(|(i, s)| (s.kind, i));
|
||||
self.log(pos, record::EventKind::Hit { drone, kind, power, object, sam });
|
||||
}
|
||||
for (pos, warhead, small) in boom {
|
||||
self.explode(pos, warhead, small, ground, player, out);
|
||||
}
|
||||
@@ -1546,11 +1587,16 @@ impl Sim {
|
||||
}
|
||||
|
||||
/// A drone hit by air defence: a flash, pieces, and it falls burning.
|
||||
fn shoot_down(&mut self, idx: usize, by: u32, out: &mut Out) {
|
||||
let d = &mut self.drones[idx];
|
||||
if !d.alive() {
|
||||
fn shoot_down(&mut self, idx: usize, by: u32, missile: Option<u32>, out: &mut Out) {
|
||||
if !self.drones[idx].alive() {
|
||||
return;
|
||||
}
|
||||
if let Some((i, s)) = self.sams.iter().enumerate().find(|(_, s)| s.id == by) {
|
||||
let (drone, kind, pos) = (self.drones[idx].id, self.drones[idx].kind, self.drones[idx].pos);
|
||||
let kill = record::EventKind::Kill { drone, kind, sam: by, sam_kind: s.kind, sam_index: i, missile };
|
||||
self.log(pos, kill);
|
||||
}
|
||||
let d = &mut self.drones[idx];
|
||||
d.flight = Flight::Falling;
|
||||
d.age = 0;
|
||||
d.vel = d.vel * 0.6 + DVec3::new(0.0, 0.15, 0.0);
|
||||
@@ -1798,7 +1844,7 @@ impl Sim {
|
||||
}
|
||||
for (t, by) in gun_hits {
|
||||
if let Some(i) = self.drones.iter().position(|d| d.id == t) {
|
||||
self.shoot_down(i, by, out);
|
||||
self.shoot_down(i, by, None, out);
|
||||
}
|
||||
}
|
||||
for i in 0..self.sams.len() {
|
||||
@@ -1950,7 +1996,7 @@ impl Sim {
|
||||
if let Some(t) = target.and_then(|t| self.drones.iter().position(|d| d.id == t)) {
|
||||
self.drones[t].engaged = self.drones[t].engaged.saturating_sub(1);
|
||||
if kill {
|
||||
self.shoot_down(t, sam, out);
|
||||
self.shoot_down(t, sam, Some(mid), out);
|
||||
}
|
||||
}
|
||||
// A missile that lost its target frees it for others.
|
||||
|
||||
Reference in New Issue
Block a user