Fix Vehicle::CopyVehicleConfigAndStatistics not releasing unit number
See: https://github.com/OpenTTD/OpenTTD/issues/12388
This commit is contained in:
@@ -2225,8 +2225,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32_t p1,
|
||||
}
|
||||
/* 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();
|
||||
if (!_settings_game.vehicle.non_leading_engines_keep_name) {
|
||||
src->name.clear();
|
||||
}
|
||||
|
@@ -3710,6 +3710,17 @@ 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()
|
||||
{
|
||||
if (this->unitnumber != 0) {
|
||||
Company::Get(this->owner)->freeunits[this->type].ReleaseID(this->unitnumber);
|
||||
this->unitnumber = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ShouldVehicleContinueWaiting(Vehicle *v)
|
||||
{
|
||||
if (v->GetNumOrders() < 1) return false;
|
||||
|
@@ -907,6 +907,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),
|
||||
@@ -917,6 +919,7 @@ public:
|
||||
{
|
||||
this->CopyConsistPropertiesFrom(src);
|
||||
|
||||
this->ReleaseUnitNumber();
|
||||
this->unitnumber = src->unitnumber;
|
||||
|
||||
this->current_order = src->current_order;
|
||||
|
Reference in New Issue
Block a user