(svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero. custombridgeheads
authorKUDr
Mon, 01 Jan 2007 23:18:33 +0000
branchcustombridgeheads
changeset 5628 6975ccb4a7bd
parent 5627 f5c656cf0a0e
child 5629 7cb2c58f4a7c
(svn r7734) [cbh] - Fix: '!Disconnecting train' when leaving bridge in Y_SE direction. Train controller needs to know train's track, so it can't be zero.
bridge_cmd.c
--- a/bridge_cmd.c	Mon Jan 01 20:13:03 2007 +0000
+++ b/bridge_cmd.c	Mon Jan 01 23:18:33 2007 +0000
@@ -1017,28 +1017,39 @@
 			/* Get the vehicle out of the wormhole, the track will be chosen later
 			   by the pathfinder */
 			v->tile = tile;
-			v->u.rail.track = 0;
+			v->u.rail.track = TrackToTrackBits(TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
 			return 4;
 		}
 		return 0;
 
 	} else {
+		TileIndex other_bridge_end_tile;
+		uint32 bridge_length;
 		/* We are on the bridge head itself, possibly entering the bridge */
 		/* Vehicle will enter the bridge wormhole when it reaches the tile edge in the
 		 * direction of the bridge. */
 		TileIndexDiffC diff = TileIndexDiffCByDiagDir(dir);
 		/* If vehicle didn't reach the edge we can return and try it next time */
 		if (((diff.x != 0 ? x : y) & 0x0F) != (diff.x + diff.y > 0 ? TILE_SIZE - 1 : 0)) return 0;
-		/* We will enter the bridge wormhole. Adjust the other coordinate to the middle of tile
-		* to allow train controller to select proper vehicle image */
-		if (diff.x != 0) v->y_pos = y; else v->x_pos = x;
+		/* We will enter the bridge wormhole. */
 
-		/* We're about to enter the bridge body, clear all up/down flags just in case */
-		v->u.rail.track = 0x40;
-		v->direction = DiagDirToDir(dir);
-		CLRBIT(v->u.rail.flags, VRF_GOINGUP);
-		CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
-		return 4;
+		other_bridge_end_tile = GetOtherBridgeEnd(tile);
+		bridge_length = GetBridgeLength(tile, other_bridge_end_tile);
+		if (bridge_length > 0) {
+			/* Non-zero bridge length. Adjust the other coordinate to the middle of tile
+			* to allow train controller to select proper vehicle image */
+			if (diff.x != 0) v->y_pos = y; else v->x_pos = x;
+			v->direction = DiagDirToDir(dir);
+			/* We're about to enter the bridge body, clear all up/down flags just in case */
+			v->u.rail.track = 0x40;
+			v->direction = DiagDirToDir(dir);
+			CLRBIT(v->u.rail.flags, VRF_GOINGUP);
+			CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
+			return 4;
+		} else {
+			/* Zero bridge length. Pretend that nothing extra happened. Custom bridge heads should act as normal tracks. */
+			;
+		}
 	}
 	return 0;
 }