Skip to content

OpenCiv4's own autosaves: each game its own name again after a load - #191

Open
MortenLyhr wants to merge 2 commits into
bssth:masterfrom
MortenLyhr:fix/autosave-game-name
Open

MortenLyhr wants to merge 2 commits into
bssth:masterfrom
MortenLyhr:fix/autosave-game-name

Conversation

@MortenLyhr

Copy link
Copy Markdown
Contributor

What it changes

OpenCiv4 saves a game played by hand at each turn's start, in Documents\My Games\openciv4\Saves\auto, ten in turn, as AutoSave_<civilization>_<game>_<n> (master's main.cpp). The civilization and the game are in the name so that each game keeps its own files. This is OpenCiv4's own naming: no rule of the original is involved, and the original's autosaves are not touched.

Before: after a load both parts of the name were empty, and every loaded game was saved as AutoSave__00000000_<n>, over the others' files. Seen in the user's play sessions of 2026-11-25 and 26 (oc4core's log: autosaved turn 173: …/Saves/auto/AutoSave__00000000_3.CivBeyondSwordSave).

  • The civilization came from the init core's getCivShortDesc, which is empty unless the player typed a name.
  • The game was the init core's map seed, getMapRandSeed. A save doesn't hold it (CvInitCore::read/write in the SDK have no seed), so after a load it is 0.

Now (apps/oc4core/AutoSaveStem.h, used by main.cpp):

  • The civilization comes from CvPlayer::getCivilizationShortDescription: the init core's name, else the civilization's own short name, as the game shows it. Anything but letters and digits becomes _, as before.
  • The game is an FNV-1a hash of the map's size and every plot's plot type (land, hills, peak, water). A save keeps those, so a game has the same name before and after a load.

The save format doesn't change: only the file's name does.

What it is based on

  • The SDK: CvInitCore::read/write (no map seed saved), CvPlayer::getCivilizationShortDescription, CvPlot::getPlotType.
  • oc4core's own log from the user's play sessions (the names above).
  • No rule of the original: these are OpenCiv4's own autosaves.

How it was checked

  • clean room: neither I nor any tool or AI agent I used looked inside the original game's executables or libraries (no disassembly, decompiling, debugging, strings/dumpbin/objdump), and nothing here comes from someone else's (CONTRIBUTING)
  • ctest --test-dir build\Release passes: 15/15 (macOS arm64 build of this branch on master)
  • game results unchanged: --turns 100 --map Fractal --size STANDARD --seed 7 gives D7D43800 at turn 100 on this branch, the same as master
  • original saves still load: not run (no save code is touched)

Autosaves are made only in a game played by hand, so an AI autoplay doesn't run this code.

  • On the user's play build (BUG + BULL, merged with the other open fixes): the save Julius Caesar BC-0250 loaded and a turn played wrote AutoSave_Rome_EF6DCD01_1. The same hash, computed again in Python from that save's plots, is EF6DCD01. Two saves of another game, Julius Caesar AD-1020 and AD-1110, both give 4D3A7092.
  • No pictures: nothing on screen changes.

Not done / not checked:

  • Two games on the same map with the same civilization (a scenario or a World Builder map played twice) get the same name and share their files, as games with the same map seed did before.
  • A plot type changed in the World Builder changes the name for the rest of the game. In the SDK, setPlotType is otherwise called only while the map is made (CvMapGenerator, CvGame::normalize…) and by CvPlot::setTerrainType when land turns to water or back. Whether a mod or scenario script does that in play was not checked.
  • Autosaves made before this change keep their old names; the old AutoSave__00000000_* files are left as they are.
  • The every-25th-turn copy (<stem>_turn<N>) uses the same stem and was not looked at separately.

🤖 Generated with Claude Code

MortenLyhr and others added 2 commits November 27, 2026 17:19
OpenCiv4's own autosaves are named AutoSave_<civilization>_<game>_<n>, so that each game keeps
its own. After a load both parts were empty: the init core's civilization name is empty unless
the player typed one, and its map seed is not in a save (CvInitCore::read/write). So every
loaded game shared AutoSave__00000000_<n> and overwrote the others' (seen in the user's play
sessions 2026-11-25/26, oc4core's log).

The civilization now comes from CvPlayer::getCivilizationShortDescription (the init core's name,
else the civilization's), and the game from a hash of the map's plot types, which a save keeps
and nothing in BtS changes. This is OpenCiv4's own naming, not the original's: no rule of the
original is involved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CvPlot::getPlotType and GET_PLAYER's inline player array are not exported from
the Windows game core (LNK2001 on bssth#191's windows-x64). The plot type now comes
from the exported isPeak/isHills/isWater, numbered as PlotTypes numbers them, so
the hash is unchanged; the player from CvPlayerAI::getPlayerNonInl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant