Changeset - r25080:d4c9906d70aa
[Not reviewed]
master
0 8 0
Patric Stout - 3 years ago 2021-03-24 09:29:01
truebrain@openttd.org
Feature: auto-detect map height limit based on generated map

This opens up the true power of the TGP terrain generator, as it
is no longer constrainted by an arbitrary low map height limit,
especially for extreme terrain types.

In other words: on a 1kx1k map with "Alpinist" terrain type, the
map is now really hilly with default settings.

People can still manually limit the map height if they so wish,
and after the terrain generation the limit is stored in the
savegame as if the user set it.

Cheats still allow you to change this value.
8 files changed with 52 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/genworld.cpp
Show inline comments
 
@@ -33,6 +33,7 @@
 
#include "game/game_instance.hpp"
 
#include "string_func.h"
 
#include "thread.h"
 
#include "tgp.h"
 

	
 
#include "safeguards.h"
 

	
 
@@ -285,6 +286,20 @@ void GenerateWorld(GenWorldMode mode, ui
 
	InitializeGame(_gw.size_x, _gw.size_y, true, reset_settings);
 
	PrepareGenerateWorldProgress();
 

	
 
	if (_settings_game.construction.map_height_limit == 0) {
 
		uint estimated_height = 0;
 

	
 
		if (_gw.mode == GWM_EMPTY && _game_mode != GM_MENU) {
 
			estimated_height = _settings_game.game_creation.se_flat_world_height;
 
		} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
 
			estimated_height = GetEstimationTGPMapHeight();
 
		} else {
 
			estimated_height = 0;
 
		}
 

	
 
		_settings_game.construction.map_height_limit = std::max(MAP_HEIGHT_LIMIT_AUTO_MINIMUM, std::min(MAX_MAP_HEIGHT_LIMIT, estimated_height + MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM));
 
	}
 

	
 
	/* Load the right landscape stuff, and the NewGRFs! */
 
	GfxLoadSprites();
 
	LoadStringWidthTable();
src/genworld.h
Show inline comments
 
@@ -46,6 +46,9 @@ static const uint CUSTOM_SEA_LEVEL_NUMBE
 
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.
 

	
 
typedef void GWDoneProc();  ///< Procedure called when the genworld process finishes
 
typedef void GWAbortProc(); ///< Called when genworld is aborted
 

	
src/genworld_gui.cpp
Show inline comments
 
@@ -46,6 +46,15 @@ enum GenerateLandscapeWindowMode {
 
};
 

	
 
/**
 
 * Get the map height limit, or if set to "auto", the absolute limit.
 
 */
 
static uint GetMapHeightLimit()
 
{
 
	if (_settings_newgame.construction.map_height_limit == 0) return MAX_MAP_HEIGHT_LIMIT;
 
	return _settings_newgame.construction.map_height_limit;
 
}
 

	
 
/**
 
 * Changes landscape type and sets genworld window dirty
 
 * @param landscape new landscape type
 
 */
 
@@ -974,7 +983,7 @@ struct CreateScenarioWindow : public Win
 
		this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN,       _settings_newgame.game_creation.starting_year <= MIN_YEAR);
 
		this->SetWidgetDisabledState(WID_CS_START_DATE_UP,         _settings_newgame.game_creation.starting_year >= MAX_YEAR);
 
		this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
 
		this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP,   _settings_newgame.game_creation.se_flat_world_height >= MAX_TILE_HEIGHT);
 
		this->SetWidgetDisabledState(WID_CS_FLAT_LAND_HEIGHT_UP,   _settings_newgame.game_creation.se_flat_world_height >= GetMapHeightLimit());
 

	
 
		this->SetWidgetLoweredState(WID_CS_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
 
		this->SetWidgetLoweredState(WID_CS_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
 
@@ -1062,7 +1071,7 @@ struct CreateScenarioWindow : public Win
 
					this->HandleButtonClick(widget);
 
					this->SetDirty();
 

	
 
					_settings_newgame.game_creation.se_flat_world_height = Clamp(_settings_newgame.game_creation.se_flat_world_height + widget - WID_CS_FLAT_LAND_HEIGHT_TEXT, 0, _settings_game.construction.map_height_limit);
 
					_settings_newgame.game_creation.se_flat_world_height = Clamp(_settings_newgame.game_creation.se_flat_world_height + widget - WID_CS_FLAT_LAND_HEIGHT_TEXT, 0, GetMapHeightLimit());
 
				}
 
				_left_button_clicked = false;
 
				break;
 
@@ -1108,7 +1117,7 @@ struct CreateScenarioWindow : public Win
 

	
 
				case WID_CS_FLAT_LAND_HEIGHT_TEXT:
 
					this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
 
					_settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, _settings_game.construction.map_height_limit);
 
					_settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMapHeightLimit());
 
					break;
 
			}
 

	
