Skip to content

Autosaves at game start and player turn start - #1067

Merged
ajhalme merged 5 commits into
C7-Game:Developmentfrom
Billytifft:billy/save-autofill-autosave
Nov 16, 2026
Merged

ajhalme merged 5 commits into
C7-Game:Developmentfrom
Billytifft:billy/save-autofill-autosave

Conversation

@Billytifft

@Billytifft Billytifft commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Autosave portion of the original save/load PR, split out per review feedback. This branch stacks on #1112, which contains the save-name, save-path, and load-default changes. Until #1112 merges, this PR includes that commit as well.

  • Autosaves to Saves/Auto/ at game start and at the start of each player turn, before tech/government/deal prompts.
  • Always keeps Turn 000 and a configurable number of recent non-Turn-000 autosaves (0 disables extras).
  • [LastGame] LastWorldSave stores the full path to the Turn 000 autosave.
  • Autosave count preference (0-99, default 5).
  • Pruning is a pure, tested function based on the -Turn NNN- filename. Same-turn overwrite is intentional.

Verification

  • Build: 0 errors
  • Tests: 241 passed, 16 skipped
  • Format: clean

Once #1112 merges, I'll rebase this branch so the diff is autosave-only.

@Billytifft
Billytifft marked this pull request as ready for review October 26, 2026 18:21
@ajhalme

ajhalme commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

I see dead code, file system logic that shouldn't be in the UI, triple nested try-catch structures, both functions that do multiple things and multiple functions for doing the same thing, as well as this curious new logic for treating a relative file path argument as an absolute one.

The Preferences scene logic braids together user input, UI updates, the actual settings config, and deeply nested control flow in a way that doesn’t spark joy.

SaveNameGenerator has a clear identity and useful looking main function. I don’t see why it needs to serve AutoSave directory information, though.

FindIniFilePath feels desperate and probably doesn’t play nicely with #1025.

GetSaveFolder somehow manages to be well over 100 lines of code. And it lives in C7Settings. I don’t see a compelling reason to support a million different ways of configuring the same thing.

I think Game.cs is doing enough as it is: we don’t need it worrying about file I/O as well.

Autosave has more of an identity, but looks needlessly complex. For one, I don’t think the Autosave class is the place to figure what civ the human is playing as. IsForSameGame looks flimsy -- and should be trivially testable. Overall, I see blatant copy-paste and deep nesting in place of a thoughtfully designed functional interface.


A more effective approach to building out functionality like this would start from the smallest useful addition, enabled with a flag in the ini file. When adding things, the focus should be on refactoring and generalising existing functionality as much as possible. User-customisable parameterisation via UI and support for variations is something one adds much later on.

@stavrosfa

Copy link
Copy Markdown
Contributor

Ngl, this is very hard to read and understand with all the try/catch blocks.

And what's up with this?!


string[] iniCandidates = new string[] {
				SettingsFilePath,
				Path.Combine(Directory.GetCurrentDirectory(), "C7.ini"),
				Path.Combine(Directory.GetCurrentDirectory(), "C7", "C7.ini"),
				Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C7.ini"),
				Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "C7.ini"),
				Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "..", "C7", "C7.ini"),
				Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "..", "..", "C7", "C7.ini"),
			};

How my experience was while testing it:

  1. Autosave is very nice to have.
  2. I didn't feel the game lagging at all while saving, so that's good.
  3. The assigned folder for was not my regular saves folder, which is the default Conquests/Saves folder. So my autosaves were not in the same place as every other save I have.
  4. Autosaves with the same name overwrite each other.

The autosave also does not happen at the beginning of the turn as it suggests, but after a player has possibly done a few things first. like choose tech, government, cancelled deals, etc..

Comment thread C7/UIElements/MainMenu/MainMenu.cs Resolved
Comment thread C7/UIElements/Civ3FileDialog.cs Resolved
Comment thread C7/UIElements/Civ3FileDialog.cs Resolved
@Billytifft

Copy link
Copy Markdown
Contributor Author
  1. The assigned folder for was not my regular saves folder, which is the default Conquests/Saves folder. So my autosaves were not in the same place as every other save I have.

This PR changes the default Saves folder to C7/Saves instead of Conquests/Saves as it is now. I can adjust this to prioritize Conquests/Saves if civ3InstallDir is set in the ini, and then default back to C7/Saves if it isnt set.

  1. Autosaves with the same name overwrite each other.

