diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1161,6 +1161,27 @@ static bool CanRoadContinueIntoNextTile( } /** + * 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. * If so we check if we are able to build it. @@ -1221,6 +1242,11 @@ static bool GrowTownWithBridge(const Tow /* 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);