Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 433e1500e2 | |||
| 01765027b1 | |||
| 24b8cce11b | |||
| 502d94c528 |
@@ -193,7 +193,9 @@ API мода `render.set-lights` (до 512, плавно интерполиру
|
||||
трек-прогноз оранжевый и помечен возрастом. Свои перехватчики — маленькие жёлтые квадраты. Это данные сети
|
||||
РЛС, как на радаре и карте; в режиме «Истина» (`/airdef truth on`, T на карте) добавляются белые рамки
|
||||
реальных дронов с их настоящим типом — отдельно от сетевых оценок, чтобы видеть расхождение. Отпустил
|
||||
клавишу — метки исчезли. Метки проектируются через камеру последнего отрисованного кадра (`render.project`,
|
||||
клавишу — метки исчезли. Метки достаются ближайшим из видимых целей: цель за камерой или за краем
|
||||
экрана бюджет кадра не тратит, а заголовок показывает, сколько целей в кадре, сколько за кадром и сколько
|
||||
не поместилось в бюджет. Метки проектируются через камеру последнего отрисованного кадра (`render.project`,
|
||||
API 31 форка) и следуют за взглядом покадрово; поверх повтора, сетки J, монитора K и карты M обзор не рисуется.
|
||||
|
||||
**Повторы.** Каждый налёт записывается сам: с первой цели в небе до момента, когда небо 5 с чисто
|
||||
|
||||
+175
-38
@@ -5,14 +5,22 @@
|
||||
//! network's. The player's own interceptors wear small yellow squares, as the radar shows them.
|
||||
//! Letting the key go hides everything. The markers are projected through the camera the last
|
||||
//! drawn frame used (`render.project`, API 31), so they sit on the world as it is drawn.
|
||||
//! Visibility comes before the draw budget (#141): each layer projects at most a bounded number
|
||||
//! of its nearest candidates, keeps the markers of the nearest visible ones, and counts a target
|
||||
//! that leaves the frame without spending a slot.
|
||||
use crate::panel::distance;
|
||||
use crate::sim::{ClassEst, Sim, Track};
|
||||
use glam::DVec3;
|
||||
use horizon_mod_sdk::render::{FillShape, Point, Rect, Shape, TextShape};
|
||||
|
||||
/// The most markers of one picture (the network's and the truth's each): a full raid still fits
|
||||
/// the HUD's 1024 shapes — a marker is four sides and a label.
|
||||
/// The most markers of one picture (the network's, the truth's and the interceptors' each): a full
|
||||
/// raid still fits the HUD's 1024 shapes — a marker is four sides and a label.
|
||||
const MAX_MARKERS: usize = 64;
|
||||
/// The most candidates of one layer the frame looks at: the nearest ones by distance. The draw
|
||||
/// budget is spent on what is in frame, but the projection work stays bounded — a crowd the frame
|
||||
/// does not hold cannot buy an unbounded scan, and what the scan never reaches counts as past the
|
||||
/// budget rather than out of the frame.
|
||||
const MAX_SCAN: usize = 4 * MAX_MARKERS;
|
||||
/// A marker's side thickness, pixels.
|
||||
const LINE: f32 = 1.0;
|
||||
/// A label line's height (the HUD font with its shadow).
|
||||
@@ -86,6 +94,50 @@ fn label_y(y: f32, half: f32, gui_h: f32, above: bool) -> f32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// What one layer shows this frame: the markers to draw (the nearest visible candidates), how
|
||||
/// many of the scanned candidates left the frame, and how many the budgets left out.
|
||||
struct Pick<T> {
|
||||
marks: Vec<(T, Point, f32)>,
|
||||
offscreen: usize,
|
||||
capped: usize,
|
||||
}
|
||||
|
||||
/// The markers one layer gets this frame. The candidates are ordered nearest the player first and
|
||||
/// at most [`MAX_SCAN`] of them are projected; a candidate the frame does not hold (behind the
|
||||
/// camera or past an edge) is counted and its slot stays free for the next, so the nearest
|
||||
/// [`MAX_MARKERS`] visible candidates are drawn. Work stays bounded by the scan, not the picture.
|
||||
fn pick<T: Copy>(
|
||||
items: impl Iterator<Item = T>,
|
||||
at: impl Fn(T) -> DVec3,
|
||||
half_at: impl Fn(T) -> f32,
|
||||
player: DVec3,
|
||||
gui: (f32, f32),
|
||||
project: &impl Fn(DVec3) -> Option<Point>,
|
||||
) -> Pick<T> {
|
||||
let near = |a: &T, b: &T| at(*a).distance(player).total_cmp(&at(*b).distance(player));
|
||||
let mut items: Vec<T> = items.collect();
|
||||
let total = items.len();
|
||||
// Only the nearest candidates are ever projected: no sort of the whole picture is needed.
|
||||
if items.len() > MAX_SCAN {
|
||||
items.select_nth_unstable_by(MAX_SCAN, near);
|
||||
items.truncate(MAX_SCAN);
|
||||
}
|
||||
items.sort_by(near);
|
||||
let mut marks = Vec::new();
|
||||
let mut offscreen = 0usize;
|
||||
for it in items {
|
||||
if marks.len() >= MAX_MARKERS {
|
||||
break;
|
||||
}
|
||||
let h = half_at(it);
|
||||
match project(at(it)) {
|
||||
Some(p) if p.x >= h && p.x <= gui.0 - h && p.y >= h && p.y <= gui.1 - h => marks.push((it, p, h)),
|
||||
_ => offscreen += 1,
|
||||
}
|
||||
}
|
||||
Pick { capped: total - marks.len() - offscreen, marks, offscreen }
|
||||
}
|
||||
|
||||
/// The overlay's shapes for this frame. `project` is the game's `render.project` (the last drawn
|
||||
/// frame's camera); a point behind the camera projects to None, a point off the screen still
|
||||
/// projects past its edges — both are counted, not drawn. Drawn only while the key is held.
|
||||
@@ -97,20 +149,17 @@ pub fn draw(sim: &Sim, player: DVec3, gui: (f32, f32), project: impl Fn(DVec3) -
|
||||
let pic = sim.air_picture();
|
||||
let now = pic.now;
|
||||
let truth = sim.truth && !pic.unaided;
|
||||
// The network's tracks, nearest first: a full raid keeps the closest markers.
|
||||
let mut tracks: Vec<&Track> = pic.tracks.iter().collect();
|
||||
tracks.sort_by(|a, b| a.est(now).distance(player).total_cmp(&b.est(now).distance(player)));
|
||||
// The frame's counts: what got a marker and what did not — out of the frame (behind the camera
|
||||
// or past an edge) or past the budget. The header keeps the two apart (#141).
|
||||
let mut shown = 0usize;
|
||||
let mut hidden = tracks.len().saturating_sub(MAX_MARKERS);
|
||||
for t in tracks.into_iter().take(MAX_MARKERS) {
|
||||
let e = t.est(now);
|
||||
let dist = e.distance(player);
|
||||
let Some(p) = project(e) else { hidden += 1; continue };
|
||||
let h = half(dist);
|
||||
if p.x < h || p.x > gui.0 - h || p.y < h || p.y > gui.1 - h {
|
||||
hidden += 1;
|
||||
continue;
|
||||
}
|
||||
let mut offscreen = 0usize;
|
||||
let mut capped = 0usize;
|
||||
// The network's tracks: the nearest visible keep the markers; a target behind the camera no
|
||||
// longer spends one, so a crowd behind cannot crowd out the target in frame.
|
||||
let net = pick(pic.tracks.iter(), |t| t.est(now), |t| half(t.est(now).distance(player)), player, gui, &project);
|
||||
offscreen += net.offscreen;
|
||||
capped += net.capped;
|
||||
for (t, p, h) in net.marks {
|
||||
// Fresh: red; a forecast: orange, fading as it ages towards the track's drop (the radar's colours).
|
||||
let (color, a) = if pic.unaided {
|
||||
(RED, 1.0)
|
||||
@@ -128,16 +177,17 @@ pub fn draw(sim: &Sim, player: DVec3, gui: (f32, f32), project: impl Fn(DVec3) -
|
||||
// with the actual type the network never shows. A tracked drone wears both: the network's
|
||||
// estimate under the square, the truth over it — the offset between them is the point.
|
||||
if truth {
|
||||
let mut drones: Vec<_> = sim.drones.iter().filter(|d| d.alive()).collect();
|
||||
drones.sort_by(|a, b| a.pos.distance(player).total_cmp(&b.pos.distance(player)));
|
||||
hidden += drones.len().saturating_sub(MAX_MARKERS);
|
||||
for d in drones.into_iter().take(MAX_MARKERS) {
|
||||
let Some(p) = project(d.pos) else { hidden += 1; continue };
|
||||
let h = half(d.pos.distance(player)) + 2.0;
|
||||
if p.x < h || p.x > gui.0 - h || p.y < h || p.y > gui.1 - h {
|
||||
hidden += 1;
|
||||
continue;
|
||||
}
|
||||
let real = pick(
|
||||
sim.drones.iter().filter(|d| d.alive()),
|
||||
|d| d.pos,
|
||||
|d| half(d.pos.distance(player)) + 2.0,
|
||||
player,
|
||||
gui,
|
||||
&project,
|
||||
);
|
||||
offscreen += real.offscreen;
|
||||
capped += real.capped;
|
||||
for (d, p, h) in real.marks {
|
||||
s.extend(square_outline(p.x, p.y, h, WHITE));
|
||||
let label = format!("{} {}", d.kind.spec().name, distance(d.pos.distance(player)));
|
||||
s.push(text(label, p.x, label_y(p.y, h, gui.1, true), WHITE, true));
|
||||
@@ -145,24 +195,18 @@ pub fn draw(sim: &Sim, player: DVec3, gui: (f32, f32), project: impl Fn(DVec3) -
|
||||
}
|
||||
}
|
||||
// The player's own interceptors: small yellow squares, no label — they are not targets, and
|
||||
// the network never hid them (the radar has always shown them).
|
||||
let mut missiles: Vec<_> = sim.missiles.iter().collect();
|
||||
missiles.sort_by(|a, b| a.pos.distance(player).total_cmp(&b.pos.distance(player)));
|
||||
for m in missiles.into_iter().take(MAX_MARKERS) {
|
||||
let Some(p) = project(m.pos) else { continue };
|
||||
let h = MISSILE_HALF;
|
||||
if p.x < h || p.x > gui.0 - h || p.y < h || p.y > gui.1 - h {
|
||||
continue;
|
||||
}
|
||||
// the network never hid them (the radar has always shown them). They keep their own budget.
|
||||
let own = pick(sim.missiles.iter(), |m| m.pos, |_| MISSILE_HALF, player, gui, &project);
|
||||
for (_, p, h) in own.marks {
|
||||
s.extend(square_outline(p.x, p.y, h, MISSILE));
|
||||
}
|
||||
// The mode, named as the map names it: the network's data by default, the sandbox's truth
|
||||
// explicitly marked. The counts say what the frame holds and what stayed behind the camera
|
||||
// or past the edges.
|
||||
// explicitly marked. The counts say what the frame holds, what left it, and what the budget cut.
|
||||
let counts = format!("в кадре {shown}, за кадром {offscreen}, сверх бюджета {capped}");
|
||||
let head = if truth {
|
||||
format!("ОБЗОР · ИСТИНА (песочница): белые рамки — реальные дроны · в кадре {shown}, за кадром {hidden}")
|
||||
format!("ОБЗОР · ИСТИНА (песочница): белые рамки — реальные дроны · {counts}")
|
||||
} else {
|
||||
format!("ОБЗОР · данные сети РЛС · в кадре {shown}, за кадром {hidden}")
|
||||
format!("ОБЗОР · данные сети РЛС · {counts}")
|
||||
};
|
||||
s.push(text(head, gui.0 / 2.0, 2.0, if truth { YELLOW } else { GREEN }, true));
|
||||
s
|
||||
@@ -201,6 +245,17 @@ mod tests {
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn head(shapes: &[Shape]) -> String {
|
||||
texts(shapes).into_iter().find(|t| t.text.starts_with("ОБЗОР")).expect("no header").text.clone()
|
||||
}
|
||||
|
||||
/// `n` targets in a row right behind the camera, each nearer than anything the tests put ahead.
|
||||
fn crowd_behind(sim: &mut Sim, n: u32) {
|
||||
for i in 0..n {
|
||||
sim.launch(DroneKind::Shahed, DVec3::new(i as f64, 64.0, -50.0), DVec3::ZERO, DVec3::new(0.0, 64.0, -5000.0), &mut Out::default());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_visible_target_gets_a_square_and_a_short_line() {
|
||||
let sim = sim_with(DroneKind::Shahed, DVec3::new(0.0, 64.0, 100.0));
|
||||
@@ -282,6 +337,88 @@ mod tests {
|
||||
assert!(fills(&shapes, RED) / 4 <= MAX_MARKERS);
|
||||
}
|
||||
|
||||
/// #141: 64 targets behind the camera and one in frame. The budget used to be spent on the
|
||||
/// crowd before the visibility check, so the picture came out empty; the target in frame must
|
||||
/// keep its marker, and the crowd is out of frame, not past the budget.
|
||||
#[test]
|
||||
fn a_crowd_behind_the_camera_leaves_the_network_budget_to_the_target_in_frame() {
|
||||
let mut sim = Sim::new(1);
|
||||
crowd_behind(&mut sim, 64);
|
||||
sim.launch(DroneKind::Shahed, DVec3::new(0.0, 64.0, 100.0), DVec3::ZERO, DVec3::new(0.0, 64.0, 5000.0), &mut Out::default());
|
||||
let shapes = draw(&sim, DVec3::new(0.0, 64.0, 0.0), GUI, ahead);
|
||||
assert_eq!(fills(&shapes, RED), 4, "the target in frame got no marker");
|
||||
assert_eq!(head(&shapes), "ОБЗОР · данные сети РЛС · в кадре 1, за кадром 64, сверх бюджета 0");
|
||||
assert!(shapes.len() <= 1024, "{} shapes", shapes.len());
|
||||
}
|
||||
|
||||
/// The truth layer keeps its own budget the same way: the real drone in frame is drawn, the
|
||||
/// crowd behind the camera costs no white marker.
|
||||
#[test]
|
||||
fn a_crowd_behind_the_camera_leaves_the_truth_budget_to_the_target_in_frame() {
|
||||
let mut sim = Sim::new(1);
|
||||
let id = sim.id();
|
||||
sim.sams.push(Sam::new(id, SamKind::Buk, DVec3::new(0.0, 64.0, 0.0), 0.0));
|
||||
sim.truth = true;
|
||||
crowd_behind(&mut sim, 64);
|
||||
sim.launch(DroneKind::Shahed, DVec3::new(0.0, 64.0, 100.0), DVec3::ZERO, DVec3::new(0.0, 64.0, 5000.0), &mut Out::default());
|
||||
let shapes = draw(&sim, DVec3::new(0.0, 64.0, 0.0), GUI, ahead);
|
||||
assert_eq!(fills(&shapes, WHITE), 4, "the drone in frame got no truth marker");
|
||||
assert_eq!(fills(&shapes, RED), 0, "the network drew a track it does not hold");
|
||||
assert_eq!(head(&shapes), "ОБЗОР · ИСТИНА (песочница): белые рамки — реальные дроны · в кадре 1, за кадром 64, сверх бюджета 0");
|
||||
assert!(shapes.len() <= 1024, "{} shapes", shapes.len());
|
||||
}
|
||||
|
||||
/// The interceptors keep their own budget too: a salvo behind the camera leaves the marker
|
||||
/// to the one in frame.
|
||||
#[test]
|
||||
fn a_crowd_behind_the_camera_leaves_the_interceptor_budget_to_the_one_in_frame() {
|
||||
let mut sim = Sim::new(1);
|
||||
for i in 0..64 {
|
||||
sim.missiles.push(crate::sim::Missile::test_at(i + 1, DVec3::new(i as f64, 64.0, -50.0), 0));
|
||||
}
|
||||
sim.missiles.push(crate::sim::Missile::test_at(100, DVec3::new(0.0, 64.0, 100.0), 0));
|
||||
let shapes = draw(&sim, DVec3::new(0.0, 64.0, 0.0), GUI, ahead);
|
||||
assert_eq!(fills(&shapes, MISSILE), 4, "the interceptor in frame got no marker");
|
||||
assert!(shapes.len() <= 1024, "{} shapes", shapes.len());
|
||||
}
|
||||
|
||||
/// The header tells what really left the frame from what the draw budget cut, and the markers
|
||||
/// go to the nearest of the visible: 64 behind the camera, 65 in frame.
|
||||
#[test]
|
||||
fn the_header_separates_the_frames_edge_from_the_draw_budget() {
|
||||
let mut sim = Sim::new(1);
|
||||
crowd_behind(&mut sim, 64);
|
||||
for i in 0..65 {
|
||||
let z = 100.0 + i as f64 * 10.0;
|
||||
sim.launch(DroneKind::Shahed, DVec3::new(0.0, 64.0, z), DVec3::ZERO, DVec3::new(0.0, 64.0, 5000.0), &mut Out::default());
|
||||
}
|
||||
let shapes = draw(&sim, DVec3::new(0.0, 64.0, 0.0), GUI, ahead);
|
||||
// The 64 nearest in frame are drawn; the farthest one is past the draw budget, not out of frame.
|
||||
assert_eq!(fills(&shapes, RED), 4 * MAX_MARKERS);
|
||||
assert!(texts(&shapes).iter().any(|t| t.text.contains("100 м")), "the nearest visible lost its marker");
|
||||
assert!(!texts(&shapes).iter().any(|t| t.text.contains("740 м")), "the farthest visible took a nearer one's marker");
|
||||
assert_eq!(head(&shapes), "ОБЗОР · данные сети РЛС · в кадре 64, за кадром 64, сверх бюджета 1");
|
||||
assert!(shapes.len() <= 1024, "{} shapes", shapes.len());
|
||||
}
|
||||
|
||||
/// The projection work itself is bounded: with more candidates than the scan budget, only the
|
||||
/// nearest `MAX_SCAN` are looked at, and the rest are counted as past the budget.
|
||||
#[test]
|
||||
fn the_projection_work_is_bounded_by_the_scan_budget() {
|
||||
let mut sim = Sim::new(1);
|
||||
for i in 0..1000 {
|
||||
sim.launch(DroneKind::Shahed, DVec3::new((i % 100) as f64, 64.0, -50.0), DVec3::ZERO, DVec3::new(0.0, 64.0, -5000.0), &mut Out::default());
|
||||
}
|
||||
let calls = std::cell::Cell::new(0usize);
|
||||
let shapes = draw(&sim, DVec3::new(0.0, 64.0, 0.0), GUI, |p| {
|
||||
calls.set(calls.get() + 1);
|
||||
ahead(p)
|
||||
});
|
||||
assert_eq!(calls.get(), MAX_SCAN, "one layer projected more than its scan budget");
|
||||
assert_eq!(head(&shapes), "ОБЗОР · данные сети РЛС · в кадре 0, за кадром 256, сверх бюджета 744");
|
||||
assert!(shapes.len() <= 1024, "{} shapes", shapes.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interceptors_wear_small_yellow_squares_without_labels() {
|
||||
let mut sim = sim_with(DroneKind::Shahed, DVec3::new(0.0, 64.0, 100.0));
|
||||
|
||||
@@ -403,7 +403,7 @@ impl Sim {
|
||||
);
|
||||
for l in &s.pending {
|
||||
body += &format!(
|
||||
"airrecobs {} {} {} {} {} {} {} {} {} {}\n",
|
||||
"airrecobs {} {} {} {} {} {} {} {} {} {} {}\n",
|
||||
l.truth,
|
||||
coord(l.area.x),
|
||||
coord(l.area.y),
|
||||
@@ -414,6 +414,7 @@ impl Sim {
|
||||
l.quality.name(),
|
||||
l.source.name(),
|
||||
l.observed,
|
||||
l.wreck,
|
||||
);
|
||||
}
|
||||
for z in &s.zones {
|
||||
@@ -715,8 +716,8 @@ impl Sim {
|
||||
recon_expect.push((pending, zones));
|
||||
}
|
||||
"airrecobs" => {
|
||||
if w.len() != 11 {
|
||||
return Err(l.bad("наблюдение разведки", "нужны юнит, место, категория, источник и такт"));
|
||||
if w.len() != 11 && w.len() != 12 {
|
||||
return Err(l.bad("наблюдение разведки", "нужны юнит, место, категория, источник, такт и признак остова"));
|
||||
}
|
||||
let Some(at) = recon_sortie_at else {
|
||||
return Err(l.bad("наблюдение разведки", "строка без разведчика"));
|
||||
@@ -739,7 +740,10 @@ impl Sim {
|
||||
let quality = recon::Quality::from_key(l.word(8, "качество")?).ok_or_else(|| l.bad("качество", "coarse или refined"))?;
|
||||
let source = recon::Source::from_key(l.word(9, "источник")?).ok_or_else(|| l.bad("источник", "flyby, emission, jamming или launch"))?;
|
||||
let observed = l.int(10, "такт наблюдения", 0, tick as i64)? as u64;
|
||||
recon.sorties[at].pending.push(recon::Look { truth, area, radius, category, role, quality, source, observed });
|
||||
// An older save has no wreck flag: every pending look it holds is of a unit
|
||||
// that was alive when it was seen.
|
||||
let wreck = if w.len() > 11 { l.flag(11, "остов")? } else { false };
|
||||
recon.sorties[at].pending.push(recon::Look { truth, area, radius, category, role, quality, source, observed, wreck });
|
||||
}
|
||||
"airreczone" => {
|
||||
if w.len() != 5 {
|
||||
|
||||
+255
-23
@@ -11,7 +11,9 @@
|
||||
//! What is reported is memory, not truth. A hidden move, a switch-off, a re-role or a
|
||||
//! kill does not rewrite a mark; only a later look can. A repeated report of the same
|
||||
//! observation does not raise its confidence: confidence is the mark's age alone, and a
|
||||
//! second independent look may refine the area and (for a radar) its role.
|
||||
//! second independent look may refine the area and (for a radar) its role. A wreck a look
|
||||
//! flies over is not a lead: a fresh one makes no mark, and one the picture already held is
|
||||
//! radioed home as destroyed and its mark leaves the picture (#139).
|
||||
use super::*;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@@ -240,6 +242,8 @@ pub(super) struct Look {
|
||||
pub(super) quality: Quality,
|
||||
pub(super) source: Source,
|
||||
pub(super) observed: u64,
|
||||
/// The unit was a wreck when it was seen: the report takes its mark out of the picture.
|
||||
pub(super) wreck: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -368,6 +372,13 @@ impl Recon {
|
||||
if look.observed <= old.observed {
|
||||
return;
|
||||
}
|
||||
// The flight saw the wreck itself: the station is off the planner's leads, and
|
||||
// only the observation — never a hidden kill — takes the mark away (#139).
|
||||
if look.wreck {
|
||||
self.marks.remove(&id);
|
||||
self.truth.remove(&id);
|
||||
return;
|
||||
}
|
||||
let refine = look.observed.saturating_sub(old.observed) >= REFINE_GAP;
|
||||
let m = self.marks.get_mut(&id).unwrap();
|
||||
m.area = look.area;
|
||||
@@ -383,6 +394,10 @@ impl Recon {
|
||||
}
|
||||
}
|
||||
None => {
|
||||
// A wreck is no target: a first look at one leaves no mark at all.
|
||||
if look.wreck {
|
||||
return;
|
||||
}
|
||||
if self.marks.len() >= MAX_MARKS || self.next >= MARK_TOP - ID_BASE - 1 {
|
||||
return;
|
||||
}
|
||||
@@ -446,6 +461,29 @@ pub(super) fn look(sams: &[Sam], state: &Recon, intel: &ew::Intel, zone: &Zone,
|
||||
break;
|
||||
}
|
||||
let old = state.mark_for_truth(s.id);
|
||||
// The jitter is the zone's, not the unit's: the mark must not carry the unit id even
|
||||
// indirectly.
|
||||
let salt = (zone.center.x.round() as i64 as u32) ^ (zone.center.z.round() as i64 as u32).rotate_left(16);
|
||||
// A wreck is no lead and no emitter (#139). A fresh one makes no mark; one the picture
|
||||
// already held is reported as destroyed, and the report takes the old mark away. A
|
||||
// hidden kill never passes through here, so it never rewrites the picture.
|
||||
if !s.alive() {
|
||||
if old.is_none() {
|
||||
continue;
|
||||
}
|
||||
out.push(Look {
|
||||
truth: s.id,
|
||||
area: area_of(s.pos, COARSE_AREA, salt),
|
||||
radius: COARSE_AREA,
|
||||
category: Category::of(s.kind),
|
||||
role: None,
|
||||
quality: Quality::Coarse,
|
||||
source: Source::Flyby,
|
||||
observed: now,
|
||||
wreck: true,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
let refine = old.is_some_and(|m| now.saturating_sub(m.observed) >= REFINE_GAP);
|
||||
let quality = if refine { Quality::Refined } else { Quality::Coarse };
|
||||
let cell = if refine { REFINED_AREA } else { COARSE_AREA };
|
||||
@@ -453,17 +491,17 @@ pub(super) fn look(sams: &[Sam], state: &Recon, intel: &ew::Intel, zone: &Zone,
|
||||
// A launch is a public event already watched by the disclosure channel; a look that
|
||||
// passes just after one can name that source too. Health, magazine and link never are.
|
||||
let launched = intel.contacts().get(&s.id).is_some_and(|c| c.seen == ew::Seen::Launch && now.saturating_sub(c.tick) < 200);
|
||||
// The switch is intent, not work: a radar is an emitter only while `radar_up`, a jammer
|
||||
// only while the transmitter is really on the air. A silent, packed or failed one is
|
||||
// just a unit the flyby saw.
|
||||
let source = match s.kind {
|
||||
SamKind::Ew if s.ew_on => Source::Jamming,
|
||||
SamKind::Radar if s.radar_on => Source::Emission,
|
||||
SamKind::Ew if s.ew_up() => Source::Jamming,
|
||||
SamKind::Radar if s.radar_up() => Source::Emission,
|
||||
_ if launched => Source::Launch,
|
||||
_ => Source::Flyby,
|
||||
};
|
||||
// The role is a public radar configuration only when a close second look can tell it.
|
||||
let role = (refine && s.kind == SamKind::Radar).then_some(s.radar_role);
|
||||
// The jitter is the zone's, not the unit's: the mark must not carry the unit id even
|
||||
// indirectly.
|
||||
let salt = (zone.center.x.round() as i64 as u32) ^ (zone.center.z.round() as i64 as u32).rotate_left(16);
|
||||
out.push(Look {
|
||||
truth: s.id,
|
||||
area: area_of(s.pos, cell, salt),
|
||||
@@ -473,6 +511,7 @@ pub(super) fn look(sams: &[Sam], state: &Recon, intel: &ew::Intel, zone: &Zone,
|
||||
quality,
|
||||
source,
|
||||
observed: now,
|
||||
wreck: false,
|
||||
});
|
||||
}
|
||||
out
|
||||
@@ -795,6 +834,7 @@ mod tests {
|
||||
quality: Quality::Refined,
|
||||
source: before.source,
|
||||
observed: before.observed,
|
||||
wreck: false,
|
||||
};
|
||||
sim.recon.report(look, before.reported + 10_000);
|
||||
let after = *sim.recon.marks.values().next().unwrap();
|
||||
@@ -824,35 +864,224 @@ mod tests {
|
||||
s.missiles = 0;
|
||||
sim.tick += 1000;
|
||||
assert_eq!(key(&sim.enemy_picture().recon), key(&before), "a hidden change rewrote the recon picture");
|
||||
// A hidden kill does not take the mark away either: it is still a lead until its age
|
||||
// runs out, and then it is forgotten like any other unrevisited mark (#139).
|
||||
let mark = before.first().expect("the look made no mark").id;
|
||||
let observed = sim.recon.marks.get(&mark).expect("the mark is gone").observed;
|
||||
assert!(sim.recon.leads(sim.tick).iter().any(|m| m.id == mark), "a hidden kill removed an active lead");
|
||||
assert!(sim.recon.leads(observed + MARK_TTL - 1).iter().any(|m| m.id == mark), "a mark died before its age");
|
||||
assert!(sim.recon.leads(observed + MARK_TTL).iter().all(|m| m.id != mark), "a mark outlived its age");
|
||||
}
|
||||
|
||||
|
||||
// #135: the channel matters. A silent radar is seen only by the flyby, a transmitting
|
||||
// radar by its emission, a jamming station by its transmission, and a just-fired system
|
||||
// by the launch the disclosure channel already watched. A hidden switch or magazine is
|
||||
// not read: only what the game shows.
|
||||
// #139: a look at a wreck is not a lead. A station destroyed before the flight arrives, with
|
||||
// its switch still on, makes no mark and no lead; its report is an empty observation.
|
||||
#[test]
|
||||
fn the_source_is_the_channel_that_showed_the_unit() {
|
||||
fn a_fresh_wreck_makes_no_mark_and_no_lead() {
|
||||
let mut sim = Sim::new(21);
|
||||
let object = DVec3::new(0.0, 70.0, 0.0);
|
||||
let id = sam(&mut sim, SamKind::Radar, object + DVec3::new(20.0, 0.0, 10.0));
|
||||
let s = sim.sams.iter_mut().find(|s| s.id == id).unwrap();
|
||||
s.health = 0.0;
|
||||
s.radar_on = true;
|
||||
assert!(!s.radar_up(), "a destroyed radar still reported itself working");
|
||||
sim.start_recon(&[object], 0.0, 300.0, &mut Out::default());
|
||||
let (_, at) = look_once(&mut sim);
|
||||
assert!(sim.recon.marks.is_empty(), "a look at a fresh wreck reached the picture");
|
||||
sim.tick = at + REPORT_DELAY;
|
||||
sim.step_recon(&mut Out::default());
|
||||
assert!(sim.recon.marks.is_empty(), "a fresh wreck made a mark");
|
||||
assert!(sim.recon.leads(sim.tick).is_empty(), "a fresh wreck became an active lead");
|
||||
}
|
||||
|
||||
// #139: a hidden kill leaves the mark as the picture remembers it, but a look that flies over
|
||||
// the wreck reports the destruction and the mark leaves the leads. Nothing of it stays to
|
||||
// aim at, and a mark no look revisits still ages out on its own.
|
||||
#[test]
|
||||
fn a_known_mark_leaves_the_leads_when_its_wreck_is_seen() {
|
||||
let mut sim = Sim::new(22);
|
||||
let object = DVec3::new(0.0, 70.0, 0.0);
|
||||
let id = sam(&mut sim, SamKind::Radar, object + DVec3::new(20.0, 0.0, 10.0));
|
||||
sim.start_recon(&[object], 0.0, 300.0, &mut Out::default());
|
||||
let (_, at) = look_once(&mut sim);
|
||||
sim.tick = at + REPORT_DELAY;
|
||||
sim.step_recon(&mut Out::default());
|
||||
let mark = sim.recon.mark_for_truth(id).expect("a live radar made no mark");
|
||||
assert!(sim.recon.leads(sim.tick).iter().any(|m| m.id == mark.id));
|
||||
|
||||
// A hidden kill is not an observation: the old assessment stands.
|
||||
sim.sams.iter_mut().find(|s| s.id == id).unwrap().health = 0.0;
|
||||
assert!(sim.recon.leads(sim.tick).iter().any(|m| m.id == mark.id), "a hidden kill removed the mark");
|
||||
|
||||
// A look that sees the wreck names it as a flyby, and its report takes the mark away.
|
||||
let zone = Zone { center: object, radius: ZONE_RADIUS };
|
||||
let wreck = super::look(&sim.sams, &sim.recon, &sim.intel, &zone, sim.tick).into_iter().find(|l| l.truth == id).expect("the wreck was not observed");
|
||||
assert!(wreck.wreck);
|
||||
assert_eq!(wreck.source, Source::Flyby, "a wreck named an emission");
|
||||
sim.recon.report(wreck, sim.tick + REPORT_DELAY);
|
||||
assert!(sim.recon.marks.is_empty(), "the wreck's report left a mark");
|
||||
assert!(sim.recon.truth.iter().all(|(_, t)| *t != id), "the wreck's truth mapping stayed");
|
||||
assert!(sim.recon.leads(sim.tick + REPORT_DELAY).is_empty(), "the wreck stayed an active lead");
|
||||
}
|
||||
|
||||
// #139: a wreck observation still waiting for its report is durable. A restored flight takes
|
||||
// the mark away on its tick, while an older save without the wreck flag reads as before.
|
||||
#[test]
|
||||
fn a_wreck_report_survives_a_save_and_removes_the_mark() {
|
||||
let mut sim = Sim::new(23);
|
||||
let object = DVec3::new(0.0, 70.0, 0.0);
|
||||
let id = sam(&mut sim, SamKind::Radar, object + DVec3::new(20.0, 0.0, 10.0));
|
||||
sim.start_recon(&[object], 0.0, 300.0, &mut Out::default());
|
||||
let (_, at) = look_once(&mut sim);
|
||||
sim.tick = at + REPORT_DELAY;
|
||||
sim.step_recon(&mut Out::default());
|
||||
let mark = sim.recon.mark_for_truth(id).expect("no mark to destroy");
|
||||
// The radar dies unseen; a second flight looks at the wreck and its report is unsent
|
||||
// when the save is taken.
|
||||
sim.sams.iter_mut().find(|s| s.id == id).unwrap().health = 0.0;
|
||||
sim.recon.sorties.clear();
|
||||
sim.recon.checked.clear();
|
||||
sim.start_recon(&[object], 0.0, 900.0, &mut Out::default());
|
||||
let (_, seen_wreck) = look_once(&mut sim);
|
||||
assert!(sim.recon.sorties.iter().flat_map(|s| &s.pending).any(|l| l.wreck), "the wreck was not pending");
|
||||
let text = sim.air_text().expect("a wreck report is durable");
|
||||
assert!(text.lines().any(|l| l.starts_with("airrecobs ") && l.ends_with(" true")), "the wreck flag was not written");
|
||||
|
||||
// An older save has no flag: the same look reads as a live re-observation.
|
||||
let legacy: String = text
|
||||
.lines()
|
||||
.map(|l| {
|
||||
if l.starts_with("airrecobs ") {
|
||||
let mut w: Vec<&str> = l.split_whitespace().collect();
|
||||
w.pop();
|
||||
w.join(" ")
|
||||
} else {
|
||||
l.to_string()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
+ "\n";
|
||||
let mut old = Sim::new(24);
|
||||
old.restore_air(Sim::parse_air(&legacy).expect("an older save reads").expect("the air section is there"));
|
||||
assert!(old.recon.sorties.iter().flat_map(|s| &s.pending).all(|l| !l.wreck), "an older save invented a wreck");
|
||||
|
||||
let mut back = Sim::new(25);
|
||||
back.restore_air(Sim::parse_air(&text).expect("the save reads").expect("the air section is there"));
|
||||
assert!(back.recon.marks.contains_key(&mark.id), "the save forgot the mark before its wreck report");
|
||||
assert!(back.recon.sorties.iter().flat_map(|s| &s.pending).any(|l| l.wreck), "the save lost the wreck report");
|
||||
back.tick = seen_wreck + REPORT_DELAY;
|
||||
back.step_recon(&mut Out::default());
|
||||
assert!(!back.recon.marks.contains_key(&mark.id), "a restored wreck report left the mark");
|
||||
assert!(back.recon.leads(back.tick).is_empty(), "a restored wreck report stayed an active lead");
|
||||
}
|
||||
|
||||
// #135/#139: the channel matters. A silent, packed or failed radar is only a flyby; so is a
|
||||
// jammer whose transmitter is off, packed or destroyed. Only a station actually working shows
|
||||
// its emission, and a wreck is no source at all. A just-fired system is still a launch the
|
||||
// disclosure channel already watched. A hidden empty magazine is not read.
|
||||
#[test]
|
||||
fn the_source_is_the_channel_that_showed_a_working_unit() {
|
||||
let mut sim = Sim::new(8);
|
||||
let zone = Zone { center: DVec3::new(0.0, 70.0, 0.0), radius: ZONE_RADIUS };
|
||||
let radar = sam(&mut sim, SamKind::Radar, DVec3::new(10.0, 70.0, 0.0));
|
||||
let ew = sam(&mut sim, SamKind::Ew, DVec3::new(-10.0, 70.0, 0.0));
|
||||
let s400 = sam(&mut sim, SamKind::S400, DVec3::new(0.0, 70.0, 10.0));
|
||||
sim.recon.checked.clear();
|
||||
let source = |sim: &Sim, id: u32| super::look(&sim.sams, &sim.recon, &sim.intel, &zone, sim.tick).into_iter().find(|l| l.truth == id).unwrap().source;
|
||||
let source = |sim: &Sim, id: u32| super::look(&sim.sams, &sim.recon, &sim.intel, &zone, sim.tick).into_iter().find(|l| l.truth == id).map(|l| l.source);
|
||||
fn unit(sim: &mut Sim, id: u32) -> &mut Sam {
|
||||
sim.sams.iter_mut().find(|s| s.id == id).unwrap()
|
||||
}
|
||||
|
||||
// Working: the radar emits and the jammer transmits.
|
||||
assert_eq!(source(&sim, radar), Some(Source::Emission));
|
||||
unit(&mut sim, ew).ew_on = true;
|
||||
assert_eq!(source(&sim, ew), Some(Source::Jamming));
|
||||
|
||||
// Off: the switch is intent, not work.
|
||||
unit(&mut sim, radar).radar_on = false;
|
||||
assert_eq!(source(&sim, radar), Some(Source::Flyby), "a silent radar was read as emitting");
|
||||
unit(&mut sim, radar).radar_on = true;
|
||||
unit(&mut sim, ew).ew_on = false;
|
||||
assert_eq!(source(&sim, ew), Some(Source::Flyby), "a silent jammer was read as transmitting");
|
||||
unit(&mut sim, ew).ew_on = true;
|
||||
|
||||
// Packed for a march: neither is on the air, whatever the switch says.
|
||||
unit(&mut sim, radar).state = SamState::Moving;
|
||||
unit(&mut sim, ew).state = SamState::Moving;
|
||||
assert_eq!(source(&sim, radar), Some(Source::Flyby), "a radar on the march was read as emitting");
|
||||
assert_eq!(source(&sim, ew), Some(Source::Flyby), "a jammer on the march was read as transmitting");
|
||||
unit(&mut sim, radar).state = SamState::Search;
|
||||
unit(&mut sim, ew).state = SamState::Search;
|
||||
|
||||
// Cooling down: a jammer locked by heat is not transmitting either.
|
||||
unit(&mut sim, ew).ew_lock = true;
|
||||
assert_eq!(source(&sim, ew), Some(Source::Flyby), "an overheated jammer was read as transmitting");
|
||||
unit(&mut sim, ew).ew_lock = false;
|
||||
|
||||
// Damage: a failed sensor is no radar; a damaged hull with a working sensor still emits.
|
||||
unit(&mut sim, radar).comps.0[Part::Sensor as usize] = 0.0;
|
||||
assert_eq!(source(&sim, radar), Some(Source::Flyby), "a radar with a failed sensor was read as emitting");
|
||||
unit(&mut sim, radar).comps.0[Part::Sensor as usize] = 1.0;
|
||||
unit(&mut sim, radar).health = 0.5;
|
||||
assert_eq!(source(&sim, radar), Some(Source::Emission), "a damaged but working radar lost its emission");
|
||||
|
||||
// Destroyed: a wreck is no source and makes no lead at all.
|
||||
unit(&mut sim, radar).health = 0.0;
|
||||
unit(&mut sim, ew).health = 0.0;
|
||||
assert_eq!(source(&sim, radar), None, "a wreck was reported as a lead");
|
||||
assert_eq!(source(&sim, ew), None, "a wrecked jammer was reported as transmitting");
|
||||
|
||||
sim.sams.iter_mut().find(|s| s.id == radar).unwrap().radar_on = false;
|
||||
assert_eq!(source(&sim, radar), Source::Flyby, "a silent radar was read as emitting");
|
||||
sim.sams.iter_mut().find(|s| s.id == radar).unwrap().radar_on = true;
|
||||
assert_eq!(source(&sim, radar), Source::Emission);
|
||||
assert_eq!(source(&sim, ew), Source::Flyby, "a silent jammer was read as transmitting");
|
||||
sim.sams.iter_mut().find(|s| s.id == ew).unwrap().ew_on = true;
|
||||
assert_eq!(source(&sim, ew), Source::Jamming);
|
||||
sim.intel.observe(sim.sams.iter().find(|s| s.id == s400).unwrap(), sim.tick, ew::Seen::Launch);
|
||||
assert_eq!(source(&sim, s400), Source::Launch);
|
||||
assert_eq!(source(&sim, s400), Some(Source::Launch));
|
||||
// A hidden empty magazine does not change the source.
|
||||
sim.sams.iter_mut().find(|s| s.id == s400).unwrap().missiles = 0;
|
||||
assert_eq!(source(&sim, s400), Source::Launch);
|
||||
assert_eq!(source(&sim, s400), Some(Source::Launch));
|
||||
}
|
||||
|
||||
// #139: a station the picture already holds, seen off, packed or damaged, stays a flyby
|
||||
// contact: the switch never turns its mark into an emitter, and a working station seen
|
||||
// again still names its emission.
|
||||
#[test]
|
||||
fn a_known_station_that_stops_working_stays_a_flyby_contact() {
|
||||
let mut sim = Sim::new(26);
|
||||
let zone = Zone { center: DVec3::new(0.0, 70.0, 0.0), radius: ZONE_RADIUS };
|
||||
let id = sam(&mut sim, SamKind::Radar, DVec3::new(10.0, 70.0, 0.0));
|
||||
let seen = |sim: &Sim, now: u64| super::look(&sim.sams, &sim.recon, &sim.intel, &zone, now).into_iter().find(|l| l.truth == id).expect("the radar was not observed");
|
||||
|
||||
let first = seen(&sim, 100);
|
||||
assert_eq!(first.source, Source::Emission);
|
||||
sim.recon.report(first, 100);
|
||||
let mark = sim.recon.mark_for_truth(id).expect("the working look made no mark");
|
||||
|
||||
// Off, then packed for a march, then with a failed sensor: the contact stays, the
|
||||
// channel is the flyby alone.
|
||||
for (change, now) in [(0, 200), (1, 900), (2, 1600)] {
|
||||
let s = sim.sams.iter_mut().find(|s| s.id == id).unwrap();
|
||||
match change {
|
||||
0 => s.radar_on = false,
|
||||
1 => {
|
||||
s.radar_on = true;
|
||||
s.state = SamState::Moving;
|
||||
}
|
||||
_ => {
|
||||
s.state = SamState::Search;
|
||||
s.comps.0[Part::Sensor as usize] = 0.0;
|
||||
}
|
||||
}
|
||||
let look = seen(&sim, now);
|
||||
assert!(!look.wreck, "case {change}: a working station was read as a wreck");
|
||||
assert_eq!(look.source, Source::Flyby, "case {change}: the switch was read as work");
|
||||
sim.recon.report(look, now);
|
||||
assert!(sim.recon.marks.contains_key(&mark.id), "case {change}: the contact was lost");
|
||||
}
|
||||
|
||||
// Working again: the refined look names the emission.
|
||||
let s = sim.sams.iter_mut().find(|s| s.id == id).unwrap();
|
||||
s.comps.0[Part::Sensor as usize] = 1.0;
|
||||
let look = seen(&sim, 2300);
|
||||
assert_eq!(look.source, Source::Emission);
|
||||
assert_eq!(look.quality, Quality::Refined);
|
||||
sim.recon.report(look, 2300);
|
||||
assert_eq!(sim.recon.mark_for_truth(id).unwrap().source, Source::Emission);
|
||||
}
|
||||
|
||||
// #135: the planner's order is the observed public role, freshness and quality, not the
|
||||
@@ -1043,6 +1272,7 @@ mod tests {
|
||||
quality: Quality::Coarse,
|
||||
source: Source::Flyby,
|
||||
observed: 100,
|
||||
wreck: false,
|
||||
};
|
||||
r.report(coarse_look, 200);
|
||||
let coarse = r.mark();
|
||||
@@ -1071,6 +1301,7 @@ mod tests {
|
||||
quality: Quality::Refined,
|
||||
source: Source::Emission,
|
||||
observed: 1000,
|
||||
wreck: false,
|
||||
};
|
||||
sim.recon.report(look(1, battery::RadarRole::Search), 1000);
|
||||
sim.recon.report(look(2, battery::RadarRole::Engagement), 1000);
|
||||
@@ -1117,6 +1348,7 @@ mod tests {
|
||||
quality: Quality::Coarse,
|
||||
source: Source::Flyby,
|
||||
observed: 100,
|
||||
wreck: false,
|
||||
},
|
||||
100,
|
||||
);
|
||||
|
||||
@@ -363,6 +363,11 @@ impl Sam {
|
||||
pub fn radar_up(&self) -> bool {
|
||||
self.radar_on && self.mode != battery::SamMode::LauncherOnly && self.alive() && !self.moving() && self.kind.spec().sensor > 0.0 && self.part(Part::Sensor) > 0.0
|
||||
}
|
||||
/// Its jammer is really on the air: the switch, a live station and a deployed one. The same
|
||||
/// state `step_ew` transmits in, so a look names jamming only while the transmitter works.
|
||||
pub fn ew_up(&self) -> bool {
|
||||
self.ew_on && !self.ew_lock && self.alive() && !self.moving()
|
||||
}
|
||||
pub fn track(&self, id: u32) -> Option<&Track> {
|
||||
self.tracks.iter().find(|t| t.id == id)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ expect.feedback = "№2 С-400: режим launcher"
|
||||
[[step]]
|
||||
command = "airdef deploy radar_track"
|
||||
|
||||
# A deployed radar keeps its equipment profile; only its emissions can be switched.
|
||||
# The profile is chosen at deployment (#134): the old role switch is refused,
|
||||
# and says where the profile comes from instead of retuning the station.
|
||||
[[step]]
|
||||
command = "airdef radar 4 search"
|
||||
expect.error = "Профиль РЛС задаётся при размещении (deploy radar_search|radar_track|radar_height); переключение в search не меняет оборудование. Доступно on/off."
|
||||
|
||||
Reference in New Issue
Block a user