Fix: Don't restore backed up vehicle name if it's no longer unique. (#10979)

(cherry picked from commit 2097719f26)
This commit is contained in:
PeterN 2023-06-09 22:18:55 +01:00 committed by Jonathan G Rennison
parent e1cb4d2397
commit 1696ef6446
3 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,7 @@
#include "vehicle_base.h" #include "vehicle_base.h"
#include "window_func.h" #include "window_func.h"
#include "station_map.h" #include "station_map.h"
#include "vehicle_func.h"
#include "safeguards.h" #include "safeguards.h"
@ -98,6 +99,9 @@ void OrderBackup::DoRestore(Vehicle *v)
InvalidateWindowClassesData(WC_STATION_LIST, 0); InvalidateWindowClassesData(WC_STATION_LIST, 0);
} }
/* Remove backed up name if it's no longer unique. */
if (!this->name.empty() && !IsUniqueVehicleName(this->name.c_str())) this->name.clear();
v->CopyConsistPropertiesFrom(this); v->CopyConsistPropertiesFrom(this);
/* Make sure orders are in range */ /* Make sure orders are in range */

View File

@ -827,7 +827,7 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32
* @param name Name to test. * @param name Name to test.
* @return True if the name is unique. * @return True if the name is unique.
*/ */
static bool IsUniqueVehicleName(const char *name) bool IsUniqueVehicleName(const char *name)
{ {
for (const Vehicle *v : Vehicle::Iterate()) { for (const Vehicle *v : Vehicle::Iterate()) {
if (!v->name.empty() && v->name == name) return false; if (!v->name.empty() && v->name == name) return false;

View File

@ -267,4 +267,6 @@ void CheckCargoCapacity(Vehicle *v);
bool VehiclesHaveSameEngineList(const Vehicle *v1, const Vehicle *v2); bool VehiclesHaveSameEngineList(const Vehicle *v1, const Vehicle *v2);
bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2); bool VehiclesHaveSameOrderList(const Vehicle *v1, const Vehicle *v2);
bool IsUniqueVehicleName(const char *name);
#endif /* VEHICLE_FUNC_H */ #endif /* VEHICLE_FUNC_H */