train_cmd.c
branchcustombridgeheads
changeset 5621 6ce400c0a2f4
parent 5615 d6197e6c420e
child 5622 2f0cb276d32a
--- a/train_cmd.c	Mon Jan 01 10:26:12 2007 +0000
+++ b/train_cmd.c	Mon Jan 01 16:07:21 2007 +0000
@@ -3014,36 +3014,6 @@
 	return NULL;
 }
 
-/** Puts a train (logically) onto a bridge body.
-  * Sets the correct coordinates to traverse the bridge
-  * and aligns the vehicle with the bridge. The function
-  * assumes the train is on a bridge head about to enter
-  * the bridge.
-  */
-static void PutTrainOntoBridge(Vehicle *v, int x, int y)
-{
-	DiagDirection dir;
-	uint8 dxy;
-	assert(IsBridgeTile(v->tile));
-	dir = GetBridgeRampDirection(v->tile);
-	v->u.rail.track = 0x40;
-	v->direction = DiagDirToDir(dir);
-	CLRBIT(v->u.rail.flags, VRF_GOINGUP);
-	CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
-
-	switch (dir) {
-		default: NOT_REACHED();
-		case DIAGDIR_NE: dxy = 0xF8; break;
-		case DIAGDIR_SE: dxy = 0x80; break;
-		case DIAGDIR_SW: dxy = 0x08; break;
-		case DIAGDIR_NW: dxy = 0x8F; break;
-	}
-	SB(x, 0, 4, GB(dxy, 4, 4));
-	SB(y, 0, 4, GB(dxy, 0, 4));
-	v->x_pos = x;
-	v->y_pos = y;
-}
-
 static void TrainController(Vehicle *v, bool update_image)
 {
 	Vehicle *prev;
@@ -3072,10 +3042,7 @@
 				} else {
 					/* is not inside depot */
 
-					if (!TrainCheckIfLineEnds(v)) {
-						/* reversing */
-						return;
-					}
+					if (!TrainCheckIfLineEnds(v)) return;
 
 					r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 					if (r & 0x8) {
@@ -3093,26 +3060,15 @@
 						InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 					}
 				}
-			} else new_tile:{
+			} else {
 				/* A new tile is about to be entered. */
 
 				byte bits;
-
 				/* Determine what direction we're entering the new tile from */
 				dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile);
 				enterdir = DirToDiagDir(dir);
 				assert(enterdir==0 || enterdir==1 || enterdir==2 || enterdir==3);
 
-				/* We should not let the train that is leaving custom bridge head (entering bridge)
-				 * to enter the tile that is under bridge. Enter the bridge wormhole instead. */
-				if (IsBridgeTile(gp.old_tile) && GetBridgeRampDirection(gp.old_tile) == enterdir) {
-					/* train entering the bridge body */
-					PutTrainOntoBridge(v, gp.x, gp.y);
-					UpdateTrainDeltaXY(v, v->direction);
-					if (update_image) v->cur_image = GetTrainImage(v, v->direction);
-					continue;
-				}
-
 				/* Get the status of the tracks in the new tile and mask
 				 * away the bits that aren't reachable. */
 				ts = GetTileTrackStatus(gp.new_tile, TRANSPORT_RAIL) & _reachable_tracks[enterdir];
@@ -3208,17 +3164,7 @@
 
 			SetSpeedLimitOnBridge(v);
 
-			if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && ((VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 0x4) != 0)) {
-				if (IsBridgeTile(gp.new_tile)) {
-					/* when on a bridge, v->tile points to one of the bridge heads. GetNewVehicleDirection will
-					 * fail, because it expects the new and old tile (gp.{new|old}tile) to be adjacent to each
-					 * other. So we set the old_tile here manually by using the current vehicle coordinates */
-					gp.old_tile = TileVirtXY(v->x_pos, v->y_pos);
-					goto new_tile; /* We need the same code when entering from a bridge than from any other tile */
-				}
-
-			} else {
-				/* vehicle stays in the bridge/tunnel wormhole */
+			if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 0x4)) {
 				v->x_pos = gp.x;
 				v->y_pos = gp.y;
 				VehiclePositionChanged(v);
@@ -3459,11 +3405,11 @@
 
 	tile = v->tile;
 
-	if (IsTunnelTile(tile)) {
-		DiagDirection dir = GetTunnelDirection(tile);
-		if (v->direction == DiagDirToDir(dir)) return true;
-	} else if (IsBridgeTile(tile)) {
-		if (TrackdirToExitdir(GetVehicleTrackdir(v)) == GetBridgeRampDirection(tile)) return true;
+	if (IsTileType(tile, MP_TUNNEL) || IsTileType(tile, MP_RAILWAY_BRIDGE)) {
+		DiagDirection dir;
+
+		dir = IsTunnelTile(tile) ? GetTunnelDirection(tile) : GetBridgeRampDirection(tile);
+		if (DiagDirToDir(dir) == v->direction) return true;
 	}
 
 	// depot?