Add passive optical observation post (#136)

- new Optical unit kind with its own catalog row and deploy item
- bounded one-contact line-of-sight checks against land and blocks
- day/night reach and hold timing; obstacle and unknown geometry block sight
- independent class observation with source, time and uncertainty, never DroneKind
- map/monitor/panel statuses and a line to the selected contact
- tests: day/night, wall/unknown, ageing, no kind leak, bounded work, passivity

Cherry-picked from 3ae21123964a9d3234bb2b3efc9ff926d64fc77d onto the
#132/#133/#134 base: the cue test's track literal now carries the shared
class/source/product/quality contract instead of a DroneKind.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
2026-11-20 22:26:16 +03:00
parent 53fbeced22
commit e5ee15a2ca
23 changed files with 1139 additions and 27 deletions
+63 -1
View File
@@ -465,7 +465,7 @@ impl MapUi {
fn sys_class(k: SamKind) -> usize {
if k.armed() {
if k == SamKind::Gepard { 1 } else { 0 }
} else if k.spec().sensor > 0.0 {
} else if k == SamKind::Optical || k.spec().sensor > 0.0 {
2
} else {
3
@@ -480,6 +480,7 @@ fn short_name(k: SamKind) -> &'static str {
SamKind::Tzm => "ТЗМ",
SamKind::Ew => "РЭБ",
SamKind::Light => "Прож.",
SamKind::Optical => "Опт.",
SamKind::Pantsir => "Панцирь",
SamKind::IrisT => "IRIS-T",
SamKind::S400 => "С-400",
@@ -1778,6 +1779,10 @@ impl AirDef {
if ui.filters[F_TRACKS] || ui.filters[F_TRAILS] {
self.map_tracks(ui, &mut s, &mut labs, &mut taken);
}
// The optical posts and the contacts they watch (#136): a line to a contact last seen in clear sight.
if ui.filters[F_SAMS] || ui.filters[F_TRACKS] {
self.map_optical(ui, &mut s, &mut labs);
}
// The truth, when the sandbox shows it, marked as such: the real drones, their routes and aims.
if self.sim.truth {
map_truth(&self.sim, ui, hover, &mut s, &mut labs, &mut taken);
@@ -1902,6 +1907,51 @@ impl AirDef {
}
}
/// The optical posts (#136): a short status by each, and a line to the contact it has in clear
/// sight (or last saw), never to a radar's measurement. At most a screenful, so a crowd stays cheap.
fn map_optical(&self, ui: &mut MapUi, s: &mut Vec<Shape>, labs: &mut Vec<Lab>) {
let now = self.sim.tick;
let picture = self.sim.picture();
let mut drawn = 0usize;
for (i, sam) in self.sim.sams.iter().enumerate().filter(|(_, sam)| sam.kind == SamKind::Optical && sam.alive()) {
if drawn >= 16 {
break;
}
let c = ui.to_screen(sam.pos.x, sam.pos.z);
if !ui.on_screen(c, 30.0) {
continue;
}
drawn += 1;
let Some(report) = self.sim.optical_report(sam.id) else { continue };
let chosen = ui.sel == Some(Sel::Sam(sam.id));
let color = match report.state {
sim::OpticalState::Observing => GREEN,
sim::OpticalState::Holding => CYAN,
sim::OpticalState::NoSight => ORANGE,
sim::OpticalState::Searching => GREY,
};
add_lab(ui, labs, format!("Опт. №{}: {}", i + 1, report.status()), c, 7.0, alpha(color, 0.95), chosen);
if chosen {
s.extend(frame(c.0 - 8.0, c.1 - 8.0, 16.0, 16.0, 1.0, GREEN));
}
// The contact it watches: its own last clear sighting, else the network cue's forecast.
let own = report.seen.is_some();
let point = report
.seen
.or_else(|| report.target.and_then(|id| picture.get(&id).map(|t| t.est(now))));
if let Some(p) = point {
let pc = ui.to_screen(p.x, p.z);
s.push(line(c, pc, 1.0, alpha(color, if chosen { 0.9 } else if own { 0.55 } else { 0.3 })));
let label = match (own, report.observation) {
(true, Some(o)) => format!("вероятно {} · {:.0}%", o.class.name(), (1.0 - o.uncertainty) * 100.0),
(true, None) => "контакт в поле зрения".into(),
(false, _) => "цель по подсказке".into(),
};
add_lab(ui, labs, label, pc, 5.0, alpha(color, 0.95), chosen);
}
}
}
/// The radars' coverage edges. A radar's edge is where the land first hides a low flyer along each ray round it;
/// each is worked out from the sim's own horizon (`low_rim`), a few a redraw, and kept a while. The selected
/// one shows its dead zones filled.
@@ -2663,6 +2713,18 @@ impl AirDef {
btns.push((if sam.radar_on { "Выключить РЛС" } else { "Включить РЛС" }.into(), Act::RadarEmission, sam.radar_on));
}
lines.push((crate::battery_view::sam_status(sam), WHITE));
if k == SamKind::Optical {
if let Some(r) = self.sim.optical_report(sam.id) {
lines.push((r.line(), WHITE));
if let Some(o) = r.observation {
lines.push((format!("Последнее наблюдение: {} · {} с назад", o.class.name(), o.age(now) / 20), WHITE));
}
lines.push(("Пассивный пост: не излучает и не ведёт огневой трек".into(), GREY));
if r.target.is_some() {
lines.push(("Выбранный контакт показан линией".into(), GREY));
}
}
}
lines.push((format!("Исправен {:.0}% · {:.0} {:.0}", sam.health * 100.0, sam.pos.x, sam.pos.z), GREY));
if k == SamKind::Depot {
lines.push((format!("Ударные RM48U: {} · снятые 48Н6: {}", sam.ground_stock, sam.air_48n6_stock), WHITE));