Codechange: use std::none_of to express clearer what the code does

This commit is contained in:
Rubidium 2024-04-07 22:57:38 +02:00 committed by rubidium42
parent 8986fb0385
commit 8fe5fdf122
1 changed files with 10 additions and 13 deletions

View File

@ -933,19 +933,17 @@ static void GenerateTerrain(int type, uint flag)
static void CreateDesertOrRainForest(uint desert_tropic_line) static void CreateDesertOrRainForest(uint desert_tropic_line)
{ {
uint update_freq = Map::Size() / 4; uint update_freq = Map::Size() / 4;
const TileIndexDiffC *data;
for (TileIndex tile = 0; tile != Map::Size(); ++tile) { for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
if (!IsValidTile(tile)) continue; if (!IsValidTile(tile)) continue;
for (data = _make_desert_or_rainforest_data; auto allows_desert = [tile, desert_tropic_line](auto &offset) {
data != endof(_make_desert_or_rainforest_data); ++data) { TileIndex t = AddTileIndexDiffCWrap(tile, offset);
TileIndex t = AddTileIndexDiffCWrap(tile, *data); return t == INVALID_TILE || (TileHeight(t) < desert_tropic_line && !IsTileType(t, MP_WATER));
if (t != INVALID_TILE && (TileHeight(t) >= desert_tropic_line || IsTileType(t, MP_WATER))) break; };
} if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_desert)) {
if (data == endof(_make_desert_or_rainforest_data)) {
SetTropicZone(tile, TROPICZONE_DESERT); SetTropicZone(tile, TROPICZONE_DESERT);
} }
} }
@ -961,12 +959,11 @@ static void CreateDesertOrRainForest(uint desert_tropic_line)
if (!IsValidTile(tile)) continue; if (!IsValidTile(tile)) continue;
for (data = _make_desert_or_rainforest_data; auto allows_rainforest = [tile](auto &offset) {
data != endof(_make_desert_or_rainforest_data); ++data) { TileIndex t = AddTileIndexDiffCWrap(tile, offset);
TileIndex t = AddTileIndexDiffCWrap(tile, *data); return t == INVALID_TILE || !IsTileType(t, MP_CLEAR) || !IsClearGround(t, CLEAR_DESERT);
if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break; };
} if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_rainforest)) {
if (data == endof(_make_desert_or_rainforest_data)) {
SetTropicZone(tile, TROPICZONE_RAINFOREST); SetTropicZone(tile, TROPICZONE_RAINFOREST);
} }
} }