src/train_cmd.cpp
changeset 8025 39c5dc3c2b4a
parent 8022 32b885de2410
child 8035 a0200ced6d9f
--- a/src/train_cmd.cpp	Wed Sep 05 17:53:14 2007 +0000
+++ b/src/train_cmd.cpp	Wed Sep 05 21:05:12 2007 +0000
@@ -1025,10 +1025,11 @@
 		/* If we move the front Engine and if the second vehicle is not an engine
 		   add the whole vehicle to the DEFAULT_GROUP */
 		if (IsFrontEngine(src) && !IsDefaultGroupID(src->group_id)) {
-			const Vehicle *v = GetNextVehicle(src);
-
-			if (v != NULL && !IsTrainEngine(v)) {
-				DoCommand(tile, DEFAULT_GROUP, v->index, flags, CMD_ADD_VEHICLE_GROUP);
+			Vehicle *v = GetNextVehicle(src);
+
+			if (v != NULL && IsTrainEngine(v)) {
+				v->group_id   = src->group_id;
+				src->group_id = DEFAULT_GROUP;
 			}
 		}
 
@@ -1079,6 +1080,7 @@
 				/* the vehicle was previously a loco. need to free the order list and delete vehicle windows etc. */
 				DeleteWindowById(WC_VEHICLE_VIEW, src->index);
 				DeleteVehicleOrders(src);
+				RemoveVehicleFromGroup(src);
 			}
 
 			if (IsFrontEngine(src) || IsFreeWagon(src)) {
@@ -1268,6 +1270,7 @@
 					new_f->cur_order_index = first->cur_order_index;
 					new_f->orders          = first->orders;
 					new_f->num_orders      = first->num_orders;
+					new_f->group_id        = first->group_id;
 
 					if (first->prev_shared != NULL) {
 						first->prev_shared->next_shared = new_f;
@@ -1277,8 +1280,6 @@
 					if (first->next_shared != NULL) {
 						first->next_shared->prev_shared = new_f;
 						new_f->next_shared = first->next_shared;
-					} else {
-						RemoveVehicleFromGroup(v);
 					}
 
 					/*
@@ -1289,6 +1290,7 @@
 					first->orders      = NULL;
 					first->prev_shared = NULL;
 					first->next_shared = NULL;
+					first->group_id    = DEFAULT_GROUP;
 
 					/* If we deleted a window then open a new one for the 'new' train */
 					if (IsLocalPlayer() && w != NULL) ShowVehicleViewWindow(new_f);
@@ -1372,8 +1374,8 @@
 				if (flags & DC_EXEC) {
 					first = UnlinkWagon(v, first);
 					DeleteDepotHighlightOfVehicle(v);
+					RemoveVehicleFromGroup(v);
 					delete v;
-					RemoveVehicleFromGroup(v);
 				}
 			}