From 8fe5fdf1224a82a951afc15e0c9c3e172f7eafe1 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 7 Apr 2024 22:57:38 +0200 Subject: [PATCH] Codechange: use std::none_of to express clearer what the code does --- src/landscape.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index 6e3eaa4daf..932b4167f1 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -933,19 +933,17 @@ static void GenerateTerrain(int type, uint flag) static void CreateDesertOrRainForest(uint desert_tropic_line) { uint update_freq = Map::Size() / 4; - const TileIndexDiffC *data; for (TileIndex tile = 0; tile != Map::Size(); ++tile) { if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); if (!IsValidTile(tile)) continue; - for (data = _make_desert_or_rainforest_data; - data != endof(_make_desert_or_rainforest_data); ++data) { - TileIndex t = AddTileIndexDiffCWrap(tile, *data); - if (t != INVALID_TILE && (TileHeight(t) >= desert_tropic_line || IsTileType(t, MP_WATER))) break; - } - if (data == endof(_make_desert_or_rainforest_data)) { + auto allows_desert = [tile, desert_tropic_line](auto &offset) { + TileIndex t = AddTileIndexDiffCWrap(tile, offset); + return t == INVALID_TILE || (TileHeight(t) < desert_tropic_line && !IsTileType(t, MP_WATER)); + }; + if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_desert)) { SetTropicZone(tile, TROPICZONE_DESERT); } } @@ -961,12 +959,11 @@ static void CreateDesertOrRainForest(uint desert_tropic_line) if (!IsValidTile(tile)) continue; - for (data = _make_desert_or_rainforest_data; - data != endof(_make_desert_or_rainforest_data); ++data) { - TileIndex t = AddTileIndexDiffCWrap(tile, *data); - if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break; - } - if (data == endof(_make_desert_or_rainforest_data)) { + auto allows_rainforest = [tile](auto &offset) { + TileIndex t = AddTileIndexDiffCWrap(tile, offset); + return t == INVALID_TILE || !IsTileType(t, MP_CLEAR) || !IsClearGround(t, CLEAR_DESERT); + }; + if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_rainforest)) { SetTropicZone(tile, TROPICZONE_RAINFOREST); } }