From 88110e9b2eb38c3b2f522e5c59fcdd0189c71607 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 13 Aug 2024 19:53:10 +0100 Subject: [PATCH] Fix: Train unit ID allocation when moving engine to new train at train limit (#12887) --- src/train_cmd.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 2b58b6b212..4e8cbd1e66 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1346,14 +1346,15 @@ CommandCost CmdMoveRailVehicle(DoCommandFlag flags, VehicleID src_veh, VehicleID SetWindowDirty(WC_COMPANY, _current_company); } - /* Add new heads to statistics */ - if (src_head != nullptr && src_head->IsFrontEngine()) GroupStatistics::CountVehicle(src_head, 1); - if (dst_head != nullptr && dst_head->IsFrontEngine()) GroupStatistics::CountVehicle(dst_head, 1); - /* Handle 'new engine' part of cases #1b, #2b, #3b, #4b and #5 in NormaliseTrainHead. */ NormaliseTrainHead(src_head); NormaliseTrainHead(dst_head); + /* Add new heads to statistics. + * This should be done after NormaliseTrainHead due to engine total limit checks in GetFreeUnitNumber. */ + if (src_head != nullptr && src_head->IsFrontEngine()) GroupStatistics::CountVehicle(src_head, 1); + if (dst_head != nullptr && dst_head->IsFrontEngine()) GroupStatistics::CountVehicle(dst_head, 1); + if ((flags & DC_NO_CARGO_CAP_CHECK) == 0) { CheckCargoCapacity(src_head); CheckCargoCapacity(dst_head);