summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-28 17:34:44 +0000
committerrubidium <rubidium@openttd.org>2011-12-28 17:34:44 +0000
commit7d2061516a61e999be51e42ffffee1a5f0c28c0e (patch)
tree2be2d8d2c2d0011711e08efc53345496678188c9
parent98fdf813201aeba23a9f87be4c8aa85720174bd9 (diff)
downloadopenttd-7d2061516a61e999be51e42ffffee1a5f0c28c0e.tar.xz
(svn r23681) -Fix [FS#4914]: vehicle numbers got misaccounted when autoreplacing failed due to length checks
-rw-r--r--src/train_cmd.cpp12
1 files 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);