feat: add shared radar batteries and animated cold launch
build / mod (push) Failing after 18s

Separate search and engagement roles, support launcher-only SAMs, animate individual tube lids and delay ground strike spending until ejection. Preserve battery configuration and launch poses in saves and replay.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
2026-11-02 23:40:40 +03:00
parent d4adbb1e47
commit 966b52f9fc
41 changed files with 2534 additions and 509 deletions
+45 -2
View File
@@ -23,6 +23,11 @@ pub struct SamKey {
/// Hull and component health at the sampled tick.
health: f32,
parts: [f32; 6],
mode: battery::SamMode,
radar_role: battery::RadarRole,
spent_cells: u8,
cap_cell: u8,
cap_open: f32,
}
impl SamKey {
@@ -38,6 +43,11 @@ impl SamKey {
beam: if sam.beam_on { ((sam.beam_free / 8.0).round() * 8.0).max(8.0) as f32 } else { 0.0 },
health: sam.health as f32,
parts: sam.comps.0.map(|v| v as f32),
mode: sam.mode,
radar_role: sam.radar_role,
spent_cells: sam.spent_cells,
cap_cell: sam.cap_cell,
cap_open: sam.cap_open,
}
}
/// The same pose (to within what could be seen).
@@ -51,6 +61,9 @@ impl SamKey {
&& self.beam == o.beam
&& self.health == o.health
&& self.parts == o.parts
&& self.mode == o.mode && self.radar_role == o.radar_role
&& self.spent_cells == o.spent_cells && self.cap_cell == o.cap_cell
&& near(self.cap_open, o.cap_open, 0.001)
}
}
@@ -93,6 +106,11 @@ impl SamTrack {
beam: a.beam,
health: a.health,
parts: a.parts,
mode: a.mode,
radar_role: a.radar_role,
spent_cells: a.spent_cells,
cap_cell: a.cap_cell,
cap_open: if a.cap_cell == b.cap_cell && a.spent_cells == b.spent_cells { l(a.cap_open, b.cap_open) } else { a.cap_open },
})
}
/// The system as it stood at `t`, as a ghost to draw with the ids from `id`.
@@ -107,6 +125,11 @@ impl SamTrack {
sam.beam_free = k.beam as f64;
sam.health = if self.lost.is_some_and(|l| t >= l as f64) { 0.0 } else { k.health as f64 };
sam.comps = Comps(k.parts.map(|v| v as f64));
sam.mode = k.mode;
sam.radar_role = k.radar_role;
sam.spent_cells = k.spent_cells;
sam.cap_cell = k.cap_cell;
sam.cap_open = k.cap_open;
Some(sam)
}
}
@@ -757,7 +780,7 @@ impl Sim {
/// Open before the combat update so transitions on the first active tick are not lost.
pub(super) fn begin_recording_if_active(&mut self) {
if self.rec.is_none() && (self.drones.iter().any(|d| d.alive()) || !self.strikes.flights.is_empty()) {
if self.rec.is_none() && (self.drones.iter().any(|d| d.alive()) || !self.strikes.flights.is_empty() || !self.strikes.pending.is_empty()) {
self.recordings += 1;
self.rec = Some(Recording::new(self.recordings, self));
}
@@ -775,7 +798,7 @@ impl Sim {
pub(super) fn record(&mut self) {
// Wrecks still falling (far off they fall a long while) don't keep it going. A counter-strike is a recorded
// object in its own right (#109): it holds the recording open until it lands, whatever the sky is doing.
let busy = self.drones.iter().any(|d| d.alive()) || !self.missiles.is_empty() || !self.queue.is_empty() || !self.strikes.flights.is_empty();
let busy = self.drones.iter().any(|d| d.alive()) || !self.missiles.is_empty() || !self.queue.is_empty() || !self.strikes.flights.is_empty() || !self.strikes.pending.is_empty();
self.begin_recording_if_active();
let Some(r) = &mut self.rec else { return };
r.note_tracks(&self.sams);
@@ -1006,6 +1029,26 @@ mod tests {
}
}
#[test]
fn replay_preserves_launcher_configuration_and_individual_cover_poses() {
let mut r = recording();
let mut sam = sam_at(0.0, 0.0, 0.0);
sam.set_mode(battery::SamMode::LauncherOnly);
sam.cap_cell = 2;
sam.cap_open = 0.5;
sam.spent_cells = 1;
r.note_sams(&[sam], 10);
for t in [10.0, 40.0, 10.0] {
let ghost = r.sam_tracks[0].ghost(r.origin, t, 160).unwrap();
assert_eq!(ghost.mode, battery::SamMode::LauncherOnly);
assert_eq!((ghost.spent_cells, ghost.cap_cell, ghost.cap_open), (1, 2, 0.5));
let mut out = Out::default();
units::draw_sam_model(&ghost, &mut Rng::new(1), &mut out);
assert_eq!(out.models.iter().filter(|m| m.name == "airdef:tpk_cap").count(), 4);
assert!(!out.models.iter().any(|m| m.name == "airdef:radar_panel"));
}
}
fn physical_strike(record_len: Option<u32>) -> (Sim, u32, DVec3) {
use crate::sim::sites::{LaunchSite, SiteClass};
use crate::sim::strike::{Estimate, Known, SiteState};