Refactor/de-duplicate rail station bridge above check methods

pull/73/head
Jonathan G Rennison 6 years ago
parent beaddc8a98
commit 6df12e77b6

@ -775,22 +775,30 @@ CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z
return cost;
}
bool IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *statspec, byte layout)
bool IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *statspec, byte layout, TileIndex northern_bridge_end, TileIndex southern_bridge_end, int bridge_height)
{
assert(layout < 8);
if (!IsBridgeAbove(tile)) return true;
if (statspec && HasBit(statspec->internal_flags, SSIF_BRIDGE_HEIGHTS_SET)) {
return (GetTileMaxZ(tile) + statspec->bridge_height[layout] <= GetBridgeHeight(GetSouthernBridgeEnd(tile)));
return (GetTileMaxZ(tile) + statspec->bridge_height[layout] <= bridge_height);
} else if (!statspec) {
// default stations/waypoints
const int height = layout < 4 ? 2 : 5;
return (GetTileMaxZ(tile) + height <= GetBridgeHeight(GetSouthernBridgeEnd(tile)));
return (GetTileMaxZ(tile) + height <= bridge_height);
} else {
return _settings_game.construction.allow_stations_under_bridges;
}
}
bool IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *statspec, byte layout)
{
if (!IsBridgeAbove(tile)) return true;
TileIndex southern_bridge_end = GetSouthernBridgeEnd(tile);
TileIndex northern_bridge_end = GetNorthernBridgeEnd(tile);
return IsRailStationBridgeAboveOk(tile, statspec, layout, northern_bridge_end, southern_bridge_end, GetBridgeHeight(southern_bridge_end));
}
/**
* Checks if a rail station can be built at the given area.
* @param tile_area Area to check.

@ -65,6 +65,8 @@ extern void DrawTrackBits(TileInfo *ti, TrackBits track);
extern void DrawRoadBits(TileInfo *ti);
extern const RoadBits _invalid_tileh_slopes_road[2][15];
extern bool IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *statspec, byte layout, TileIndex northern_bridge_end, TileIndex southern_bridge_end, int bridge_height);
/**
* Mark bridge tiles dirty.
* Note: The bridge does not need to exist, everything is passed via parameters.
@ -497,16 +499,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
case STATION_RAIL:
case STATION_WAYPOINT: {
const StationSpec *statspec = GetStationSpec(tile);
if (statspec && HasBit(statspec->internal_flags, SSIF_BRIDGE_HEIGHTS_SET)) {
uint layout = GetStationGfx (tile);
assert(layout < 8);
if (GetTileMaxZ(tile) + statspec->bridge_height[layout] > z_start + 1) goto not_valid_below;
} else if (!statspec) {
// default stations/waypoints
const int height = GetStationGfx(tile) < 4 ? 2 : 5;
if (GetTileMaxZ(tile) + height > z_start + 1) goto not_valid_below;
} else if (!_settings_game.construction.allow_stations_under_bridges) {
if (!IsRailStationBridgeAboveOk(tile, GetStationSpec(tile), GetStationGfx(tile), tile_start, tile_end, z_start + 1)) {
goto not_valid_below;
}
break;

Loading…
Cancel
Save