Allow specifying a custom number of industries in map generation window

pull/341/head
Jonathan G Rennison 2 years ago
parent b807f0d50e
commit b69521ea87

@ -31,6 +31,7 @@
#include "newgrf_townname.h"
#include "townname_type.h"
#include "video/video_driver.hpp"
#include "industry.h"
#include "widgets/genworld_widget.h"
@ -408,7 +409,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 _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_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);
@ -482,7 +483,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_LANDSCAPE_PULLDOWN: SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
case WID_GL_TERRAIN_PULLDOWN:
if (_settings_newgame.difficulty.terrain_type == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
@ -656,7 +667,12 @@ 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_LANDSCAPE_PULLDOWN: strs = _landscape; break;
case WID_GL_TERRAIN_PULLDOWN:
@ -997,7 +1013,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;
@ -1037,6 +1061,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;
case WID_GL_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
@ -1080,6 +1105,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;

@ -2284,10 +2284,12 @@ 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<uint>(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number);
return std::min<uint>(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty]));
}

@ -57,6 +57,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.
};
@ -407,6 +409,7 @@ struct GameCreationSettings {
uint8 amount_of_rocks; ///< the amount of rocks
uint8 height_affects_rocks; ///< the affect that map height has on rocks
uint8 build_public_roads; ///< build public roads connecting towns
uint16 custom_industry_number; ///< manually entered number of industries
};
/** Settings related to construction in-game */

@ -222,7 +222,7 @@ var = difficulty.industry_density
type = SLE_UINT8
from = SLV_97
flags = SF_GUI_DROPDOWN
def = ID_END - 1
def = ID_HIGH
min = 0
max = ID_END - 1
interval = 1
@ -3709,6 +3709,15 @@ min = 1
max = 5000
cat = SC_BASIC
[SDT_VAR]
var = game_creation.custom_industry_number
type = SLE_UINT16
def = 1
min = 1
max = 64000
cat = SC_BASIC
patxname = ""game_creation.custom_industry_number""
[SDT_VAR]
var = construction.extra_tree_placement
type = SLE_UINT8

Loading…
Cancel
Save