MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FindNearestGoodCoastalTownSpot

Function FindNearestGoodCoastalTownSpot

src/town_cmd.cpp:2337–2360  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

2335 * @return tile that was found
2336 */
2337static 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.

Callers 1

CreateRandomTownFunction · 0.85

Calls 7

SpiralTileSequenceClass · 0.85
IsTileTypeFunction · 0.85
IsTileFlatFunction · 0.85
IsTileAlignedToGridFunction · 0.85
TownCanBePlacedHereFunction · 0.85
GetClosestWaterDistanceFunction · 0.85
FailedMethod · 0.80

Tested by

no test coverage detected