Files
airdef/airdef-mod/src/sim/catalog.rs
T
chexit 858735a4c6 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>
2026-11-20 23:11:12 +03:00

259 lines
11 KiB
Rust

//! Stable identities and availability for the existing simulation content.
//!
//! Balance and rendering remain in `DroneSpec` and `SamSpec`: the catalog
//! refers to those typed definitions instead of copying their values. The
//! first eleven drone entries retain the historical positional wave-save order.
use super::{battery::RadarProfile, battery::RadarRole, battery::SamMode, DroneKind, SamKind};
#[derive(Clone, Copy, Debug)]
pub struct Aircraft {
pub kind: DroneKind,
/// Inventory item, when this type has a player launch item.
pub launch_item: Option<&'static str>,
/// May appear as a selectable type in the raid menu.
pub raid: bool,
}
impl Aircraft {
/// Existing save/command key; changing it requires an explicit migration.
pub fn id(self) -> &'static str { self.kind.spec().key }
}
/// A variant of a complex: a configuration over an existing kind, deployed
/// under its own command/menu id. Not new balance.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UnitVariant {
/// Existing command/menu key; changing it requires an explicit migration.
pub id: &'static str,
pub kind: SamKind,
pub mode: SamMode,
pub role: RadarRole,
/// The deploy menu's row.
pub label: &'static str,
/// What the configuration is for (shown in the deploy menu).
pub description: &'static str,
}
impl UnitVariant {
/// The typed radar profile behind a separate radar variant.
pub fn radar_profile(self) -> Option<RadarProfile> {
(self.kind == SamKind::Radar).then(|| RadarProfile::of(self.role))
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum GroundStrike {
/// Game-only RM48U coordinate-strike profile for S-400. Evidence: official agency report,
/// not independent certification: https://gur.gov.ua/content/warsanctions-hur-mo-rozkryvaie-budovu-komponentnu-bazu-ta-pidpryiemstva-kooperatsii-z-vyrobnytstva-udarnykh-raket-rm48u.html
/// The range and flight are game abstractions, not real parameters.
Rm48uGame,
/// No implemented game profile; this is not a claim of physical impossibility.
Unavailable { reason: &'static str },
}
impl GroundStrike {
/// Evidence describes provenance, not independent certification.
pub fn evidence(self) -> Option<&'static str> {
match self { GroundStrike::Rm48uGame => Some("official-agency-report"), GroundStrike::Unavailable { .. } => None }
}
}
#[derive(Clone, Copy, Debug)]
pub struct Unit {
pub kind: SamKind,
pub deploy_item: &'static str,
}
impl Unit {
pub fn id(self) -> &'static str { self.kind.spec().key }
/// Whether the unit has a gun; callers need no access to the private weapon profile.
pub fn has_gun(self) -> bool { self.kind.spec().gun.is_some() }
pub fn ground_strike(self) -> GroundStrike {
if self.kind == SamKind::S400 { GroundStrike::Rm48uGame } else { GroundStrike::Unavailable { reason: "Для этой техники не задан профиль удара по координатам" } }
}
}
use DroneKind::*;
/// Stable sound IDs shared with the audio resource generator.
pub mod sound {
include!("catalog_sound_ids.rs");
}
// Generated entries keep the historical raid and unit ordering.
include!("catalog_entries.rs");
include!("unit_variants_generated.rs");
/// Existing positional serialization makes the first entries' order part of the save format.
const fn raid_count() -> usize {
let mut i = 0;
let mut count = 0;
while i < AIRCRAFT.len() {
if AIRCRAFT[i].raid { count += 1; }
i += 1;
}
count
}
pub const RAID_COUNT: usize = raid_count();
const fn raid_kinds() -> [DroneKind; RAID_COUNT] {
let mut result = [Gerbera; RAID_COUNT];
let mut i = 0;
let mut out = 0;
while i < AIRCRAFT.len() {
if AIRCRAFT[i].raid { result[out] = AIRCRAFT[i].kind; out += 1; }
i += 1;
}
result
}
pub const RAID_KINDS: [DroneKind; RAID_COUNT] = raid_kinds();
pub const UNIT_COUNT: usize = UNITS.len();
const fn unit_kinds() -> [SamKind; UNIT_COUNT] {
let mut result = [SamKind::Patriot; UNIT_COUNT];
let mut i = 0;
while i < result.len() { result[i] = UNITS[i].kind; i += 1; }
result
}
pub const UNIT_KINDS: [SamKind; UNIT_COUNT] = unit_kinds();
pub fn unit(kind: SamKind) -> &'static Unit {
UNITS.iter().find(|entry| entry.kind == kind).expect("unit kind missing from catalog")
}
/// Inventory ordering is stable for existing remotes, while availability comes from the same entries as raids.
const fn inventory_count() -> usize {
let mut n = UNIT_COUNT + 4;
let mut i = 0;
while i < AIRCRAFT.len() {
if AIRCRAFT[i].launch_item.is_some() { n += 1; }
i += 1;
}
n
}
pub const INVENTORY_COUNT: usize = inventory_count();
const fn inventory_items() -> [&'static str; INVENTORY_COUNT] {
let mut out = [""; INVENTORY_COUNT];
out[0] = "airdef:designator";
let mut n = 1;
let mut i = 0;
while i < AIRCRAFT.len() {
if let Some(item) = AIRCRAFT[i].launch_item { out[n] = item; n += 1; }
i += 1;
}
i = 0;
while i < UNITS.len() { out[n] = UNITS[i].deploy_item; n += 1; i += 1; }
out[n] = "airdef:mover";
out[n + 1] = "airdef:flare_gun";
out[n + 2] = "airdef:remover";
out
}
pub const INVENTORY: [&str; INVENTORY_COUNT] = inventory_items();
pub fn launch_item(id: &str) -> Option<DroneKind> {
AIRCRAFT.iter().find(|entry| entry.launch_item == Some(id)).map(|entry| entry.kind)
}
pub fn deploy_item(id: &str) -> Option<SamKind> {
UNITS.iter().find(|entry| entry.deploy_item == id).map(|entry| entry.kind)
}
pub fn variant(id: &str) -> Option<&'static UnitVariant> {
VARIANTS.iter().find(|variant| variant.id == id)
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashSet;
use super::super::units::Muzzle;
#[test]
fn identities_cover_the_simulation_and_raid_order_is_compatible() {
let mut ids = HashSet::new();
let mut kinds = HashSet::new();
let mut items = HashSet::new();
for (i, e) in AIRCRAFT.iter().enumerate() {
assert!(ids.insert(e.id()), "duplicate aircraft ID {}", e.id());
assert!(kinds.insert(e.kind), "duplicate aircraft kind {:?}", e.kind);
if i < 11 { assert!(e.raid); }
if let Some(item) = e.launch_item {
assert!(items.insert(item), "duplicate item {item}");
assert_eq!(item, format!("airdef:launch_{}", e.id()));
}
}
assert_eq!(kinds, DroneKind::ALL.into_iter().collect());
let mut kinds = HashSet::new();
for e in UNITS {
assert!(ids.insert(e.id()), "duplicate unit ID {}", e.id());
assert!(kinds.insert(e.kind), "duplicate unit kind {:?}", e.kind);
assert!(items.insert(e.deploy_item), "duplicate item {}", e.deploy_item);
assert_eq!(e.deploy_item, format!("airdef:deploy_{}", e.id()));
let spec = e.kind.spec();
assert!(spec.sensor.is_finite() && spec.sensor >= 0.0);
match (&spec.missile, spec.muzzle) {
(Some(_), Muzzle::None) => panic!("{} has missiles but no muzzle", e.id()),
(_, Muzzle::Grid(cols, rows, size)) => assert!(cols > 0 && rows > 0 && size.is_finite() && size > 0.0),
(_, Muzzle::Rails(xs)) => assert!(!xs.is_empty() && xs.iter().all(|v| v.is_finite())),
_ => {}
}
}
assert_eq!(kinds, SamKind::ALL.into_iter().collect());
assert_eq!(&RAID_KINDS[..11], &[Gerbera, Shahed, Geran3, Lancet, Kh101, Kalibr, Kh22, Zircon, Iskander, Kinzhal, Oreshnik]);
}
/// A variant is a configuration of an existing kind, one row in the catalog,
/// under an id that stays out of the other identities' keys; the battery-menu
/// order is part of the UI's tested behaviour.
#[test]
fn variants_configure_existing_units_under_free_ids() {
let ids: Vec<&str> = VARIANTS.iter().map(|v| v.id).collect();
assert_eq!(ids, ["s400_launcher", "s500_launcher", "radar_search", "radar_track", "radar_height"]);
for v in VARIANTS {
assert!(UNITS.iter().any(|unit| unit.kind == v.kind), "{} configures an unknown kind", v.id);
assert!(SamKind::from_key(v.id).is_none(), "{} shadows a unit kind", v.id);
assert!(!INVENTORY.contains(&format!("airdef:{}", v.id).as_str()), "{} doubles an item", v.id);
assert!(!v.label.is_empty() && !v.description.is_empty());
assert_eq!(variant(v.id).map(|u| (u.kind, u.mode, u.role)), Some((v.kind, v.mode, v.role)));
if v.kind == SamKind::Radar {
let profile = v.radar_profile().expect("a radar variant has a profile");
assert_eq!(profile.id, v.id, "the stable profile ID is the variant ID");
assert_eq!(profile.role(), v.role);
assert!(profile.channels <= 3 && profile.cycle > 0);
} else {
assert!(v.radar_profile().is_none());
}
}
let launcher = variant("s400_launcher").unwrap();
assert_eq!((launcher.kind, launcher.mode, launcher.role), (SamKind::S400, SamMode::LauncherOnly, RadarRole::Multifunction));
assert_eq!(VARIANTS[4].id, "radar_height");
assert!(variant("miss").is_none() && variant("s400").is_none());
}
/// The catalog is the only copy of the numbers: a kind without a row, or a row under
/// another kind, would be a silent balance change.
#[test]
fn generated_specs_cover_every_kind_and_keep_their_keys() {
let mut drones = HashSet::new();
let mut drone_keys = HashSet::new();
for (kind, key) in super::super::DRONE_SPEC_KEYS {
assert_eq!(kind.spec().key, key, "profile/key mismatch for {kind:?}");
assert!(drones.insert(kind), "duplicate drone profile {kind:?}");
assert!(drone_keys.insert(key), "duplicate drone save key {key}");
assert!(kind.spec().rcs > 0.0 && kind.spec().launch_sound.starts_with("airdef:"));
}
assert_eq!(drones, DroneKind::ALL.into_iter().collect());
let mut missiles = HashSet::new();
for (kind, model) in super::super::MISSILE_SPEC_MODELS {
assert_eq!(kind.spec().model, model, "profile/model mismatch for {kind:?}");
assert!(missiles.insert(kind), "duplicate missile profile {kind:?}");
}
let mut units = HashSet::new();
let mut unit_keys = HashSet::new();
for (kind, key) in super::super::units::UNIT_SPEC_KEYS {
assert_eq!(kind.spec().key, key, "profile/key mismatch for {kind:?}");
assert!(units.insert(kind), "duplicate unit profile {kind:?}");
assert!(unit_keys.insert(key), "duplicate unit save key {key}");
}
assert_eq!(units, SamKind::ALL.into_iter().collect());
}
}