From f838069a44677135e248fb2bbc7c405f02c19733 Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 6 Feb 2011 18:11:39 +0000 Subject: [PATCH] (svn r22000) -Codechange: Introduce an enum for the industry density setting. --- src/genworld_gui.cpp | 2 ++ src/industry_cmd.cpp | 12 ++++++------ src/industry_gui.cpp | 2 +- src/settings_type.h | 14 +++++++++++++- src/table/settings.h | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 029ea1055e..a62c2e4f5b 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -339,6 +339,8 @@ static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_N 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 _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID}; +assert_compile(lengthof(_num_inds) == ID_END + 1); + struct GenerateLandscapeWindow : public QueryStringBaseWindow { uint widget_id; uint x; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 30aee89097..6ef93e91b2 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1847,7 +1847,7 @@ static uint32 GetScaledIndustryGenerationProbability(IndustryType it, bool *forc uint32 chance = ind_spc->appear_creation[_settings_game.game_creation.landscape] * 16; // * 16 to increase precision if (!ind_spc->enabled || chance == 0 || ind_spc->num_table == 0 || !CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION) || - (_game_mode != GM_EDITOR && _settings_game.difficulty.number_industries == 0)) { + (_game_mode != GM_EDITOR && _settings_game.difficulty.number_industries == ID_FUND_ONLY)) { *force_at_least_one = false; return 0; } else { @@ -1868,7 +1868,7 @@ static uint32 GetScaledIndustryGenerationProbability(IndustryType it, bool *forc */ static uint16 GetIndustryGamePlayProbability(IndustryType it, byte *min_number) { - if (_settings_game.difficulty.number_industries == 0) { + if (_settings_game.difficulty.number_industries == ID_FUND_ONLY) { *min_number = 0; return 0; } @@ -1902,8 +1902,8 @@ static uint GetNumberOfIndustries() 80, // high }; - assert(_settings_game.difficulty.number_industries < lengthof(numof_industry_table)); - uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_industries : 2; + assert(lengthof(numof_industry_table) == ID_END); + uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_industries : (uint)ID_VERY_LOW; return ScaleByMapSize(numof_industry_table[difficulty]); } @@ -1994,7 +1994,7 @@ void IndustryBuildData::Reset() void IndustryBuildData::MonthlyLoop() { static const int NEWINDS_PER_MONTH = 0x38000 / (10 * 12); // lower 16 bits is a float fraction, 3.5 industries per decade, divided by 10 * 12 months. - if (_settings_game.difficulty.number_industries == 0) return; // 'no industries' setting, + if (_settings_game.difficulty.number_industries == ID_FUND_ONLY) return; // 'no industries' setting, /* To prevent running out of unused industries for the player to connect, * add a fraction of new industries each month, but only if the manager can keep up. */ @@ -2010,7 +2010,7 @@ void IndustryBuildData::MonthlyLoop() */ void GenerateIndustries() { - if (_game_mode != GM_EDITOR && _settings_game.difficulty.number_industries == 0) return; // No industries in the game. + if (_game_mode != GM_EDITOR && _settings_game.difficulty.number_industries == ID_FUND_ONLY) return; // No industries in the game. uint32 industry_probs[NUM_INDUSTRYTYPES]; bool force_at_least_one[NUM_INDUSTRYTYPES]; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 94a09111b9..799044975b 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -602,7 +602,7 @@ public: this->SetupArrays(); const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type); - if (indsp == NULL) this->enabled[this->selected_index] = _settings_game.difficulty.number_industries != 0; + if (indsp == NULL) this->enabled[this->selected_index] = _settings_game.difficulty.number_industries != ID_FUND_ONLY; this->SetButtons(); } }; diff --git a/src/settings_type.h b/src/settings_type.h index 4c24887e55..c5ee6f1250 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -19,11 +19,23 @@ #include "company_type.h" #include "openttd.h" +/** Available industry map generation densities. */ +enum IndustryDensity { + ID_FUND_ONLY, ///< The game does not build industries. + ID_MINIMAL, ///< Start with just the industries that must be present. + ID_VERY_LOW, ///< Very few industries at game start. + ID_LOW, ///< Few industries at game start. + ID_NORMAL, ///< Normal amount of industries at game start. + ID_HIGH, ///< Many industries at game start. + + ID_END, ///< Number of industry density settings. +}; + /** Settings related to the difficulty of the game */ struct DifficultySettings { byte max_no_competitors; ///< the number of competitors (AIs) byte number_towns; ///< the amount of towns - byte number_industries; ///< the amount of industries + byte number_industries; ///< The industry density. @see IndustryDensity uint32 max_loan; ///< the maximum initial loan byte initial_interest; ///< amount of interest (to pay over the loan) byte vehicle_costs; ///< amount of money spent on vehicle running cost diff --git a/src/table/settings.h b/src/table/settings.h index cf2a752b09..426f71350b 100644 --- a/src/table/settings.h +++ b/src/table/settings.h @@ -348,7 +348,7 @@ const SettingDesc _settings[] = { SDT_CONDVAR(GameSettings, difficulty.max_no_competitors, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0,0,MAX_COMPANIES-1,1,STR_NULL, MaxNoAIsChange), SDT_CONDNULL( 1, 97, 109), SDT_CONDVAR(GameSettings, difficulty.number_towns, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 2, 0, 4, 1, STR_NUM_VERY_LOW, DifficultyChange), - SDT_CONDVAR(GameSettings, difficulty.number_industries, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, 5, 0, 5, 1, STR_FUNDING_ONLY, DifficultyChange), + SDT_CONDVAR(GameSettings, difficulty.number_industries, SLE_UINT8, 97, SL_MAX_VERSION, 0,NG, ID_END-1, 0,ID_END-1, 1, STR_FUNDING_ONLY, DifficultyChange), SDT_CONDVAR(GameSettings, difficulty.max_loan, SLE_UINT32, 97, SL_MAX_VERSION, 0,NS|CR,300000,100000,500000,50000,STR_NULL, DifficultyChange), SDT_CONDVAR(GameSettings, difficulty.initial_interest, SLE_UINT8, 97, SL_MAX_VERSION, 0,NS, 2, 2, 4, 1, STR_NULL, DifficultyChange), SDT_CONDVAR(GameSettings, difficulty.vehicle_costs, SLE_UINT8, 97, SL_MAX_VERSION, 0,NS, 0, 0, 2, 1, STR_SEA_LEVEL_LOW, DifficultyChange), @@ -362,7 +362,7 @@ const SettingDesc _settings[] = { SDT_CONDVAR(GameSettings, difficulty.economy, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 1, 1, STR_ECONOMY_STEADY, DifficultyChange), SDT_CONDVAR(GameSettings, difficulty.line_reverse_mode, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 1, 1, STR_REVERSE_AT_END_OF_LINE_AND_AT_STATIONS,DifficultyChange), SDT_CONDVAR(GameSettings, difficulty.disasters, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 1, 1, STR_DISASTERS_OFF, DifficultyChange), - SDT_CONDVAR(GameSettings, difficulty.town_council_tolerance, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 2, 1, STR_CITY_APPROVAL_PERMISSIVE, DifficultyNoiseChange), + SDT_CONDVAR(GameSettings, difficulty.town_council_tolerance, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 0, 0, 2, 1, STR_CITY_APPROVAL_PERMISSIVE, DifficultyNoiseChange), SDT_CONDVAR(GameSettings, difficulty.diff_level, SLE_UINT8, 97, SL_MAX_VERSION, 0, 0, 3, 0, 3, 0, STR_NULL, DifficultyReset), /* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */