1
0
Fork 0

Codechange: Optimize FindSpring

pull/13258/head
SamuXarick 2025-01-03 16:32:56 +00:00
parent b3660bf24a
commit 003f152b89
1 changed files with 11 additions and 14 deletions

View File

@ -992,29 +992,26 @@ static void CreateDesertOrRainForest(uint desert_tropic_line)
*/ */
static bool FindSpring(TileIndex tile, void *) static bool FindSpring(TileIndex tile, void *)
{ {
int reference_height;
if (!IsTileFlat(tile, &reference_height) || IsWaterTile(tile)) return false;
/* In the tropics rivers start in the rainforest. */ /* In the tropics rivers start in the rainforest. */
if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return false; if (_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return false;
int reference_height;
if (IsWaterTile(tile) || !IsTileFlat(tile, &reference_height)) return false;
/* Are there enough higher tiles to warrant a 'spring'? */ /* Are there enough higher tiles to warrant a 'spring'? */
uint num = 0; uint num = 0;
for (int dx = -1; dx <= 1; dx++) { for (Direction d = DIR_BEGIN; d != DIR_END; d++) {
for (int dy = -1; dy <= 1; dy++) { TileIndex t = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(d));
TileIndex t = TileAddWrap(tile, dx, dy); if (IsValidTile(t) && GetTileMaxZ(t) > reference_height) num++;
if (t != INVALID_TILE && GetTileMaxZ(t) > reference_height) num++; if (num == 4) break;
} }
}
if (num < 4) return false; if (num < 4) return false;
/* Are we near the top of a hill? */ /* Are we near the top of a hill? */
for (int dx = -16; dx <= 16; dx++) { reference_height += 2;
for (int dy = -16; dy <= 16; dy++) { TileArea tile_area = TileArea(tile, 1, 1).Expand(16);
TileIndex t = TileAddWrap(tile, dx, dy); for (TileIndex t : tile_area) {
if (t != INVALID_TILE && GetTileMaxZ(t) > reference_height + 2) return false; if (!IsTileType(t, MP_VOID) && GetTileMaxZ(t) > reference_height) return false;
}
} }
return true; return true;