02f99c31f6
build / mod (push) Successful in 30m51s
Gameplay fixes and art from the owner's balance review of 2026-12-05. - The P1-SUN never launched (0 launches in 12 seeds of a 196-target raid): it has no radar of its own and only a separate launcher could fire on another station's plot. A unit without its own radar now fires like one (`why::on_network`), on the fresh own fire plot of an engagement or multifunction radar within link reach. Seven P1-SUN then launch 26-42 and kill 13-24 per raid; the leak count does not change. - The С-400 and С-500 exist only as separate launchers (`mode: "launcher"` in the catalog). The `s400_launcher`/`s500_launcher` variants and their remotes are gone: `deploy s400`/`s500` and their remotes place a launcher. A system saved with its own radar loads as a launcher; `battery <n> integrated` is refused for these kinds. - Every radar role has its own model: a wide curved array (search), a parabolic dish (engagement), a small head on mast sections (height); the multifunction radar keeps its panel, the optical post gets its own post and a turning head with a lens. A variant may carry its own `parts` in `catalog/content.json`; `Sam::parts()` resolves them. - The enemy remembers the sides each approach raided from: a raid ordered the same way and within 200 blocks of the same distance comes from the same sides, so its sites stand where the last ones did. A launch area the radars fixed is remembered (up to 32): a site placed there again is known before its first launch and can be struck at once. Neither is saved yet. - `sim/balance.rs` flies several raids over one cluster with stocked depots (`supply_raids`). With the 16-block depot reach, depots 30 blocks from the batteries leave 10 / 36 / 80 leaks over three raids against 6 / 10 / 17 for depots within reach; the reach itself is unchanged by decision of the owner. The saturation checkpoint is re-recorded (123 kills / 323 launches instead of 129 / 344): that loadout has no fire radar, so its С-400/С-500 fire less as launchers. Verified: airdef-core release 363 passed and 8 scenarios; airdef-mod 135 passed, 1 boundary, 2 saturation, 5 scenarios; gen_catalog/gen_models/gen_sounds --check; test_gen_assets, test_model_bounds, test_web_panel; git diff --check. Not run: the actual WASM contract, the models in game, CI. Co-Authored-By: ZCode <zcode@localhost>
172 lines
8.0 KiB
Rust
172 lines
8.0 KiB
Rust
//! The saturation regression (#145): a deterministic native replica of the WASM budget
|
||
//! scenario's checkpoint (`tests/budgets/wasm_flat_budget.toml`, tick 2102). 64 integrated
|
||
//! complexes stand where `/airdef deploy` puts them (8 blocks south of the player at the world
|
||
//! origin), two `airdef wave oreshnik 40 2600` orders 100 ticks apart, flat land at y=64, the
|
||
//! engine's own seed for the first morning. The render answers are produced exactly as the WASM
|
||
//! test host produces them (`horizon_mods::world_query::trace`, the same section fill), so the
|
||
//! replica replays the same fight the heavy run measures. It exists to explain and guard the
|
||
//! intercept count under saturation: the counters and `Sim::launch_audit` say why the systems
|
||
//! hold their fire, which the fuel-bound WASM run cannot afford to diagnose per tick.
|
||
//!
|
||
//! Run: `cargo test --test saturation -- --nocapture`.
|
||
use airdef::sim::world::{Fill, RayReply, SectionAnswer};
|
||
use airdef::sim::{Aim, Approach, DroneKind, Ground, Out, RaidOrder, Sam, SamKind, Sim};
|
||
use glam::DVec3;
|
||
use horizon_mods::world_query::{self, BlockProbe, Cell, Trace};
|
||
|
||
/// The seed the mod derives on the first tick of a fresh world (`open_world`, game_time 1).
|
||
const SEED: u64 = 1u64.wrapping_mul(2654435761) ^ 0x9e37;
|
||
/// Where the test player stands, and where every deploy lands (`deploy_configured`: 8 blocks ahead).
|
||
const PLAYER: DVec3 = DVec3::new(0.5, 64.0, 0.5);
|
||
const DEPLOY_AT: DVec3 = DVec3::new(0.5, 64.0, 8.5);
|
||
const GROUND_Y: i32 = 64;
|
||
/// The fixture's deploy order: nine rounds of seven kinds, then one more S-400 (64 complexes).
|
||
const KINDS: [SamKind; 7] = [SamKind::S400, SamKind::Patriot, SamKind::Pantsir, SamKind::Gepard, SamKind::Nasams, SamKind::IrisT, SamKind::Tor];
|
||
/// The checkpoint the WASM fixture asserts at step 271.
|
||
const CHECKPOINT: u64 = 2102;
|
||
|
||
/// The flat world the test host answers from: solid below `GROUND_Y`, air above.
|
||
struct Flat;
|
||
impl BlockProbe for Flat {
|
||
fn cell(&mut self, _x: i32, y: i32, _z: i32) -> Cell<'_> {
|
||
if y < GROUND_Y { Cell::Solid(None) } else { Cell::Empty }
|
||
}
|
||
}
|
||
|
||
/// A section's fill, exactly as `answer_flat_world` computes it.
|
||
fn section_fill(sec: (i32, i32, i32)) -> SectionAnswer {
|
||
let base = i64::from(sec.1) * 16;
|
||
let solid = (i64::from(GROUND_Y) - base).clamp(0, 16) as usize;
|
||
let fill = match solid {
|
||
0 => Fill::Empty,
|
||
16 => Fill::Full,
|
||
_ => {
|
||
let mut bits = [0u8; 512];
|
||
bits[..solid * 32].fill(255);
|
||
Fill::Mixed(Box::new(bits))
|
||
}
|
||
};
|
||
SectionAnswer { sec, fill }
|
||
}
|
||
|
||
/// A ray's reply, exactly as `answer_flat_world` traces it.
|
||
fn ray_reply(id: u32, a: DVec3, b: DVec3) -> RayReply {
|
||
match world_query::trace(&mut Flat, [a.x, a.y, a.z], [b.x, b.y, b.z]) {
|
||
Trace::Clear => RayReply { id, clear: true, hit: false, fraction: 1.0, normal: [0; 3], block: [0; 3] },
|
||
Trace::Hit { fraction, normal, block } => RayReply { id, clear: false, hit: true, fraction, normal, block },
|
||
Trace::Unknown { .. } => RayReply { id, clear: false, hit: false, fraction: 0.0, normal: [0; 3], block: [0; 3] },
|
||
}
|
||
}
|
||
|
||
fn order(sim: &mut Sim, out: &mut Out) -> u32 {
|
||
let o = RaidOrder { kinds: vec![(DroneKind::Oreshnik, 40)], approach: Approach::Sector, dist: 2600.0, aim: Aim::Objects };
|
||
sim.order_raid(&o, &[PLAYER], out)
|
||
}
|
||
|
||
fn deploy(sim: &mut Sim) {
|
||
for _ in 0..9 {
|
||
for kind in KINDS {
|
||
let id = sim.id();
|
||
sim.sams.push(Sam::new(id, kind, DEPLOY_AT, std::f64::consts::PI));
|
||
sim.settle(id);
|
||
}
|
||
}
|
||
let id = sim.id();
|
||
sim.sams.push(Sam::new(id, SamKind::S400, DEPLOY_AT, std::f64::consts::PI));
|
||
sim.settle(id);
|
||
assert_eq!(sim.sams.len(), 64);
|
||
}
|
||
|
||
/// Steps the replica to `ticks`, ordering the two waves and the HD effects where the fixture does,
|
||
/// and answering render queries one tick later exactly as the WASM host does.
|
||
fn run_to(ticks: u64) -> Sim {
|
||
let mut sim = Sim::new(SEED);
|
||
let mut ground = Ground::default();
|
||
let mut out = Out::default();
|
||
let mut columns: Vec<(i32, i32, i32)> = Vec::new();
|
||
let mut sections: Vec<SectionAnswer> = Vec::new();
|
||
let mut rays: Vec<RayReply> = Vec::new();
|
||
let mut changes_epoch = 0u32;
|
||
for now in 1..=ticks {
|
||
// Commands run between ticks: deploys and the first wave after tick 2, the second after
|
||
// tick 102, `airdef shader hd` after tick 1102 (effects only, but kept exact).
|
||
if now == 3 {
|
||
deploy(&mut sim);
|
||
assert!(order(&mut sim, &mut out) > 0, "the first wave was refused");
|
||
}
|
||
if now == 103 {
|
||
assert!(order(&mut sim, &mut out) > 0, "the second wave was refused (the first still planning)");
|
||
}
|
||
if now == 1103 {
|
||
sim.shader = true;
|
||
}
|
||
// The mod's tick reads the previous tick's answers at the clock it had then (sim.tick).
|
||
let now0 = sim.tick;
|
||
ground.world.changed_rev(changes_epoch, 0, false, &[]);
|
||
ground.answer(std::mem::take(&mut columns), now0);
|
||
ground.world.answer(std::mem::take(&mut sections), now0);
|
||
ground.world.answer_rays(&std::mem::take(&mut rays));
|
||
sim.day_time = Some(now);
|
||
sim.night = (13000..23000).contains(&(now % 24000));
|
||
out = Out::default();
|
||
sim.step(&mut ground, Some(PLAYER), &mut out);
|
||
// The queries this tick asks; the host answers them before the next tick.
|
||
columns = ground.take_wanted().into_iter().map(|(x, z)| (x, z, GROUND_Y)).collect();
|
||
let _chunks = ground.take_chunks();
|
||
let rq = ground.world.take_rays(now);
|
||
let sq = ground.world.take_wanted(now);
|
||
if !rq.is_empty() || !sq.is_empty() {
|
||
changes_epoch = 1;
|
||
}
|
||
rays = rq.into_iter().map(|(id, a, b)| ray_reply(id, a, b)).collect();
|
||
sections = sq.into_iter().map(section_fill).collect();
|
||
}
|
||
sim
|
||
}
|
||
|
||
/// No depot is deployed in this fixture. Both waves spend the initial ammunition;
|
||
/// the checkpoint records the outcome with finite magazines and the heavy batteries'
|
||
/// confirmed-class engagement rules. Re-recorded on 2026-12-05: the С-400 and С-500 are separate
|
||
/// launchers now and this loadout has no fire radar to feed them (129 kills / 344 launches before).
|
||
const REPLICA_KILLS: u32 = 123;
|
||
const REPLICA_HITS: u32 = 2243;
|
||
const REPLICA_AIRBORNE: usize = 184;
|
||
const REPLICA_FIRED: u32 = 323;
|
||
|
||
#[test]
|
||
fn checkpoint_replica_matches_the_finite_ammunition_baseline() {
|
||
let sim = run_to(CHECKPOINT);
|
||
let airborne = sim.drones.iter().filter(|d| d.alive()).count();
|
||
let fired: u32 = sim.sams.iter().map(|s| s.fired).sum();
|
||
eprintln!(
|
||
"checkpoint tick {}: airborne {airborne}, missiles {}, kills {}, hits {}, fired {}",
|
||
sim.tick,
|
||
sim.missiles.len(),
|
||
sim.kills,
|
||
sim.hits,
|
||
fired
|
||
);
|
||
eprintln!("tally: {}", sim.tally.text());
|
||
eprintln!("audit: {}", sim.launch_audit().text());
|
||
assert_eq!(airborne, REPLICA_AIRBORNE, "the sky at the checkpoint");
|
||
assert_eq!(sim.kills, REPLICA_KILLS, "intercepts at the checkpoint (deterministic replica baseline)");
|
||
assert_eq!(sim.hits, REPLICA_HITS, "hits at the checkpoint");
|
||
assert_eq!(fired, REPLICA_FIRED, "launches at the checkpoint");
|
||
assert!(sim.sams.iter().all(|s| s.fired <= s.kind.missile_magazine().unwrap_or(0)),
|
||
"a battery fired more than its initial load with no depot");
|
||
}
|
||
|
||
#[test]
|
||
fn the_saturation_loadout_has_no_separate_radar_channels_to_hold() {
|
||
// #140 (stale own fire channels held by network relays) is a separate-radar bug: it binds only
|
||
// where a profile has channels. This loadout deploys integrated complexes alone — every radar
|
||
// is the weapon's embedded one, whose profile has no channel limit — so #140 cannot affect it.
|
||
// Fact, not assumption: the A/B that relaxed the channel limit changed nothing (243 -> 243).
|
||
let sim = run_to(CHECKPOINT);
|
||
assert_eq!(sim.sams.len(), 64);
|
||
for s in &sim.sams {
|
||
assert_ne!(s.kind, SamKind::Radar, "the fixture deploys no separate radar");
|
||
assert_eq!(s.radar_profile().channels, 0, "an embedded radar has no channel limit");
|
||
}
|
||
}
|