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

@@ -251,8 +251,8 @@ static void CheckValidVehicles()
extern uint8_t _age_cargo_skip_counter; // From misc_sl.cpp
/** Called after load to update coordinates */
void AfterLoadVehicles(bool part_of_load)
/** Called after load for phase 1 of vehicle initialisation */
void AfterLoadVehiclesPhase1(bool part_of_load)
{
for (Vehicle *v : Vehicle::Iterate()) {
/* Reinstate the previous pointer */
@@ -408,9 +408,13 @@ void AfterLoadVehicles(bool part_of_load)
}
CheckValidVehicles();
}
/** Called after load for phase 2 of vehicle initialisation */
void AfterLoadVehiclesPhase2(bool part_of_load)
{
for (Vehicle *v : Vehicle::Iterate()) {
assert(v->first != nullptr);
assert(v->First() != nullptr);
v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);