Fix #12831: Delay vehicle cache init to after map upgrades in load

Split AfterLoadVehicles into two functions.
Vehicle cache init and other functionality requiring an upgraded and
valid map is now performed later in the load process.
This commit is contained in:
Jonathan G Rennison
2024-07-01 17:05:39 +01:00
committed by rubidium42
parent dfb74e25f7
commit f19829d029
7 changed files with 35 additions and 22 deletions

View File

@@ -828,8 +828,8 @@ bool AfterLoadGame()
}
}
/* Update all vehicles */
AfterLoadVehicles(true);
/* Update all vehicles: Phase 1 */
AfterLoadVehiclesPhase1(true);
/* make sure there is a town in the game */
if (_game_mode == GM_NORMAL && Town::GetNumItems() == 0) {
@@ -1356,11 +1356,6 @@ bool AfterLoadGame()
break;
}
}
for (Train *v : Train::Iterate()) {
if (v->IsFrontEngine() || v->IsFreeWagon()) v->ConsistChanged(CCF_TRACK);
}
}
/* In version 16.1 of the savegame a company can decide if trains, which get
@@ -1493,7 +1488,7 @@ bool AfterLoadGame()
* preference of a user, let elrails enabled; it can be disabled manually */
if (IsSavegameVersionBefore(SLV_38)) _settings_game.vehicle.disable_elrails = false;
/* do the same as when elrails were enabled/disabled manually just now */
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
UpdateDisableElrailSettingState(_settings_game.vehicle.disable_elrails, false);
InitializeRailGUI();
/* From version 53, the map array was changed for house tiles to allow
@@ -2815,9 +2810,6 @@ bool AfterLoadGame()
}
}
/* The center of train vehicles was changed, fix up spacing. */
if (IsSavegameVersionBefore(SLV_164)) FixupTrainLengths();
if (IsSavegameVersionBefore(SLV_165)) {
for (Town *t : Town::Iterate()) {
/* Set the default cargo requirement for town growth */
@@ -2925,6 +2917,14 @@ bool AfterLoadGame()
}
}
/* Beyond this point, tile types which can be accessed by vehicles must be in a valid state. */
/* Update all vehicles: Phase 2 */
AfterLoadVehiclesPhase2(true);
/* The center of train vehicles was changed, fix up spacing. */
if (IsSavegameVersionBefore(SLV_164)) FixupTrainLengths();
/* In version 2.2 of the savegame, we have new airports, so status of all aircraft is reset.
* This has to be called after all map array updates */
if (IsSavegameVersionBefore(SLV_2, 2)) UpdateOldAircraft();
@@ -3342,7 +3342,8 @@ void ReloadNewGRFData()
RecomputePrices();
/* reload vehicles */
ResetVehicleHash();
AfterLoadVehicles(false);
AfterLoadVehiclesPhase1(false);
AfterLoadVehiclesPhase2(false);
StartupEngines();
GroupStatistics::UpdateAfterLoad();
/* update station graphics */