Changeset - r25082:dba738c5114f
[Not reviewed]
master
0 7 0
Patric Stout - 3 years ago 2021-03-24 22:25:51
truebrain@openttd.org
Feature: allow setting a custom terrain type to define highest peak

At least, TGP will try to reach it. It heavily depends on the map
if it is reachable at all. But for sure it will do its atmost to
get there!
7 files changed with 67 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/genworld.h
Show inline comments
 
@@ -39,12 +39,14 @@ enum TgenSmoothness {
 
	TGEN_SMOOTHNESS_ROUGH,      ///< Smoothness preset 'rough'.
 
	TGEN_SMOOTHNESS_VERY_ROUGH, ///< Smoothness preset 'very rough'.
 

	
 
	TGEN_SMOOTHNESS_END,        ///< Used to iterate.
 
};
 

	
 
static const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY = 5; ///< Value for custom terrain type in difficulty settings.
 

	
 
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4; ///< Value for custom sea level in difficulty settings.
 
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1;    ///< Minimum percentage a user can specify for custom sea level.
 
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90;   ///< Maximum percentage a user can specify for custom sea level.
 

	
 
static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM = 30; ///< When map height limit is auto, make this the lowest possible map height limit.
 
static const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM = 15; ///< When map height limit is auto, the map height limit will be the higest peak plus this value.
src/genworld_gui.cpp
Show inline comments
 
@@ -344,13 +344,13 @@ static DropDownList BuildTownNameDropDow
 
	std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
 

	
 
	return list;
 
}
 

	
 

	
 
static const StringID _elevations[]  = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, INVALID_STRING_ID};
 
static const StringID _elevations[]  = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, STR_TERRAIN_TYPE_CUSTOM, INVALID_STRING_ID};
 
static const StringID _sea_lakes[]   = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM, INVALID_STRING_ID};
 
static const StringID _rivers[]      = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
 
static const StringID _smoothness[]  = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID};
 
static const StringID _rotation[]    = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
 
static const StringID _landscape[]   = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
 
static const StringID _num_towns[]   = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
 
@@ -375,14 +375,15 @@ struct GenerateLandscapeWindow : public 
 
		this->mode = (GenerateLandscapeWindowMode)this->window_number;
 

	
 
		/* Disable town and industry in SE */
 
		this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN,     _game_mode == GM_EDITOR);
 
		this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
 

	
 
		/* In case the map_height_limit is changed, clamp heightmap_height. */
 
		/* In case the map_height_limit is changed, clamp heightmap_height and custom_terrain_type. */
 
		_settings_newgame.game_creation.heightmap_height = Clamp(_settings_newgame.game_creation.heightmap_height, MIN_HEIGHTMAP_HEIGHT, GetMapHeightLimit());
 
		_settings_newgame.game_creation.custom_terrain_type = Clamp(_settings_newgame.game_creation.custom_terrain_type, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
 

	
 
		this->OnInvalidateData();
 
	}
 

	
 

	
 
	void SetStringParameters(int widget) const override
 
