Implement the first full radar-profile slice (#134)
Give the separate radar three real profiles over SamKind::Radar and the typed catalog variants: - radar_search: coarse, slow, long-range search plots; no fire authority. - radar_height: raised mast, local refinement of low plots; no fire authority. - radar_track: local search, fast revisit, two refined/fire channels. - radar_multi remains the compatible universal profile, not best everywhere. Tracks now carry the measuring station, product (search/refine/fire), and quality (separate from identification), and keep the station's own plot when a fresher network relay replaces the published position. A relay never refreshes the measurement or authorizes a launch. Ordinary launches need the battery's own confirmed fire plot; launcher-only batteries use a supporting radar's own plot, and the existing heavy far shot keeps its cue-radar exception. Per-tick refinement/fire work is bounded by profile channels and local search radius. Off, damage, network and save/replay behavior are preserved: new saves write the stable profile ID, old role-only lines migrate, and embedded SAM radars keep their own fire authority. The deploy menu, status lines, map, monitor, radar scope and /airdef why explain the profile, source, age, quality, channels and refusal reason. Models/textures are untouched: all profiles reuse the existing radar silhouette (the separate art zone remains for its owner). Tests: profile single/pair/full scenarios and duplicate station, channels, relay source/age/quality, Off/damage, save migration, replay, embedded and Multifunction radars, catalog/generator checks, airdef-mod suites, core lib (non-balance on one thread; the four active balance tests in release) and core scenarios. Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! Radar scan cycles with ageing tracks (#46) and damage to a system's parts (#50).
|
||||
use super::sight::{swept, FORECAST_AGE};
|
||||
use super::battery::{Measure, RadarRole};
|
||||
use super::sight::{swept, FIRE_QUALITY, FORECAST_AGE};
|
||||
use super::*;
|
||||
|
||||
fn flat() -> (Ground, Out) {
|
||||
@@ -376,7 +377,8 @@ fn a_gun_lets_go_of_a_track_classified_out_of_its_roles() {
|
||||
let seed = |sim: &mut Sim, class| {
|
||||
let d = sim.drones[0].clone();
|
||||
sim.sams[p].tracks.retain(|t| t.id != d.id);
|
||||
sim.sams[p].tracks.push(Track { id: d.id, class, pos: d.pos, vel: d.vel, tick: sim.tick, own_tick: sim.tick, ttl: 400, hits: 3, locked: false });
|
||||
let source = sim.sams[p].id;
|
||||
sim.sams[p].tracks.push(Track { id: d.id, class, pos: d.pos, vel: d.vel, tick: sim.tick, own_tick: sim.tick, source, product: battery::Measure::Fire, quality: 90, own_product: battery::Measure::Fire, own_quality: 90, ttl: 400, hits: 3, locked: false });
|
||||
};
|
||||
// Taken while the class was unknown: the general rules make it a candidate.
|
||||
seed(&mut sim, ClassEst::Unknown);
|
||||
@@ -420,3 +422,269 @@ fn forecasts_and_relays_add_no_confidence() {
|
||||
assert!(relayed > 100, "the network never passed the track ({relayed})");
|
||||
assert!(prev.is_some_and(|(_, c)| c.class().is_some()), "the source never classified the contact");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- separate radar profiles (#134)
|
||||
|
||||
fn radar_with_role(sim: &mut Sim, role: RadarRole, x: f64) -> usize {
|
||||
let id = sim.id();
|
||||
let mut sam = Sam::new(id, SamKind::Radar, DVec3::new(x, 70.0, 0.0), 0.0);
|
||||
sam.set_radar_role(role);
|
||||
sim.sams.push(sam);
|
||||
sim.sams.len() - 1
|
||||
}
|
||||
|
||||
fn bearing(from: DVec3, to: DVec3) -> f64 {
|
||||
(to.x - from.x).atan2(-(to.z - from.z))
|
||||
}
|
||||
|
||||
/// The beam of every radar is pointed at one of `targets` in turn, so a test
|
||||
/// does not depend on where the initial phase happened to be.
|
||||
fn sweep(sim: &mut Sim, ground: &mut Ground, radars: &[usize], targets: &[DVec3], tick: u64) {
|
||||
sim.tick = tick;
|
||||
for (k, &i) in radars.iter().enumerate() {
|
||||
let at = targets[(tick as usize + k) % targets.len()];
|
||||
sim.sams[i].beam = bearing(sim.sams[i].pos, at);
|
||||
}
|
||||
sim.update_sight(ground);
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
struct ProfileStats {
|
||||
first_high: Option<u64>,
|
||||
first_low_refined: Option<u64>,
|
||||
first_close_fire: Option<u64>,
|
||||
max_channels: usize,
|
||||
search_or_height_authorized: bool,
|
||||
}
|
||||
|
||||
/// A low contact at 330 blocks (above the search/engagement horizon but below
|
||||
/// the mast's), a high contact at 700/430 (inside the search reach but outside
|
||||
/// the mast's and engagement's local search), and two close contacts for the
|
||||
/// tracked-contact channels.
|
||||
fn profile_world(roles: &[RadarRole]) -> (Sim, Vec<usize>, Vec<u32>, Ground) {
|
||||
let mut sim = Sim::new(134);
|
||||
let radars: Vec<usize> = roles.iter().map(|role| radar_with_role(&mut sim, *role, 0.0)).collect();
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(330.0, 95.0, 0.0), DVec3::Z, DVec3::new(330.0, 95.0, 0.0));
|
||||
let low = sim.drones.last().unwrap().id;
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(700.0, 500.0, 0.0), DVec3::Z, DVec3::new(700.0, 500.0, 0.0));
|
||||
let high = sim.drones.last().unwrap().id;
|
||||
sim.add_drone(DroneKind::Gerbera, DVec3::new(120.0, 120.0, 0.0), DVec3::Z, DVec3::new(120.0, 120.0, 0.0));
|
||||
let close1 = sim.drones.last().unwrap().id;
|
||||
sim.add_drone(DroneKind::Gerbera, DVec3::new(180.0, 130.0, 40.0), DVec3::Z, DVec3::new(180.0, 130.0, 40.0));
|
||||
let close2 = sim.drones.last().unwrap().id;
|
||||
(sim, radars, vec![low, high, close1, close2], Ground::default())
|
||||
}
|
||||
|
||||
fn run_profile_world(roles: &[RadarRole], ticks: u64) -> (ProfileStats, Sim, Vec<usize>, Vec<u32>) {
|
||||
let (mut sim, radars, ids, mut ground) = profile_world(roles);
|
||||
let [low, high, close1, close2] = [ids[0], ids[1], ids[2], ids[3]];
|
||||
let targets: Vec<DVec3> = sim.drones.iter().map(|d| d.pos).collect();
|
||||
let mut stats = ProfileStats::default();
|
||||
for tick in 1..=ticks {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
for &i in &radars {
|
||||
let sam = &sim.sams[i];
|
||||
for t in sam.tracks.iter().filter(|t| t.own_tick > 0) {
|
||||
match t.id {
|
||||
id if id == high && stats.first_high.is_none() => stats.first_high = Some(tick),
|
||||
id if id == low && t.product == Measure::Refine && stats.first_low_refined.is_none() => stats.first_low_refined = Some(tick),
|
||||
id if (id == close1 || id == close2) && t.product == Measure::Fire && t.own_authorizes(sim.tick) && stats.first_close_fire.is_none() => stats.first_close_fire = Some(tick),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if sam.radar_profile().id == "radar_search" || sam.radar_profile().id == "radar_height" {
|
||||
stats.search_or_height_authorized |= sam.tracks.iter().any(|t| t.own_authorizes(sim.tick));
|
||||
}
|
||||
stats.max_channels = stats.max_channels.max(sam.own_channels_used());
|
||||
}
|
||||
}
|
||||
(stats, sim, radars, ids)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_profile_is_useful_alone_and_the_full_set_covers_all_three_jobs() {
|
||||
let search = run_profile_world(&[RadarRole::Search], 500).0;
|
||||
assert!(search.first_high.is_some(), "the search radar gives no early high plot: {search:?}");
|
||||
assert!(search.first_low_refined.is_none(), "search refined a low contact it does not reach: {search:?}");
|
||||
assert!(search.first_close_fire.is_none(), "search authorized a launch: {search:?}");
|
||||
|
||||
let height = run_profile_world(&[RadarRole::Height], 500).0;
|
||||
assert!(height.first_high.is_none(), "the mast radar searched beyond its local patch: {height:?}");
|
||||
assert!(height.first_low_refined.is_some(), "the mast radar did not refine the low contact: {height:?}");
|
||||
assert!(height.first_close_fire.is_none(), "the mast radar authorized a launch: {height:?}");
|
||||
|
||||
let engagement = run_profile_world(&[RadarRole::Engagement], 500).0;
|
||||
assert!(engagement.first_high.is_none(), "the engagement radar searched beyond its local patch: {engagement:?}");
|
||||
assert!(engagement.first_low_refined.is_none(), "the engagement radar reached a low contact below the horizon: {engagement:?}");
|
||||
assert!(engagement.first_close_fire.is_some(), "the engagement radar gave no fire plot: {engagement:?}");
|
||||
assert!(engagement.max_channels <= 2, "more than two tracked contacts: {engagement:?}");
|
||||
|
||||
let search_height = run_profile_world(&[RadarRole::Search, RadarRole::Height], 500).0;
|
||||
assert!(search_height.first_high.is_some() && search_height.first_low_refined.is_some());
|
||||
assert!(search_height.first_close_fire.is_none(), "a search/height pair authorized a launch: {search_height:?}");
|
||||
|
||||
let search_engagement = run_profile_world(&[RadarRole::Search, RadarRole::Engagement], 500).0;
|
||||
assert!(search_engagement.first_high.is_some() && search_engagement.first_close_fire.is_some());
|
||||
assert!(search_engagement.first_low_refined.is_none(), "the pair covered the mast's low gap: {search_engagement:?}");
|
||||
|
||||
let height_engagement = run_profile_world(&[RadarRole::Height, RadarRole::Engagement], 500).0;
|
||||
assert!(height_engagement.first_low_refined.is_some() && height_engagement.first_close_fire.is_some());
|
||||
assert!(height_engagement.first_high.is_none(), "the pair covered the search's far picture: {height_engagement:?}");
|
||||
|
||||
let full = run_profile_world(&[RadarRole::Search, RadarRole::Height, RadarRole::Engagement], 500).0;
|
||||
assert!(full.first_high.is_some() && full.first_low_refined.is_some() && full.first_close_fire.is_some(), "{full:?}");
|
||||
assert!(!full.search_or_height_authorized, "a non-fire radar authorized a launch");
|
||||
// There is no set bonus in the profile table: a duplicated station adds no
|
||||
// function, and the full set's advantage is only the union of the three jobs.
|
||||
let duplicate = run_profile_world(&[RadarRole::Search, RadarRole::Search], 500).0;
|
||||
assert!(duplicate.first_low_refined.is_none() && duplicate.first_close_fire.is_none(), "two search radars invented another function: {duplicate:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn network_relay_keeps_source_age_and_quality_but_not_launch_authority() {
|
||||
let mut sim = Sim::new(1341);
|
||||
let search = radar_with_role(&mut sim, RadarRole::Search, 0.0);
|
||||
let engagement = radar_with_role(&mut sim, RadarRole::Engagement, 10.0);
|
||||
let receiver = {
|
||||
let id = sim.id();
|
||||
let mut s400 = Sam::new(id, SamKind::S400, DVec3::new(20.0, 70.0, 0.0), 0.0);
|
||||
// A blind receiver: only the network can give it a track.
|
||||
s400.comps.0[Part::Sensor as usize] = 0.0;
|
||||
s400.roles = 0xff;
|
||||
sim.sams.push(s400);
|
||||
sim.sams.len() - 1
|
||||
};
|
||||
sim.add_drone(DroneKind::Shahed, DVec3::new(200.0, 120.0, 0.0), DVec3::Z, DVec3::new(200.0, 120.0, 0.0));
|
||||
let id = sim.drones[0].id;
|
||||
let mut ground = Ground::default();
|
||||
let targets = vec![sim.drones[0].pos];
|
||||
let radars = [search, engagement];
|
||||
for tick in 1..=120 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
}
|
||||
let own = sim.sams[engagement].track(id).expect("the engagement radar measured the target");
|
||||
assert_eq!(own.source, sim.sams[engagement].id);
|
||||
assert_eq!(own.product, Measure::Fire);
|
||||
assert!(own.quality >= FIRE_QUALITY && own.own_authorizes(sim.tick));
|
||||
let relayed = sim.sams[receiver].track(id).expect("the network shared the plot");
|
||||
assert_eq!(relayed.own_tick, 0, "a relay became the receiver's own measurement");
|
||||
assert_eq!(relayed.tick, own.tick, "a relay refreshed the measurement's age");
|
||||
assert!(relayed.product == Measure::Fire && relayed.quality == own.quality, "relay lost product/quality");
|
||||
assert_eq!(relayed.source, sim.sams[engagement].id, "relay lost the measuring station");
|
||||
assert!(!relayed.own_authorizes(sim.tick));
|
||||
let opts = why::Opts { last_chance: false, far_shots: false };
|
||||
{
|
||||
let load = sim.sams[receiver].kind.spec().missile.as_ref().unwrap();
|
||||
let drone = &sim.drones[0];
|
||||
assert!(why::basis(&sim.sams[receiver], load, relayed, drone, sim.tick, 0, 1.0, opts, true, false).is_none(), "a relayed plot authorized a launch");
|
||||
}
|
||||
// A launcher without a radar may use the supporting radar's own confirmed plot.
|
||||
sim.sams[receiver].set_mode(battery::SamMode::LauncherOnly);
|
||||
for tick in 121..=122 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
}
|
||||
let relayed = *sim.sams[receiver].track(id).expect("the launcher re-received the network plot");
|
||||
assert!(why::radar_cue(&sim.sams[receiver], &[&sim.sams[engagement]], id, sim.tick));
|
||||
{
|
||||
let load = sim.sams[receiver].kind.spec().missile.as_ref().unwrap();
|
||||
let drone = &sim.drones[0];
|
||||
assert!(why::basis(&sim.sams[receiver], load, &relayed, drone, sim.tick, 0, 1.0, opts, true, false).is_some());
|
||||
}
|
||||
// The search radar's plot is coarse: it does not authorize even a launcher.
|
||||
assert!(!why::radar_cue(&sim.sams[receiver], &[&sim.sams[search]], id, sim.tick));
|
||||
// A broken data link ends the cue even while the radar itself still measures.
|
||||
sim.sams[engagement].comps.0[Part::Comms as usize] = 0.0;
|
||||
assert_eq!(sim.sams[engagement].link_range(), 0.0);
|
||||
assert!(!why::radar_cue(&sim.sams[receiver], &[&sim.sams[engagement]], id, sim.tick), "a broken link still cued a launch");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_air_picture_prefers_the_better_plot_at_one_tick() {
|
||||
let mut sim = Sim::new(1345);
|
||||
let search = radar_with_role(&mut sim, RadarRole::Search, 0.0);
|
||||
let track = radar_with_role(&mut sim, RadarRole::Engagement, 10.0);
|
||||
sim.add_drone(DroneKind::Gerbera, DVec3::new(120.0, 120.0, 0.0), DVec3::Z, DVec3::new(120.0, 120.0, 0.0));
|
||||
let id = sim.drones[0].id;
|
||||
let mut ground = Ground::default();
|
||||
let targets = vec![sim.drones[0].pos];
|
||||
for tick in 1..=5 {
|
||||
sweep(&mut sim, &mut ground, &[search, track], &targets, tick);
|
||||
}
|
||||
let pic = sim.air_picture();
|
||||
let t = pic.tracks.iter().find(|t| t.id == id).expect("the raid is on the picture");
|
||||
assert_eq!(t.source, sim.sams[track].id, "a coarse plot won over the better one at the same tick");
|
||||
assert_eq!(t.product, Measure::Fire);
|
||||
assert!(t.own_authorizes(sim.tick));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tracked_channels_are_a_hard_limit_but_the_rest_keep_search_plots() {
|
||||
let mut sim = Sim::new(1344);
|
||||
let engagement = radar_with_role(&mut sim, RadarRole::Engagement, 0.0);
|
||||
for x in [100.0, 140.0, 180.0, 220.0] {
|
||||
sim.add_drone(DroneKind::Gerbera, DVec3::new(x, 120.0, 0.0), DVec3::Z, DVec3::new(x, 120.0, 0.0));
|
||||
}
|
||||
let mut ground = Ground::default();
|
||||
let targets: Vec<DVec3> = sim.drones.iter().map(|d| d.pos).collect();
|
||||
for tick in 1..=40 {
|
||||
sweep(&mut sim, &mut ground, &[engagement], &targets, tick);
|
||||
}
|
||||
let own: Vec<&Track> = sim.sams[engagement].tracks.iter().filter(|t| t.own_tick > 0).collect();
|
||||
let precise = own.iter().filter(|t| t.own_product != Measure::Search).count();
|
||||
assert_eq!(precise, 2, "the station refined more contacts than its channels: {own:?}");
|
||||
assert_eq!(sim.sams[engagement].own_channels_used(), 2);
|
||||
assert_eq!(own.len(), 4, "a full station stopped giving coarse search plots: {own:?}");
|
||||
assert!(own.iter().filter(|t| t.own_product == Measure::Search).all(|t| !t.own_authorizes(sim.tick)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn off_and_damage_remove_the_station_and_its_quality_without_touching_neighbours() {
|
||||
let mut sim = Sim::new(1342);
|
||||
let search = radar_with_role(&mut sim, RadarRole::Search, 0.0);
|
||||
let engagement = radar_with_role(&mut sim, RadarRole::Engagement, 20.0);
|
||||
sim.add_drone(DroneKind::Gerbera, DVec3::new(150.0, 120.0, 0.0), DVec3::Z, DVec3::new(150.0, 120.0, 0.0));
|
||||
let id = sim.drones[0].id;
|
||||
let mut ground = Ground::default();
|
||||
let targets = vec![sim.drones[0].pos];
|
||||
let radars = [search, engagement];
|
||||
for tick in 1..=80 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
}
|
||||
assert!(sim.sams[engagement].track(id).is_some_and(|t| t.own_authorizes(sim.tick)));
|
||||
let healthy = sim.sams[engagement].track(id).unwrap().own_quality;
|
||||
// Off: the station emits nothing, its own plots stop, the neighbour still feeds the network.
|
||||
sim.sams[engagement].radar_on = false;
|
||||
let before = sim.sams[engagement].track(id).map(|t| t.own_tick);
|
||||
for tick in 81..=110 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
}
|
||||
assert!(!sim.sams[engagement].radar_up());
|
||||
assert_eq!(sim.sams[engagement].track(id).map(|t| t.own_tick), before, "a silent radar renewed its own plot");
|
||||
assert!(sim.sams[search].track(id).is_some_and(|t| t.own_tick > 0));
|
||||
// Damage: a worn sensor still measures, with worse quality and no launch right.
|
||||
sim.sams[engagement].radar_on = true;
|
||||
sim.sams[engagement].comps.0[Part::Sensor as usize] = 0.2;
|
||||
for tick in 111..=180 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
}
|
||||
let worn = sim.sams[engagement].track(id).expect("a worn radar still measures");
|
||||
assert!(worn.own_quality < healthy, "damage did not lower quality: {worn:?}");
|
||||
assert!(!worn.own_authorizes(sim.tick), "a worn sensor still authorized a launch");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multifunction_and_embedded_radars_keep_their_fire_authority() {
|
||||
let mut sim = Sim::new(1343);
|
||||
let multi = radar_with_role(&mut sim, RadarRole::Multifunction, 0.0);
|
||||
let pantsir = radar_at(&mut sim, SamKind::Pantsir, 20.0);
|
||||
sim.add_drone(DroneKind::Gerbera, DVec3::new(120.0, 120.0, 0.0), DVec3::Z, DVec3::new(120.0, 120.0, 0.0));
|
||||
let id = sim.drones[0].id;
|
||||
let mut ground = Ground::default();
|
||||
let targets = vec![sim.drones[0].pos];
|
||||
let radars = [multi, pantsir];
|
||||
for tick in 1..=100 {
|
||||
sweep(&mut sim, &mut ground, &radars, &targets, tick);
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user