src/lang/english.txt
Show inline comments
 
@@ -1206,7 +1206,9 @@ STR_CONFIG_SETTING_CITY_APPROVAL        
 
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
 
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_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
src/table/settings.ini
Show inline comments
 
@@ -394,16 +394,16 @@ base     = GameSettings
 
var      = construction.map_height_limit
 
type     = SLE_UINT8
 
from     = SLV_194
 
guiflags = SGF_NEWGAME_ONLY | SGF_SCENEDIT_TOO
 
def      = DEF_MAP_HEIGHT_LIMIT
 
guiflags = SGF_NEWGAME_ONLY | SGF_SCENEDIT_TOO | SGF_0ISDISABLED
 
def      = 0
 
min      = MIN_MAP_HEIGHT_LIMIT
 
max      = MAX_MAP_HEIGHT_LIMIT
 
interval = 1
 
str      = STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT
 
strhelp  = STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_HELPTEXT
 
strval   = STR_JUST_INT
 
strval   = STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_VALUE
 
proc     = ChangeMaxHeightLevel
 
cat      = SC_BASIC
 
cat      = SC_ADVANCED
 

	
 
[SDT_BOOL]
 
base     = GameSettings
src/tgp.cpp
Show inline comments
 
@@ -237,7 +237,20 @@ static height_t TGPGetMaxHeight()
 
	int map_size_bucket = std::min(MapLogX(), MapLogY()) - MIN_MAP_SIZE_BITS;
 
	int max_height_from_table = max_height[_settings_game.difficulty.terrain_type][map_size_bucket];
 

	
 
	return I2H(std::min<uint>(max_height_from_table, _settings_game.construction.map_height_limit));
 
	/* If there is a manual map height limit, clamp to it. */
 
	if (_settings_game.construction.map_height_limit != 0) {
 
		max_height_from_table = std::min<uint>(max_height_from_table, _settings_game.construction.map_height_limit);
 
	}
 

	
 
	return I2H(max_height_from_table);
 
}
 

	
 
/**
 
 * Get an overestimation of the highest peak TGP wants to generate.
 
 */
 
uint GetEstimationTGPMapHeight()
 
{
 
	return H2I(TGPGetMaxHeight());
 
}
 

	
 
/**
src/tgp.h
Show inline comments
 
@@ -11,5 +11,6 @@
 
#define TGP_H
 

	
 
void GenerateTerrainPerlin();
 
uint GetEstimationTGPMapHeight();
 

	
 
#endif /* TGP_H */
src/tile_type.h
Show inline comments
 
@@ -22,7 +22,6 @@ static const int MAX_VEHICLE_PIXEL_Y  = 
 
static const uint MAX_TILE_HEIGHT     = 255;                   ///< Maximum allowed tile height
 

	
 
static const uint MIN_MAP_HEIGHT_LIMIT = 15;                   ///< Lower bound of maximum allowed heightlevel (in the construction settings)
 
static const uint DEF_MAP_HEIGHT_LIMIT = 30;                   ///< Default 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
0 comments (0 inline, 0 general)