From e21c6cfb8a14a0aa258baa8c9c2e40a1229bc47c Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Sun, 1 Jan 2023 13:00:01 -0500 Subject: [PATCH] Codechange: Sync economy and calendar dates when loading old saves --- src/saveload/afterload.cpp | 8 ++++++++ src/saveload/misc_sl.cpp | 3 +++ src/saveload/saveload.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index e6fd1c7ba1..b44b0b92c9 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -60,6 +60,7 @@ #include "../water.h" #include "../timer/timer.h" #include "../timer/timer_game_calendar.h" +#include "../timer/timer_game_economy.h" #include "../timer/timer_game_tick.h" #include "saveload_internal.h" @@ -734,6 +735,13 @@ bool AfterLoadGame() * must be done before loading sprites as some newgrfs check it */ TimerGameCalendar::SetDate(TimerGameCalendar::date, TimerGameCalendar::date_fract); + /* Update economy year. If we don't have a separate economy date saved, follow the calendar date. */ + if (IsSavegameVersionBefore(SLV_ECONOMY_DATE)) { + TimerGameEconomy::SetDate(TimerGameCalendar::date.base(), TimerGameCalendar::date_fract); + } else { + TimerGameEconomy::SetDate(TimerGameEconomy::date, TimerGameEconomy::date_fract); + } + /* * Force the old behaviour for compatibility reasons with old savegames. As new * settings can only be loaded from new savegames loading old savegames with new diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index f50cab48b5..a28021f520 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -13,6 +13,7 @@ #include "compat/misc_sl_compat.h" #include "../timer/timer_game_calendar.h" +#include "../timer/timer_game_economy.h" #include "../zoom_func.h" #include "../window_gui.h" #include "../window_func.h" @@ -85,6 +86,8 @@ static const SaveLoad _date_desc[] = { SLEG_VAR("date_fract", TimerGameCalendar::date_fract, SLE_UINT16), SLEG_CONDVAR("tick_counter", TimerGameTick::counter, SLE_FILE_U16 | SLE_VAR_U64, SL_MIN_VERSION, SLV_U64_TICK_COUNTER), SLEG_CONDVAR("tick_counter", TimerGameTick::counter, SLE_UINT64, SLV_U64_TICK_COUNTER, SL_MAX_VERSION), + SLEG_CONDVAR("economy_date", TimerGameEconomy::date, SLE_INT32, SLV_ECONOMY_DATE, SL_MAX_VERSION), + SLEG_CONDVAR("economy_date_fract", TimerGameEconomy::date_fract, SLE_UINT16, SLV_ECONOMY_DATE, SL_MAX_VERSION), SLEG_CONDVAR("age_cargo_skip_counter", _age_cargo_skip_counter, SLE_UINT8, SL_MIN_VERSION, SLV_162), SLEG_CONDVAR("cur_tileloop_tile", _cur_tileloop_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), SLEG_CONDVAR("cur_tileloop_tile", _cur_tileloop_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION), diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 4c784ba70d..97625fb482 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -368,6 +368,7 @@ enum SaveLoadVersion : uint16_t { SLV_WATER_REGIONS, ///< 324 PR#10543 Water Regions for ship pathfinder. SLV_WATER_REGION_EVAL_SIMPLIFIED, ///< 325 PR#11750 Simplified Water Region evaluation. + SLV_ECONOMY_DATE, ///< 326 PR#10700 Split calendar and economy timers and dates. SL_MAX_VERSION, ///< Highest possible saveload version };