mirror of https://github.com/OpenTTD/OpenTTD
(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
parent
8a77808f65
commit
fedebdd09b
|
@ -624,15 +624,14 @@ static TileIndex FindEdgesOfBridge(TileIndex tile, TileIndex *endtile)
|
||||||
|
|
||||||
static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
||||||
{
|
{
|
||||||
|
DiagDirection direction;
|
||||||
|
TileIndexDiff delta;
|
||||||
TileIndex endtile;
|
TileIndex endtile;
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
Town *t;
|
Town *t;
|
||||||
Axis direction;
|
|
||||||
|
|
||||||
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
||||||
|
|
||||||
direction = GB(_m[tile].m5, 0, 1);
|
|
||||||
|
|
||||||
if (IsBridgeMiddle(tile)) {
|
if (IsBridgeMiddle(tile)) {
|
||||||
if (IsTransportUnderBridge(tile)) {
|
if (IsTransportUnderBridge(tile)) {
|
||||||
/* delete transport route under the bridge */
|
/* delete transport route under the bridge */
|
||||||
|
@ -677,23 +676,24 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
||||||
|
|
||||||
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR;
|
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR;
|
||||||
|
|
||||||
|
direction = GetBridgeRampDirection(tile);
|
||||||
|
delta = TileOffsByDir(direction);
|
||||||
|
|
||||||
/* Make sure there's no vehicle on the bridge
|
/* Make sure there's no vehicle on the bridge
|
||||||
Omit tile and endtile, since these are already checked, thus solving the problem
|
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
|
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 */
|
/* 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) {
|
if (v != NULL) {
|
||||||
VehicleInTheWayErrMsg(v);
|
VehicleInTheWayErrMsg(v);
|
||||||
return CMD_ERROR;
|
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
|
t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
|
||||||
// check if you're allowed to remove the bridge owned by a town.
|
// check if you're allowed to remove the bridge owned by a town.
|
||||||
// removal allowal depends on difficulty settings
|
// removal allowal depends on difficulty settings
|
||||||
|
@ -702,7 +702,6 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
|
||||||
TileIndex c;
|
TileIndex c;
|
||||||
|
|
||||||
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
|
//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
|
||||||
|
@ -739,15 +738,11 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSignalsOnBothDir(tile, direction == AXIS_X ? TRACK_X : TRACK_Y);
|
UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
|
||||||
SetSignalsOnBothDir(endtile, direction == AXIS_X ? TRACK_X : TRACK_Y);
|
UpdateSignalsOnSegment(endtile, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == AXIS_X) {
|
return (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge;
|
||||||
return (TileX(endtile) - TileX(tile) + 1) * _price.clear_bridge;
|
|
||||||
} else {
|
|
||||||
return (TileY(endtile) - TileY(tile) + 1) * _price.clear_bridge;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
|
static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
|
||||||
|
|
Loading…
Reference in New Issue