From 433484cda3c1cecc0441dc0080c1cb1a765cf807 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 27 Mar 2024 20:20:27 +0000 Subject: [PATCH] Fix #12388: Vehicle::CopyVehicleConfigAndStatistics not releasing unit number (#12389) --- src/train_cmd.cpp | 3 +-- src/vehicle.cpp | 9 +++++++++ src/vehicle_base.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 4413a2e777..51353c5281 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1336,8 +1336,7 @@ CommandCost CmdMoveRailVehicle(DoCommandFlag flags, VehicleID src_veh, VehicleID } /* Remove stuff not valid anymore for non-front engines. */ DeleteVehicleOrders(src); - Company::Get(src->owner)->freeunits[src->type].ReleaseID(src->unitnumber); - src->unitnumber = 0; + src->ReleaseUnitNumber(); src->name.clear(); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 044c8013c9..7d6e8489ea 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2401,6 +2401,15 @@ void Vehicle::ResetRefitCaps() for (Vehicle *v = this; v != nullptr; v = v->Next()) v->refit_cap = v->cargo_cap; } +/** + * Release the vehicle's unit number. + */ +void Vehicle::ReleaseUnitNumber() +{ + Company::Get(this->owner)->freeunits[this->type].ReleaseID(this->unitnumber); + this->unitnumber = 0; +} + /** * Handle the loading of the vehicle; when not it skips through dummy * orders and does nothing in all other cases. diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 3c4e2ea65f..592063323c 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -750,6 +750,8 @@ public: void ResetRefitCaps(); + void ReleaseUnitNumber(); + /** * Copy certain configurations and statistics of a vehicle after successful autoreplace/renew * The function shall copy everything that cannot be copied by a command (like orders / group etc), @@ -760,6 +762,7 @@ public: { this->CopyConsistPropertiesFrom(src); + this->ReleaseUnitNumber(); this->unitnumber = src->unitnumber; this->current_order = src->current_order;