Refactor/de-duplicate rail station bridge above check methods
This commit is contained in:
@@ -775,22 +775,30 @@ CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z
|
|||||||
return cost;
|
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);
|
assert(layout < 8);
|
||||||
if (!IsBridgeAbove(tile)) return true;
|
|
||||||
|
|
||||||
if (statspec && HasBit(statspec->internal_flags, SSIF_BRIDGE_HEIGHTS_SET)) {
|
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) {
|
} else if (!statspec) {
|
||||||
// default stations/waypoints
|
// default stations/waypoints
|
||||||
const int height = layout < 4 ? 2 : 5;
|
const int height = layout < 4 ? 2 : 5;
|
||||||
return (GetTileMaxZ(tile) + height <= GetBridgeHeight(GetSouthernBridgeEnd(tile)));
|
return (GetTileMaxZ(tile) + height <= bridge_height);
|
||||||
} else {
|
} else {
|
||||||
return _settings_game.construction.allow_stations_under_bridges;
|
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.
|
* Checks if a rail station can be built at the given area.
|
||||||
* @param tile_area Area to check.
|
* @param tile_area Area to check.
|
||||||
|
@@ -65,6 +65,8 @@ extern void DrawTrackBits(TileInfo *ti, TrackBits track);
|
|||||||
extern void DrawRoadBits(TileInfo *ti);
|
extern void DrawRoadBits(TileInfo *ti);
|
||||||
extern const RoadBits _invalid_tileh_slopes_road[2][15];
|
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.
|
* Mark bridge tiles dirty.
|
||||||
* Note: The bridge does not need to exist, everything is passed via parameters.
|
* 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_RAIL:
|
||||||
case STATION_WAYPOINT: {
|
case STATION_WAYPOINT: {
|
||||||
const StationSpec *statspec = GetStationSpec(tile);
|
if (!IsRailStationBridgeAboveOk(tile, GetStationSpec(tile), GetStationGfx(tile), tile_start, tile_end, z_start + 1)) {
|
||||||
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) {
|
|
||||||
goto not_valid_below;
|
goto not_valid_below;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user