diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 26c0965a50..6bb11658b7 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -32,6 +32,7 @@ #include "video/video_driver.hpp" #include "ai/ai_gui.hpp" #include "game/game_gui.hpp" +#include "industry.h" #include "widgets/genworld_widget.h" @@ -396,7 +397,7 @@ static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIV 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 _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID}; -static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, INVALID_STRING_ID}; +static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID}; static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID}; static_assert(lengthof(_num_inds) == ID_END + 1); @@ -463,7 +464,17 @@ struct GenerateLandscapeWindow : public Window { 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_INDUSTRY_PULLDOWN: + if (_game_mode == GM_EDITOR) { + SetDParam(0, STR_CONFIG_SETTING_OFF); + } else if (_settings_newgame.difficulty.industry_density == ID_CUSTOM) { + SetDParam(0, STR_NUM_CUSTOM_NUMBER); + SetDParam(1, _settings_newgame.game_creation.custom_industry_number); + } else { + SetDParam(0, _num_inds[_settings_newgame.difficulty.industry_density]); + } + break; + case WID_GL_TERRAIN_PULLDOWN: if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) { SetDParam(0, STR_TERRAIN_TYPE_CUSTOM_VALUE); @@ -620,7 +631,11 @@ struct GenerateLandscapeWindow : public Window { *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER)); break; - case WID_GL_INDUSTRY_PULLDOWN: strs = _num_inds; break; + case WID_GL_INDUSTRY_PULLDOWN: + strs = _num_inds; + SetDParamMaxValue(0, IndustryPool::MAX_SIZE); + *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER)); + break; case WID_GL_TERRAIN_PULLDOWN: strs = _elevations; @@ -908,7 +923,15 @@ struct GenerateLandscapeWindow : public Window { } break; - case WID_GL_INDUSTRY_PULLDOWN: _settings_newgame.difficulty.industry_density = index; break; + case WID_GL_INDUSTRY_PULLDOWN: + if ((uint)index == ID_CUSTOM) { + this->widget_id = widget; + SetDParam(0, _settings_newgame.game_creation.custom_industry_number); + ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_INDUSTRIES, 5, this, CS_NUMERAL, QSF_NONE); + } + _settings_newgame.difficulty.industry_density = index; + break; + case WID_GL_TERRAIN_PULLDOWN: { if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) { this->widget_id = widget; @@ -948,6 +971,7 @@ struct GenerateLandscapeWindow : public Window { 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_INDUSTRY_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(); @@ -979,6 +1003,10 @@ struct GenerateLandscapeWindow : public Window { _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER); break; + case WID_GL_INDUSTRY_PULLDOWN: + _settings_newgame.game_creation.custom_industry_number = Clamp(value, 1, IndustryPool::MAX_SIZE); + break; + case WID_GL_TERRAIN_PULLDOWN: _settings_newgame.game_creation.custom_terrain_type = Clamp(value, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit()); break; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 78a0966a45..cdf1f9d430 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2236,10 +2236,14 @@ static uint GetNumberOfIndustries() 25, // low 55, // normal 80, // high + 0, // custom }; assert(lengthof(numof_industry_table) == ID_END); uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.industry_density : (uint)ID_VERY_LOW; + + if (difficulty == ID_CUSTOM) return std::min(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number); + return std::min(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty])); } diff --git a/src/settings_type.h b/src/settings_type.h index a83384cdb3..2a33d3be0e 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -58,6 +58,8 @@ enum IndustryDensity { ID_NORMAL, ///< Normal amount of industries at game start. ID_HIGH, ///< Many industries at game start. + ID_CUSTOM, ///< Custom number of industries. + ID_END, ///< Number of industry density settings. }; @@ -326,6 +328,7 @@ struct GameCreationSettings { 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 + uint16 custom_industry_number; ///< manually entered number of industries 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 diff --git a/src/table/settings/difficulty_settings.ini b/src/table/settings/difficulty_settings.ini index de1b54955c..d47da817d6 100644 --- a/src/table/settings/difficulty_settings.ini +++ b/src/table/settings/difficulty_settings.ini @@ -83,7 +83,7 @@ var = difficulty.industry_density type = SLE_UINT8 from = SLV_97 flags = SF_GUI_DROPDOWN -def = ID_END - 1 +def = ID_NORMAL min = 0 max = ID_END - 1 interval = 1 diff --git a/src/table/settings/world_settings.ini b/src/table/settings/world_settings.ini index 479f1e7442..d5fafd9d83 100644 --- a/src/table/settings/world_settings.ini +++ b/src/table/settings/world_settings.ini @@ -271,6 +271,13 @@ min = 1 max = 5000 cat = SC_BASIC +[SDT_VAR] +var = game_creation.custom_industry_number +type = SLE_UINT16 +def = 1 +min = 1 +max = 64000 + [SDT_VAR] var = game_creation.custom_terrain_type type = SLE_UINT8