Codechange: Split dates and timers into Economy and Calendar time (#10700)

This commit is contained in:
Tyler Trahan
2024-01-22 09:04:34 -05:00
committed by GitHub
parent 419f48dfb3
commit 735abfe111
65 changed files with 952 additions and 550 deletions
+14 -6
View File
@@ -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"
@@ -260,8 +261,8 @@ static void InitializeWindowsAndCaches()
/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
* accordingly if it is not the case. No need to set it on companies that are not been used already,
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != CalendarTime::MIN_YEAR) {
c->inaugurated_year = TimerGameCalendar::year;
if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != EconomyTime::MIN_YEAR) {
c->inaugurated_year = TimerGameEconomy::year;
}
}
@@ -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
@@ -1429,11 +1437,11 @@ bool AfterLoadGame()
for (Station *st : Station::Iterate()) st->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
for (Engine *e : Engine::Iterate()) e->intro_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
for (Company *c : Company::Iterate()) c->inaugurated_year += CalendarTime::ORIGINAL_BASE_YEAR;
for (Industry *i : Industry::Iterate()) i->last_prod_year += CalendarTime::ORIGINAL_BASE_YEAR;
for (Company *c : Company::Iterate()) c->inaugurated_year += EconomyTime::ORIGINAL_BASE_YEAR;
for (Industry *i : Industry::Iterate()) i->last_prod_year += EconomyTime::ORIGINAL_BASE_YEAR;
for (Vehicle *v : Vehicle::Iterate()) {
v->date_of_last_service += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
v->date_of_last_service += EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
v->build_year += CalendarTime::ORIGINAL_BASE_YEAR;
}
}
@@ -3258,7 +3266,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_NEWGRF_LAST_SERVICE)) {
/* Set service date provided to NewGRF. */
for (Vehicle *v : Vehicle::Iterate()) {
v->date_of_last_service_newgrf = v->date_of_last_service;
v->date_of_last_service_newgrf = v->date_of_last_service.base();
}
}
+2 -2
View File
@@ -50,12 +50,12 @@ public:
/* Old array structure used for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
static CargoID old_cargo[INDUSTRY_NUM_INPUTS];
static uint16_t old_waiting[INDUSTRY_NUM_INPUTS];
static TimerGameCalendar::Date old_last_accepted[INDUSTRY_NUM_INPUTS];
static TimerGameEconomy::Date old_last_accepted[INDUSTRY_NUM_INPUTS];
};
/* static */ CargoID SlIndustryAccepted::old_cargo[INDUSTRY_NUM_INPUTS];
/* static */ uint16_t SlIndustryAccepted::old_waiting[INDUSTRY_NUM_INPUTS];
/* static */ TimerGameCalendar::Date SlIndustryAccepted::old_last_accepted[INDUSTRY_NUM_INPUTS];
/* static */ TimerGameEconomy::Date SlIndustryAccepted::old_last_accepted[INDUSTRY_NUM_INPUTS];
class SlIndustryProducedHistory : public DefaultSaveLoadHandler<SlIndustryProducedHistory, Industry::ProducedCargo> {
public:
+3
View File
@@ -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),
+2 -2
View File
@@ -859,7 +859,7 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
if (i->type > 0x06) i->type++; // Printing Works were added
if (i->type == 0x0A) i->type = 0x12; // Iron Ore Mine has different ID
TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date);
TimerGameEconomy::YearMonthDay ymd = TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::date);
i->last_prod_year = ymd.year;
i->random_colour = RemapTTOColour(i->random_colour);
@@ -1034,7 +1034,7 @@ static bool LoadOldCompany(LoadgameState *ls, int num)
}
_company_colours[num] = c->colour;
c->inaugurated_year -= CalendarTime::ORIGINAL_BASE_YEAR;
c->inaugurated_year -= EconomyTime::ORIGINAL_BASE_YEAR;
return true;
}
+1
View File
@@ -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
};