# Save-format history for KeeperFX: Tux Edition
#
# READ THIS BEFORE RUNNING check-save-format.sh --update.
#
# WHAT THE CHECK COMPARES NOW
# ---------------------------
# Since upstream #5424 (synced 2026-10-19) a saved game describes its own
# layout. Each file carries a schema -- every saved field's name, type and
# size -- and the loader matches fields by name: one the file lacks keeps the
# default the tables give it, one the build no longer has is skipped, and
# arrays may change length. A struct change no longer breaks saves by itself.
#
# What can still lose players' games:
#   * a save-format major version bump, a raised SAVE_MIN_READABLE_MAJOR or a
#     dropped migration (src/kfx/save/core/save_codec.h): older saves are
#     refused;
#   * a renamed field without an alias: its value is lost on load;
#   * a narrowed type or a shrunk array: values are clipped;
#   * a struct member that is not in the field tables
#     (src/kfx/save/core/schema/): it is never saved at all, and nothing fails.
#
# packaging/ci/check-save-format.sh builds upstream's tools/save-tool, dumps
# what the tables say into packaging/ci/save-format/ and compares that with the
# committed copy. A difference fails the check with the verdict of upstream's
# own policy check (tools/save-tool/policy.py) on whether older saves still
# load. packaging/ci/check-save-tables.sh fails when the tables miss a member
# of a saved struct -- add every field this edition adds to a saved struct to
# its table, as trap.rearm_route_failed_turn was on 2026-10-19.
#
# HOW TO REACT WHEN THE CHECK FAILS
# ---------------------------------
# Read the policy verdict it prints. If older saves keep loading, accept the
# change in the same commit with --update and say in the commit message what
# changed. If it breaks them, fix the change if you can; if the break is
# accepted, say so in the commit message and CHANGELOG.md -- the release notes
# warn players automatically once packaging/ci/save-format/ records it.
#
# The release-note check also knows the one break the new format cost: a
# release whose tree has no packaging/ci/save-format/ wrote raw struct Game
# dumps, which no later build reads.

# 2026-10-19: upstream sync (dkfans 6c159ad53), upstream #5424 "Break all
# saves, so saves will never break again in the future". Saved games, the
# continue link, campaign progress, high scores and fxconfig.net became KFXS
# files, and this file stopped holding sizeof(struct Game): the check compares
# the format's tables instead (above). Every save written before it -- 5660,
# 5762 and every other earlier build -- is refused, listed greyed, kept on
# disk, and trashed rather than overwritten if a save is made into its slot.
# Campaign progress (fx1contn.sav) and high scores are imported, including the
# 64-bit layouts earlier Linux builds wrote. Accepted: the last break of its
# kind, at upstream's design.

# HISTORY: THE RAW struct Game ERA
# --------------------------------
# Until 2026-10-19 a saved game was a raw dump of struct Game and the loader
# refused any save whose size differed from sizeof(struct Game), so this file
# held that size. The entries below are kept for the record.

# 2026-08-25: upstream's custom-icon feature (#5147, #5139) added
#     short icon_idx;   // 2 bytes (+ padding)
# to `struct Event`, embedded as `struct Event event[EVENTS_COUNT]` in
# `struct Game` (EVENTS_COUNT = 200). 53318509 -> 53350681 between builds
# 5554 and this one. Accepted deliberately: the field records which custom
# icon a QUICK_OBJECTIVE/QUICK_INFORMATION event/objective marker was given,
# and needs to persist for the marker's lifetime, which can span a save/load
# -- dropping it from the save would silently revert a custom icon back to
# the default one after loading, a real (if minor) behavioural regression
# from what upstream shipped, not merely a compatibility inconvenience.

# 2026-09-07: upstream sync (dkfans 33e94e51b). 53350681 -> 53362616 between
# builds 5596 and this one. Two layout changes inside `struct Game`:
#   - #5216 moved the local-only view state (engine window, minimap position
#     and zoom, palette fade steps, lens/main palette pointers, the
#     tooltip/status-menu/pause restore flags) out of `struct PlayerInfo`,
#     embedded as `players[PLAYERS_COUNT]`, into a separate `local_info`
#     that is not saved. Correct: none of it belongs to the game state.
#   - #5207 widened `IntralevelData.next_level` from char to LevelNumber so
#     SET_NEXT_LEVEL can name levels above 127 from bonus levels.
# Accepted: both are upstream design corrections; carrying the old layout
# would mean forking struct Game itself.

# 2026-09-16: upstream sync (dkfans 08816fbef). 53362616 -> 53362370 between
# builds 5652 and this one. Upstream's UserState refactor (#5220, #5229,
# #5248) moved the per-human-user fields (cursor and possession state, chosen
# room/trap/spell, battle id, cheat selection, ...) out of `struct PlayerInfo`,
# embedded as `players[PLAYERS_COUNT]`, into `user_states[MAX_NET_USERS]`,
# also inside `struct Game`; fewer users than players, so the total shrinks.
# Accepted: an upstream design correction, and carrying the old layout would
# mean forking struct Game itself.