@@ -414,13 +415,20 @@ struct GenerateLandscapeWindow : public 
 
				SetDParam(0, name);
 
				break;
 
			}
 

	
 
			case WID_GL_INDUSTRY_PULLDOWN:   SetDParam(0, _game_mode == GM_EDITOR ? STR_CONFIG_SETTING_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
 
			case WID_GL_LANDSCAPE_PULLDOWN:  SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
 
			case WID_GL_TERRAIN_PULLDOWN:    SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
 
			case WID_GL_TERRAIN_PULLDOWN:
 
				if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
 
					SetDParam(0, STR_TERRAIN_TYPE_CUSTOM_VALUE);
 
					SetDParam(1, _settings_newgame.game_creation.custom_terrain_type);
 
				} else {
 
					SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
 
				}
 
				break;
 

	
 
			case WID_GL_WATER_PULLDOWN:
 
				if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
 
					SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
 
					SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
 
				} else {
 
@@ -508,16 +516,20 @@ struct GenerateLandscapeWindow : public 
 
		this->SetWidgetDisabledState(WID_GL_START_DATE_UP,   _settings_newgame.game_creation.starting_year >= MAX_YEAR);
 
		this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_DOWN, _settings_newgame.game_creation.snow_coverage <= 0 || _settings_newgame.game_creation.landscape != LT_ARCTIC);
 
		this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_UP,   _settings_newgame.game_creation.snow_coverage >= 100 || _settings_newgame.game_creation.landscape != LT_ARCTIC);
 
		this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_DOWN, _settings_newgame.game_creation.desert_coverage <= 0 || _settings_newgame.game_creation.landscape != LT_TROPIC);
 
		this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_UP,   _settings_newgame.game_creation.desert_coverage >= 100 || _settings_newgame.game_creation.landscape != LT_TROPIC);
 

	
 
		/* Do not allow a custom sea level with the original land generator. */
 
		if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL &&
 
				_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
 
			_settings_newgame.difficulty.quantity_sea_lakes = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE;
 
		/* Do not allow a custom sea level or terrain type with the original land generator. */
 
		if (_settings_newgame.game_creation.land_generator == LG_ORIGINAL) {
 
			if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
 
				_settings_newgame.difficulty.quantity_sea_lakes = 1;
 
			}
 
			if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
 
				_settings_newgame.difficulty.terrain_type = 1;
 
			}
 
		}
 

	
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
@@ -560,13 +572,19 @@ struct GenerateLandscapeWindow : public 
 
				SetDParamMaxValue(0, CUSTOM_TOWN_MAX_NUMBER);
 
				*size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
 
				break;
 

	
 
			case WID_GL_INDUSTRY_PULLDOWN:   strs = _num_inds; break;
 
			case WID_GL_LANDSCAPE_PULLDOWN:  strs = _landscape; break;
 
			case WID_GL_TERRAIN_PULLDOWN:    strs = _elevations; break;
 

	
 
			case WID_GL_TERRAIN_PULLDOWN:
 
				strs = _elevations;
 
				SetDParamMaxValue(0, MAX_MAP_HEIGHT_LIMIT);
 
				*size = maxdim(*size, GetStringBoundingBox(STR_TERRAIN_TYPE_CUSTOM_VALUE));
 
				break;
 

	
 
			case WID_GL_WATER_PULLDOWN:
 
				strs = _sea_lakes;
 
				SetDParamMaxValue(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
 
				*size = maxdim(*size, GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE));
 
				break;
 

	
 
@@ -851,13 +869,21 @@ struct GenerateLandscapeWindow : public 
 
					_settings_newgame.game_creation.town_name = index;
 
					SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
 
				}
 
				break;
 

	
 
			case WID_GL_INDUSTRY_PULLDOWN: _settings_newgame.difficulty.industry_density = index; break;
 
			case WID_GL_TERRAIN_PULLDOWN:  _settings_newgame.difficulty.terrain_type     = index; break;
 
			case WID_GL_TERRAIN_PULLDOWN: {
 
				if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
 
					this->widget_id = widget;
 
					SetDParam(0, _settings_newgame.game_creation.custom_terrain_type);
 
					ShowQueryString(STR_JUST_INT, STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
 
				}
 
				_settings_newgame.difficulty.terrain_type = index;
 
				break;
 
			}
 

	
 
			case WID_GL_WATER_PULLDOWN: {
 
				if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
 
					this->widget_id = widget;
 
					SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
 
					ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, this, CS_NUMERAL, QSF_NONE);
 
