* Given a spot on the map (presumed to be a water tile), find a good * coastal spot to build a city. We don't want to build too close to * the edge if we can help it (since that inhibits city growth) hence * the search within a search within a search. O(n*m^2), where n is * how far to search for land, and m is how far inland to look for a * flat spot. * * @param tile Start looking from this
| 2335 | * @return tile that was found |
| 2336 | */ |
| 2337 | static TileIndex FindNearestGoodCoastalTownSpot(TileIndex tile, TownLayout layout) |
| 2338 | { |
| 2339 | for (auto coast : SpiralTileSequence(tile, 40)) { |
| 2340 | /* Find nearest land tile */ |
| 2341 | if (!IsTileType(coast, MP_CLEAR)) continue; |
| 2342 | |
| 2343 | TileIndex furthest = INVALID_TILE; |
| 2344 | uint max_dist = 0; |
| 2345 | for (auto test : SpiralTileSequence(coast, 10)) { |
| 2346 | if (!IsTileType(test, MP_CLEAR) || !IsTileFlat(test) || !IsTileAlignedToGrid(test, layout)) continue; |
| 2347 | if (TownCanBePlacedHere(test, true).Failed()) continue; |
| 2348 | |
| 2349 | uint dist = GetClosestWaterDistance(test, true); |
| 2350 | if (dist > max_dist) { |
| 2351 | furthest = test; |
| 2352 | max_dist = dist; |
| 2353 | } |
| 2354 | } |
| 2355 | return furthest; |
| 2356 | } |
| 2357 | |
| 2358 | /* if we get here just give up */ |
| 2359 | return INVALID_TILE; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * Get the HouseZones climate mask for the current landscape type. |
no test coverage detected