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.

Re-order load update for SLV_139, it is no longer required to be
performed before the first phase of vehicle updates
This commit is contained in:
Jonathan G Rennison
2024-07-01 23:40:11 +01:00
parent f5b0874c1c
commit a99e6b5082
8 changed files with 56 additions and 41 deletions

View File

@@ -703,7 +703,11 @@ void DrawRailCatenary(const TileInfo *ti)
void SettingsDisableElrail(int32_t new_value)
{
bool disable = (new_value != 0);
UpdateDisableElrailSettingState(disable, true);
}
void UpdateDisableElrailSettingState(bool disable, bool update_vehicles)
{
/* pick appropriate railtype for elrail engines depending on setting */
const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
@@ -731,10 +735,12 @@ void SettingsDisableElrail(int32_t new_value)
}
/* Fix the total power and acceleration for trains */
for (Train *t : Train::IterateFrontOnly()) {
/* power and acceleration is cached only for front engines */
if (t->IsFrontEngine()) {
t->ConsistChanged(CCF_TRACK);
if (update_vehicles) {
for (Train *t : Train::IterateFrontOnly()) {
/* power and acceleration is cached only for front engines */
if (t->IsFrontEngine()) {
t->ConsistChanged(CCF_TRACK);
}
}
}