diff options
-rw-r--r-- | src/genworld.cpp | 15 | ||||
-rw-r--r-- | src/genworld.h | 3 | ||||
-rw-r--r-- | src/genworld_gui.cpp | 15 | ||||
-rw-r--r-- | src/lang/english.txt | 4 | ||||
-rw-r--r-- | src/table/settings.ini | 8 | ||||
-rw-r--r-- | src/tgp.cpp | 15 | ||||
-rw-r--r-- | src/tgp.h | 1 | ||||
-rw-r--r-- | src/tile_type.h | 1 |
8 files changed, 52 insertions, 10 deletions
diff --git a/src/genworld.cpp b/src/genworld.cpp index 0bd64f896..d357a1516 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -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, uint size_x, uint size_y, bool reset_setti 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(); diff --git a/src/genworld.h b/src/genworld.h index e780ed169..71dae3f36 100644 --- a/src/genworld.h +++ b/src/genworld.h @@ -46,6 +46,9 @@ static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4; ///< Value for custom 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 diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 0ca4543f2..5e1fac685 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -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 Window 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 Window 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 Window 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; } diff --git a/src/lang/english.txt b/src/lang/english.txt index bc38876e4..94dbba787 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1206,7 +1206,9 @@ STR_CONFIG_SETTING_CITY_APPROVAL :Town council's 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 diff --git a/src/table/settings.ini b/src/table/settings.ini index 67403a3bf..ae6a40e9f 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -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 diff --git a/src/tgp.cpp b/src/tgp.cpp index 92e714d9b..3ced2a1b0 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -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()); } /** @@ -11,5 +11,6 @@ #define TGP_H void GenerateTerrainPerlin(); +uint GetEstimationTGPMapHeight(); #endif /* TGP_H */ diff --git a/src/tile_type.h b/src/tile_type.h index ad3d1b563..17b4ad206 100644 --- a/src/tile_type.h +++ b/src/tile_type.h @@ -22,7 +22,6 @@ static const int MAX_VEHICLE_PIXEL_Y = 96; ///< Maximum heig 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 |