Remove road vehicles during load which are uncorrectably invalid
This commit is contained in:
@@ -6055,6 +6055,7 @@ STR_GAME_SAVELOAD_ERROR_DATA_INTEGRITY_CHECK_FAILED :Data integrity
|
||||
STR_GAME_SAVELOAD_ERROR_PATCHPACK :Savegame is made with a modified version
|
||||
STR_GAME_SAVELOAD_NOT_AVAILABLE :<not available>
|
||||
STR_WARNING_LOADGAME_REMOVED_TRAMS :{WHITE}Game was saved in version without tram support. All trams have been removed
|
||||
STR_WARNING_LOADGAME_REMOVED_UNCORRECTABLE_VEHICLES :{WHITE}Removed {NUM} vehicles found to be uncorrectably invalid during load
|
||||
|
||||
STR_GAME_SAVELOAD_FROM_VERSION : from version {PUSH_COLOUR}{ORANGE}{RAW_STRING}{POP_COLOUR}{}
|
||||
STR_GAME_SAVELOAD_ERROR_TOO_NEW_FEATURE_VERSION :Savegame{0:STRING1} has version {PUSH_COLOUR}{ORANGE}{2:NUM}{POP_COLOUR} of feature '{PUSH_COLOUR}{ORANGE}{1:RAW_STRING}{POP_COLOUR}', but the maximum supported version is {PUSH_COLOUR}{ORANGE}{3:NUM}{POP_COLOUR}
|
||||
|
@@ -4109,6 +4109,8 @@ bool AfterLoadGame()
|
||||
AfterLoadCompanyStats();
|
||||
AfterLoadStoryBook();
|
||||
|
||||
AfterLoadVehiclesRemoveAnyFoundInvalid();
|
||||
|
||||
GamelogPrintDebug(1);
|
||||
|
||||
InitializeWindowsAndCaches();
|
||||
|
@@ -26,6 +26,7 @@ void MoveWaypointsToBaseStations();
|
||||
SaveLoadTable GetBaseStationDescription();
|
||||
|
||||
void AfterLoadVehicles(bool part_of_load);
|
||||
void AfterLoadVehiclesRemoveAnyFoundInvalid();
|
||||
void AfterLoadEngines();
|
||||
void FixupTrainLengths();
|
||||
void AfterLoadTemplateVehicles();
|
||||
|
@@ -20,6 +20,8 @@
|
||||
#include "../disaster_vehicle.h"
|
||||
#include "../scope_info.h"
|
||||
#include "../string_func.h"
|
||||
#include "../error.h"
|
||||
#include "../strings_func.h"
|
||||
|
||||
#include "saveload.h"
|
||||
|
||||
@@ -238,9 +240,13 @@ static void CheckValidVehicles()
|
||||
|
||||
extern byte _age_cargo_skip_counter; // From misc_sl.cpp
|
||||
|
||||
static std::vector<Vehicle *> _load_invalid_vehicles_to_delete;
|
||||
|
||||
/** Called after load to update coordinates */
|
||||
void AfterLoadVehicles(bool part_of_load)
|
||||
{
|
||||
_load_invalid_vehicles_to_delete.clear();
|
||||
|
||||
const Vehicle *si_v = nullptr;
|
||||
SCOPE_INFO_FMT([&si_v], "AfterLoadVehicles: %s", scope_dumper().VehicleInfo(si_v));
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
@@ -427,9 +433,16 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
|
||||
rv->roadtype = Engine::Get(rv->engine_type)->u.road.roadtype;
|
||||
rv->compatible_roadtypes = GetRoadTypeInfo(rv->roadtype)->powered_roadtypes;
|
||||
bool is_invalid = false;
|
||||
for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
|
||||
u->roadtype = rv->roadtype;
|
||||
u->compatible_roadtypes = rv->compatible_roadtypes;
|
||||
if (GetRoadType(u->tile, GetRoadTramType(u->roadtype)) == INVALID_ROADTYPE) is_invalid = true;
|
||||
}
|
||||
|
||||
if (is_invalid && part_of_load) {
|
||||
_load_invalid_vehicles_to_delete.push_back(rv);
|
||||
break;
|
||||
}
|
||||
|
||||
RoadVehUpdateCache(rv);
|
||||
@@ -510,6 +523,21 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
}
|
||||
}
|
||||
|
||||
void AfterLoadVehiclesRemoveAnyFoundInvalid()
|
||||
{
|
||||
if (!_load_invalid_vehicles_to_delete.empty()) {
|
||||
DEBUG(sl, 0, "Removing %u vehicles found to be uncorrectably invalid during load", (uint)_load_invalid_vehicles_to_delete.size());
|
||||
SetDParam(0, (uint)_load_invalid_vehicles_to_delete.size());
|
||||
ShowErrorMessage(STR_WARNING_LOADGAME_REMOVED_UNCORRECTABLE_VEHICLES, INVALID_STRING_ID, WL_CRITICAL);
|
||||
GroupStatistics::UpdateAfterLoad();
|
||||
}
|
||||
|
||||
for (Vehicle *v : _load_invalid_vehicles_to_delete) {
|
||||
delete v;
|
||||
}
|
||||
_load_invalid_vehicles_to_delete.clear();
|
||||
}
|
||||
|
||||
bool TrainController(Train *v, Vehicle *nomove, bool reverse = true); // From train_cmd.cpp
|
||||
void ReverseTrainDirection(Train *v);
|
||||
void ReverseTrainSwapVeh(Train *v, int l, int r);
|
||||
|
Reference in New Issue
Block a user