Changeset - r26747:6a13b72c8f80
[Not reviewed]
master
0 5 0
Tyler Trahan - 17 months ago 2023-01-14 10:12:29
tyler@tylertrahan.com
Feature: Set a custom number of industries in map generation window (#10340)
5 files changed with 47 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/genworld_gui.cpp
Show inline comments
 
@@ -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[]      = {
 
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 
 
				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 
 
				*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 
 
				}
 
				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 
 
				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 
 
				_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;
src/industry_cmd.cpp
Show inline comments
 
@@ -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<uint>(IndustryPool::MAX_SIZE, _settings_game.game_creation.custom_industry_number);
 

	
 
	return std::min<uint>(IndustryPool::MAX_SIZE, ScaleByMapSize(numof_industry_table[difficulty]));
 
}
 

	
src/settings_type.h
Show inline comments
 
@@ -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
src/table/settings/difficulty_settings.ini
Show inline comments
 
@@ -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
src/table/settings/world_settings.ini
Show inline comments
 
@@ -272,6 +272,13 @@ 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
 
from     = SLV_MAPGEN_SETTINGS_REVAMP
0 comments (0 inline, 0 general)