(svn r3899) Use wrapper functions to make more clear how deleting stuff under bridges works; also remove an unnecessary local variable

This commit is contained in:
tron 2006-03-16 06:06:05 +00:00
parent 1ac97fe008
commit 666c0a379d
2 changed files with 33 additions and 24 deletions

View File

@ -45,6 +45,11 @@ static inline bool IsClearUnderBridge(TileIndex t)
return GB(_m[t].m5, 3, 3) == 0; 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) static inline bool IsTransportUnderBridge(TileIndex t)
{ {

View File

@ -633,34 +633,38 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
direction = GB(_m[tile].m5, 0, 1); direction = GB(_m[tile].m5, 0, 1);
/* delete stuff under the middle part if there's a transport route there..? */ if (IsBridgeMiddle(tile)) {
if ((_m[tile].m5 & 0xE0) == 0xE0) { if (IsTransportUnderBridge(tile)) {
int32 cost; /* delete transport route under the bridge */
int32 cost;
// check if we own the tile below the bridge.. // check if we own the tile below the bridge..
if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile)))) if (_current_player != OWNER_WATER && (!CheckTileOwnership(tile) || !EnsureNoVehicleZ(tile, TilePixelHeight(tile))))
return CMD_ERROR; 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) { if (flags & DC_EXEC) {
SetClearUnderBridge(tile); SetClearUnderBridge(tile);
MarkTileDirtyByTile(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); tile = FindEdgesOfBridge(tile, &endtile);