changeset 16481:89cd59264ee1 draft

(svn r21205) -Fix [FS#4207]: Under some conditions, group count would be wrong after moving train engines in the depot window.
author terkhen <terkhen@openttd.org>
date Tue, 16 Nov 2010 12:05:41 +0000
parents 26ce45382f07
children 91f657d6370b
files src/train_cmd.cpp
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1251,7 +1251,7 @@
 		 *     a) the 'next' part is a wagon that becomes a free wagon chain.
 		 *     b) the 'next' part is an engine that becomes a front engine.
 		 *     c) there is no 'next' part, nothing else happens
-		 *  3) front engine gets moved to later in the current train, it is not an engine anymore.
+		 *  3) front engine gets moved to later in the current train, it is not a front engine anymore.
 		 *     a) the 'next' part is a wagon that becomes a free wagon chain.
 		 *     b) the 'next' part is an engine that becomes a front engine.
 		 *  4) free wagon gets moved
@@ -1270,14 +1270,15 @@
 			DeleteWindowById(WC_VEHICLE_DETAILS, src->index);
 			DeleteWindowById(WC_VEHICLE_TIMETABLE, src->index);
 
-			/* We are going to be move to another train. So we
-			 * are no part of this group anymore. In case we
-			 * are not moving group... well, then we do not need
-			 * to move.
-			 * Or we are moving to later in the train and our
-			 * new head isn't a front engine anymore.
-			 */
-			if (dst_head != NULL ? dst_head != src : !src_head->IsFrontEngine()) {
+			/* We are going to be moved to a different train, and
+			 * we were the front engine of the original train. */
+			if (dst_head != NULL && dst_head != src && (src_head == NULL || !src_head->IsFrontEngine())) {
+				DecreaseGroupNumVehicle(src->group_id);
+			}
+
+			/* The front engine is going to be moved later in the
+			 * current train, and it will not be a train anymore. */
+			if (dst_head == NULL && !src_head->IsFrontEngine()) {
 				DecreaseGroupNumVehicle(src->group_id);
 			}
 
@@ -1288,6 +1289,12 @@
 			src->unitnumber = 0;
 		}
 
+		/* We were a front engine and we are becoming one for a different train.
+		 * Increase the group counter accordingly. */
+		if (original_src_head == src && dst_head == src) {
+			IncreaseGroupNumVehicle(src->group_id);
+		}
+
 		/* We weren't a front engine but are becoming one. So
 		 * we should be put in the default group. */
 		if (original_src_head != src && dst_head == src) {