(svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
authortron
Thu, 16 Mar 2006 06:30:47 +0000
changeset 3227 8bb33a2299a5
parent 3226 6e2613e33234
child 3228 270ab760cc16
(svn r3900) When clearing a bridge determine the bridge direction and tile offset once instead of all over the place; also use UpdateSignalsOnSegment() instead of SetSignalsOnBothDir(), because this is sufficient
tunnelbridge_cmd.c
--- a/tunnelbridge_cmd.c	Thu Mar 16 06:06:05 2006 +0000
+++ b/tunnelbridge_cmd.c	Thu Mar 16 06:30:47 2006 +0000
@@ -624,15 +624,14 @@
 
 static int32 DoClearBridge(TileIndex tile, uint32 flags)
 {
+	DiagDirection direction;
+	TileIndexDiff delta;
 	TileIndex endtile;
 	Vehicle *v;
 	Town *t;
-	Axis direction;
 
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
-	direction = GB(_m[tile].m5, 0, 1);
-
 	if (IsBridgeMiddle(tile)) {
 		if (IsTransportUnderBridge(tile)) {
 			/* delete transport route under the bridge */
@@ -677,23 +676,24 @@
 
 	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR;
 
+	direction = GetBridgeRampDirection(tile);
+	delta = TileOffsByDir(direction);
+
 	/*	Make sure there's no vehicle on the bridge
 			Omit tile and endtile, since these are already checked, thus solving the problem
 			of bridges over water, or higher bridges, where z is not increased, eg level bridge
 	*/
-	tile		+= (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
-	endtile	-= (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 	/* Bridges on slopes might have their Z-value offset..correct this */
-	v = FindVehicleBetween(tile, endtile, TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile));
+	v = FindVehicleBetween(
+		tile    + delta,
+		endtile - delta,
+		TilePixelHeight(tile) + 8 + GetCorrectTileHeight(tile)
+	);
 	if (v != NULL) {
 		VehicleInTheWayErrMsg(v);
 		return CMD_ERROR;
 	}
 
-	/* Put the tiles back to start/end position */
-	tile		-= (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
-	endtile	+= (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
-
 	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
 	// check if you're allowed to remove the bridge owned by a town.
 	// removal allowal depends on difficulty settings
@@ -702,7 +702,6 @@
 	}
 
 	if (flags & DC_EXEC) {
-		TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 		TileIndex c;
 
 		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
@@ -739,15 +738,11 @@
 			}
 		}
 
-		SetSignalsOnBothDir(tile,    direction == AXIS_X ? TRACK_X : TRACK_Y);
-		SetSignalsOnBothDir(endtile, direction == AXIS_X ? TRACK_X : TRACK_Y);
+		UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
+		UpdateSignalsOnSegment(endtile, direction);
 	}
 
-	if (direction == AXIS_X) {
-		return (TileX(endtile) - TileX(tile) + 1) * _price.clear_bridge;
-	} else {
-		return (TileY(endtile) - TileY(tile) + 1) * _price.clear_bridge;
-	}
+	return (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge;
 }
 
 static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)