Reduce duplication in CreateDesertOrRainForest
This commit is contained in:
		@@ -1001,50 +1001,41 @@ static void GenerateTerrain(int type, uint flag)
 | 
			
		||||
 | 
			
		||||
#include "table/genland.h"
 | 
			
		||||
 | 
			
		||||
static std::pair<const TileIndexDiffC *, const TileIndexDiffC *> GetDesertOrRainforestData()
 | 
			
		||||
{
 | 
			
		||||
	switch (_settings_game.game_creation.coast_tropics_width) {
 | 
			
		||||
		case 0:
 | 
			
		||||
			return { _make_desert_or_rainforest_data, endof(_make_desert_or_rainforest_data) };
 | 
			
		||||
		case 1:
 | 
			
		||||
			return { _make_desert_or_rainforest_data_medium, endof(_make_desert_or_rainforest_data_medium) };
 | 
			
		||||
		case 2:
 | 
			
		||||
			return { _make_desert_or_rainforest_data_large, endof(_make_desert_or_rainforest_data_large) };
 | 
			
		||||
		default:
 | 
			
		||||
			NOT_REACHED();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void CreateDesertOrRainForest(uint desert_tropic_line)
 | 
			
		||||
{
 | 
			
		||||
	TileIndex update_freq = MapSize() / 4;
 | 
			
		||||
	const TileIndexDiffC *data;
 | 
			
		||||
 | 
			
		||||
	const std::pair<const TileIndexDiffC *, const TileIndexDiffC *> desert_rainforest_data = GetDesertOrRainforestData();
 | 
			
		||||
 | 
			
		||||
	for (TileIndex tile = 0; tile != MapSize(); ++tile) {
 | 
			
		||||
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
 | 
			
		||||
 | 
			
		||||
		if (!IsValidTile(tile)) continue;
 | 
			
		||||
 | 
			
		||||
		if (_settings_game.game_creation.coast_tropics_width == 0) {
 | 
			
		||||
			for (data = _make_desert_or_rainforest_data;
 | 
			
		||||
				data != endof(_make_desert_or_rainforest_data); ++data) {
 | 
			
		||||
		for (data = desert_rainforest_data.first; data != desert_rainforest_data.second; ++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)) {
 | 
			
		||||
		if (data == desert_rainforest_data.second) {
 | 
			
		||||
			SetTropicZone(tile, TROPICZONE_DESERT);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		if (_settings_game.game_creation.coast_tropics_width == 1) {
 | 
			
		||||
			for (data = _make_desert_or_rainforest_data_medium;
 | 
			
		||||
				data != endof(_make_desert_or_rainforest_data_medium); ++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_medium)) {
 | 
			
		||||
				SetTropicZone(tile, TROPICZONE_DESERT);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (_settings_game.game_creation.coast_tropics_width == 2) {
 | 
			
		||||
			for (data = _make_desert_or_rainforest_data_large;
 | 
			
		||||
				data != endof(_make_desert_or_rainforest_data_large); ++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_large)) {
 | 
			
		||||
				SetTropicZone(tile, TROPICZONE_DESERT);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (uint i = 0; i != 256; i++) {
 | 
			
		||||
		if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
 | 
			
		||||
 | 
			
		||||
@@ -1056,39 +1047,14 @@ static void CreateDesertOrRainForest(uint desert_tropic_line)
 | 
			
		||||
 | 
			
		||||
		if (!IsValidTile(tile)) continue;
 | 
			
		||||
 | 
			
		||||
		if (_settings_game.game_creation.coast_tropics_width == 0) {
 | 
			
		||||
			for (data = _make_desert_or_rainforest_data;
 | 
			
		||||
				data != endof(_make_desert_or_rainforest_data); ++data) {
 | 
			
		||||
		for (data = desert_rainforest_data.first; data != desert_rainforest_data.second; ++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)) {
 | 
			
		||||
		if (data == desert_rainforest_data.second) {
 | 
			
		||||
			SetTropicZone(tile, TROPICZONE_RAINFOREST);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		if (_settings_game.game_creation.coast_tropics_width == 1) {
 | 
			
		||||
			for (data = _make_desert_or_rainforest_data_medium;
 | 
			
		||||
				data != endof(_make_desert_or_rainforest_data_medium); ++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_medium)) {
 | 
			
		||||
				SetTropicZone(tile, TROPICZONE_RAINFOREST);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (_settings_game.game_creation.coast_tropics_width == 2) {
 | 
			
		||||
			for (data = _make_desert_or_rainforest_data_large;
 | 
			
		||||
				data != endof(_make_desert_or_rainforest_data_large); ++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_large)) {
 | 
			
		||||
				SetTropicZone(tile, TROPICZONE_RAINFOREST);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user