That is on purpose. If you load a save from a few turns ago and then play a few turns, the autosave files will be from the new branch of play than the old one.

The autosave also does not happen at the beginning of the turn as it suggests, but after a player has possibly done a few things first. like choose tech, government, cancelled deals, etc..

This is how it works in the original. The save happens right before you first get control of your units.

@Billytifft

Copy link
Copy Markdown
Contributor Author
  • Structure: Save-path and autosave logic moved out of Game.cs and the UI into C7Engine.SavePaths and a simplified C7Engine.Autosave; UI components now call those APIs.
  • Ini/settings: Deleted FindIniFilePath, ReadIniValue, GetSaveFolder, and SetSaveFolder; C7Settings.SettingsFilePath from Resolve C7.ini and log.txt relative to the game, not the working dire… #1025 is now the single source.
  • Save folder: One precedence chain — explicit SaveFolder → civ3InstallDir/Conquests/Saves (non-standalone) → Saves next to C7.ini; relative paths resolve against the ini directory and resolved defaults are not written back.
  • Autosave: Perform(GameData, Player, turnsToKeep) takes the player from the caller, uses one logged try/catch, and exposes pruning as a pure, tested function that always keeps Turn 000 plus the N most recent other turns (0 keeps only Turn 000).
  • Timing: Autosave runs first at player turn start, before tech/government/deal prompts, and at game start.
  • Cleanup: SaveNameGenerator only generates names; Civ3FileDialog has one load/save directory API and one shared PrefillLoadWithLatestSave; Preferences handlers were deduplicated; same-turn overwrite is unchanged and intentional.

let me know what you think.

@ajhalme

ajhalme commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

This is looking better now.

That said, I'd like to see this one split in two parts: a separate PR for the non-autosave stuff, and this one for the autosave proper. If we get the former in first, this one will be much more manageable.

@Billytifft
Billytifft force-pushed the billy/save-autofill-autosave branch from 62e5e5d to 72ffe85 Compare November 15, 2026 02:47
@Billytifft Billytifft changed the title Save name auto-fill, autosaves, and improved save/load defaults Autosaves at game start and player turn start Nov 15, 2026
@Billytifft

Copy link
Copy Markdown
Contributor Author

This is looking better now.

That said, I'd like to see this one split in two parts: a separate PR for the non-autosave stuff, and this one for the autosave proper. If we get the former in first, this one will be much more manageable.

#1112 has only the save/load enhancements. This one has both but after 1112 merges and the merge back, this will only show the auto save functionality.

@ajhalme

ajhalme commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

If you go into your Assets folder, cd ./C7/Assets/ and run git switch main and git pull, that should update the reference and clear out the Assets change in this PR.

I wonder if auto save files should have something in the filename to signal they are not manual saves. I believe the original game does this. What do you think?

Caesar of the Romans-Turn 060-1500 BC.json
Caesar of the Romans-Turn 060-1500 BC-auto.json

@Billytifft

Copy link
Copy Markdown
Contributor Author

Will do. Didn't mean to pick up that change.

The original games doesn't change the file name for auto saves. It just puts them in the Auto subfolder which is what i did here. It also always keeps the 4000bc save to enable the "Play Last World" button from civ3 (button not included in this Pr)

@ajhalme

ajhalme commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

The scenarios produce files like:

Conquests Autosave 1490 AD.SAV
Conquests Autosave 1491 AD.SAV
Conquests Autosave 1492 AD.SAV
Conquests Autosave 1493 AD.SAV

But we can omit the extra name for now. The save name generating machinery you assembled works well with this autosave and auto-cleanup stuff.

@Billytifft

Copy link
Copy Markdown
Contributor Author

I think this may differ between civ3 versions. I'm playing the complete edition from gog on Mac via porting Kit and even with the conquest scenario it gives the name as "leader of the tribe year"

@ajhalme

ajhalme commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixed a bug with the toggle. The Civ3Button needs an extra update nudge when setting the state for the first time.

Also polished the UI a bit:
autosave

@ajhalme
ajhalme merged commit 1d080ae into C7-Game:Development Nov 16, 2026
3 checks passed
@Billytifft

Copy link
Copy Markdown
Contributor Author

Thanks. what you have is definitely better. I was struggling getting the text to be the correct size with the input text box.

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.

3 participants