Catalog typed battery variants (#91)

The battery deploy pieces (s400_launcher, s500_launcher, radar_search/
track/height) were described three times: the menu table and the
configuration match in lib.rs, and a chained id list in commands.rs. One
catalog decision instead: catalog/content.json gains a variants section
(mode/role reuse the existing SamMode/RadarRole save keys), gen_catalog.py
generates catalog::UnitVariant rows, and the loader rejects duplicates,
unknown kinds/modes and id collisions with kinds or items. The battery
menu, its click handler and the deploy completion read the generated
table; the historical row order and labels are unchanged.

No variant carries its own balance: per-variant ammo profiles stay open
pending a confirmed profile and an explicitly labelled game abstraction
(PAC-3 note on #91), so no new specs, no new matches and no save/replay
change - a variant is only a deploy key over the same kind.

Checks: gen_catalog.py --check and gen_models.py --check clean, the
python catalog/asset and sound tests pass, airdef-core 234 unit + 8
scenarios, airdef-mod 69 unit + 1 boundary + 5 scenarios (save/load and
state round trips included), zero failures.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
2026-11-20 18:38:23 +03:00
parent 306af49744
commit c59bfe9e54
9 changed files with 162 additions and 25 deletions
+19 -1
View File
@@ -14,6 +14,8 @@ CLASSES = {"drone": "Drone", "jet": "Jet", "cruise": "Cruise", "supersonic": "Su
"ballistic": "Ballistic"}
FAMILIES = {"trainable": "Trainable", "gun": "Gun", "turret": "Turret", "vertical": "Vertical",
"static": "Static", "truck": "Truck", "light": "Light"}
MODES = {"integrated": "Integrated", "launcher": "LauncherOnly"}
ROLES = {"multi": "Multifunction", "search": "Search", "engagement": "Engagement", "height": "Height"}
SOUND_PREFIX = "sound::"
@@ -304,16 +306,32 @@ def generate_unit_specs(data):
return "\n".join(lines + ["];", ""])
def generate_variants(data):
"""A variant of a complex is one record: a deploy id over an existing unit's
typed configuration (`battery::SamMode`, `battery::RadarRole`). No balance of
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] = &["]
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'])} }},")
return "\n".join(lines + ["];", ""])
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check", action="store_true")
args = parser.parse_args()
sound_output = OUTPUT.with_name("catalog_sound_ids.rs")
variant_output = OUTPUT.with_name("unit_variants_generated.rs")
specs = load_specs()
outputs = ((OUTPUT, generate(load())),
(sound_output, generate_sound_ids(load_sounds())),
(SPEC_OUTPUT, generate_specs(specs)),
(UNIT_SPEC_OUTPUT, generate_unit_specs(specs)))
(UNIT_SPEC_OUTPUT, generate_unit_specs(specs)),
(variant_output, generate_variants(load())))
for path, generated in outputs:
if args.check:
if not path.exists() or path.read_text(encoding="utf-8") != generated: