Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
f6ba05b
City screen: clicks on its plots choose the tiles worked
MortenLyhr Nov 19, 2026
75bf0f8
City screen: the map in its frame takes clicks
MortenLyhr Nov 19, 2026
ca59cbd
City screen: no unit stays selected under it
MortenLyhr Nov 19, 2026
eeba7b7
End turn button as the original's: brass ring, tinted glass, its colo…
MortenLyhr Nov 19, 2026
78a15e3
Game core: wide "+" in wide formats (text with a sign no longer lost …
MortenLyhr Nov 19, 2026
bf8951e
Interface: isDebugMenuCreated and IsModem answer false
MortenLyhr Nov 19, 2026
f322731
Command line: --map with a scenario file relative to the current folder
MortenLyhr Nov 19, 2026
30daf68
Text in the game's own Sylfaen: its font folders and a Wine prefix's,…
MortenLyhr Nov 20, 2026
16c8d3e
Multiline text in the theme's normal font (size 3, 16 px), as the ori…
MortenLyhr Nov 20, 2026
d91dc7a
Next/previous city with no city selected: the city nearest the camera
MortenLyhr Nov 20, 2026
4d78cc3
Minimap toggles kept in the player's profile, as the original keeps them
MortenLyhr Nov 20, 2026
4c04a52
Options: player options kept in the profile, the theme's check boxes,…
MortenLyhr Nov 20, 2026
0053b86
Options: the player options' code apart from the minimap toggles' (me…
MortenLyhr Nov 20, 2026
bb31c52
Options: leave the W A S D comment's lines as they were (merges clean…
MortenLyhr Nov 20, 2026
e12acd4
Options window as the original's: the theme's title bar, window and t…
MortenLyhr Nov 20, 2026
f16f0d9
Messages at the top as the original's: box, bullets, colours, newest …
MortenLyhr Nov 20, 2026
8a0fdf3
Tech advisor as the original's: tech colours, choosing and queueing s…
MortenLyhr Nov 20, 2026
61766d0
Popups as the original's: choices on stone buttons, the glass inside …
MortenLyhr Nov 20, 2026
a4ea00b
Options: a profile the old screen wrote gets the defaults it never sh…
MortenLyhr Nov 20, 2026
c1c1f9b
City screen: the units selected before are selected again when it closes
MortenLyhr Nov 20, 2026
3ddcdb8
Right button held: the buttons for that plot, recommended ones glow; …
MortenLyhr Nov 20, 2026
d562307
Tech advisor: read the research through CyPlayer and CyTeam (Windows …
MortenLyhr Nov 20, 2026
2c474a0
Merge branch 'fix/city-screen-tiles' into fix/city-double-click
MortenLyhr Nov 20, 2026
cb1cd52
Merge branch 'fix/options-screen' into fix/city-double-click
MortenLyhr Nov 20, 2026
21986ab
Game font icons mods add: every cell of a group's rows, and GameFont_…
MortenLyhr Nov 20, 2026
155f0f8
Screens laid out as the original's: panel titles, rows sharing a pane…
MortenLyhr Nov 20, 2026
cc6b07a
City on the map: a double click opens it, one click on its bar select…
MortenLyhr Nov 20, 2026
15456ef
Multi list buttons in the theme's look: ring, hover glow, pressed, di…
MortenLyhr Nov 20, 2026
50a48aa
Screens: a screen's own minimap in its widgets' order; theme alpha by…
MortenLyhr Nov 20, 2026
ccf0960
The main interface's help in the theme's see-through HUD help panel
MortenLyhr Nov 20, 2026
b6da36d
Tables and list boxes: the theme's row skins, row heights and background
MortenLyhr Nov 20, 2026
8fa44a3
Screens: tell the scripts when the mouse goes onto a widget and off it
MortenLyhr Nov 20, 2026
b44baa0
Domestic Advisor: BUG's saved pages load; table headers in the theme'…
MortenLyhr Nov 20, 2026
06f19ab
Screens: a screen's help beside its widget; labels don't light up und…
MortenLyhr Nov 20, 2026
98e2053
Screens: a screen widget's help as wide as its widest line, wrapped g…
MortenLyhr Nov 20, 2026
3f34951
Screens: the top messages over the main interface, under the game's s…
MortenLyhr Nov 20, 2026
a5f072a
UiLayer: civic buttons as the original: the highlight alone, no frames
MortenLyhr Nov 20, 2026
12864de
Tables as the original's GTable: sort arrows, the lit first row, cell…
MortenLyhr Nov 20, 2026
d258d31
Table cells: a cell of one character or icon is never cut
MortenLyhr Nov 20, 2026
6ccf0c8
Screens: a cursor move's getMouseX is the mouse's x, not a column
MortenLyhr Nov 20, 2026
cbfc120
Tables drawn with a grid show the theme's grid lines
MortenLyhr Nov 20, 2026
ac0d8a3
Screens: setText plain at size 3, determineWidth measures it so
MortenLyhr Nov 20, 2026
d082f6b
Screens: list rows as the original's espionage advisor lays them out
MortenLyhr Nov 20, 2026
8ff2f5f
BUG's dot map: the mouse over the map for the scripts, as the original's
MortenLyhr Nov 21, 2026
8d8ad9b
BUG's dot map: crosses and dots drawn as the original's
MortenLyhr Nov 21, 2026
66d7273
Options Audio tab as the original's: theme sliders, speakers, own mus…
MortenLyhr Nov 21, 2026
c4ef27a
Options > Other: profiles, the clock and the alarm as the original's;…
MortenLyhr Nov 21, 2026
8a78754
Options -> Graphics: every option as the original's, without a restart
MortenLyhr Nov 21, 2026
e6ab288
Scroll bars: drag the grip, arrows and paging as the original's
MortenLyhr Nov 21, 2026
ca2a295
Popups: their list's grip follows the mouse while held
MortenLyhr Nov 21, 2026
29854ab
Popups: 400 wide, 18 from the right, 19 under the last button, as the…
MortenLyhr Nov 21, 2026
149def7
Game menu at the top right, as the original's
MortenLyhr Nov 21, 2026
0589024
Merge branch 'fix/show-moves' into fix/quick-enemy-moves
MortenLyhr Nov 21, 2026
7033d63
OpenCiv4 option Quick enemy moves: the others' shown moves in 0.6 s i…
MortenLyhr Nov 21, 2026
5a699d1
World Builder: help for its buttons and palette items; diplomacy mode…
MortenLyhr Nov 20, 2026
d5edae8
World Builder: tooltips at the widget, palette items' game help, the …
MortenLyhr Nov 20, 2026
9ee1241
World Builder: each feature variety with its own button (the forest's…
MortenLyhr Nov 21, 2026
5ae664a
World Builder: the map mode's tabs as the original's, the next one cu…
MortenLyhr Nov 22, 2026
5b329eb
Options: CivilizationIV.ini's settings on the OpenCiv4 tab
MortenLyhr Nov 21, 2026
ab18f1d
Options: the field of view set once a game has started (no defines be…
MortenLyhr Nov 21, 2026
98cb2d6
Options: the edit box hook optional (other tests' stand-ins for oc4sc…
MortenLyhr Nov 21, 2026
d14b27f
Autosaves: the year from CyGame (Windows: the game core does not expo…
MortenLyhr Nov 21, 2026
da50565
Merge #85
MortenLyhr Nov 23, 2026
3fc290d
Merge #87
MortenLyhr Nov 23, 2026
821c64f
Merge #118
MortenLyhr Nov 23, 2026
0995761
Merge #119
MortenLyhr Nov 23, 2026
722903b
Merge #120
MortenLyhr Nov 23, 2026
8333ca9
Merge #132
MortenLyhr Nov 23, 2026
09a0546
Merge #137
MortenLyhr Nov 23, 2026
1420f64
Bundle: the options PRs together, as tested on the play branch
MortenLyhr Nov 21, 2026
b6b6303
Options screens: a scroll panel clips what it holds and scrolls it
MortenLyhr Nov 22, 2026
861e5a8
Options screens: nested scroll panels keep their height; an edit box …
MortenLyhr Nov 22, 2026
812558c
Merge #84
MortenLyhr Nov 23, 2026
bd3d04e
Merge #72
MortenLyhr Nov 23, 2026
e13f524
Merge #94
MortenLyhr Nov 23, 2026
3879cdc
Merge #98
MortenLyhr Nov 23, 2026
11ecaeb
Merge #134
MortenLyhr Nov 23, 2026
9096412
Merge #100
MortenLyhr Nov 23, 2026
ff9ccb9
Merge #114
MortenLyhr Nov 23, 2026
484459f
Merge #117
MortenLyhr Nov 23, 2026
12afc63
Merge #70
MortenLyhr Nov 23, 2026
d3a90be
Merge #113
MortenLyhr Nov 23, 2026
6922934
Merge #86
MortenLyhr Nov 23, 2026
a82802c
Merge #144
MortenLyhr Nov 23, 2026
647a378
Bundle: the interface PRs together, as tested on the play branch
MortenLyhr Nov 21, 2026
148ae06
City on the map: a double click as forgiving as the original's
MortenLyhr Nov 21, 2026
7879df1
City on the map: a double click keeps the units selected before it
MortenLyhr Nov 21, 2026
83fb461
Popups: a choice with a picture is the theme's label button, as the o…
MortenLyhr Nov 22, 2026
95343f0
Popups: the turn's questions are modal, as the original's
MortenLyhr Nov 22, 2026
4007d5b
Merge #96
MortenLyhr Nov 23, 2026
e1354d4
Merge #107
MortenLyhr Nov 23, 2026
087e962
Merge #115
MortenLyhr Nov 23, 2026
846b91f
Merge #121
MortenLyhr Nov 23, 2026
1d5ee05
Merge #122
MortenLyhr Nov 23, 2026
e55cabe
Merge #126
MortenLyhr Nov 23, 2026
8e537d6
Merge #128
MortenLyhr Nov 23, 2026
fcdb42b
Merge #133
MortenLyhr Nov 23, 2026
7b4660c
Merge #138
MortenLyhr Nov 23, 2026
946c80c
Merge #136
MortenLyhr Nov 23, 2026
b33d63c
Merge #139
MortenLyhr Nov 23, 2026
845a07e
Merge #140
MortenLyhr Nov 23, 2026
e48f0ac
Merge #141
MortenLyhr Nov 23, 2026
5fe7d48
BUG's dot map editor: the city under the mouse drawn full, the clicks…
MortenLyhr Nov 21, 2026
90c6f7d
BUG's dot map editor: no way for the units drawn while it picks a plot
MortenLyhr Nov 22, 2026
0b633f1
Sounds: the player's music folder and its files' paths as UTF-8
MortenLyhr Nov 23, 2026
0a37f3f
Options: profile names and folders as UTF-8; a profile file written w…
MortenLyhr Nov 23, 2026
651df8b
Autosaves: none without a Documents folder; the settings behind a loc…
MortenLyhr Nov 23, 2026
b7aede1
README: the player options go to the profile's own file
MortenLyhr Nov 23, 2026
c156717
Comments: their sources without dates, no change history
MortenLyhr Nov 23, 2026
6990530
Restack: bundle 4-options with its review fixes
MortenLyhr Nov 23, 2026
8ba2c8a
Comments: their sources without dates or backlog numbers
MortenLyhr Nov 23, 2026
a154297
Restack: bundle 5-interface-popups with the review fixes
MortenLyhr Nov 23, 2026
a2bc2d7
Play: the mouse buttons seen, the outlined plot and a pick's press ke…
MortenLyhr Nov 23, 2026
5d518bc
Pick plot: a left click picks the plot for the scripts (onPlotPicked)…
MortenLyhr Nov 23, 2026
990e5ef
Comments: no backlog numbers or dates
MortenLyhr Nov 23, 2026
6510608
World Builder: clicking the cut tab moves the strip a tab on, as the …
MortenLyhr Nov 23, 2026
dbe0078
Options: profile files read and written as UTF-8, not the system's co…
MortenLyhr Nov 23, 2026
523d89e
Restack: bundle 4-options with the profile files in UTF-8
MortenLyhr Nov 23, 2026
a4ae626
Restack: bundle 5-interface-popups with the profile files in UTF-8
MortenLyhr Nov 23, 2026
f3eb023
City screen: the selected units stay selected under it, as the origin…
MortenLyhr Nov 23, 2026
876503d
Restack: bundle 5-interface-popups with the selected units kept under…
MortenLyhr Nov 23, 2026
f10551f
City screen: the numpad's moves don't move the units kept under it
MortenLyhr Nov 23, 2026
bb2afa7
Restack: bundle 5-interface-popups with the numpad dead under the cit…
MortenLyhr Nov 23, 2026
cab2a87
Options: each OpenCiv4 option goes to the host on its own
MortenLyhr Nov 23, 2026
63c86de
Restack: bundle 4-options with each option sent to the host on its own
MortenLyhr Nov 23, 2026
a0058cb
Restack: bundle 5-interface-popups with each option sent to the host …
MortenLyhr Nov 23, 2026
f3f7336
Options: the OpenCiv4 tab ends as the game's tabs do, with Restore De…
MortenLyhr Nov 23, 2026
a28189d
Restack: bundle 4-options with the OpenCiv4 tab's Restore Defaults an…
MortenLyhr Nov 23, 2026
5a7c294
Restack: bundle 5-interface-popups with the OpenCiv4 tab's Restore De…
MortenLyhr Nov 23, 2026
93e8526
Right button held: the buttons are the goto plot's, as the original's
MortenLyhr Nov 23, 2026
750a7f5
Restack: bundle 5-interface-popups with the goto plot's buttons while…
MortenLyhr Nov 23, 2026
805cacf
City screen: the help goes beside the widget under the mouse, as the …
MortenLyhr Nov 23, 2026
b9ab021
Restack: bundle 5-interface-popups with the city screen's help beside…
MortenLyhr Nov 23, 2026
3ccf422
World Builder: the Terrains tab grouped as the original's, no doubled…
MortenLyhr Nov 23, 2026
bd2b9ce
World Builder: the techs the player knows framed in yellow, as the or…
MortenLyhr Nov 23, 2026
072f8de
World Builder: a known tech's frame is the original's yellow glow
MortenLyhr Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.user
/external/
/mods/
*.pyc
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ endif()
if(WIN32)
target_link_libraries(oc4core PRIVATE dbghelp bcrypt winmm shell32 ole32 advapi32 ws2_32)
endif()
if(APPLE)
# (the user's time format for the interface clock: CFDateFormatter)
target_link_libraries(oc4core PRIVATE "-framework CoreFoundation")
endif()
# Includes the SDK headers, so it shares the game core's dialect (no UNICODE, lenient conformance).
target_compile_definitions(oc4core PRIVATE OC4_GAMECORE_IMPORT _USRDLL _CRT_SECURE_NO_WARNINGS "OC4_DEFAULT_PYTHON_HOME=\"${OC4_PYTHON27_DIR}\""
"OC4_GAME_CORE_DLL=\"${OC4_GAME_CORE_NAME}.dll\"")
Expand Down Expand Up @@ -374,12 +378,36 @@ target_include_directories(edge_scroll_test PRIVATE src)
add_test(NAME edge_scroll COMMAND edge_scroll_test)
set_target_properties(edge_scroll_test PROPERTIES FOLDER "tests")

add_executable(double_click_test tests/double_click_test.cpp)
target_include_directories(double_click_test PRIVATE src)
add_test(NAME double_click COMMAND double_click_test)
set_target_properties(double_click_test PROPERTIES FOLDER "tests")

add_executable(auto_end_turn_test tests/auto_end_turn_test.cpp)
target_include_directories(auto_end_turn_test PRIVATE apps/oc4core)
target_link_libraries(auto_end_turn_test PRIVATE oc4_options)
add_test(NAME auto_end_turn COMMAND auto_end_turn_test)
set_target_properties(auto_end_turn_test PROPERTIES FOLDER "tests")

add_executable(auto_saves_test tests/auto_saves_test.cpp)
target_include_directories(auto_saves_test PRIVATE apps/oc4core)
target_link_libraries(auto_saves_test PRIVATE oc4_options)
add_test(NAME auto_saves COMMAND auto_saves_test)
set_target_properties(auto_saves_test PROPERTIES FOLDER "tests")

# The player options kept in the player's profile, and the options screen's OpenCiv4 tab
# (oc4options.py, with a stand-in host).
find_package(Python3 COMPONENTS Interpreter QUIET)
if(Python3_Interpreter_FOUND)
add_test(NAME player_options COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/tests/player_options_test.py
${CMAKE_CURRENT_SOURCE_DIR}/apps/oc4core/python)
# CivilizationIV.ini's settings on the OpenCiv4 tab, kept in the profile.
add_test(NAME ini_options COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/tests/ini_options_test.py
${CMAKE_CURRENT_SOURCE_DIR}/apps/oc4core/python)
add_test(NAME options_other COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/tests/options_other_test.py
${CMAKE_CURRENT_SOURCE_DIR}/apps/oc4core/python)
endif()

add_executable(xml_decode_test tests/xml_decode_test.cpp)
target_include_directories(xml_decode_test PRIVATE apps/oc4core)
target_link_libraries(xml_decode_test PRIVATE oc4_options)
Expand Down Expand Up @@ -414,6 +442,22 @@ target_include_directories(flag_art_test PRIVATE src)
target_link_libraries(flag_art_test PRIVATE oc4_options oc4_render)
add_test(NAME flag_art COMMAND flag_art_test)
set_target_properties(flag_art_test PROPERTIES FOLDER "tests")
# The minimap's toggles kept in the player's profile (oc4options.py, with a stand-in host).
find_package(Python3 COMPONENTS Interpreter QUIET)
if(Python3_Interpreter_FOUND)
add_test(NAME minimap_toggles COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/tests/minimap_toggles_test.py
${CMAKE_CURRENT_SOURCE_DIR}/apps/oc4core/python)
endif()
add_executable(game_fonts_test tests/game_fonts_test.cpp)
target_include_directories(game_fonts_test PRIVATE src)
target_link_libraries(game_fonts_test PRIVATE oc4_options oc4_render)
add_test(NAME game_fonts COMMAND game_fonts_test)
set_target_properties(game_fonts_test PROPERTIES FOLDER "tests")
add_executable(theme_table_test tests/theme_table_test.cpp)
target_include_directories(theme_table_test PRIVATE src)
target_link_libraries(theme_table_test PRIVATE oc4_options oc4_render)
add_test(NAME theme_table COMMAND theme_table_test)
set_target_properties(theme_table_test PROPERTIES FOLDER "tests")

if(WIN32 AND TARGET freetype)
add_executable(text_layout_freetype_test tests/text_layout_test.cpp src/render/TextLayout.cpp src/render/FontFreeType.cpp src/render/FontVdmx.cpp)
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Ctrl+Shift+F shows the frame rate and the longest frame of the last half second
from the start).

W A S D can pan the map as the arrows do, an option that is off by default: "Pan the map with
W A S D" on the options' Game tab turns it on and off, and while it is on Ctrl+Shift+W turns it off
W A S D" on the options' OpenCiv4 tab turns it on and off, and while it is on Ctrl+Shift+W turns it off
too (a note at the top says so; with the option off, Ctrl+Shift+W is the game's own); it is kept in profile.ini as `wasdPan`, and `--wasd-pan` turns it on for one run. Only
the letters pressed alone pan, so while it is on their own hotkeys (S Sentry, A Automate, W the
next unit, D destroy) need the unit's buttons; with Shift, Ctrl or Alt they are still the game's
Expand All @@ -197,17 +197,34 @@ only when a unit moved in it (and "Wait at End of Turn" is off); with this on, a
going until something needs you. A popup, a talk, a screen or the city screen pauses it, and a
key or click while it waits keeps that turn; hot seat and by-email games never use it. Ctrl+Shift+E
turns it on and off (with a note at the top), and so does "End idle turns automatically" on the
options' Game tab; it is kept in profile.ini as `autoEndTurn`, and `--auto-end-turn` turns it on
options' OpenCiv4 tab; it is kept in profile.ini as `autoEndTurn`, and `--auto-end-turn` turns it on
for one run. `OC4_PLAY_LOG=1` prints "idle, ended by itself" for each such turn. Decisions: it is
in the engine (`apps/oc4core/AutoEndTurn.h`, called from the play loop), not the game core, so the
game's rules, AI and saves are untouched; it sends the same end-turn control as Enter. Tested by
`tests/auto_end_turn_test.cpp`.

The mouse at the window's edge scrolls the map, as in the original; "Scroll the map at the screen
edge" on the options' Game tab turns it off (on by default). It is kept in profile.ini as
edge" on the options' OpenCiv4 tab turns it off (on by default). It is kept in profile.ini as
`edgeScroll`, and `--no-edge-scroll` turns it off for one run (scripted runs with `--view-seconds`
never edge scroll). The rule is `src/render/EdgeScroll.h`, tested by `tests/edge_scroll_test.cpp`.

Your cities on the map open as in the original: a double click on the city or its name bar opens
its screen, one click on the bar selects the city (what it builds in the bottom panel), and one click
on its plot is any plot's (the units there). "Open a city with a single click" on the options'
OpenCiv4 tab opens the screen with one click instead (off by default; `cityOneClick` in profile.ini).
A double click is as forgiving as the original's: up to 500 ms between the presses (their own times,
not a frame's), a few points apart, and its second click counts on what the first was on; a click on
your own city (its plot, bar or a unit's figure in it) leaves the camera where it is, as the
original's, so the city stays under the mouse. The rule is `src/render/DoubleClick.h`, tested by
`tests/double_click_test.cpp`.

The player options (Options → Game: Wait at End of Turn, Quick Combat, …) are kept in the player's
profile, as the original keeps them in its own (`Profiles\<name>.pfl`): a choice is written at
once to the profile's file (`Profiles/<name>.ini` beside profile.ini, `player.N=`), and every game, new or loaded, starts with the profile's, which
the game core sends to the active player (a save's own options are overwritten, as in the original).
OpenCiv4's own options (W A S D, idle turns, edge scrolling, one click on a city) are on a tab of their own, OpenCiv4,
after the original's four. Tested by `tests/player_options_test.py`.

The globe view's colour layers (Culture, Trade, Religion) are drawn on the globe itself.

Tools for the game's files, in `build\Release\bin`:
Expand Down
92 changes: 92 additions & 0 deletions apps/oc4core/AutoSaves.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#pragma once
// The game's autosaves as the original makes them (CivilizationIV.ini's AutoSaveInterval and
// MaxAutoSaves; the options' OpenCiv4 tab), as seen in the running original under Wine
// (interval 2, 3 kept, Saves\single\auto listed at each of 16 turns): the game's first
// turn as AutoSave_Initial_BC-4000, then at the start of every interval's turn (2, 4, 6, ...)
// AutoSave_<year> (AutoSave_BC-3920); when one more than the number kept is written, the oldest
// AutoSave_<year> goes. The initial save doesn't count and stays. Interval 0: none, as the ini's
// comment says. Or openciv4's own way: each game its own files, the kept ones in turn.

#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <format>
#include <functional>
#include <mutex>
#include <string>
#include <system_error>
#include <utility>
#include <vector>

namespace oc4::host
{
struct AutoSaveSettings
{
int interval = 4, kept = 5; // (the ini's defaults; interval 0: no autosaves)
bool openciv4 = false; // openciv4's own (My Games\openciv4\Saves\auto, one in 25 turns kept)
};

// The settings as the options' script sets them and the game's thread reads them.
class SharedAutoSaveSettings
{
public:
void set(const AutoSaveSettings& how)
{
std::lock_guard lock(m_mutex);
m_how = how;
}
AutoSaveSettings get() const
{
std::lock_guard lock(m_mutex);
return m_how;
}

private:
mutable std::mutex m_mutex;
AutoSaveSettings m_how;
};

// Whether the game saves at this turn's start (the game's first: its initial save).
inline bool autoSaveDue(const AutoSaveSettings& how, int turn, bool initial)
{
return how.interval > 0 && (initial || turn % how.interval == 0);
}

// The original's file name: AutoSave_[Initial_]BC-4000.CivBeyondSwordSave. (Only BC years were
// seen; an AD year is written the same way, AD-1250, as our guess.)
inline std::wstring autoSaveName(bool initial, int year)
{
return std::format(L"AutoSave_{}{}-{}.CivBeyondSwordSave", initial ? L"Initial_" : L"", year < 0 ? L"BC" : L"AD", std::abs(year));
}

// openciv4's own: <stem>_<slot>, the kept ones in turn.
inline std::wstring openciv4AutoSaveName(const std::wstring& stem, const AutoSaveSettings& how, int turn)
{
return std::format(L"{}_{}.CivBeyondSwordSave", stem, turn / std::max(1, how.interval) % std::max(1, how.kept));
}

// openciv4's own: whether this turn's save is also kept for good, the first save in each 25 turns
// (turn 25, 50, ... when the interval divides it; else the first save after each).
inline bool openciv4KeepsForGood(const AutoSaveSettings& how, int turn)
{
const int every = std::max(1, how.interval);
return turn > 0 && turn / 25 != (turn - every) / 25;
}

// The AutoSave_<year> saves in the folder beyond the newest kept ones (the oldest first to go);
// not the initial save, nor any other file.
inline std::vector<std::filesystem::path> autoSavesBeyond(const std::filesystem::path& folder, int kept)
{
std::vector<std::pair<std::filesystem::file_time_type, std::filesystem::path>> saves;
std::error_code ec;
for (const auto& e : std::filesystem::directory_iterator(folder, ec))
if (const std::wstring name = e.path().filename().wstring();
e.is_regular_file() && name.starts_with(L"AutoSave_") && !name.starts_with(L"AutoSave_Initial_"))
saves.push_back({ e.last_write_time(), e.path() });
std::ranges::sort(saves, std::greater{});
std::vector<std::filesystem::path> out;
for (size_t i = size_t(std::max(1, kept)); i < saves.size(); ++i)
out.push_back(saves[i].second);
return out;
}
}
14 changes: 3 additions & 11 deletions apps/oc4core/GameSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ namespace oc4::host
void GameSession::startScenario(const NewGameSettings& settings)
{
m_utility.setGameInitializing(true);
m_utility.setProfileOptionsFromPlayer(NO_PLAYER);
m_python.run(std::format("import random\nrandom.seed({})\n", settings.seed));
setupScenarioInitCore(settings);
CvInitCore& ic = GC.getInitCore();
Expand Down Expand Up @@ -477,7 +476,6 @@ namespace oc4::host
return;
}
m_utility.setGameInitializing(true);
m_utility.setProfileOptionsFromPlayer(NO_PLAYER);
setupInitCore(settings);
CvInitCore& ic = GC.getInitCore();
CvGame& game = GC.getGame();
Expand Down Expand Up @@ -624,7 +622,6 @@ namespace oc4::host
player(p).updateHuman();
}
GC.getGame().setActivePlayer(static_cast<PlayerTypes>(seat));
m_utility.setProfileOptionsFromPlayer(static_cast<PlayerTypes>(seat));
// (the mods' scripts draw from Python's random module too: the same numbers in every game)
m_python.run(std::format("import random\nrandom.seed({})\n", ic.getSyncRandSeed() ^ unsigned(GC.getGame().getGameTurn())));
setInterfaceTime(true); // (from now on, between frames)
Expand Down Expand Up @@ -805,9 +802,9 @@ namespace oc4::host
throw std::runtime_error(path.filename().string() + ": game data does not match this game core (wrong mod or DLL?)");

// CvGame::read picks the active player of single player games; for hotseat and
// other multiplayer types the engine does: the human whose turn it is. The saved
// options of the human at the seat stand in for the user profile (the DLL sends
// the profile's options to the new active player).
// other multiplayer types the engine does: the human whose turn it is. The DLL then
// sends the user profile's options to the active player, as in the original (the
// saved ones are overwritten: the profile's are the player's, in every game).
if (GC.getGame().getActivePlayer() == NO_PLAYER)
{
int chosen = NO_PLAYER;
Expand All @@ -818,13 +815,8 @@ namespace oc4::host
if (player(p).isHuman())
chosen = p;
if (chosen != NO_PLAYER)
{
m_utility.setProfileOptionsFromPlayer(static_cast<PlayerTypes>(chosen));
GC.getGame().setActivePlayer(static_cast<PlayerTypes>(chosen));
}
}
else
m_utility.setProfileOptionsFromPlayer(GC.getGame().getActivePlayer());

// Script data back to Python: CvAppInterface.onLoad((pickle,)).
void* args[] = { PyString_FromStringAndSize(save.pythonData.data(), Py_ssize_t(save.pythonData.size())) };
Expand Down
Loading
Loading