1
0
Fork 0

Feature: Set a custom number of industries in map generation window (#10340)

pull/10447/head
Tyler Trahan 2023-01-14 05:12:29 -05:00 committed by Michael Lutz
parent 556e9e8434
commit 05c0295d32
5 changed files with 49 additions and 5 deletions

View File

@ -32,6 +32,7 @@
#include "video/video_driver.hpp" #include "video/video_driver.hpp"
#include "ai/ai_gui.hpp" #include "ai/ai_gui.hpp"
#include "game/game_gui.hpp" #include "game/game_gui.hpp"
#include "industry.h"
#include "widgets/genworld_widget.h" #include "widgets/genworld_widget.h"
@ -399,7 +400,7 @@ static const StringID _smoothness[] = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_
static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, 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 _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}; 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 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); static_assert(lengthof(_num_inds) == ID_END + 1);
@ -461,8 +462,19 @@ struct GenerateLandscapeWindow : public Window {
break; 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_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break; case WID_GL_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
case WID_GL_TERRAIN_PULLDOWN: case WID_GL_TERRAIN_PULLDOWN:
if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) { if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
SetDParam(0, STR_TERRAIN_TYPE_CUSTOM_VALUE); SetDParam(0, STR_TERRAIN_TYPE_CUSTOM_VALUE);
@ -619,7 +631,12 @@ struct GenerateLandscapeWindow : public Window {
*size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER)); *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
break; 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_LANDSCAPE_PULLDOWN: strs = _landscape; break; case WID_GL_LANDSCAPE_PULLDOWN: strs = _landscape; break;
case WID_GL_TERRAIN_PULLDOWN: case WID_GL_TERRAIN_PULLDOWN:
@ -919,7 +936,15 @@ struct GenerateLandscapeWindow : public Window {
} }
break; 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: { case WID_GL_TERRAIN_PULLDOWN: {
if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) { if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
this->widget_id = widget; this->widget_id = widget;
@ -959,6 +984,7 @@ struct GenerateLandscapeWindow : public Window {
case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; 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_DESERT_COVERAGE_TEXT: value = DEF_DESERT_COVERAGE; break;
case WID_GL_TOWN_PULLDOWN: value = 1; 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_TERRAIN_PULLDOWN: value = MIN_MAP_HEIGHT_LIMIT; break;
case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break; case WID_GL_WATER_PULLDOWN: value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
default: NOT_REACHED(); default: NOT_REACHED();
@ -990,6 +1016,10 @@ struct GenerateLandscapeWindow : public Window {
_settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER); _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
break; 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: case WID_GL_TERRAIN_PULLDOWN:
_settings_newgame.game_creation.custom_terrain_type = Clamp(value, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit()); _settings_newgame.game_creation.custom_terrain_type = Clamp(value, MIN_CUSTOM_TERRAIN_TYPE, GetMapHeightLimit());
break; break;

View File

@ -2237,10 +2237,14 @@ static uint GetNumberOfIndustries()
25, // low 25, // low
55, // normal 55, // normal
80, // high 80, // high
0, // custom
}; };
assert(lengthof(numof_industry_table) == ID_END); assert(lengthof(numof_industry_table) == ID_END);
uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.industry_density : (uint)ID_VERY_LOW; uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.industry_density : (uint)ID_VERY_LOW;
if (difficulty == ID_CUSTOM) return std::min<uint>(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number);
return std::min<uint>(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty])); return std::min<uint>(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty]));
} }

View File

@ -58,6 +58,8 @@ enum IndustryDensity {
ID_NORMAL, ///< Normal amount of industries at game start. ID_NORMAL, ///< Normal amount of industries at game start.
ID_HIGH, ///< Many industries at game start. ID_HIGH, ///< Many industries at game start.
ID_CUSTOM, ///< Custom number of industries.
ID_END, ///< Number of industry density settings. ID_END, ///< Number of industry density settings.
}; };
@ -326,6 +328,7 @@ struct GameCreationSettings {
byte landscape; ///< the landscape we're currently in byte landscape; ///< the landscape we're currently in
byte water_borders; ///< bitset of the borders that are water byte water_borders; ///< bitset of the borders that are water
uint16 custom_town_number; ///< manually entered number of towns 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 variety; ///< variety level applied to TGP
byte custom_terrain_type; ///< manually entered height for TGP to aim for 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 custom_sea_level; ///< manually entered percentage of water in the map

View File

@ -83,7 +83,7 @@ var = difficulty.industry_density
type = SLE_UINT8 type = SLE_UINT8
from = SLV_97 from = SLV_97
flags = SF_GUI_DROPDOWN flags = SF_GUI_DROPDOWN
def = ID_END - 1 def = ID_NORMAL
min = 0 min = 0
max = ID_END - 1 max = ID_END - 1
interval = 1 interval = 1

View File

@ -271,6 +271,13 @@ min = 1
max = 5000 max = 5000
cat = SC_BASIC cat = SC_BASIC
[SDT_VAR]
var = game_creation.custom_industry_number
type = SLE_UINT16
def = 1
min = 1
max = 64000
[SDT_VAR] [SDT_VAR]
var = game_creation.custom_terrain_type var = game_creation.custom_terrain_type
type = SLE_UINT8 type = SLE_UINT8