From 666c0a379dee78fd51c35e5275b7761f9a1ebf61 Mon Sep 17 00:00:00 2001 From: tron Date: Thu, 16 Mar 2006 06:06:05 +0000 Subject: [PATCH] (svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable --- bridge_map.h | 5 +++++ tunnelbridge_cmd.c | 52 +++++++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/bridge_map.h b/bridge_map.h index 4f4b33d53c..6107280607 100644 --- a/bridge_map.h +++ b/bridge_map.h @@ -45,6 +45,11 @@ static inline bool IsClearUnderBridge(TileIndex t) return GB(_m[t].m5, 3, 3) == 0; } +static inline bool IsWaterUnderBridge(TileIndex t) +{ + return GB(_m[t].m5, 3, 3) == 1; +} + static inline bool IsTransportUnderBridge(TileIndex t) { diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 6496dfd101..63cb93dcf9 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -633,34 +633,38 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags) direction = GB(_m[tile].m5, 0, 1); - /* delete stuff under the middle part if there's a transport route there..? */ - if ((_m[tile].m5 & 0xE0) == 0xE0) { - int32 cost; + if (IsBridgeMiddle(tile)) { + if (IsTransportUnderBridge(tile)) { + /* delete transport route under the bridge */ + int32 cost; - // check if we own the tile below the bridge.. - if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) - return CMD_ERROR; + // check if we own the tile below the bridge.. + if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) + return CMD_ERROR; - cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail; + if (GetTransportTypeUnderBridge(tile) == TRANSPORT_RAIL) { + cost = _price.remove_rail; + } else { + cost = _price.remove_road * 2; + } - if (flags & DC_EXEC) { - SetClearUnderBridge(tile); - MarkTileDirtyByTile(tile); + if (flags & DC_EXEC) { + SetClearUnderBridge(tile); + MarkTileDirtyByTile(tile); + } + return cost; + } else if (IsWaterUnderBridge(tile) && TilePixelHeight(tile) != 0) { + /* delete canal under bridge */ + + // check for vehicles under bridge + if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR; + + if (flags & DC_EXEC) { + SetClearUnderBridge(tile); + MarkTileDirtyByTile(tile); + } + return _price.clear_water; } - return cost; - - /* delete canal under bridge */ - } else if ((_m[tile].m5 & 0xC8) == 0xC8 && TilePixelHeight(tile) != 0) { - int32 cost; - - // check for vehicles under bridge - if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR; - cost = _price.clear_water; - if (flags & DC_EXEC) { - SetClearUnderBridge(tile); - MarkTileDirtyByTile(tile); - } - return cost; } tile = FindEdgesOfBridge(tile, &endtile);