(svn r245) -Fix: [1022689] Bug when dragging a part of a multiheaded engine to 'sell-whole-train'. The rear-head of the multiheaded train will now not be sold automatically. You have to drag it manually (Celestar)
authordarkvater
Tue, 14 Sep 2004 14:26:12 +0000
changeset 244 57a3922a029c
parent 243 9a40daa560ae
child 245 4f6f81046437
(svn r245) -Fix: [1022689] Bug when dragging a part of a multiheaded engine to 'sell-whole-train'. The rear-head of the multiheaded train will now not be sold automatically. You have to drag it manually (Celestar)
train_cmd.c
--- a/train_cmd.c	Tue Sep 14 14:19:53 2004 +0000
+++ b/train_cmd.c	Tue Sep 14 14:26:12 2004 +0000
@@ -776,11 +776,12 @@
 		last = GetLastVehicleInChain(first);
 		//now if:
 		// 1) we delete a whole a chain, and
-		// 2) the first and the last vehicle of that train are of the same type, and
-		// 3) the first and the last vehicle of the chain are not identical, and
-		// 4) and of "engine" type (i.e. not a carriage)
+		// 2) we don't actually try to delete the last engine
+		// 3) the first and the last vehicle of that train are of the same type, and
+		// 4) the first and the last vehicle of the chain are not identical
+		// 5) and of "engine" type (i.e. not a carriage)
 		// then let the last vehicle live
-		if ( (p2 == 1) && ( last->engine_type == first->engine_type ) && (last != first) && (first->subtype == 0) )
+		if ( (p2 == 1) && (v != last) && ( last->engine_type == first->engine_type ) && (last != first) && (first->subtype == 0) )
 			last = GetPrevVehicleInChain(last);
 		else
 			last = NULL;
@@ -833,9 +834,12 @@
 			first = UnlinkWagon(v, first);
 			cost -= v->value;
 			tmp = v;
-			v = v->next;
 			DeleteVehicle(tmp);
-			if (v == last || p2 != 1) break;
+			if ( v == last ) {
+				last = NULL;
+				break;
+			}
+			if ( (v=v->next) == last || p2 != 1) break;
 		}
 
 		// delete last vehicle of multiheaded train?
@@ -854,7 +858,11 @@
 		cost = 0;
 		for(;;) {
 			cost -= v->value;
-			if ((v=v->next) == last || p2 != 1) break;
+			if ( v == last ) {
+				last = NULL;
+				break;
+			}
+			if ( (v=v->next) == last || p2 != 1) break;
 		}
 		if (last) cost -= last->value;
 	}