From 7d2061516a61e999be51e42ffffee1a5f0c28c0e Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 28 Dec 2011 17:34:44 +0000 Subject: (svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks --- src/train_cmd.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 44e8d9efe..5bdef09a7 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1200,11 +1200,9 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u Train *original_src_head = src_head; Train *original_dst_head = (dst_head == src_head ? NULL : dst_head); - if (flags & DC_EXEC) { - /* Remove old heads from the statistics */ - if (original_src_head != NULL && original_src_head->IsFrontEngine()) GroupStatistics::CountVehicle(original_src_head, -1); - if (original_dst_head != NULL && original_dst_head->IsFrontEngine()) GroupStatistics::CountVehicle(original_dst_head, -1); - } + /* We want this information from before the rearrangement, but execute this after the validation. */ + bool original_src_head_front_engine = original_src_head != NULL && original_src_head->IsFrontEngine(); + bool original_dst_head_front_engine = original_dst_head != NULL && original_dst_head->IsFrontEngine(); /* (Re)arrange the trains in the wanted arrangement. */ ArrangeTrains(&dst_head, dst, &src_head, src, move_chain); @@ -1224,6 +1222,10 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u /* do it? */ if (flags & DC_EXEC) { + /* Remove old heads from the statistics */ + if (original_src_head_front_engine) GroupStatistics::CountVehicle(original_src_head, -1); + if (original_dst_head_front_engine) GroupStatistics::CountVehicle(original_dst_head, -1); + /* First normalise the sub types of the chains. */ NormaliseSubtypes(src_head); NormaliseSubtypes(dst_head); -- cgit v1.2.3-70-g09d2