Stage the cold launch and spool every interceptor's motor (#129)

The interceptor's launch is one sequence: the cap opens, the round is
thrown out unlit and slows under linear gas drag (`cold` ticks), the motor
lights where it has reached, it turns with a growing rate while thrust
spools up (`boost` ticks), and full guidance starts only at `cold + boost`.
A rail launch lights at once but spools over the same `boost` ticks; the
electric P1-SUN has no rocket spool or plume.

S-400/500 now hold the unlit ejection for 20/24 ticks (1.00/1.20 s at
20 Hz); IRIS-T/Tor keep shorter 8-tick throws. Ignition, its sound, flame
and recorded MotorIgnition event all use the missile's current position.
The RM48U strike follows the same 20-tick choreography, counts the throw
in its flight time and starts its recorded smoke at ignition.

Maximum speed, turn, accel, pk and every collision rule are unchanged.

Co-Authored-By: Kimi Code <noreply@kimi.com>
This commit is contained in:
2026-11-06 13:18:01 +03:00
parent a592ece6e3
commit 1261c30724
9 changed files with 399 additions and 36 deletions
+50 -11
View File
@@ -824,10 +824,15 @@ struct MissileSpec {
speed: f64,
accel: f64,
turn: f64,
/// Ticks of straight flight before guidance.
/// Departure: ticks from ignition to full guidance (spool-up; a cold launch also captures
/// its course); full guidance starts at `cold + boost`.
boost: u32,
/// Thrown out of the tube by gas first; the motor lights this many ticks later.
/// Thrown out of the tube by gas first; the motor lights this many ticks later (#129).
cold: u32,
/// Gas-throw speed out of the tube, blocks a tick (cold-launched kinds only).
eject: f64,
/// The ejection's linear drag, blocks a tick² (cold-launched kinds only).
eject_drag: f64,
pk: f64,
fuse: f64,
life: u32,
@@ -843,6 +848,31 @@ struct MissileSpec {
voice: (&'static str, f32, f32),
}
impl MissileSpec {
/// The launch choreography is one sequence of stages (#129): the cap opens on the ground
/// (`launch::OPEN_TICKS`), the round is thrown out of the tube unlit and slows under drag
/// (`age <= cold`), the motor lights where it has reached (`age == cold + 1`), it tips onto
/// its course with a growing rate while the motor spools up (`cold < age < cold + boost`),
/// and full guidance — terrain lofting, the seeker, full turn — runs from `age >= cold + boost`.
/// Rail-launched kinds (`cold == 0`) light at once but spool up over the same `boost` ticks:
/// their stages are ignition, departure, guidance.
fn guided(&self, age: u32) -> bool {
age >= self.cold + self.boost
}
/// The departure's course-capture rate as a share of the full turn (0..=1).
fn departure_ramp(&self, age: u32) -> f64 {
(age.saturating_sub(self.cold) as f64 / self.boost.max(1) as f64).clamp(0.0, 1.0)
}
/// The motor's spool-up as a share of the full acceleration (0..=1). A rail launch spools over
/// the same `boost` ticks its departure lasts; an electric kind has no rocket motor to light.
fn spool(&self, age: u32, guided: bool) -> f64 {
if guided || self.flame <= 0.0 {
return 1.0;
}
0.45 + 0.55 * self.departure_ramp(age)
}
}
impl MissileKind {
/// How thick its motor smoke is (its size); `None` for an electric one.
pub fn trail_scale(self) -> Option<f32> {
@@ -2543,7 +2573,7 @@ impl Sim {
.map(|tr| Fix { pos: tr.pos, vel: tr.vel, tick: tr.tick, seeker: false });
let spec = kind.spec();
let id = self.id();
let v0 = if spec.cold > 0 { 0.7 } else { 0.8 };
let v0 = if spec.cold > 0 { spec.eject } else { 0.8 };
self.missiles.push(Missile { id, kind, pos: muzzle, vel: dir * v0, target, sam, age: 0, hold: 0, fix, seen: 0 });
if spec.cold > 0 {
// Thrown out by gas: a puff, a thump; the motor lights later.
@@ -2612,10 +2642,15 @@ impl Sim {
if m.age == spec.cold + m.kind.burn_ticks() + 1 {
burnouts.push((m.pos, m.id, m.kind));
}
// The launch's stages (#129): ejection (unlit, gas drag), ignition (the motor lights
// where the round has reached), departure (spool-up and course capture) and guidance.
// Guidance never runs before ignition: it starts at `cold + boost`, the motor at `cold`.
let guided = spec.guided(m.age);
let speed = if m.age <= spec.cold {
(m.vel.length() * 0.97).max(0.4)
// The gas throw bleeds off linearly; the round is never left hanging still.
(m.vel.length() - spec.eject_drag).max(spec.eject * 0.25)
} else if lit {
(m.vel.length() + spec.accel).min(spec.speed)
(m.vel.length() + spec.accel * spec.spool(m.age, guided)).min(spec.speed)
} else {
m.vel.length() * 0.995
};
@@ -2627,8 +2662,7 @@ impl Sim {
m.fix = Some(Fix { pos: tr.pos, vel: tr.vel, tick: tr.tick, seeker: false });
}
if let Some(t) = target
&& m.age > spec.cold
&& m.age >= spec.boost
&& guided
&& m.kind.seeker() > 0.0
{
let range = m.kind.seeker() * t.kind.rcs().powf(0.25).clamp(0.6, 1.6);
@@ -2643,14 +2677,14 @@ impl Sim {
}
}
// Nothing new for too long and no seeker on it: the interceptor has lost its target.
if target.is_some() && m.fix.is_none_or(|f| now.saturating_sub(f.tick) > MAX_COAST) && m.age > spec.boost + 20 {
if target.is_some() && m.fix.is_none_or(|f| now.saturating_sub(f.tick) > MAX_COAST) && m.age > spec.cold + spec.boost + 20 {
expired += 1;
done.push((m.id, None, false, m.sam));
continue;
}
let aim = m.fix.map(|f| (f.est(now), f.vel));
let new = match aim {
Some((at, vel)) if m.age >= spec.boost => {
Some((at, vel)) if guided => {
// Time to go by the closing speed: head-on targets come to meet it.
let los = (at - m.pos).normalize_or_zero();
let closing = (speed - vel.dot(los)).max(1.0);
@@ -2674,8 +2708,13 @@ impl Sim {
}
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),
// Departure: after a cold launch it tips onto the target's course while the motor
// spools up, at a rate that grows into the full one — no snap from the vertical to
// the horizontal (#129). A rail launch already points along its rail; it keeps that
// course until guidance can loft it over the land, as before.
Some((at, _)) if lit && spec.cold > 0 => {
turn(dir, at - m.pos, spec.turn * (0.2 + 0.8 * spec.departure_ramp(m.age)))
}
_ => dir,
};
let before = m.pos;