rail_cmd.c
branch0.4.5
changeset 9946 d3cb7e05c5a6
parent 9942 56446313309e
--- a/rail_cmd.c	Wed Mar 22 11:17:21 2006 +0000
+++ b/rail_cmd.c	Wed Mar 22 11:23:22 2006 +0000
@@ -395,6 +395,7 @@
 	TileIndex tile;
 	byte m5;
 	int32 cost = _price.remove_rail;
+	bool crossing = false;
 
 	if (!ValParamTrackOrientation(p2)) return CMD_ERROR;
 	trackbit = TrackToTrackBits(track);
@@ -453,7 +454,9 @@
 			SetTileOwner(tile, _m[tile].m3);
 			break;
 
-		case MP_RAILWAY:
+		case MP_RAILWAY: {
+			TrackBits present;
+
 			if (!IsPlainRailTile(tile))
 				return CMD_ERROR;
 
@@ -461,6 +464,10 @@
 			if (!(GetTrackBits(tile) & trackbit))
 				return CMD_ERROR;
 
+			present = GetTrackBits(tile);
+			if ((present & trackbit) == 0) return CMD_ERROR;
+			if (present == (TRACK_BIT_DIAG1 | TRACK_BIT_DIAG2)) crossing = true;
+
 			/* Charge extra to remove signals on the track, if they are there */
 			if (HasSignalOnTrack(tile, track))
 				cost += DoCommand(x, y, track, 0, flags, CMD_REMOVE_SIGNALS);
@@ -478,13 +485,26 @@
 				goto skip_mark_dirty;
 			}
 			break;
+		}
 
 		default:
 			assert(0);
 	}
 
 	/* mark_dirty */
-	MarkTileDirtyByTile(tile);
+	if (flags & DC_EXEC) {
+		MarkTileDirtyByTile(tile);
+		if (crossing) {
+			/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
+			 * are removing one of these pieces, we'll need to update signals for
+			 * both directions explicitly, as after the track is removed it won't
+			 * 'connect' with the other piece. */
+			SetSignalsOnBothDir(tile, TRACK_DIAG1);
+			SetSignalsOnBothDir(tile, TRACK_DIAG2);
+		} else {
+			SetSignalsOnBothDir(tile, track);
+		}
+	}
 
 skip_mark_dirty:;