(svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
authorbjarni
Sat, 08 Jan 2005 01:05:24 +0000
changeset 933 90817bb28f1d
parent 932 5fcff6cdc612
child 934 81642cba8833
(svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
vehicle.c
--- a/vehicle.c	Sat Jan 08 00:48:10 2005 +0000
+++ b/vehicle.c	Sat Jan 08 01:05:24 2005 +0000
@@ -1488,6 +1488,8 @@
 
 		/* We do not really buy a new vehicle, we upgrade the old one */
 		if (v->engine_type != new_engine_type) {
+			byte old_engine = v->engine_type;
+			byte sprite = v->spritenum;
 			byte cargo_type = v->cargo_type;
 			v->engine_type = new_engine_type;
 			v->max_age = e->lifelength * 366;
@@ -1498,13 +1500,13 @@
 			// using if (true) to declare the const
 				{
 				const RailVehicleInfo *rvi = RailVehInfo(new_engine_type);
+				const RailVehicleInfo *rvi2 = RailVehInfo(old_engine);
 				byte capacity = rvi->capacity;
 
-				if (rvi->flags & RVI_MULTIHEAD && v->next == NULL ) {
-					v->spritenum = rvi->image_index + 1;	// +1 is the mirrored end of the dualheaded engines
-				} else {
-					v->spritenum = rvi->image_index;
-				}
+				/* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way
+				if it is a multiheaded engine (rear engine)
+				(sprite - rvi2->image_index) is 1 if the engine is heading the other way, otherwise 0*/
+				v->spritenum = rvi->image_index + (sprite - rvi2->image_index);
 				
 				v->cargo_type = rvi->cargo_type;
 				v->cargo_cap = rvi->capacity;