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:
2026-11-20 22:30:10 +03:00
parent ac7521936d
commit 858735a4c6
25 changed files with 1074 additions and 122 deletions
+83 -11
View File
@@ -101,14 +101,17 @@ impl SamKind {
/// A live big radar in data-link reach of `sam` that measured `id` recently.
pub(super) fn radar_cue(sam: &Sam, radars: &[&Sam], id: u32, now: u64) -> bool {
radars.iter().any(|r| {
r.radar_role.authorizes()
r.radar_profile().products & battery::RadarProfile::FIRE_BIT != 0
&& r.link_range() > 0.0
&& sam.link_range() > 0.0
&& r.alive()
&& !r.moving()
&& r.radar_up()
&& r.pos.distance(sam.pos) <= r.link_range().min(sam.link_range())
&& r.track(id).is_some_and(|t| t.own_tick > 0 && now.saturating_sub(t.own_tick) <= if sam.mode == battery::SamMode::LauncherOnly { sight::MISSILE_AGE } else { FAR_RADAR_AGE })
&& r.track(id).is_some_and(|t| {
let age = if sam.mode == battery::SamMode::LauncherOnly { sight::MISSILE_AGE } else { FAR_RADAR_AGE };
t.own_fire_within(now, age)
})
})
}
@@ -146,7 +149,17 @@ pub(super) struct Opts {
/// `role_in_reach` that the system has a target of its roles in range anyway (no long shots then).
#[allow(clippy::too_many_arguments)]
pub(super) fn basis(sam: &Sam, load: &units::MissileLoad, track: &Track, d: &Drone, now: u64, claimed: u32, k: f64, opts: Opts, cued: bool, role_in_reach: bool) -> Option<Basis> {
if sam.mode == battery::SamMode::LauncherOnly && !cued { return None; }
// A launch rests on the battery's own confirmed fire plot. A launcher
// without its own radar may use a supporting radar's own fire plot; a
// relayed plot, a search plot or a height refinement never authorizes an
// ordinary shot. A heavy system's *far* shot is the exception it already
// had: it may use the cue radar's own confirmed fire plot beyond its reach.
let own = track.own_authorizes(now);
if sam.mode == battery::SamMode::LauncherOnly {
if !cued { return None; }
} else if !own && !cued {
return None;
}
let blocks = target_blocks(sam.roles, Some(track), now, d);
if blocks & !ROLE != 0 {
return None;
@@ -159,12 +172,14 @@ pub(super) fn basis(sam: &Sam, load: &units::MissileLoad, track: &Track, d: &Dro
return None;
}
if reach == 0 {
return Some(Basis::Role);
// A normal shot belongs to the battery's own confirmed measurement;
// a launcher-only battery uses its supporting radar's (checked above).
return (own || sam.mode == battery::SamMode::LauncherOnly).then_some(Basis::Role);
}
let far = reach == TOO_FAR && reach_blocks(load.min, load.max, FAR_K, sam.pos, track.est(now)) == 0;
return (far && far_blocks(opts.far_shots, sam, load, cued, role_in_reach) == 0).then_some(Basis::FarShot);
}
(reach == 0 && last_chance(opts.last_chance, sam.roles, est, d, claimed)).then_some(Basis::LastChance)
(reach == 0 && (own || sam.mode == battery::SamMode::LauncherOnly) && last_chance(opts.last_chance, sam.roles, est, d, claimed)).then_some(Basis::LastChance)
}
/// The kill chance of an interceptor that met its target `dist` from the launcher whose reach is `max`:
@@ -317,6 +332,37 @@ impl Sim {
return v;
}
if !sam.kind.armed() {
if sam.kind == SamKind::Radar {
let profile = sam.radar_profile();
v.push(check(true, format!(
"профиль {} [{}]: {}, оборот {:.1} с, каналы {}, локальный поиск {}",
profile.name,
profile.id,
profile.products_text(),
profile.cycle as f64 / 20.0,
profile.channels,
if profile.local >= 1.0 { "во всей дальности".to_string() } else { format!("{:.0}% дальности", profile.local * 100.0) },
)));
v.push(check(true, format!("ограничение: {}", profile.limit)));
v.push(check(true, format!("свои треки: {}, каналы {}/{}", sam.own.len(), sam.own_channels_used(), profile.channels)));
let now = self.tick;
let mut tracks: Vec<&Track> = sam.tracks.iter().filter(|t| t.own_tick > 0).collect();
tracks.sort_by_key(|t| std::cmp::Reverse(t.quality));
for t in tracks.into_iter().take(4) {
v.push(check(
t.own_authorizes(now),
format!(
"цель {}: {} ({}), качество {}, возраст {:.1} с{}",
t.id,
t.own_product.name(),
if t.own_authorizes(now) { "право на пуск" } else { "пуск не разрешает" },
t.own_quality,
now.saturating_sub(t.own_tick) as f64 / 20.0,
if t.own_authorizes(now) { "" } else { "; нужно подтверждённое измерение станции" },
),
));
}
}
v.push(check(false, "нет оружия (РЛС, склад, РЭБ, прожектор)"));
return v;
}
@@ -447,7 +493,15 @@ impl Sim {
let age = tr.age(now) as f64 / 20.0;
let lock = if tr.own_within(now, sight::GUN_AGE) && tr.locked { ", захват" } else { "" };
let how = if tr.forecast(now) { format!("прогноз ±{:.0} м", tr.uncertainty(now)) } else { "измерение".to_string() };
format!("трек {kind}: {}, возраст {age:.1} с, {how}{lock}, {}, {}", tr.ident().name(), tr.class.name(), if blocks & STALE != 0 { "устарел для пуска" } else { "годен для пуска" })
let radars: Vec<&Sam> = self.sams.iter().filter(|s| s.kind == SamKind::Radar).collect();
let authority = tr.own_authorizes(now) || (sam.mode == battery::SamMode::LauncherOnly && radar_cue(sam, &radars, t.id, now));
format!(
"трек {kind}: {}, возраст {age:.1} с, {how}{lock}, {}, {}; право на пуск: {}",
tr.ident().name(),
tr.class.name(),
if blocks & STALE != 0 { "устарел" } else { "годен" },
if authority { "своё подтверждённое измерение" } else { "нет (сеть или обзор не дают права)" }
)
}
_ => "не обнаружена ни своей РЛС, ни сетью".to_string(),
};
@@ -549,7 +603,9 @@ impl Sim {
));
}
let doc_ok = chance || area | held_back == 0;
let grounds = (sam.mode != battery::SamMode::LauncherOnly || cued) && blocks & !ROLE == 0 && (blocks & ROLE == 0 || chance) && doc_ok && (reach == 0 || far_ok);
let own = track.is_some_and(|tr| tr.own_authorizes(now));
let authorized = own || (sam.mode == battery::SamMode::LauncherOnly && cued) || far_ok;
let grounds = authorized && blocks & !ROLE == 0 && (blocks & ROLE == 0 || chance) && doc_ok && (reach == 0 || far_ok);
fires |= grounds && free < need && mb == 0 && aligned && land == 0;
}
if let Some(gun) = &spec.gun {
@@ -648,7 +704,8 @@ mod tests {
let now = sim.tick;
let d = sim.drones[0].clone();
sim.sams[0].tracks.retain(|t| t.id != d.id);
sim.sams[0].tracks.push(Track { id: d.id, class, pos: d.pos, vel: d.vel, tick: now, own_tick: now, ttl: 400, hits: 3, locked: false });
let source = sim.sams[0].id;
sim.sams[0].tracks.push(Track { id: d.id, class, pos: d.pos, vel: d.vel, tick: now, own_tick: now, source, product: battery::Measure::Fire, quality: 90, own_product: battery::Measure::Fire, own_quality: 90, ttl: 400, hits: 3, locked: false });
}
#[test]
@@ -810,7 +867,7 @@ mod tests {
assert!(w.iter().any(|c| c.legacy_text().contains("не в ролях")), "{:?}", w.iter().map(|c| c.legacy_text()).collect::<Vec<_>>());
// Holding fire (no roles at all): nothing is a candidate, the unidentified either.
let d = sim.drones[0].clone();
let unknown = Track { id: d.id, class: ClassEst::Unknown, pos: d.pos, vel: DVec3::ZERO, tick: 0, own_tick: 0, ttl: 400, hits: 1, locked: false };
let unknown = Track { id: d.id, class: ClassEst::Unknown, pos: d.pos, vel: DVec3::ZERO, tick: 0, own_tick: 0, source: 0, product: battery::Measure::Search, quality: 40, own_product: battery::Measure::Search, own_quality: 0, ttl: 400, hits: 1, locked: false };
assert_ne!(why::target_blocks(0, Some(&unknown), 0, &d) & why::ROLE, 0, "with no roles (hold fire) even the unknown is blocked");
}
@@ -832,12 +889,27 @@ mod tests {
.drones
.iter()
.filter(|d| d.alive())
.map(|d| Track { id: d.id, class: ClassEst::Firm(d.kind.spec().class), pos: d.pos, vel: d.vel, tick: now, own_tick: now, ttl: 400, hits: 3, locked: false })
.map(|d| Track {
id: d.id,
class: ClassEst::Firm(d.kind.spec().class),
pos: d.pos,
vel: d.vel,
tick: now,
own_tick: now,
source: 0,
product: battery::Measure::Fire,
quality: 90,
own_product: battery::Measure::Fire,
own_quality: 90,
ttl: 400,
hits: 3,
locked: false,
})
.collect();
for r in sim.sams.iter_mut().filter(|s| s.kind == SamKind::Radar) {
for t in &tracks {
r.tracks.retain(|o| o.id != t.id);
r.tracks.push(*t);
r.tracks.push(Track { source: r.id, ..*t });
}
}
}