Files
uconsole_asw_game/src/core/save_schema.py
T
db9979andClaude Fable 5.1 e85a9006d6 Save v15: the crewed boat's crew state survives a save and a load
The crew block keeps the boat's orders, modes, mast, wires, plot, feed and
its sonar station; sub rows carry the crew-facing orders and the uConsole's
local side is part of the ui block. A loaded boat keeps its crew binding for
UBOOT_RESTORE_HOLD_S until its crew returns, then the AI takes it back. The
frigate's sonar save/restore/validation is shared with the boat's station.
v14 documents are rejected without migration.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 23:52:24 +02:00

77 lines
3.5 KiB
Python

"""Declarative exact key sets for the ``u-jagd-save-v15`` document.
Every persisted block whose shape is validated exactly is declared here, so a
new saved field is added in exactly three places: this module,
``Game.save_state()`` and ``Game._restore_state()``. The loader additionally
re-serializes every restored candidate and requires byte-for-byte equality
with the input, so a field missing from any of the three places fails loudly.
"""
SAVE_ROOT_FIELDS = frozenset({
"version", "save_schema", "platform_state_version", "catalog_snapshot",
"seed", "level", "mission_type", "scenario_key", "mission_name",
"mission_runtime", "world", "sim_t", "mission_time", "time_scale_idx",
"score", "mission_result", "result_reason", "ship", "torpedoes",
"chaff_cd", "vls_cells", "ciws_ammo", "roe", "sonar_mode", "radars",
"asm_sel", "radio_sel", "hq_timer", "damage", "dmg_cursor", "dmg_team",
"incident", "subs", "animals", "civilians", "warships", "decoys",
"torpedoes_in_flight", "enemy_torpedoes", "asw", "air_defense", "asms", "essms",
"buoys", "helo", "flights", "sonar_controls", "sonar", "messages",
"hfdf_fixes", "hfdf_log", "radio_picture", "air_picture",
"opz_affiliations", "air_threat_reported", "esm", "next_entity_ids",
"asm_spawned", "asm_seq", "warship_asm_seq", "torpedo_seq", "buoy_seq",
"ciws_cooldown_s", "ciws_mount_deg", "chaff_clouds", "chaff_seq",
"schedulers", "rngs", "ui",
"autocrew", "ais", "plot",
"crew",
})
# Save v15: the crewed submarine binding (``Game._opfor``), or None.
CREW_FIELDS = frozenset({
"sub_id", "orders", "command_page", "chart_follow", "plot", "feed",
"feed_seq", "hold_s", "station",
})
CREW_ORDERS_FIELDS = frozenset({
"silent", "bottomed", "mast", "alarm_seq", "ping_bearing",
"torpedo_bearing", "esm", "esm_seen", "wires", "known_torpedoes",
"last_course", "torpedo_depth", "salvo", "pending_bearing",
"steer_torpedo", "events", "battery_state", "keel_warned",
"obstacle_warned", "obstacle_ahead_nm",
})
CREW_WIRE_FIELDS = frozenset({"state", "ship_out_nm", "stress_s"})
CREW_WIRE_STATES = ("ACTIVE", "BROKEN", "CUT")
CREW_BATTERY_STATES = ("ok", "low", "empty")
CREW_FEED_FIELDS = frozenset({"seq", "t", "stamp", "category", "text"})
CREW_STATION_FIELDS = frozenset({
"mode", "controls", "sonar", "selected_contact_id", "target_id", "rng",
})
# Sub rows carry the crew-facing orders beside the AI state.
SUB_CREW_FIELDS = frozenset({
"manual", "order_course", "order_speed", "order_depth", "last_bottom_m",
"manual_ping_pending",
})
RNG_STREAMS = frozenset({
"world", "world_weather", "asm", "damage", "helo", "sonar",
"flight", "asw", "raid",
})
SHIP_FIELDS = frozenset({
"x", "y", "course", "target_course", "speed", "target_speed",
"order_idx", "astern", "hull", "grounding", "turn_rate_scale",
"rudder_angle", "yaw_rate", "roll", "pitch", "quiet_mode", "clock",
"fuel_capacity_kg", "fuel_kg", "roll_rate", "pitch_rate", "wake",
})
WORLD_FIELDS = frozenset({
"hour", "sea_state", "weather_shift_timer", "mode", "generator", "coast",
"ocean",
})
DAMAGE_FIELDS = frozenset({"repair_mult", "compartments", "teams",
"team_position", "team_eta", "patch_kits",
"cooked_off", "capsized", "draft_m"})
COMPARTMENT_FIELDS = frozenset({"state", "flood", "fire", "hole_m2", "heat_s",
"shorted"})
COMPARTMENT_STATES = ("OK", "FLUTEND", "BESCHAEDIGT", "ZERSTOERT")