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
+43 -5
View File
@@ -9,6 +9,8 @@
use glam::{DQuat, DVec3};
use std::collections::HashMap;
pub mod battery;
pub mod launch;
pub mod catalog;
mod generated_bounds;
mod damage;
@@ -1278,6 +1280,11 @@ pub const MAX_COAST: u64 = 240;
/// Ticks the seeker keeps a target it lost sight of (it looks again round the last place).
const REACQUIRE: u64 = 12;
impl Missile {
/// Whether the main motor is running (cold ejection has no exhaust).
pub fn engine_lit(&self) -> bool { self.age > self.kind.spec().cold }
}
impl MissileKind {
/// How far its own seeker holds a target of average size (blocks); 0: command guidance only.
pub fn seeker(self) -> f64 {
@@ -1355,6 +1362,12 @@ pub struct Sam {
launched: u32,
pub id: u32,
pub kind: SamKind,
pub mode: battery::SamMode,
pub radar_role: battery::RadarRole,
pub spent_cells: u8,
preparing: Option<launch::Prepare>,
cap_cell: u8,
cap_open: f32,
/// The vehicle's centre on the ground.
pub pos: DVec3,
/// Where its nose points (radians, as `look`'s yaw).
@@ -1441,6 +1454,12 @@ impl Sam {
Self {
id,
kind,
mode: battery::SamMode::Integrated,
radar_role: battery::RadarRole::Multifunction,
spent_cells: 0,
preparing: None,
cap_cell: 0,
cap_open: 0.0,
pos,
heading,
yaw: heading,
@@ -1544,6 +1563,9 @@ impl Sam {
SamKind::Light => return format!("{text}{}", if self.target.is_some() { ": в луче цель" } else { "" }),
_ => {}
}
if let Some(p) = self.preparing {
text += &format!(" · открытие ТПК №{}", p.cell + 1);
}
if self.empty && self.missiles == 0 {
text += " ЖДЁТ БК";
}
@@ -1829,6 +1851,8 @@ impl Sim {
}
pub fn clear(&mut self) {
self.strikes.pending.clear();
for sam in &mut self.sams { sam.cancel_prepare(); }
self.drones.clear();
self.missiles.clear();
self.fx.clear();
@@ -1889,6 +1913,7 @@ impl Sim {
self.step_ew(out);
self.update_sight(ground);
self.step_lights(ground, out);
self.prepare_ground_strikes(out);
self.step_sams(ground, out);
self.step_missiles(ground, out);
self.step_strikes(ground, player, out);
@@ -2489,6 +2514,13 @@ impl Sim {
// ------------------------------------------------ air defence
fn step_sams(&mut self, ground: &mut Ground, out: &mut Out) {
for sam in &mut self.sams {
sam.sync_tube_cells();
if (self.hold && !sam.preparing.is_some_and(|p| p.ground)) || !sam.alive() || sam.moving() || sam.reloading > 0 || sam.part(Part::Launcher) <= 0.0 {
sam.cancel_prepare();
}
}
if self.hold {
for i in 0..self.sams.len() {
if self.sams[i].alive() && !self.sams[i].moving() {
@@ -2573,10 +2605,10 @@ impl Sim {
let opts = why::Opts { last_chance: self.last_chance, far_shots: self.far_shots };
let target = spec.missile.as_ref().map(|load| {
// A launcher with nothing to fire (reloading, empty, failed) claims no target: others take it.
if me.missiles == 0 || me.reloading > 0 || me.part(Part::Launcher) <= 0.0 {
if me.missiles == 0 || me.reloading > 0 || me.part(Part::Launcher) <= 0.0 || me.preparing.is_some_and(|p| p.ground) {
return None;
}
let radars: Vec<&Sam> = if me.kind.far_shooter() && opts.far_shots { self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect() } else { Vec::new() };
let radars: Vec<&Sam> = if me.mode == battery::SamMode::LauncherOnly || (me.kind.far_shooter() && opts.far_shots) { self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect() } else { Vec::new() };
let cued = |id: u32| !radars.is_empty() && why::radar_cue(me, &radars, id, now);
let basis = |tr: &Track, k: f64, role_in_reach: bool| {
drone(tr).filter(|_| open(tr.id)).and_then(|d| why::basis(me, load, tr, d, now, claimed(d), k, opts, cued(tr.id), role_in_reach))
@@ -2641,6 +2673,10 @@ impl Sim {
self.sams[i].gun_target = gun_target;
}
let sam = &mut self.sams[i];
if sam.preparing.is_some_and(|p| !p.ground && Some(p.target) != sam.target) { sam.cancel_prepare(); }
if let Some(p) = sam.preparing.filter(|p| !p.ground) {
sam.cap_open = (now.saturating_sub(p.start) as f32 / launch::OPEN_TICKS as f32).clamp(0.0, 1.0);
}
// What the turret or launcher points at: guns first when a target is close.
let aim = sam
.gun_target
@@ -2783,11 +2819,11 @@ impl Sim {
}
// Missiles.
if let (Some(load), Some(mt)) = (&spec.missile, sam.target) {
let ready = why::missile_blocks(sam) == 0;
let ready = why::missile_blocks(sam) == 0 && !sam.preparing.is_some_and(|p| p.ground);
// The missile turns after its boost, but the launcher must point near the target.
let t = sam.track(mt).filter(|_| drone_at.contains_key(&mt)).map(|tr| tr.est(now));
let aligned = why::missile_aligned(spec.family, sam.yaw, mount, t, aim_id, mt, aim_error);
let n = load.magazine - sam.missiles;
let n = if sam.animated_tubes() { sam.preparing.map_or_else(|| sam.next_tube_cell(), |p| p.cell) } else { load.magazine - sam.missiles };
let (muzzle, dir) = sam.muzzle(n);
// The land: a target behind a hill, or a path the hill closes, is not fired at; the system looks for another.
let land = if ready && aligned {
@@ -2816,9 +2852,11 @@ impl Sim {
if land == terrain::WAIT {
// The land under the shot is not known yet: it waits.
} else if land != 0 {
sam.cancel_prepare();
retarget(&mut missile_on, Some(mt), None);
sam.target = None;
} else if ready && aligned {
} else if ready && aligned && sam.prepare_tube(mt, now) {
sam.eject_cell(n);
// Past its normal reach: a long shot, and the next waits.
if sam.kind.far_shooter() && t.is_some_and(|t| t.distance(sam.pos) >= load.max) {
sam.far_cooldown = why::FAR_COOLDOWN;