Give each battery variant its own placeable remote
build / mod (push) Failing after 28s

Every catalog variant now has a `airdef:deploy_<id>` remote in `give` and
in the hotbar: deploy_radar_search, deploy_radar_track, deploy_radar_height,
deploy_s400_launcher and deploy_s500_launcher. The variant rows carry their
remote item in the generated catalog, and the inventory appends them after
the existing remotes so no ordinary remote changes slot.

Placing a remote now resolves the item back to its (kind, mode, role)
configuration and settles the system, the same path `/airdef deploy <key>`
already used. The base remotes keep deploying the ordinary integrated,
multifunction system; the radar remotes place Search/Engagement/Height
profiles, so radar_track gets fire authority and the others do not.

The N menu's battery-deploy page is removed entirely (button, page and its
handlers); variants remain available through `/airdef deploy` and now the
remotes. Items, icons (aliased to the unit silhouettes), lang entries and
generated assets are regenerated from the content catalog.

Checks: gen_catalog.py --check, gen_models.py --check, test_gen_assets (11),
airdef-mod lib 115 + integration suites, airdef-core 327, cargo build.
This commit is contained in:
2026-11-21 16:44:23 +03:00
parent b735458dd8
commit 4d7815834d
25 changed files with 278 additions and 63 deletions
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "airdef:item/deploy_radar_height"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "airdef:item/deploy_radar_search"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "airdef:item/deploy_radar_track"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "airdef:item/deploy_s400_launcher"
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "airdef:item/deploy_s500_launcher"
}
}
+5
View File
@@ -124,6 +124,11 @@
"item.airdef.deploy_ew": "Развернуть станцию РЭБ",
"item.airdef.deploy_light": "Развернуть прожектор",
"item.airdef.deploy_optical": "Развернуть оптический пост",
"item.airdef.deploy_s400_launcher": "Развернуть С-400 (пусковая)",
"item.airdef.deploy_s500_launcher": "Развернуть С-500 (пусковая)",
"item.airdef.deploy_radar_search": "Развернуть РЛС обзора",
"item.airdef.deploy_radar_track": "Развернуть РЛС сопровождения",
"item.airdef.deploy_radar_height": "Развернуть мачтовую РЛС",
"item.airdef.mover": "Пульт перемещения",
"item.airdef.flare_gun": "Осветительная ракета",
"item.airdef.remover": "Свернуть ПВО",
+5
View File
@@ -124,6 +124,11 @@
"item.airdef.deploy_ew": "Развернуть станцию РЭБ",
"item.airdef.deploy_light": "Развернуть прожектор",
"item.airdef.deploy_optical": "Развернуть оптический пост",
"item.airdef.deploy_s400_launcher": "Развернуть С-400 (пусковая)",
"item.airdef.deploy_s500_launcher": "Развернуть С-500 (пусковая)",
"item.airdef.deploy_radar_search": "Развернуть РЛС обзора",
"item.airdef.deploy_radar_track": "Развернуть РЛС сопровождения",
"item.airdef.deploy_radar_height": "Развернуть мачтовую РЛС",
"item.airdef.mover": "Пульт перемещения",
"item.airdef.flare_gun": "Осветительная ракета",
"item.airdef.remover": "Свернуть ПВО",
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "airdef:item/deploy_radar"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "airdef:item/deploy_radar"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "airdef:item/deploy_radar"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "airdef:item/deploy_s400"
}
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "airdef:item/deploy_s500"
}
}
@@ -0,0 +1,4 @@
{
"template": "minecraft:stick",
"max_stack_size": 1
}
@@ -0,0 +1,4 @@
{
"template": "minecraft:stick",
"max_stack_size": 1
}
@@ -0,0 +1,4 @@
{
"template": "minecraft:stick",
"max_stack_size": 1
}
@@ -0,0 +1,4 @@
{
"template": "minecraft:stick",
"max_stack_size": 1
}
@@ -0,0 +1,4 @@
{
"template": "minecraft:stick",
"max_stack_size": 1
}
+17 -2
View File
@@ -119,8 +119,13 @@ d8ac6a9258e2fc2e0791bbce18a3a07a72e471fbc72b6be7b5ca545c53f8d633 assets/airdef/
e2353c70f6e5053864ab2fdf51df886d72c03e5c34db84fef8f3fff9c84a7ae4 assets/airdef/items/deploy_pantsir.json
68dd9b1382b2dd6ad23d0f507a8cfcdcfa18ef5c4203e69c61f6ade9cfbf238e assets/airdef/items/deploy_patriot.json
d93b6bf77de4aed1f1955e76353661729f06445788ad7a6654ed6af1a67fc48d assets/airdef/items/deploy_radar.json
84306c42dd25300f1cef69c83e3211ccc921fa606046157295a4ca3e3d568a0a assets/airdef/items/deploy_radar_height.json
28f6b71116bdc911e70d2382807c86edff40adae44acd256f798360dc60bd572 assets/airdef/items/deploy_radar_search.json
0e470cfa2a13383fadb74336c5333449f4079659d9d83596dcfcf2d592521a4c assets/airdef/items/deploy_radar_track.json
0b9445f3b54a9e958da0b9bd4243a41d85fc8f12b5c4e56bbc070edb8f1bf618 assets/airdef/items/deploy_s400.json
77355fc96ed50feb117bc6e7f7f70e9559bc69174a7a84afe7e3121db65efbfd assets/airdef/items/deploy_s400_launcher.json
dd7478f447d87dcad42e1a7e6dcb5fae555c832e933a3722022d0e10e2de011e assets/airdef/items/deploy_s500.json
47dabb117d3e6fb44005f4be8c2be2b6c4f8d7e06ff5ed2d426ac1e58e6408ce assets/airdef/items/deploy_s500_launcher.json
14e9a20dcddee5a6262ef624783900576dac2bd16e5079e731cf6115f13c76ec assets/airdef/items/deploy_tor.json
d4ff57f630ca92bf52ba228d8c6fd5292928b685d6bb5a9c9b9dc0c3d586fc2e assets/airdef/items/deploy_tzm.json
044fc626ad99ff8be6db0800f96dc743fc80606d813bd59abad531396bf9d8ce assets/airdef/items/designator.json
@@ -137,8 +142,8 @@ b4d98a938486d49db28c6c7a608ca3b6ab0c9c3eac266ecf12c7dd931cc28f93 assets/airdef/
489799dcb5b441e9d4be8bfb3d73a6ebd5fdf2b5ee614b62f38b85bb2fbfad75 assets/airdef/items/launch_zircon.json
6b6da5887aa8d9bc987b2c181c243bc2afdd5846a869818f699b59204e559929 assets/airdef/items/mover.json
177f7535e4c52ed975d6f737c2b2acb7741b7a928955c8899aced85211443bbf assets/airdef/items/remover.json
14c7fae39807f31ed6a20ebf8d0805c845f4d94e46ef5c38d1f2ba5c2671f768 assets/airdef/lang/en_us.json
14c7fae39807f31ed6a20ebf8d0805c845f4d94e46ef5c38d1f2ba5c2671f768 assets/airdef/lang/ru_ru.json
ddfba1d8e940c870b43268a5d8ebae130a4061f2f734a750df4bfd54452c8012 assets/airdef/lang/en_us.json
ddfba1d8e940c870b43268a5d8ebae130a4061f2f734a750df4bfd54452c8012 assets/airdef/lang/ru_ru.json
b9b5b5bec33a77e944552c225ee2f526ab9820fa8fca4b3ccf311f2a325925ee assets/airdef/models/block/amraam_missile.json
c54e6b24ab69e9d9a2dbbbc63fe2ac60fa37735bf644500ddd5c3de0b91908cf assets/airdef/models/block/barge.json
a4198ff647de5866919f9b82a3d53e6486fc56cc9f175f7907951d063a6f4526 assets/airdef/models/block/beam.json
@@ -260,8 +265,13 @@ e80ee81085241b9712e024bbef73ef744ef5493eebb88770f4912d8aae138fe6 assets/airdef/
8b1af688bc83be5a8065673bca7054deee86ca425f0bfd1fb4ffb491844e90bf assets/airdef/models/item/deploy_pantsir.json
d0091d809816350c648e532a90ae59a3c5c9b94f837b2a46b5695e7f985a00f9 assets/airdef/models/item/deploy_patriot.json
332f9de8c88658a562748fc7a6de7ec37847273ac0cd0733e23c0dff4b44418c assets/airdef/models/item/deploy_radar.json
332f9de8c88658a562748fc7a6de7ec37847273ac0cd0733e23c0dff4b44418c assets/airdef/models/item/deploy_radar_height.json
332f9de8c88658a562748fc7a6de7ec37847273ac0cd0733e23c0dff4b44418c assets/airdef/models/item/deploy_radar_search.json
332f9de8c88658a562748fc7a6de7ec37847273ac0cd0733e23c0dff4b44418c assets/airdef/models/item/deploy_radar_track.json
9ee1dfa7d2c2587c85a8f73554962a02a06f1969a9a56c56110162dd93db7301 assets/airdef/models/item/deploy_s400.json
9ee1dfa7d2c2587c85a8f73554962a02a06f1969a9a56c56110162dd93db7301 assets/airdef/models/item/deploy_s400_launcher.json
55f1dae5cd7f0126533825c9da3ed3ee316e74d4be8f9bb217a3ebc6f827d24d assets/airdef/models/item/deploy_s500.json
55f1dae5cd7f0126533825c9da3ed3ee316e74d4be8f9bb217a3ebc6f827d24d assets/airdef/models/item/deploy_s500_launcher.json
aca5ea765ca0d84ed12444bf433c024b57d6ea9b9b7cf06449dfbd6892a66ae6 assets/airdef/models/item/deploy_tor.json
67912cc711c2f1514e6e2f8f17aa340fa9a99534fbbaeb2b8e319aa6ef80f38d assets/airdef/models/item/deploy_tzm.json
d0976d990130c6398f4adf5d3086e9cf50e5a2adbec081e4682e810af368c332 assets/airdef/models/item/designator.json
@@ -574,8 +584,13 @@ cc0877f40434365b45b03429222926aa0cf135e504017311be53263fd27c5f8f data/airdef/ho
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_pantsir.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_patriot.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_radar.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_radar_height.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_radar_search.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_radar_track.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_s400.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_s400_launcher.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_s500.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_s500_launcher.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_tor.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/deploy_tzm.json
2a3912a7c9d5bb8025b1ac16a1a1d6b5eff0360bb3184e810d319e498255bf97 data/airdef/horizon/item/designator.json
+53 -49
View File
@@ -202,7 +202,6 @@ fn travels(event: &str) -> bool {
#[derive(Clone, Copy, PartialEq)]
enum Page {
Main,
BatteryDeploy,
Roles(SamKind),
/// The raid's make-up, then its parameters and the launch.
Wave,
@@ -221,12 +220,12 @@ enum Page {
}
const MENU_KINDS: u32 = 1;
const BTN_BATTERY: u32 = 22;
const BATTERY_ROWS: u32 = sim::catalog::VARIANTS.len() as u32;
/// A battery deploy piece from the catalog: a unit kind or one of its variants.
/// A battery deploy piece from the catalog: a unit kind, one of its variants, or
/// the remote item that places either.
fn deploy_configuration(key: &str) -> Option<(SamKind, sim::battery::SamMode, sim::battery::RadarRole)> {
use sim::battery::{RadarRole as R, SamMode as M};
if let Some(config) = sim::catalog::deploy_item_configuration(key) { return Some(config); }
match sim::catalog::variant(key) {
Some(v) => Some((v.kind, v.mode, v.role)),
// A bare kind deploys its ordinary integrated configuration.
@@ -355,21 +354,16 @@ impl AirDef {
None => say("Наведитесь на блок или отметьте цель"),
}
}
_ if sim::catalog::deploy_item(id).is_some() => {
let Some(kind) = sim::catalog::deploy_item(id) else { return };
_ if sim::catalog::deploy_item_configuration(id).is_some() => {
let Some((kind, mode, role)) = sim::catalog::deploy_item_configuration(id) else { return };
match aim() {
Some(at) => {
let d = view(&p);
let heading = (-d.x).atan2(-d.z);
let sid = self.sim.id();
let mut sam = Sam::new(sid, kind, at, heading);
if let Some(r) = self.sim.roles.get(&kind) {
sam.roles = *r;
}
self.sim.sams.push(sam);
self.place(kind, mode, role, at, heading);
out.sound("minecraft:block.anvil.place", at, 2.0, 0.7);
say(&format!("{} развёрнут", kind.name()));
self.dirty = true;
let profile = if kind == SamKind::Radar { format!(", профиль {}", role.profile().id) } else { String::new() };
say(&format!("{} развёрнут{profile}", kind.name()));
}
None => say("Наведитесь на землю, где поставить комплекс"),
}
@@ -1614,20 +1608,26 @@ impl AirDef {
};
}
fn deploy_configured(&mut self, key: &str) -> Result<String, String> {
let (kind, mode, role) = deploy_configuration(key).ok_or("Неизвестный вид техники")?;
let p = player().ok_or("Нет игрока")?;
let d = view(&p);
let flat = DVec3::new(d.x, 0.0, d.z).normalize_or(DVec3::NEG_Z);
let at = DVec3::new(p.x, p.y, p.z) + flat * 8.0;
/// Places a configured system at `at` facing `heading` and settles it.
fn place(&mut self, kind: SamKind, mode: sim::battery::SamMode, role: sim::battery::RadarRole, at: DVec3, heading: f64) -> u32 {
let id = self.sim.id();
let mut sam = Sam::new(id, kind, at, (-flat.x).atan2(-flat.z));
let mut sam = Sam::new(id, kind, at, heading);
sam.set_mode(mode);
sam.set_radar_role(role);
if let Some(r) = self.sim.roles.get(&kind) { sam.roles = *r; }
self.sim.sams.push(sam);
self.sim.settle(id);
self.dirty = true;
id
}
fn deploy_configured(&mut self, key: &str) -> Result<String, String> {
let (kind, mode, role) = deploy_configuration(key).ok_or("Неизвестный вид техники")?;
let p = player().ok_or("Нет игрока")?;
let d = view(&p);
let flat = DVec3::new(d.x, 0.0, d.z).normalize_or(DVec3::NEG_Z);
let at = DVec3::new(p.x, p.y, p.z) + flat * 8.0;
self.place(kind, mode, role, at, (-flat.x).atan2(-flat.z));
let profile = if kind == SamKind::Radar { format!(", профиль {}", role.profile().id) } else { String::new() };
Ok(format!("{} развёрнут ({}, {}{profile})", kind.name(), mode.key(), role.key()))
}
@@ -1650,7 +1650,6 @@ impl AirDef {
.collect();
widgets.push(Widget::List(ListWidget { id: MENU_KINDS, rows, selected: None }));
let _ = &self.monitor;
widgets.push(Widget::Button(ButtonWidget { id: BTN_BATTERY, label: "Разместить элементы батареи…".into() }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_GRID, label: "Командный пункт: все комплексы (J)".into() }));
let custom = self.sim.sams.iter().filter(|s| !s.doctrine.is_default()).count();
widgets.push(Widget::Button(ButtonWidget { id: BTN_DOCTRINE, label: format!("Доктрины: охрана, сектор, резерв (особых: {custom})…") }));
@@ -1659,15 +1658,6 @@ impl AirDef {
widgets.push(Widget::Button(ButtonWidget { id: BTN_RECON, label: "Разведка противника (разбор)…".into() }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_MORE, label: "Огонь, ремонт, эффекты…".into() }));
}
Page::BatteryDeploy => {
title = "Размещение батареи — клик создаёт технику перед игроком".into();
widgets.push(Widget::List(ListWidget {
id: BATTERY_ROWS,
rows: sim::catalog::VARIANTS.iter().map(|v| format!("{} — {}", v.label, v.description)).collect(),
selected: None,
}));
widgets.push(Widget::Button(ButtonWidget { id: BTN_BACK, label: "← Назад".into() }));
}
Page::Replays => {
match self.sim.replays.last() {
Some(rec) => {
@@ -2258,23 +2248,6 @@ impl Mod for AirDef {
}
return;
}
(Page::Main, BTN_BATTERY) => {
self.open_menu(Page::BatteryDeploy);
return;
}
(Page::BatteryDeploy, BATTERY_ROWS) => {
if let Some(v) = sim::catalog::VARIANTS.get(row as usize) {
match self.deploy_configured(v.id) {
Ok(message) => say(&message),
Err(error) => say(&error),
}
}
return;
}
(Page::BatteryDeploy, BTN_BACK) => {
self.open_menu(Page::Main);
return;
}
(Page::Main, BTN_DOCTRINE) => {
self.open_menu(Page::Fleet);
return;
@@ -2879,7 +2852,7 @@ horizon_mod_sdk::export_mod!(AirDef);
#[cfg(test)]
mod tests {
#[test]
fn battery_menu_presets_leave_existing_catalog_indices_intact() {
fn deploy_presets_and_remotes_resolve_the_same_configuration() {
use super::*;
assert_eq!(sim::catalog::INVENTORY[0], "airdef:designator");
assert_eq!(sim::catalog::UNITS[3].kind, SamKind::S400);
@@ -2888,6 +2861,10 @@ mod tests {
for v in sim::catalog::VARIANTS {
let (actual, mode, role) = deploy_configuration(v.id).unwrap();
assert_eq!((actual, mode, role), (v.kind, v.mode, v.role));
// The variant's own remote deploys exactly the same configuration.
let (actual, mode, role) = deploy_configuration(v.deploy_item).unwrap();
assert_eq!((actual, mode, role), (v.kind, v.mode, v.role));
assert!(sim::catalog::INVENTORY.contains(&v.deploy_item));
}
for kind in SamKind::ALL {
let (actual, mode, role) = deploy_configuration(kind.key()).unwrap();
@@ -2897,6 +2874,33 @@ mod tests {
}
}
/// A variant remote places its own kind, mode and role; a base remote stays
/// the ordinary integrated multifunction system.
#[test]
fn placing_a_remote_deploys_its_configuration() {
let mut game = test_mod();
for (item, kind, mode, role) in [
("airdef:deploy_radar", SamKind::Radar, sim::battery::SamMode::Integrated, sim::battery::RadarRole::Multifunction),
("airdef:deploy_radar_search", SamKind::Radar, sim::battery::SamMode::Integrated, sim::battery::RadarRole::Search),
("airdef:deploy_radar_track", SamKind::Radar, sim::battery::SamMode::Integrated, sim::battery::RadarRole::Engagement),
("airdef:deploy_radar_height", SamKind::Radar, sim::battery::SamMode::Integrated, sim::battery::RadarRole::Height),
("airdef:deploy_s400_launcher", SamKind::S400, sim::battery::SamMode::LauncherOnly, sim::battery::RadarRole::Multifunction),
("airdef:deploy_s500_launcher", SamKind::S500, sim::battery::SamMode::LauncherOnly, sim::battery::RadarRole::Multifunction),
] {
let (k, m, r) = sim::catalog::deploy_item_configuration(item).expect(item);
assert_eq!((k, m, r), (kind, mode, role), "{item}");
let id = game.place(k, m, r, DVec3::new(game.sim.sams.len() as f64 * 10.0, 70.0, 0.0), 0.0);
let sam = game.sim.sams.iter().find(|s| s.id == id).unwrap();
assert_eq!((sam.kind, sam.mode, sam.radar_role), (kind, mode, role), "{item}");
if kind == SamKind::Radar {
assert_eq!(sam.radar_profile().role(), role);
if let Some(v) = sim::catalog::VARIANTS.iter().find(|v| v.deploy_item == item) {
assert_eq!(sam.radar_profile().id, v.id);
}
}
}
}
use super::*;
#[test]
+41 -1
View File
@@ -25,6 +25,8 @@ impl Aircraft {
pub struct UnitVariant {
/// Existing command/menu key; changing it requires an explicit migration.
pub id: &'static str,
/// Its own placeable remote, so every configuration is a separate item.
pub deploy_item: &'static str,
pub kind: SamKind,
pub mode: SamMode,
pub role: RadarRole,
@@ -121,7 +123,7 @@ pub fn unit(kind: SamKind) -> &'static Unit {
/// 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 n = UNIT_COUNT + VARIANTS.len() + 4;
let mut i = 0;
while i < AIRCRAFT.len() {
if AIRCRAFT[i].launch_item.is_some() { n += 1; }
@@ -144,6 +146,10 @@ const fn inventory_items() -> [&'static str; INVENTORY_COUNT] {
out[n] = "airdef:mover";
out[n + 1] = "airdef:flare_gun";
out[n + 2] = "airdef:remover";
// Variant remotes come last: every existing remote keeps its slot.
n += 3;
i = 0;
while i < VARIANTS.len() { out[n] = VARIANTS[i].deploy_item; n += 1; i += 1; }
out
}
pub const INVENTORY: [&str; INVENTORY_COUNT] = inventory_items();
@@ -154,6 +160,14 @@ pub fn launch_item(id: &str) -> Option<DroneKind> {
pub fn deploy_item(id: &str) -> Option<SamKind> {
UNITS.iter().find(|entry| entry.deploy_item == id).map(|entry| entry.kind)
}
/// The configuration a remote item deploys: a unit's ordinary integrated
/// system or a variant's own mode and radar role.
pub fn deploy_item_configuration(id: &str) -> Option<(SamKind, SamMode, RadarRole)> {
if let Some(kind) = deploy_item(id) {
return Some((kind, SamMode::Integrated, RadarRole::Multifunction));
}
VARIANTS.iter().find(|entry| entry.deploy_item == id).map(|entry| (entry.kind, entry.mode, entry.role))
}
pub fn variant(id: &str) -> Option<&'static UnitVariant> {
VARIANTS.iter().find(|variant| variant.id == id)
@@ -197,9 +211,32 @@ mod tests {
}
assert_eq!(kinds, SamKind::ALL.into_iter().collect());
for e in VARIANTS {
assert!(items.insert(e.deploy_item), "duplicate item {}", e.deploy_item);
assert_eq!(e.deploy_item, format!("airdef:deploy_{}", e.id));
}
assert_eq!(&RAID_KINDS[..11], &[Gerbera, Shahed, Geran3, Lancet, Kh101, Kalibr, Kh22, Zircon, Iskander, Kinzhal, Oreshnik]);
}
/// `give` hands out every remote once; the ordinary units keep their historical
/// slots and the variant remotes are appended after them.
#[test]
fn inventory_holds_every_remote_once_and_keeps_existing_slots() {
let unique: HashSet<&str> = INVENTORY.iter().copied().collect();
assert_eq!(unique.len(), INVENTORY.len(), "duplicate inventory item");
let launches = AIRCRAFT.iter().filter(|a| a.launch_item.is_some()).count();
let first_unit = 1 + launches;
for (i, unit) in UNITS.iter().enumerate() {
assert_eq!(INVENTORY[first_unit + i], unit.deploy_item);
assert_eq!(deploy_item_configuration(unit.deploy_item), Some((unit.kind, SamMode::Integrated, RadarRole::Multifunction)));
}
let tail = first_unit + UNITS.len();
assert_eq!(&INVENTORY[tail..tail + 3], &["airdef:mover", "airdef:flare_gun", "airdef:remover"]);
assert_eq!(&INVENTORY[tail + 3..], &VARIANTS.iter().map(|v| v.deploy_item).collect::<Vec<_>>()[..]);
assert_eq!(deploy_item_configuration("airdef:designator"), None);
assert_eq!(deploy_item_configuration("airdef:deploy_radar_track"), Some((SamKind::Radar, SamMode::Integrated, RadarRole::Engagement)));
}
/// 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.
@@ -211,6 +248,9 @@ mod tests {
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_eq!(v.deploy_item, format!("airdef:deploy_{}", v.id));
assert!(INVENTORY.contains(&v.deploy_item), "{} has no remote in the inventory", v.id);
assert_eq!(deploy_item_configuration(v.deploy_item), Some((v.kind, v.mode, v.role)));
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 {
@@ -1,8 +1,8 @@
// Generated by tools/gen_catalog.py from catalog/content.json. Do not edit.
pub const VARIANTS: &[UnitVariant] = &[
UnitVariant { id: "s400_launcher", kind: SamKind::S400, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-400 — отдельная пусковая", description: "Пусковая С-400 без своей РЛС: работает по данным сети." },
UnitVariant { id: "s500_launcher", kind: SamKind::S500, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-500 — отдельная пусковая", description: "Пусковая С-500 без своей РЛС: работает по данным сети." },
UnitVariant { id: "radar_search", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Search, label: "РЛС обзора", description: "Дальний обзор: редкие грубые отметки и область поиска; права на пуск не даёт." },
UnitVariant { id: "radar_track", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Engagement, label: "РЛС сопровождения", description: "Сопровождение: локальный поиск, два канала точных треков; собственное измерение даёт право на пуск." },
UnitVariant { id: "radar_height", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Height, label: "Мачтовая РЛС", description: "Мачтовая: поднятая антенна уточняет низкие контакты над рельефом; права на пуск не даёт." },
UnitVariant { id: "s400_launcher", deploy_item: "airdef:deploy_s400_launcher", kind: SamKind::S400, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-400 — отдельная пусковая", description: "Пусковая С-400 без своей РЛС: работает по данным сети." },
UnitVariant { id: "s500_launcher", deploy_item: "airdef:deploy_s500_launcher", kind: SamKind::S500, mode: SamMode::LauncherOnly, role: RadarRole::Multifunction, label: "С-500 — отдельная пусковая", description: "Пусковая С-500 без своей РЛС: работает по данным сети." },
UnitVariant { id: "radar_search", deploy_item: "airdef:deploy_radar_search", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Search, label: "РЛС обзора", description: "Дальний обзор: редкие грубые отметки и область поиска; права на пуск не даёт." },
UnitVariant { id: "radar_track", deploy_item: "airdef:deploy_radar_track", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Engagement, label: "РЛС сопровождения", description: "Сопровождение: локальный поиск, два канала точных треков; собственное измерение даёт право на пуск." },
UnitVariant { id: "radar_height", deploy_item: "airdef:deploy_radar_height", kind: SamKind::Radar, mode: SamMode::Integrated, role: RadarRole::Height, label: "Мачтовая РЛС", description: "Мачтовая: поднятая антенна уточняет низкие контакты над рельефом; права на пуск не даёт." },
];
+14 -3
View File
@@ -172,7 +172,7 @@ impl WaveConfig {
#[cfg(test)]
mod catalog_tests {
use super::*;
use crate::sim::catalog::{AIRCRAFT, UNITS};
use crate::sim::catalog::{AIRCRAFT, UNITS, VARIANTS};
fn assets() -> std::path::PathBuf {
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets/airdef")
@@ -215,15 +215,26 @@ mod catalog_tests {
for model in [p.launcher, p.pack, p.dish.map(|v| v.0), p.spinner.map(|v| v.0)].into_iter().flatten() { model_exists(model); }
for (model, _, _) in p.fixed { model_exists(model); }
}
for variant in VARIANTS {
item_exists(variant.deploy_item);
}
}
#[test]
fn inventory_entries_match_catalog_and_scenario_order_round_trips() {
for item in AIRCRAFT.iter().filter_map(|a| a.launch_item).chain(UNITS.iter().map(|u| u.deploy_item)) {
let catalogued = |item: &str| {
AIRCRAFT.iter().any(|a| a.launch_item == Some(item))
|| UNITS.iter().any(|u| u.deploy_item == item)
|| VARIANTS.iter().any(|v| v.deploy_item == item)
};
for item in AIRCRAFT.iter().filter_map(|a| a.launch_item)
.chain(UNITS.iter().map(|u| u.deploy_item))
.chain(VARIANTS.iter().map(|v| v.deploy_item))
{
assert_eq!(crate::ITEMS.iter().filter(|i| **i == item).count(), 1, "{item}");
}
for item in crate::ITEMS.iter().filter(|i| i.starts_with("airdef:launch_") || i.starts_with("airdef:deploy_")) {
assert!(AIRCRAFT.iter().any(|a| a.launch_item == Some(*item)) || UNITS.iter().any(|u| u.deploy_item == *item), "uncatalogued item {item}");
assert!(catalogued(item), "uncatalogued item {item}");
}
let mut wave = WaveConfig::default();
for (i, count) in wave.counts.iter_mut().enumerate() { *count = i as u32; }
+45
View File
@@ -418,6 +418,51 @@
90
]
},
{
"id": "deploy_s400_launcher",
"title": "Развернуть С-400 (пусковая)",
"color": [
60,
80,
50
]
},
{
"id": "deploy_s500_launcher",
"title": "Развернуть С-500 (пусковая)",
"color": [
108,
110,
80
]
},
{
"id": "deploy_radar_search",
"title": "Развернуть РЛС обзора",
"color": [
108,
110,
80
]
},
{
"id": "deploy_radar_track",
"title": "Развернуть РЛС сопровождения",
"color": [
108,
110,
80
]
},
{
"id": "deploy_radar_height",
"title": "Развернуть мачтовую РЛС",
"color": [
108,
110,
80
]
},
{
"id": "mover",
"title": "Пульт перемещения",
+6
View File
@@ -346,6 +346,12 @@ ICON_DRAW = {
# radar icon). The alias is part of the generated model, so no duplicate texture is written.
ICON_ALIAS = {
"deploy_optical": "deploy_radar",
# A variant remote keeps its unit's silhouette: only the configuration differs.
"deploy_s400_launcher": "deploy_s400",
"deploy_s500_launcher": "deploy_s500",
"deploy_radar_search": "deploy_radar",
"deploy_radar_track": "deploy_radar",
"deploy_radar_height": "deploy_radar",
}
+7 -3
View File
@@ -312,12 +312,16 @@ def generate_variants(data):
its own — everything but the label comes from the unit rows it points at."""
lines = ["// Generated by tools/gen_catalog.py from catalog/content.json. Do not edit.",
"pub const VARIANTS: &[UnitVariant] = &["]
registered = {entry["id"] for entry in data["items"]}
for entry in data["variants"]:
mode = MODES[entry["mode"]]
role = ROLES[entry["role"]]
lines.append(f" UnitVariant {{ id: {text(entry['id'])}, kind: SamKind::{entry['kind']}, "
f"mode: SamMode::{mode}, role: RadarRole::{role}, label: {text(entry['label'])}, "
f"description: {text(entry['description'])} }},")
item = f"deploy_{entry['id']}"
if item not in registered:
raise ValueError(f"variants[{entry['id']}]: remote {item} is not a registered item")
lines.append(f" UnitVariant {{ id: {text(entry['id'])}, deploy_item: \"airdef:{item}\", "
f"kind: SamKind::{entry['kind']}, mode: SamMode::{mode}, role: RadarRole::{role}, "
f"label: {text(entry['label'])}, description: {text(entry['description'])} }},")
return "\n".join(lines + ["];", ""])