ead87343d2
catalog/specs.json is now the single copy of the numeric rows for
DroneSpec, MissileSpec and SamSpec: speed, guidance, warheads, models'
parts, RCS, seekers, launch and motor sounds, mount drives, gravity,
the Oreshnik split height and logistics limits, plus the named part
sets. tools/gen_catalog.py generates airdef-mod/src/sim/specs_generated.rs
(included by mod.rs, so the mod and airdef-core compile the same rows)
and unit_specs_generated.rs (included by units.rs). The hand-written
spec matches are gone; DroneKind::spec, MissileKind::spec and
SamKind::spec read the generated constants.
load_specs validates the schema, sound references, kind coverage against
content.json, named-part references and unused rows. gen_catalog.py
--check already runs in the CI generated-assets step, so a JSON/Rust
drift fails the build.
Every value was compared with the literals at 632061d field by field.
The only mismatch was the P1-SUN motor voice pitch in JSON (1.6 instead
of the actual 1.7, the flame == 0 branch in voices.rs); the JSON was
corrected and behaviour is unchanged. Save keys, raid order, RNG and
gameplay traces are untouched.
Verified: core release 194 passed + 8 scenarios (7 ignored), adapter
64 unit + 1 boundary + 5 scenarios, WASM contract 27 steps, catalog and
model generators fresh, asset/sound/model-bound/report tests pass.
204 lines
8.1 KiB
Rust
204 lines
8.1 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::{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 }
|
|
}
|
|
|
|
#[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");
|
|
|
|
/// 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)
|
|
}
|
|
|
|
#[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]);
|
|
}
|
|
|
|
/// 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());
|
|
}
|
|
}
|