src/train_cmd.cpp
changeset 8168 a1351d83d0d4
parent 8162 70bce0f4e095
child 8169 31d57d9de945
--- a/src/train_cmd.cpp	Mon Dec 31 18:56:39 2007 +0000
+++ b/src/train_cmd.cpp	Mon Dec 31 21:51:16 2007 +0000
@@ -1063,7 +1063,15 @@
 		Vehicle *src_previous = src->Previous();
 
 		while (next_to_attach != NULL) {
+			/* Back up and clear the first_engine data to avoid using wagon override group */
+			EngineID first_engine = next_to_attach->u.rail.first_engine;
+			next_to_attach->u.rail.first_engine = INVALID_ENGINE;
+
 			uint16 callback = GetVehicleCallbackParent(CBID_TRAIN_ALLOW_WAGON_ATTACH, 0, 0, dst_head->engine_type, next_to_attach, dst_head);
+
+			/* Restore original first_engine data */
+			next_to_attach->u.rail.first_engine = first_engine;
+
 			if (callback != CALLBACK_FAILED) {
 				StringID error = STR_NULL;
 
@@ -1088,6 +1096,9 @@
 				}
 			}
 
+			/* Only check further wagons if told to move the chain */
+			if (!HasBit(p2, 0)) break;
+
 			/*
 			 * Adding a next wagon to the chain so we can test the other wagons.
 			 * First 'take' the first wagon from 'next_to_attach' and move it