Prototype finite interceptor motor and coast

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
2026-11-02 23:50:33 +03:00
parent b377a5d8d2
commit 143d9b2858
4 changed files with 71 additions and 11 deletions
+30 -9
View File
@@ -1280,9 +1280,20 @@ 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 MissileKind {
/// Fictional game motor duration in ticks, independent of the flight lifetime.
pub fn burn_ticks(self) -> u32 {
let spec = self.spec();
if self == MissileKind::P1sun { spec.life } else { spec.life * 2 / 3 }
}
}
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 }
/// Cold ejection and post-burn coast have no powered exhaust.
pub fn engine_lit(&self) -> bool {
let spec = self.kind.spec();
self.age > spec.cold && self.age <= spec.cold + self.kind.burn_ticks()
}
}
impl MissileKind {
@@ -2949,6 +2960,7 @@ impl Sim {
let (mut missed, mut expired, mut orphaned) = (0u32, 0u32, 0u32);
let (mut blocked, mut scrubbed) = (0u32, 0u32);
let mut ignitions = Vec::new();
let mut burnouts = Vec::new();
#[cfg(test)]
let mut scrub_log = Vec::new();
let sams_fit: HashMap<u32, f64> = self.sams.iter().map(|s| (s.id, 1.0 - 0.3 * (1.0 - s.health.clamp(0.0, 1.0)))).collect();
@@ -2968,11 +2980,17 @@ impl Sim {
m.age += 1;
let spec = m.kind.spec();
let target = self.drones.iter().find(|d| d.id == m.target && d.alive());
let lit = m.age > spec.cold;
let lit = m.engine_lit();
let coast = m.age > spec.cold + m.kind.burn_ticks();
if m.age == spec.cold + m.kind.burn_ticks() + 1 {
burnouts.push((m.pos, m.id, m.kind));
}
let speed = if !lit {
(m.vel.length() * 0.97).max(0.4)
} else {
} else if lit {
(m.vel.length() + spec.accel).min(spec.speed)
} else {
m.vel.length() * 0.995
};
let dir = m.vel.normalize_or(DVec3::Y);
// What it knows: the link's newest track, and its own seeker once the target is in its reach and in view.
@@ -2982,7 +3000,7 @@ impl Sim {
m.fix = Some(Fix { pos: tr.pos, vel: tr.vel, tick: tr.tick, seeker: false });
}
if let Some(t) = target
&& lit
&& m.age > spec.cold
&& m.age >= spec.boost
&& m.kind.seeker() > 0.0
{
@@ -3027,7 +3045,7 @@ impl Sim {
done.push((m.id, target.map(|t| t.id), false, m.sam));
continue;
}
turn(dir, want, spec.turn)
turn(dir, want, spec.turn * if coast { (speed / spec.speed).clamp(0.15, 1.0) } else { 1.0 })
}
// After a cold launch it tips over towards the target while the motor burns.
Some((at, _)) if lit && spec.cold > 0 => turn(dir, at - m.pos, spec.turn * 0.5),
@@ -3070,9 +3088,9 @@ impl Sim {
let k = (-rel0.dot(delta) / delta.length_squared().max(1e-9)).clamp(0.0, 1.0);
if (rel0 + delta * k).length() < spec.fuse && world.map(|w| w.0).or(waiting).is_none_or(|w| k <= w) {
// A target faster than the interceptor is hard to hit.
let ratio = (spec.speed / t.vel.length().max(0.1)).min(1.0).powf(1.5);
let ratio = (speed / t.vel.length().max(0.1)).min(1.0).powf(1.5);
let fit = sams_fit.get(&m.sam).copied().unwrap_or(1.0) * launchers.get(&m.sam).map_or(1.0, |(at, max)| why::reach_fit(*max, at.distance(m.pos)));
let kill = self.rng.chance(spec.pk * fit * ratio / t.kind.spec().stealth.sqrt());
let kill = self.rng.chance(spec.pk * fit * ratio);
missed += u32::from(!kill);
done.push((m.id, Some(t.id), kill, m.sam));
continue;
@@ -3120,6 +3138,9 @@ impl Sim {
for (pos, missile, kind, sound) in ignitions {
self.scene_event(pos, record::SceneKind::MotorIgnition { missile, kind, sound });
}
for (pos, missile, kind) in burnouts {
self.scene_event(pos, record::SceneKind::MotorBurnout { missile, kind });
}
#[cfg(test)]
self.scrubs.extend(scrub_log);
self.note(|t| {
@@ -3154,7 +3175,7 @@ impl Sim {
let spec = m.kind.spec();
let rot = look(m.vel, 0.0) * DQuat::from_rotation_z(m.age as f64 * 0.3);
out.model(m.id, spec.model, m.pos, rot, spec.scale, false);
if m.age > spec.cold && spec.flame > 0.0 {
if m.engine_lit() && spec.flame > 0.0 {
let back = (spec.rear - 8.0) / 16.0 * spec.scale + spec.flame;
let size = spec.flame * if m.age < 40 { 1.2 } else { 0.8 } * (0.85 + 0.15 * self.vis.f());
out.model(m.id + 1, "airdef:flame", m.pos + rot * DVec3::new(0.0, 0.0, back), rot, size, true);