Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -990,7 +990,7 @@ fn fires_start_merge_and_are_limited() {
|
||||
// interceptors keep clear of it. A synthetic land (a height function) stands in for the game.
|
||||
|
||||
/// Land from a height function: blocks below it are solid, and the game's height map says the same.
|
||||
struct Land<F: Fn(i32, i32) -> i32>(F);
|
||||
pub(super) struct Land<F: Fn(i32, i32) -> i32>(F);
|
||||
impl<F: Fn(i32, i32) -> i32> world::WorldSource for Land<F> {
|
||||
fn solid(&self, x: i32, y: i32, z: i32) -> Option<bool> {
|
||||
Some(y < (self.0)(x, z))
|
||||
@@ -998,7 +998,7 @@ impl<F: Fn(i32, i32) -> i32> world::WorldSource for Land<F> {
|
||||
}
|
||||
|
||||
/// What the game answers a tick after the sim asked: land heights, and the sections it needs.
|
||||
fn answer_land<F: Fn(i32, i32) -> i32>(ground: &mut Ground, land: &Land<F>, now: u64) {
|
||||
pub(super) fn answer_land<F: Fn(i32, i32) -> i32>(ground: &mut Ground, land: &Land<F>, now: u64) {
|
||||
let columns = ground.take_wanted().into_iter().map(|(x, z)| (x, z, (land.0)(x, z))).collect();
|
||||
ground.answer(columns, now);
|
||||
let sections = ground.world.take_wanted(now);
|
||||
@@ -1010,7 +1010,7 @@ fn ridge(rise: i32, half: i32) -> Land<impl Fn(i32, i32) -> i32> {
|
||||
ridge_at(300, rise, half)
|
||||
}
|
||||
|
||||
fn ridge_at(crest: i32, rise: i32, half: i32) -> Land<impl Fn(i32, i32) -> i32> {
|
||||
pub(super) fn ridge_at(crest: i32, rise: i32, half: i32) -> Land<impl Fn(i32, i32) -> i32> {
|
||||
Land(move |x, _| 64 + (rise - (x - crest).abs() * rise / half).max(0))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Radar scan cycles with ageing tracks (#46) and damage to a system's parts (#50).
|
||||
use super::battery::{Measure, RadarRole};
|
||||
use super::regress::{answer_land, ridge_at};
|
||||
use super::sight::{swept, FIRE_QUALITY, FORECAST_AGE};
|
||||
use super::*;
|
||||
|
||||
@@ -688,3 +689,96 @@ fn multifunction_and_embedded_radars_keep_their_fire_authority() {
|
||||
assert!(sim.sams[multi].track(id).is_some_and(|t| t.own_authorizes(sim.tick)), "the universal profile lost its own fire plot");
|
||||
assert!(sim.sams[pantsir].track(id).is_some_and(|t| t.own_authorizes(sim.tick)), "an embedded radar lost its own fire plot");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn profiles_keep_their_jobs_over_a_ridge_on_one_seed_and_land() {
|
||||
// One seed and one ridge: the low contact hides behind it, the high one flies over it,
|
||||
// and two close contacts compete for the engagement channels on the far side.
|
||||
let targets = [
|
||||
DVec3::new(250.0, 84.0, 0.0),
|
||||
DVec3::new(700.0, 500.0, 0.0),
|
||||
DVec3::new(240.0, 90.0, 30.0),
|
||||
DVec3::new(260.0, 95.0, -20.0),
|
||||
];
|
||||
#[derive(Default, Debug)]
|
||||
struct RidgeStats {
|
||||
low_marked: bool,
|
||||
low_refined: bool,
|
||||
low_fire: bool,
|
||||
high_marked: bool,
|
||||
track_channels: usize,
|
||||
nonfire_authorized: bool,
|
||||
}
|
||||
let run = |stations: &[(RadarRole, DVec3)], land| -> RidgeStats {
|
||||
let mut sim = Sim::new(134);
|
||||
let radars: Vec<usize> = stations
|
||||
.iter()
|
||||
.map(|(role, pos)| {
|
||||
let id = sim.id();
|
||||
let mut sam = Sam::new(id, SamKind::Radar, *pos, 0.0);
|
||||
sam.set_radar_role(*role);
|
||||
sim.sams.push(sam);
|
||||
sim.sams.len() - 1
|
||||
})
|
||||
.collect();
|
||||
for (k, pos) in targets.iter().enumerate() {
|
||||
let kind = if k < 2 { DroneKind::Shahed } else { DroneKind::Gerbera };
|
||||
sim.add_drone(kind, *pos, DVec3::Z, *pos);
|
||||
}
|
||||
let ids: Vec<u32> = sim.drones.iter().map(|d| d.id).collect();
|
||||
let mut ground = Ground::default();
|
||||
// Unknown land hides nothing: let the heights answer before any measurement counts.
|
||||
for tick in 1..=60 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
answer_land(&mut ground, land, tick);
|
||||
}
|
||||
for i in &radars {
|
||||
sim.sams[*i].tracks.clear();
|
||||
}
|
||||
let mut stats = RidgeStats::default();
|
||||
for tick in 61..=560 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
answer_land(&mut ground, land, tick);
|
||||
for &i in &radars {
|
||||
let sam = &sim.sams[i];
|
||||
let profile = sam.radar_profile();
|
||||
for t in sam.tracks.iter().filter(|t| t.own_tick > 0) {
|
||||
if t.id == ids[0] {
|
||||
stats.low_marked = true;
|
||||
stats.low_refined |= t.product == Measure::Refine;
|
||||
stats.low_fire |= t.own_authorizes(sim.tick);
|
||||
}
|
||||
stats.high_marked |= t.id == ids[1];
|
||||
}
|
||||
if profile.id == "radar_track" {
|
||||
stats.track_channels = stats.track_channels.max(sam.own_channels_used());
|
||||
}
|
||||
if profile.id == "radar_search" || profile.id == "radar_height" {
|
||||
stats.nonfire_authorized |= sam.tracks.iter().any(|t| t.own_authorizes(sim.tick));
|
||||
}
|
||||
}
|
||||
}
|
||||
stats
|
||||
};
|
||||
let near = DVec3::new(0.0, 64.0, 0.0);
|
||||
let far = DVec3::new(220.0, 64.0, 0.0);
|
||||
let ridge = ridge_at(150, 100, 60);
|
||||
let search = run(&[(RadarRole::Search, near)], &ridge);
|
||||
assert!(search.high_marked, "the search radar lost the high contact over the ridge: {search:?}");
|
||||
assert!(!search.low_marked, "the search radar saw through the ridge: {search:?}");
|
||||
// The same station on flat land does mark the low contact: the ridge is what hides it.
|
||||
let flat = ridge_at(150, 0, 60);
|
||||
let control = run(&[(RadarRole::Search, near)], &flat);
|
||||
assert!(control.low_marked, "the control lost the low contact on flat land: {control:?}");
|
||||
let height = run(&[(RadarRole::Height, far)], &ridge);
|
||||
assert!(height.low_refined, "the mast did not refine the low contact behind the ridge: {height:?}");
|
||||
assert!(!height.high_marked && !height.low_fire, "the mast left its patch or authorized a launch: {height:?}");
|
||||
let engagement = run(&[(RadarRole::Engagement, far)], &ridge);
|
||||
assert!(engagement.low_fire, "the engagement radar gave no fire plot on the low contact: {engagement:?}");
|
||||
assert!(!engagement.high_marked, "the engagement radar searched beyond its patch: {engagement:?}");
|
||||
assert!(engagement.track_channels <= 2, "more than two tracked contacts: {engagement:?}");
|
||||
let full = run(&[(RadarRole::Search, near), (RadarRole::Height, far), (RadarRole::Engagement, far)], &ridge);
|
||||
assert!(full.high_marked && full.low_refined && full.low_fire, "the full set lost a job on the ridge: {full:?}");
|
||||
assert!(!full.nonfire_authorized, "a non-fire radar authorized a launch: {full:?}");
|
||||
assert!(full.track_channels <= 2, "the engagement radar exceeded its channels: {full:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user