Playtest fixes: smoke by engine, searchlights, far launch sites that load their chunks, air defence balance, last chance and radar-cued shots, radars in smart raids, echo, Windows release build from a tag
build / mod (push) Successful in 4m4s
release / windows (push) Successful in 23m13s

Smoke: one rule by engine, no heat on trails, no trail on P1-SUN. Searchlights: two lamps a target, off with an empty sky. Halos fade before their reach and their sum is limited. Launch sites load chunks through the server thread, go off-map as a last resort, and reach 4000 blocks. Air defence: ranges x1.5, shots grow with urgency, claims released, /airdef lastchance, long shots on a big radar's tracks. Build: rust-toolchain.toml, airdef.py check, generator manifest and --check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 23:44:14 +03:00
parent 5003376e70
commit ccc3e20902
67 changed files with 4573 additions and 328 deletions
+297
View File
@@ -0,0 +1,297 @@
//! Balance measurements: a whole raid on flat land, flown headlessly against a cluster of systems.
//! The `#[ignore]`d tests print tables (`cargo test --release balance -- --ignored --nocapture`);
//! the others assert the cheap invariants. The tables are what the air defence's tuning is judged by.
use super::sites::testland::{Land, serve};
use super::*;
/// The ten armed kinds in the order a cluster takes them (long-range heavy ones spread evenly).
const MIX: [SamKind; 10] = [
SamKind::Patriot,
SamKind::IrisT,
SamKind::S400,
SamKind::Pantsir,
SamKind::Nasams,
SamKind::Tor,
SamKind::S500,
SamKind::Buk,
SamKind::Gepard,
SamKind::P1sun,
];
/// What one drone went through, for saying why it got through.
#[derive(Default, Clone)]
struct Hist {
kind: Option<DroneKind>,
/// Ticks any system held a track of it.
seen: u32,
/// Ticks some loaded launcher with the class in its roles had it in range (`cover`), and held its track too (`reach`).
cover: u32,
reach: u32,
/// Distinct interceptors sent at it.
shots: std::collections::HashSet<u32>,
dead: bool,
last: (DVec3, DVec3),
/// Ticks to the aim when first covered, first tracked by a covering launcher, first shot at.
ttg: (f64, f64, f64),
}
#[derive(Default, Debug, Clone)]
pub(super) struct Result {
pub launched: u32,
pub kills: u32,
pub leaked: u32,
pub missiles: u32,
pub ticks: u64,
/// Leaks by cause.
pub unseen: u32,
pub no_cover: u32,
pub untracked: u32,
pub hits: u32,
pub crashes: u32,
pub unshot: u32,
pub missed: u32,
/// Missiles fired by the heavy systems (S-400, S-500, Patriot).
pub heavy: u32,
pub by_kind: Vec<(DroneKind, u32, u32)>,
pub tally: String,
}
pub(super) struct Setup {
pub systems: usize,
pub smart: bool,
pub seed: u64,
pub size: u32,
pub radars: usize,
pub objects: usize,
/// Called on the sim before the raid (a test sets its switches).
pub tweak: fn(&mut Sim),
}
impl Setup {
pub fn new(systems: usize, smart: bool, seed: u64) -> Self {
Setup { systems, smart, seed, size: 36, radars: (systems / 10).max(1), objects: 36, tweak: |_| {} }
}
}
/// The cluster: `objects` in a grid, systems of the mix scattered round them, radars among them.
pub(super) fn cluster(sim: &mut Sim, s: &Setup) {
let mut rng = Rng::new(s.seed.wrapping_mul(977) + 5);
let side = (s.objects as f64).sqrt().ceil() as usize;
for k in 0..s.objects {
let p = DVec3::new(((k % side) as f64 - side as f64 / 2.0) * 70.0, 70.0, ((k / side) as f64 - side as f64 / 2.0) * 70.0);
sim.targets.push(p);
sim.target_health.push(100.0);
}
let objects = sim.targets.clone();
for i in 0..s.systems {
let at = objects[(rng.f() * objects.len() as f64) as usize % objects.len()];
let a = rng.f() * TAU;
let r = 30.0 + rng.f() * 110.0;
let id = sim.id();
sim.sams.push(Sam::new(id, MIX[i % MIX.len()], at + DVec3::new(a.sin() * r, 0.0, a.cos() * r), rng.f() * TAU));
}
for _ in 0..s.radars {
let a = rng.f() * TAU;
let r = rng.f() * 220.0;
let id = sim.id();
sim.sams.push(Sam::new(id, SamKind::Radar, DVec3::new(a.sin() * r, 70.0, a.cos() * r), 0.0));
}
}
/// Flies one raid to its end and counts.
pub(super) fn fly(s: &Setup) -> Result {
let mut sim = Sim::new(s.seed);
cluster(&mut sim, s);
(s.tweak)(&mut sim);
let mut ground = Ground::default();
let land = Land(|_, _| 64);
let mut out = Out::default();
for _ in 0..200 {
serve(&mut ground, &land, sim.tick);
sim.step(&mut ground, None, &mut out);
}
let mut order = crate::wave::WaveConfig::mix(s.size, 500.0);
// The Oreshnik's blocks are a raid of their own; this measures the ordinary mass raid.
order.kinds.retain(|k| k.0 != DroneKind::Oreshnik);
if s.smart {
order.aim = raid::Aim::Smart;
order.approach = raid::Approach::AllSides;
}
let targets = sim.targets.clone();
let fired0: u32 = sim.sams.iter().map(|m| m.fired).sum();
sim.order_raid(&order, &targets, &mut out);
let mut hist: HashMap<u32, Hist> = HashMap::new();
let mut result = Result::default();
let start = sim.tick;
let mut gone_unkilled: Vec<Hist> = Vec::new();
for _ in 0..9000 {
serve(&mut ground, &land, sim.tick);
out = Out::default();
sim.step(&mut ground, None, &mut out);
let now = sim.tick;
for d in &sim.drones {
let h = hist.entry(d.id).or_default();
h.kind = Some(d.kind);
h.last = (d.pos, d.target);
if !d.alive() {
h.dead = true;
continue;
}
if sim.sams.iter().any(|m| m.seen.contains(&d.id)) {
h.seen += 1;
}
let class = d.kind.spec().class.bit();
let covers = |m: &&Sam| {
m.alive() && m.roles & class != 0 && m.missiles > 0 && m.kind.spec().missile.as_ref().is_some_and(|l| (l.min..l.max).contains(&m.pos.distance(d.pos)))
};
let ttg = why::arrival(d);
if h.cover == 0 && sim.sams.iter().filter(covers).next().is_some() {
h.ttg.0 = ttg;
}
if h.reach == 0 && sim.sams.iter().filter(covers).any(|m| m.seen.contains(&d.id)) {
h.ttg.1 = ttg;
}
h.cover += u32::from(sim.sams.iter().filter(covers).next().is_some());
h.reach += u32::from(sim.sams.iter().filter(covers).any(|m| m.seen.contains(&d.id)));
}
for m in &sim.missiles {
if let Some(h) = hist.get_mut(&m.target) {
if h.shots.is_empty() {
h.ttg.2 = h.last.0.distance(h.last.1) / h.kind.map_or(1.0, |k| k.spec().speed);
}
h.shots.insert(m.id);
}
}
// Drones gone from the sky that were never brought down arrived (or crashed).
let here: std::collections::HashSet<u32> = sim.drones.iter().map(|d| d.id).collect();
let queued: std::collections::HashSet<u32> = sim.queue.iter().map(|q| q.1.id).collect();
let vanished: Vec<u32> = hist.iter().filter(|(id, h)| !here.contains(id) && !queued.contains(id) && !h.dead && h.kind.is_some()).map(|(id, _)| *id).collect();
for id in vanished {
if let Some(h) = hist.remove(&id) {
// Gone from the sky near its aim: arrived. (A kill that detonates or breaks up removes the drone too.)
let k = h.kind.unwrap();
if !k.spec().decoy && h.last.0.distance(h.last.1) < 2.0 * k.spec().speed + 12.0 {
if std::env::var("LEAKS").is_ok() {
eprintln!(" leak {k:?} seen {} cover {} reach {} shots {} ttg cover/track/shot {:.0}/{:.0}/{:.0}", h.seen, h.cover, h.reach, h.shots.len(), h.ttg.0, h.ttg.1, h.ttg.2);
}
gone_unkilled.push(h);
}
}
}
// Dead ones that have landed are forgotten.
hist.retain(|id, h| !(h.dead && !here.contains(id)));
if now - start > 300 && sim.queue.is_empty() && !sim.planning() && !sim.drones.iter().any(|d| d.alive()) && sim.missiles.is_empty() {
break;
}
}
result.ticks = sim.tick - start;
result.launched = sim.launched;
result.kills = sim.kills;
result.missiles = sim.sams.iter().map(|m| m.fired).sum::<u32>() - fired0;
result.heavy = sim.sams.iter().filter(|m| matches!(m.kind, SamKind::S400 | SamKind::S500 | SamKind::Patriot)).map(|m| m.fired).sum();
result.hits = sim.hits;
result.crashes = sim.crashes;
result.leaked = sim.hits;
let mut kinds: HashMap<DroneKind, (u32, u32)> = HashMap::new();
for h in &gone_unkilled {
let k = h.kind.unwrap();
kinds.entry(k).or_default().0 += 1;
if h.seen == 0 {
result.unseen += 1;
} else if h.cover == 0 {
result.no_cover += 1;
} else if h.reach == 0 {
result.untracked += 1;
} else if h.shots.is_empty() {
result.unshot += 1;
} else {
result.missed += 1;
}
}
result.by_kind = kinds.into_iter().map(|(k, v)| (k, v.0, v.1)).collect();
result.by_kind.sort_by_key(|k| k.0 as u8);
result.tally = sim.tally.text();
result
}
pub(super) fn table(title: &str, smart: bool, size: u32, systems: &[usize], seeds: &[u64], tweak: fn(&mut Sim)) -> Vec<(usize, f64)> {
let mut means = Vec::new();
eprintln!("== {title} ({} raid)", if smart { "smart" } else { "mix" });
eprintln!("{:>4} {:>4} {:>5} {:>5} {:>5} {:>6} {:>6} | leaks: unseen nocover untrk unshot missed hits crash", "sams", "seed", "sent", "kills", "leak", "missil", "heavy");
for &n in systems {
let (mut total, mut missiles, mut heavy, mut clean) = (0, 0, 0, 0);
for &seed in seeds {
let mut s = Setup::new(n, smart, seed);
s.tweak = tweak;
s.size = size;
let r = fly(&s);
total += r.leaked;
clean += u32::from(r.leaked == 0);
missiles += r.missiles;
heavy += r.heavy;
if std::env::var("ROWS").is_ok() { eprintln!("{n:>4} {seed:>4} {:>5} {:>5} {:>5} {:>6} {:>6} | {:>12} {:>7} {:>5} {:>6} {:>6} {:>4} {:>5} {:?}", r.launched, r.kills, r.leaked, r.missiles, r.heavy, r.unseen, r.no_cover, r.untracked, r.unshot, r.missed, r.hits, r.crashes, r.by_kind.iter().map(|k| format!("{:?}:{}", k.0, k.1)).collect::<Vec<_>>()); }
if seed == seeds[0] && std::env::var("ROWS").is_ok() {
eprintln!(" tally: {}", r.tally);
}
}
let mean = total as f64 / seeds.len() as f64;
let k = seeds.len() as f64;
eprintln!("{n:>4} mean leaks {mean:.1} (clean seeds {clean}/{}), missiles {:.0}, of them heavy {:.0}", seeds.len(), missiles as f64 / k, heavy as f64 / k);
means.push((n, mean));
}
means
}
#[test]
#[ignore]
fn raid_table() {
for smart in [false, true] {
table("current", smart, 36, &[20, 50, 150], &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], |_| {});
}
}
/// A raid of 80 (about 100 drones): 20 systems clearly lose, 150 hold (a loose bound, one seed).
#[test]
fn a_small_cluster_loses_and_a_big_one_holds() {
let mut s = Setup::new(20, false, 2);
s.size = 80;
let small = fly(&s);
let mut s = Setup::new(150, false, 2);
s.size = 80;
let big = fly(&s);
eprintln!("20 systems: {small:?}\n150 systems: {big:?}");
assert!(small.launched >= 80, "the raid was not launched: {small:?}");
assert!(small.leaked >= 10, "20 systems should clearly lose, leaked {}", small.leaked);
assert!(big.leaked <= 5, "150 systems leaked {}", big.leaked);
}
/// What each of the new rules adds, one at a time (the raid of 36 and a heavier one of 80).
#[test]
#[ignore]
fn rules_one_by_one() {
for size in [36, 80] {
for smart in [false, true] {
table(&format!("size {size}: roles only"), smart, size, &[20, 50, 150], &[1, 2, 3, 4, 5, 6], |s| {
s.last_chance = false;
s.far_shots = false;
});
table(&format!("size {size}: + last chance"), smart, size, &[20, 50, 150], &[1, 2, 3, 4, 5, 6], |s| s.far_shots = false);
table(&format!("size {size}: + last chance + long shots"), smart, size, &[20, 50, 150], &[1, 2, 3, 4, 5, 6], |_| {});
}
}
}
/// One raid in detail, for hunting a leak: `LEAKS=1 cargo test --release one_raid -- --ignored --nocapture`.
#[test]
#[ignore]
fn one_raid() {
let n: usize = std::env::var("SAMS").ok().and_then(|v| v.parse().ok()).unwrap_or(150);
let smart = std::env::var("SMART").is_ok();
let size: u32 = std::env::var("SIZE").ok().and_then(|v| v.parse().ok()).unwrap_or(36);
for seed in 1..=12 {
let mut s = Setup::new(n, smart, seed);
s.size = size;
let r = fly(&s);
eprintln!("seed {seed}: sent {} kills {} leaked {} missiles {} ticks {}", r.launched, r.kills, r.leaked, r.missiles, r.ticks);
}
}