(svn r26879) -Codechange: remove most MayHaveBridgeAbove calls since the data is now always accessible

This commit is contained in:
rubidium 2014-09-21 11:24:51 +00:00
parent 982f5a6aa2
commit 9daf7e749c
14 changed files with 38 additions and 43 deletions

View File

@ -37,18 +37,6 @@ static inline bool IsBridgeTile(TileIndex t)
return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
}
/**
* checks for the possibility that a bridge may be on this tile
* These are in fact all the tile types on which a bridge can be found
* @param t The tile to analyze
* @return true if a bridge might be present
*/
static inline bool MayHaveBridgeAbove(TileIndex t)
{
return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
}
/**
* checks if a bridge is set above the ground of this tile
* @param t The tile to analyze

View File

@ -407,7 +407,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
* Remove those (simply by ANDing with allowed, since these markers are never allowed) */
if ((PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
if (IsBridgeAbove(ti->tile)) {
Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
@ -446,7 +446,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
if (IsTunnelTile(ti->tile)) return;
/* Don't draw a wire under a low bridge */
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BRIDGES)) {
if (IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_BRIDGES)) {
int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
if (height <= GetTileMaxZ(ti->tile) + 1) return;

View File

@ -1390,7 +1390,7 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
} else {
CommandCost ret = EnsureNoVehicleOnGround(cur_tile);
if (ret.Failed()) return ret;
if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);

View File

@ -295,7 +295,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* Finally do a check for bridges. */
TILE_AREA_LOOP(t, ta) {
if (MayHaveBridgeAbove(t) && IsBridgeAbove(t) && (
if (IsBridgeAbove(t) && (
!(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) ||
(GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);

View File

@ -953,7 +953,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (cost.Failed()) return cost;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!Depot::CanAllocateItem()) return CMD_ERROR;

View File

@ -1015,7 +1015,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (cost.Failed()) return cost;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!Depot::CanAllocateItem()) return CMD_ERROR;
@ -1185,7 +1185,7 @@ void DrawTramCatenary(const TileInfo *ti, RoadBits tram)
if (IsInvisibilitySet(TO_CATENARY)) return;
/* Don't draw the catenary under a low bridge */
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
if (IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
if (height <= GetTileMaxZ(ti->tile) + 1) return;
@ -1292,7 +1292,7 @@ static void DrawRoadBits(TileInfo *ti)
if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
/* Do not draw details (street lights, trees) under low bridge */
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && (roadside == ROADSIDE_TREES || roadside == ROADSIDE_STREET_LIGHTS)) {
if (IsBridgeAbove(ti->tile) && (roadside == ROADSIDE_TREES || roadside == ROADSIDE_STREET_LIGHTS)) {
int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
int minz = GetTileMaxZ(ti->tile) + 2;

View File

@ -505,6 +505,18 @@ static uint FixVehicleInclination(Vehicle *v, Direction dir)
return 1U << GVF_GOINGUP_BIT;
}
/**
* Checks for the possibility that a bridge may be on this tile
* These are in fact all the tile types on which a bridge can be found
* @param t The tile to analyze
* @return True if a bridge might have been present prior to savegame 194.
*/
static inline bool MayHaveBridgeAbove(TileIndex t)
{
return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
}
/**
* Perform a (large) amount of savegame conversion *magic* in order to
* load older savegames and to fill the caches for various purposes.

View File

@ -721,7 +721,7 @@ CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags);
*/
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge = true)
{
if (check_bridge && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
if (check_bridge && IsBridgeAbove(tile)) {
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}
@ -2489,7 +2489,7 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
if (ret.Failed()) return ret;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret;
@ -2500,7 +2500,7 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
}
if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
/* Get the water class of the water tile before it is cleared.*/
WaterClass wc = GetWaterClass(tile_cur);

View File

@ -254,7 +254,7 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (pass == 0) {
/* Check if bridge would take damage */
if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) &&
if (direction == 1 && IsBridgeAbove(tile) &&
GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max) {
_terraform_err_tile = tile; // highlight the tile under the bridge
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);

View File

@ -868,7 +868,7 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
if (DistanceFromEdge(tile) == 0) return false;
/* Prevent towns from building roads under bridges along the bridge. Looks silly. */
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) && GetBridgeAxis(tile) == DiagDirToAxis(dir)) return false;
if (IsBridgeAbove(tile) && GetBridgeAxis(tile) == DiagDirToAxis(dir)) return false;
/* Check if there already is a road at this point? */
if (GetTownRoadBits(tile) == ROAD_NONE) {
@ -2018,7 +2018,7 @@ static inline bool CanBuildHouseHere(TileIndex tile, TownID town, bool noslope)
if ((noslope && slope != SLOPE_FLAT) || IsSteepSlope(slope)) return false;
/* building under a bridge? */
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false;
if (IsBridgeAbove(tile)) return false;
/* do not try to build over house owned by another town */
if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) != town) return false;
@ -2790,7 +2790,7 @@ static bool SearchTileForStatue(TileIndex tile, void *user_data)
/* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */
if (IsSteepSlope(GetTileSlope(tile))) return false;
/* Don't build statues under bridges. */
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false;
if (IsBridgeAbove(tile)) return false;
/* A clear-able open space is always preferred. */
if ((IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) && TryClearTile(tile)) {

View File

@ -376,15 +376,13 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
const TileIndex heads[] = {tile_start, tile_end};
for (int i = 0; i < 2; i++) {
if (MayHaveBridgeAbove(heads[i])) {
if (IsBridgeAbove(heads[i])) {
TileIndex north_head = GetNorthernBridgeEnd(heads[i]);
if (IsBridgeAbove(heads[i])) {
TileIndex north_head = GetNorthernBridgeEnd(heads[i]);
if (direction == GetBridgeAxis(heads[i])) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (direction == GetBridgeAxis(heads[i])) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (z_start + 1 == GetBridgeHeight(north_head)) {
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}
if (z_start + 1 == GetBridgeHeight(north_head)) {
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}
}
}
@ -393,7 +391,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
for (TileIndex tile = tile_start + delta; tile != tile_end; tile += delta) {
if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN);
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
if (IsBridgeAbove(tile)) {
/* Disallow crossing bridges for the time being */
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}

View File

@ -2460,7 +2460,7 @@ void Vehicle::ShowVisualEffect() const
* - The vehicle is a train engine that is currently unpowered */
if (effect_model == VESM_NONE ||
v->vehstatus & VS_HIDDEN ||
(MayHaveBridgeAbove(v->tile) && IsBridgeAbove(v->tile)) ||
IsBridgeAbove(v->tile) ||
IsDepotTile(v->tile) ||
IsTunnelTile(v->tile) ||
(v->type == VEH_TRAIN &&

View File

@ -109,8 +109,7 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
}
if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
(MayHaveBridgeAbove(tile2) && IsBridgeAbove(tile2))) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!IsTileFlat(tile) || !IsTileFlat(tile2)) {
/* Prevent depots on rapids */
@ -289,9 +288,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
(MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) ||
(MayHaveBridgeAbove(tile + delta) && IsBridgeAbove(tile + delta))) {
if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) {
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}

View File

@ -133,7 +133,7 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
}
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
return CommandCost();
}
@ -289,7 +289,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);