Feature: Towns don't build parallel, redundant bridges

pull/444/head
Tyler Trahan 2 years ago committed by Michael Lutz
parent 252111512f
commit 47a998fb0c

@ -1160,6 +1160,27 @@ static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, con
return Command<CMD_BUILD_ROAD>::Do(DC_AUTO | DC_NO_WATER, next_tile, rcmd, rt, DRD_NONE, t->index).Succeeded();
}
/**
* CircularTileSearch proc which checks for a nearby parallel bridge to avoid building redundant bridges.
* @param tile The tile to search.
* @param user_data Reference to the valid direction of the proposed bridge.
* @return true if another bridge exists, else false.
*/
static bool RedundantBridgeExistsNearby(TileIndex tile, void *user_data)
{
/* Don't look into the void. */
if (!IsValidTile(tile)) return false;
/* Only consider bridge head tiles. */
if (!IsBridgeTile(tile)) return false;
/* Only consider road bridges. */
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return false;
/* If the bridge is facing the same direction as the proposed bridge, we've found a redundant bridge. */
return (GetTileSlope(tile) & InclinedSlope(ReverseDiagDir(*(DiagDirection *)user_data)));
}
/**
* Grows the town with a bridge.
* At first we check if a bridge is reasonable.
@ -1221,6 +1242,11 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
/* Make sure the road can be continued past the bridge. At this point, bridge_tile holds the end tile of the bridge. */
if (!CanRoadContinueIntoNextTile(t, bridge_tile, bridge_dir)) return false;
/* If another parallel bridge exists nearby, this one would be redundant and shouldn't be built. We don't care about flat bridges. */
TileIndex search = tile;
DiagDirection direction_to_match = bridge_dir;
if (slope != SLOPE_FLAT && CircularTileSearch(&search, bridge_length, 0, 0, RedundantBridgeExistsNearby, &direction_to_match)) return false;
for (uint8 times = 0; times <= 22; times++) {
byte bridge_type = RandomRange(MAX_BRIDGES - 1);

Loading…
Cancel
Save