Fix #10334: Store separate newgrf-safe version of date_of_last_service. (#11124)

This value is not changed when the date cheat is used, which caused issues with changing properties based on service date.

Co-authored-by: Peter Nelson <peter1138@openttd.org>
This commit is contained in:
Tyler Trahan
2023-08-06 12:57:10 -04:00
committed by GitHub
parent 77c00dfe98
commit 9a602ff304
11 changed files with 24 additions and 3 deletions

View File

@@ -3234,6 +3234,13 @@ bool AfterLoadGame()
_new_competitor_timeout.fired = _new_competitor_timeout.period == 0;
}
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;
}
}
AfterLoadLabelMaps();
AfterLoadCompanyStats();
AfterLoadStoryBook();

View File

@@ -358,6 +358,7 @@ enum SaveLoadVersion : uint16_t {
SLV_INDUSTRY_CARGO_REORGANISE, ///< 315 PR#10853 Industry accepts/produced data reorganised.
SLV_PERIODS_IN_TRANSIT_RENAME, ///< 316 PR#11112 Rename days in transit to (cargo) periods in transit.
SLV_NEWGRF_LAST_SERVICE, ///< 317 PR#11124 Added stable date_of_last_service to avoid NewGRF trouble.
SL_MAX_VERSION, ///< Highest possible saveload version
};

View File

@@ -675,6 +675,7 @@ public:
SLE_CONDVAR(Vehicle, max_age, SLE_INT32, SLV_31, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, SLV_31, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, date_of_last_service_newgrf, SLE_INT32, SLV_NEWGRF_LAST_SERVICE, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SL_MIN_VERSION, SLV_31),
SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SLV_31, SLV_180),
SLE_CONDVAR(Vehicle, service_interval, SLE_UINT16, SLV_180, SL_MAX_VERSION),