@@ -882,12 +908,13 @@ struct GenerateLandscapeWindow : public 
 
			switch (this->widget_id) {
 
				case WID_GL_HEIGHTMAP_HEIGHT_TEXT: value = MAP_HEIGHT_LIMIT_AUTO_MINIMUM; break;
 
				case WID_GL_START_DATE_TEXT: value = DEF_START_YEAR; break;
 
				case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break;
 
				case WID_GL_DESERT_COVERAGE_TEXT: value = DEF_DESERT_COVERAGE; break;
 
				case WID_GL_TOWN_PULLDOWN: value = 1; break;
 
				case WID_GL_TERRAIN_PULLDOWN: value = MIN_MAP_HEIGHT_LIMIT; break;
 
				case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
 
				default: NOT_REACHED();
 
			}
 
		}
 

	
 
		switch (this->widget_id) {
 
@@ -912,12 +939,16 @@ struct GenerateLandscapeWindow : public 
 
				break;
 

	
 
			case WID_GL_TOWN_PULLDOWN:
 
				_settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
 
				break;
 

	
 
			case WID_GL_TERRAIN_PULLDOWN:
 
				_settings_newgame.game_creation.custom_terrain_type = Clamp(value, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
 
				break;
 

	
 
			case WID_GL_WATER_PULLDOWN:
 
				_settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
 
				break;
 
		}
 

	
 
		this->InvalidateData();
src/lang/english.txt
Show inline comments
 
@@ -1121,12 +1121,14 @@ STR_SUBSIDY_X4                          
 

	
 
STR_TERRAIN_TYPE_VERY_FLAT                                      :Very Flat
 
STR_TERRAIN_TYPE_FLAT                                           :Flat
 
STR_TERRAIN_TYPE_HILLY                                          :Hilly
 
STR_TERRAIN_TYPE_MOUNTAINOUS                                    :Mountainous
 
STR_TERRAIN_TYPE_ALPINIST                                       :Alpinist
 
STR_TERRAIN_TYPE_CUSTOM                                         :Custom height
 
STR_TERRAIN_TYPE_CUSTOM_VALUE                                   :Custom height ({NUM})
 

	
 
STR_CITY_APPROVAL_PERMISSIVE                                    :Permissive
 
STR_CITY_APPROVAL_TOLERANT                                      :Tolerant
 
STR_CITY_APPROVAL_HOSTILE                                       :Hostile
 

	
 
STR_WARNING_NO_SUITABLE_AI                                      :{WHITE}No suitable AIs available...{}You can download several AIs via the 'Online Content' system
 
@@ -1203,13 +1205,13 @@ STR_CONFIG_SETTING_TRAIN_REVERSING_HELPT
 
STR_CONFIG_SETTING_DISASTERS                                    :Disasters: {STRING2}
 
STR_CONFIG_SETTING_DISASTERS_HELPTEXT                           :Toggle disasters which may occasionally block or destroy vehicles or infrastructure
 
STR_CONFIG_SETTING_CITY_APPROVAL                                :Town council's attitude towards area restructuring: {STRING2}
 
STR_CONFIG_SETTING_CITY_APPROVAL_HELPTEXT                       :Choose how much noise and environmental damage by companies affect their town rating and further construction actions in their area
 

	
 
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT                             :Map height limit: {STRING2}
 
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_HELPTEXT                    :Set the maximum allowed height of the map; neither the terrain generator nor you can build higher than this limit. On (auto) it will pick a good value after terrain generation
 
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_HELPTEXT                    :Set the maximum height of the map terrain. With "(auto)" a good value will be picked after terrain generation
 
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_VALUE                       :{NUM}
 
STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_AUTO                        :(auto)
 
STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN                            :{WHITE}You can't set the map height limit to this value. At least one mountain on the map is higher
 
STR_CONFIG_SETTING_AUTOSLOPE                                    :Allow landscaping under buildings, tracks, etc.: {STRING2}
 
STR_CONFIG_SETTING_AUTOSLOPE_HELPTEXT                           :Allow landscaping under buildings and tracks without removing them
 
STR_CONFIG_SETTING_CATCHMENT                                    :Allow more realistically sized catchment areas: {STRING2}
 
@@ -2933,12 +2935,13 @@ STR_MAPGEN_BORDER_MANUAL                
 

	
 
STR_MAPGEN_HEIGHTMAP_ROTATION                                   :{BLACK}Heightmap rotation:
 
STR_MAPGEN_HEIGHTMAP_NAME                                       :{BLACK}Heightmap name:
 
STR_MAPGEN_HEIGHTMAP_SIZE_LABEL                                 :{BLACK}Size:
 
STR_MAPGEN_HEIGHTMAP_SIZE                                       :{ORANGE}{NUM} x {NUM}
 

	
 
STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT                              :{WHITE}Target peak height
 
STR_MAPGEN_HEIGHTMAP_HEIGHT_QUERY_CAPT                          :{WHITE}Highest peak
 
STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT                             :{WHITE}Snow coverage (in %)
 
STR_MAPGEN_DESERT_COVERAGE_QUERY_CAPT                           :{WHITE}Desert coverage (in %)
 
STR_MAPGEN_START_DATE_QUERY_CAPT                                :{WHITE}Change starting year
 

	
 
# SE Map generation
src/settings_type.h
Show inline comments
 
@@ -306,12 +306,13 @@ struct GameCreationSettings {
 
	byte   se_flat_world_height;             ///< land height a flat world gets in SE
 
	byte   town_name;                        ///< the town name generator used for town names
 
	byte   landscape;                        ///< the landscape we're currently in
 
	byte   water_borders;                    ///< bitset of the borders that are water
 
	uint16 custom_town_number;               ///< manually entered number of towns
 
	byte   variety;                          ///< variety level applied to TGP
 
	byte   custom_terrain_type;              ///< manually entered height for TGP to aim for
 
	byte   custom_sea_level;                 ///< manually entered percentage of water in the map
 
	byte   min_river_length;                 ///< the minimum river length
 
	byte   river_route_random;               ///< the amount of randomicity for the route finding
 
	byte   amount_of_rivers;                 ///< the amount of rivers
 
};
 

	
src/table/settings.ini
Show inline comments
 
@@ -263,13 +263,13 @@ base     = GameSettings
 
var      = difficulty.terrain_type
 
type     = SLE_UINT8
 
from     = SLV_97
 
guiflags = SGF_MULTISTRING | SGF_NEWGAME_ONLY
 
def      = 1
 
min      = 0
 
max      = 4
 
max      = 5
 
interval = 1
 
str      = STR_CONFIG_SETTING_TERRAIN_TYPE
 
strhelp  = STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT
 
strval   = STR_TERRAIN_TYPE_VERY_FLAT
 
cat      = SC_BASIC
 

	
 
@@ -2462,12 +2462,23 @@ str      = STR_CONFIG_SETTING_EXTRA_TREE
 
strhelp  = STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_HELPTEXT
 
strval   = STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_NO_SPREAD
 
cat      = SC_BASIC
 

	
 
[SDT_VAR]
 
base     = GameSettings
 
var      = game_creation.custom_terrain_type
 
type     = SLE_UINT8
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
guiflags = SGF_NEWGAME_ONLY
 
def      = MAP_HEIGHT_LIMIT_AUTO_MINIMUM
 
min      = MIN_CUSTOM_TERRAIN_TYPE
 
max      = MAX_MAP_HEIGHT_LIMIT
 
interval = 1
 

	
 
[SDT_VAR]
 
base     = GameSettings
 
var      = game_creation.custom_sea_level
 
type     = SLE_UINT8
 
from     = SLV_149
 
def      = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
 
min      = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
 
max      = CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
src/tgp.cpp
Show inline comments
 
@@ -212,12 +212,19 @@ static const amplitude_t _water_percent[
 
 * mapsize, terraintype, and the maximum height level.
 
 * @return The maximum height for the map generation.
 
 * @note Values should never be lower than 3 since the minimum snowline height is 2.
 
 */
 
static height_t TGPGetMaxHeight()
 
{
 
	if (_settings_game.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
 
		/* TGP never reaches this height; this means that if a user inputs "2",
 
		 * it would create a flat map without the "+ 1". But that would
 
		 * overflow on "255". So we reduce it by 1 to get back in range. */
 
		return I2H(_settings_game.game_creation.custom_terrain_type + 1) - 1;
 
	}
 

	
 
	/**
 
	 * Desired maximum height - indexed by:
 
	 *  - _settings_game.difficulty.terrain_type
 
	 *  - min(MapLogX(), MapLogY()) - MIN_MAP_SIZE_BITS
 
	 *
 
	 * It is indexed by map size as well as terrain type since the map size limits the height of
src/tile_type.h
Show inline comments
 
@@ -19,12 +19,13 @@ static const uint MAX_BUILDING_PIXELS = 
 
static const int MAX_VEHICLE_PIXEL_X  = 192;                   ///< Maximum width of a vehicle in pixels in #ZOOM_LVL_BASE.
 
static const int MAX_VEHICLE_PIXEL_Y  = 96;                    ///< Maximum height of a vehicle in pixels in #ZOOM_LVL_BASE.
 

	
 
static const uint MAX_TILE_HEIGHT     = 255;                   ///< Maximum allowed tile height
 

	
 
static const uint MIN_HEIGHTMAP_HEIGHT = 1;                    ///< Lowest possible peak value for heightmap creation
 
static const uint MIN_CUSTOM_TERRAIN_TYPE = 1;                 ///< Lowest possible peak value for world generation
 

	
 
static const uint MIN_MAP_HEIGHT_LIMIT = 15;                   ///< Lower bound of maximum allowed heightlevel (in the construction settings)
 
static const uint MAX_MAP_HEIGHT_LIMIT = MAX_TILE_HEIGHT;      ///< Upper bound of maximum allowed heightlevel (in the construction settings)
 

	
 
static const uint MIN_SNOWLINE_HEIGHT = 2;                     ///< Minimum snowline height
 
static const uint DEF_SNOWLINE_HEIGHT = 10;                    ///< Default snowline height
0 comments (0 inline, 0 general)