Shaders, profiling and the rest of the issues: GTAO and HD GPU pass timing in the fork (patch 15; #9), explosion effects culled early per pixel (#11), a native sim runner with scenario tests run in CI (#8), named scenarios (#17), /airdef why and failure counters in raid reports (#18), IRIS-T and AMRAAM models and launch sounds by kind (#28)
build / mod (push) Successful in 3m24s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 16:43:48 +03:00
parent 67a2a523b4
commit ed2db8523b
38 changed files with 3912 additions and 87 deletions
+80 -42
View File
@@ -18,6 +18,7 @@ mod lights;
mod logistics;
mod orders;
mod units;
mod why;
#[cfg(test)]
mod regress;
pub use ew::EW_RADIUS;
@@ -112,6 +113,10 @@ impl Rng {
pub fn new(seed: u64) -> Self {
Self(seed | 1)
}
/// The generator's state: `new(state())` continues the same sequence.
pub fn state(&self) -> u64 {
self.0
}
pub fn next(&mut self) -> u64 {
self.0 ^= self.0 << 13;
self.0 ^= self.0 >> 7;
@@ -400,6 +405,17 @@ impl DroneKind {
DroneKind::OreshnikBlock,
DroneKind::OreshnikSub,
];
/// The sound of a launch from the ground: a light catapult shot, a rocket booster, a heavy ballistic launch.
pub fn launch_sound(self) -> &'static str {
match self {
DroneKind::Shahed | DroneKind::Geran3 | DroneKind::Lancet | DroneKind::Gerbera => "airdef:launch.s400_eject",
DroneKind::Kh101 | DroneKind::Kalibr | DroneKind::Kh22 => "airdef:launch.patriot",
DroneKind::Zircon => "airdef:launch.s400",
DroneKind::Iskander | DroneKind::Kinzhal | DroneKind::Oreshnik | DroneKind::OreshnikBlock | DroneKind::OreshnikSub => {
"airdef:launch.s500"
}
}
}
pub fn spec(self) -> &'static DroneSpec {
match self {
DroneKind::Shahed => &DroneSpec {
@@ -818,7 +834,7 @@ impl MissileKind {
rear: 32.0,
},
MissileKind::IrisT => &MissileSpec {
model: "airdef:pac3",
model: "airdef:irist_missile",
speed: 7.0,
accel: 0.5,
turn: 0.35,
@@ -832,7 +848,7 @@ impl MissileKind {
rear: 28.0,
},
MissileKind::Amraam => &MissileSpec {
model: "airdef:pac3",
model: "airdef:amraam_missile",
speed: 6.0,
accel: 0.45,
turn: 0.3,
@@ -1179,6 +1195,8 @@ pub struct Sim {
rec: Option<record::Recording>,
pub replays: Vec<record::Recording>,
recordings: u32,
/// What went wrong for the air defence, counted for the raid report and the recordings.
pub tally: record::Tally,
/// What the enemy has learned.
intel: ew::Intel,
/// Night: guns need light (the mod sets it from the game's clock).
@@ -1220,6 +1238,7 @@ impl Sim {
rec: None,
replays: Vec::new(),
recordings: 0,
tally: record::Tally::default(),
intel: ew::Intel::default(),
night: false,
flares: Vec::new(),
@@ -1304,7 +1323,7 @@ impl Sim {
let dir = DVec3::new(dir.x, dir.y.max(0.35), dir.z).normalize_or(DVec3::Y);
let from = if kind.spec().ballistic.is_some() { from + DVec3::Y * 2.0 } else { from };
self.add_drone(kind, from, dir, target);
out.sound("airdef:launch.patriot", from, 1.0, 1.3);
out.sound(kind.launch_sound(), from, 1.0, 1.3);
out.particles("minecraft:large_smoke", from, 0.6, DVec3::ZERO, 0.05, 30);
out.particles("minecraft:flame", from, 0.3, -dir * 0.2, 0.05, 12);
}
@@ -1763,12 +1782,9 @@ impl Sim {
// Drones by id (none come or go while the systems act), and how many systems have each as their
// missile target and as their gun target: counted once, then kept up to date as targets change.
let drone_at: HashMap<u32, usize> = self.drones.iter().enumerate().map(|(k, d)| (d.id, k)).collect();
let mut missile_on: HashMap<u32, u32> = HashMap::new();
let mut guns_on: HashMap<u32, u32> = HashMap::new();
for s in &self.sams {
retarget(&mut missile_on, None, s.target);
retarget(&mut guns_on, None, s.gun_target);
}
let (mut missile_on, mut guns_on) = why::engagement_counts(&self.sams);
// For the raid's report: tracks dropped and systems that ran dry and wait for a truck.
let (mut tracks_lost, mut ammo_waits) = (0u32, 0u32);
let mut launches: Vec<(MissileKind, DVec3, DVec3, u32, u32)> = Vec::new();
let mut gun_hits: Vec<(u32, u32)> = Vec::new();
let mut tracers: Vec<(u32, DVec3, DVec3, u32)> = Vec::new();
@@ -1816,16 +1832,12 @@ impl Sim {
let (had_target, had_gun) = (self.sams[i].target, self.sams[i].gun_target);
let (target, gun_target) = {
let (seen, own) = (&self.sams[i].seen, &self.sams[i].own);
let allowed = |d: &Drone| d.alive() && roles & d.kind.spec().class.bit() != 0 && seen.contains(&d.id);
// Interceptors a target has or will have: in flight, and other systems' launchers on it.
let claimed = |d: &Drone| {
let on = missile_on.get(&d.id).copied().unwrap_or(0) - u32::from(had_target == Some(d.id));
d.engaged + on
};
// Ballistic missiles get a pair; anything else one.
let needed = |d: &Drone| if d.kind.spec().class == Class::Ballistic { 2 } else { 1 };
// The conditions are `why`'s, shared with the diagnostic.
let allowed = |d: &Drone| why::allowed(roles, seen, d);
let claimed = |d: &Drone| why::claimed(d, &missile_on, had_target);
let needed = why::needed;
let target = spec.missile.as_ref().map(|load| {
let in_reach = |d: &Drone, k: f64| (load.min..load.max * k).contains(&d.pos.distance(pos));
let in_reach = |d: &Drone, k: f64| why::in_reach(load.min, load.max, k, pos, d);
let keep = had_target.filter(|t| {
drone_at.get(t).is_some_and(|&k| allowed(&self.drones[k]) && in_reach(&self.drones[k], 1.1))
});
@@ -1844,7 +1856,7 @@ impl Sim {
};
self.drones
.iter()
.filter(|d| allowed(d) && own.contains(&d.id) && d.pos.distance(pos) < gun.track)
.filter(|d| why::gun_candidate(roles, seen, own, gun.track, pos, d))
.map(|d| {
let busy = 1.0 + 2.0 * on_it(d) + if d.engaged > 0 { 1.5 } else { 0.0 };
(d.pos.distance(pos) * busy, d.id)
@@ -1855,6 +1867,13 @@ impl Sim {
(target, gun_target)
};
if let Some(target) = target {
// A target still in the sky that the system had and now doesn't: its track was lost.
if let Some(h) = had_target
&& target != Some(h)
&& drone_at.get(&h).is_some_and(|&k| self.drones[k].alive())
{
tracks_lost += 1;
}
retarget(&mut missile_on, had_target, target);
self.sams[i].target = target;
}
@@ -1871,7 +1890,12 @@ impl Sim {
// combined system's crew would), not only once both are spent.
let spent = (spec.missile.is_some() && sam.missiles == 0) || (spec.gun.is_some() && sam.bursts == 0);
if spent && sam.reloading == 0 && !sam.empty {
if logistics { sam.empty = true } else { sam.reloading = spec.reload }
if logistics {
sam.empty = true;
ammo_waits += 1;
} else {
sam.reloading = spec.reload
}
}
sam.state = if sam.reloading > 0 {
SamState::Reload
@@ -1886,10 +1910,7 @@ impl Sim {
};
let (mount, _) = sam.mount();
let lead_speed = spec.gun.as_ref().map_or(5.0, |g| g.shell);
let lead = aim.pos + aim.vel * (aim.pos.distance(mount) / lead_speed);
let to = lead - mount;
let want_yaw = heading_of(to);
let want_pitch = (to.y / to.length().max(0.01)).asin().clamp(-0.1, 1.45);
let (lead, want_yaw, want_pitch) = why::aim_wants(mount, aim, lead_speed);
let cells = matches!(spec.muzzle, Muzzle::Cells);
match spec.family {
// Vertical launch: no aiming (the Tor's turret turns its radar to the target).
@@ -1900,11 +1921,7 @@ impl Sim {
_ => sam.aim_towards(want_yaw, Some(want_pitch)),
}
// How far the mount still is from the aim, over the axes this family aims.
let yaw_error = angle_diff(sam.yaw, want_yaw).abs();
let aim_error = match spec.family {
Family::Trainable | Family::Vertical => yaw_error,
_ => yaw_error + (want_pitch - sam.pitch).abs(),
};
let aim_error = why::aim_error(spec.family, sam.yaw, sam.pitch, want_yaw, want_pitch);
let vertical = spec.family == Family::Vertical;
sam.state = if sam.reloading > 0 {
SamState::Reload
@@ -1925,13 +1942,18 @@ impl Sim {
if let (Some(gun), Some(gt)) = (&spec.gun, sam.gun_target) {
if let Some(t) = drone_at.get(&gt).map(|&k| &self.drones[k]) {
let dist = t.pos.distance(mount);
if aim.id == gt && aim_error < 0.1 && dist < gun.range && sam.gun_cooldown == 0 && sam.reloading == 0 && sam.bursts > 0 {
if why::gun_blocks(sam, aim.id, gt, aim_error, dist, gun.range) == 0 {
sam.gun_cooldown = 2;
sam.bursts -= 1;
sam.flash = 2;
sam.recoil = 1.0;
if sam.bursts == 0 && sam.missiles == 0 {
if logistics { sam.empty = true } else { sam.reloading = spec.reload }
if logistics {
sam.empty = true;
ammo_waits += 1;
} else {
sam.reloading = spec.reload
}
}
let (_, rot) = sam.mount();
let s = spec.scale;
@@ -1968,16 +1990,10 @@ impl Sim {
}
// Missiles.
if let (Some(load), Some(mt)) = (&spec.missile, sam.target) {
let ready = sam.cooldown == 0 && sam.reloading == 0 && sam.missiles > 0;
let aligned = match spec.family {
Family::Trainable => {
let t = drone_at.get(&mt).map(|&k| &self.drones[k]);
// The missile turns after its boost, but the launcher must point near the target.
t.is_some_and(|t| angle_diff(sam.yaw, heading_of(t.pos - mount)).abs() < 0.15)
}
Family::Turret => aim.id == mt && aim_error < 0.15,
_ => true,
};
let ready = why::missile_blocks(sam) == 0;
// The missile turns after its boost, but the launcher must point near the target.
let t = drone_at.get(&mt).map(|&k| &self.drones[k]);
let aligned = why::missile_aligned(spec.family, sam.yaw, mount, t, aim.id, mt, aim_error);
if ready && aligned {
let n = load.magazine - sam.missiles;
let (muzzle, dir) = sam.muzzle(n);
@@ -1994,11 +2010,20 @@ impl Sim {
sam.fired += 1;
sam.cooldown = load.interval;
if sam.missiles == 0 && (spec.gun.is_none() || sam.bursts == 0) {
if logistics { sam.empty = true } else { sam.reloading = spec.reload }
if logistics {
sam.empty = true;
ammo_waits += 1;
} else {
sam.reloading = spec.reload
}
}
}
}
}
self.note(|t| {
t.tracks_lost += tracks_lost;
t.ammo_waits += ammo_waits;
});
for (kind, muzzle, dir, target, sam) in launches {
// A launch gives the system away.
if let Some(s) = self.sams.iter().find(|s| s.id == sam) {
@@ -2038,6 +2063,7 @@ impl Sim {
fn step_missiles(&mut self, out: &mut Out) {
let mut done: Vec<(u32, Option<u32>, bool, u32)> = Vec::new(); // (missile, target, kill, sam)
let (mut missed, mut expired, mut orphaned) = (0u32, 0u32, 0u32);
let sams_fit: HashMap<u32, f64> = self.sams.iter().map(|s| (s.id, s.fitness())).collect();
for m in &mut self.missiles {
m.age += 1;
@@ -2076,11 +2102,18 @@ impl Sim {
let ratio = (spec.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);
let kill = self.rng.chance(spec.pk * fit * ratio / t.kind.spec().stealth.sqrt());
missed += u32::from(!kill);
done.push((m.id, Some(t.id), kill, m.sam));
continue;
}
}
if m.age > spec.life || (target.is_none() && m.age > 30) {
// Its target gone (shot down by another, or lost), or its life spent chasing one.
if target.is_none() {
orphaned += 1;
} else {
expired += 1;
}
done.push((m.id, None, false, m.sam));
continue;
}
@@ -2114,6 +2147,11 @@ impl Sim {
}
}
}
self.note(|t| {
t.missed += missed;
t.expired += expired;
t.orphaned += orphaned;
});
for (mid, target, kill, sam) in done {
if let Some(i) = self.missiles.iter().position(|m| m.id == mid) {
let m = self.missiles.swap_remove(i);