# Sizes of releases that predate this file, measured afterwards by compiling
# packaging/ci/save_format_probe.c against the tagged tree. The release-note
# check consults these when the previous release of the channel has no
# baseline of its own -- without them the first stable after the guard was
# added would have shipped with no warning at all.
# (was) sizeof_struct_game@v1.4.0.5425=53269285

# 2026-09-21: upstream sync (dkfans 7ca23d191). 53362370 -> 53383086 between
# builds 5700 and this one. Three layout changes inside `struct Game`:
#   - #5343 flattened the union in `struct Room` (storage capacity, entrance
#     list links, per-model lair counts and the hatchery turn were
#     alternatives sharing one slot; they are now all present) -- embedded as
#     `rooms[ROOMS_COUNT]`, so this is nearly all of the growth.
#   - #5307 moved `user_defined_roomspace_width` / `roomspace_no_default` out
#     of `struct PlayerInfo`, embedded as `players[PLAYERS_COUNT]`, into the
#     unsaved `local_state`.
#   - #5317 dropped the unused `packet_load_initialized` byte from `struct Game`.
# Accepted: the union let a room's fields alias each other by kind, which
# upstream stopped relying on; carrying the old layout would mean forking
# struct Game itself.

# 2026-10-06: the FILE FRAMING around struct Game, checked since the
# 2026-09-28 sync slipped a change past the line above. Upstream's replay
# rewrite (#5353) turned `struct FileChunkHeader`'s three `unsigned long`s
# into uint32_t. On upstream's 32-bit Windows build nothing changed; on 64-bit
# Linux every chunk header went from 24 bytes to 12, struct Game did not move,
# and so this check stayed green while builds 5751..5768 read every older save
# as an empty slot (its info block failed the id check) -- hidden from Load,
# listed as "Unused", and overwritable from the save menu. read_chunk_header()
# in src/game_saves.c now reads both layouts and writes the 12-byte one. These
# two lines make any further framing change fail here instead of in players'
# save folders.
# (was) sizeof_chunk_header=12
# (was) sizeof_catalogue_entry=412

# 2026-10-10: the fork's own fix, not an upstream sync. 53383086 -> 53317550.
# `struct ScriptValue` (src/lvl_script.h), saved as
# `script.values[SCRIPT_VALUES_COUNT]` (2048) inside `struct Game`, declared
# its `longs[8]`/`ulongs[8]` union members as `long`: 4 bytes on upstream's
# 32-bit Windows build, 8 here, so the union was 64 bytes instead of 32 and
# the level-script commands that pack shorts and bytes next to a long slot by
# index overlapped differently than upstream (ADD_EFFECT_GENERATOR_TO_LEVEL,
# CREATE_EFFECTS_LINE, DISPLAY_VARIABLE_WITH_LABEL, ...). They are int32_t and
# uint32_t now, as on Windows: 69 -> 37 bytes per value, x2048 = -65536.
# Accepted deliberately by the owner: the alternative is keeping a script
# value layout that silently runs level scripts wrong; saves from earlier
# builds will not load.

# 2026-10-10: upstream sync (dkfans fb0ab7f4d, 48 commits 2026-09-29 to
# 2026-10-09). 53317550 -> 53384602 (+67052), every byte accounted for by
# diffing `ptype /o struct Game` from both trees:
#   +61440  #5396 added `last_turn_pushed` + `pushed_by_player` to struct Thing
#           (5 bytes x things_data[12288]), for the "lost in battle" message
#           when a creature is pushed into the abyss.
#    +9024  #5394/#5402 unlocked inertia and fall acceleration: new fields in
#           the creature and object configs held in game.conf.
#     +468  #5377 (camera refactor) and #5417 (user preferences out of saves
#           and packets) moved the cameras, view mode and zoom levels from
#    -2556  `players[9]` into `user_states[4]`; fewer users than players.
#    -1024  #5377 dropped `head_bob` from struct CreatureControl (x1024).
#     -300  #5376 (replay rewrite) moved the packet-file state out of struct
#           Game (-315), #5383 added the host timestamp Lua's date/time now
#           reads (+16), #5417 dropped easter_eggs_enabled (-1).
# Accepted: all upstream design changes, and carrying the old layout would mean
# forking struct Game itself.
# The same sync split campaign progress out of fx1contn.sav into one file per
# campaign (#5360), importing the old file once. That import only accepted the
# 32-bit-long layout, so on Linux it would have dropped every player's progress;
# src/game_saves.c reads the 64-bit layout too (tests/test_legacy_progress.c).
