summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-03-25 19:21:22 +0000
committerrubidium <rubidium@openttd.org>2007-03-25 19:21:22 +0000
commit45e788d524b4ce088b1f3e4ba27ed3a5340fdcda (patch)
tree42c2659d5af4c40e76cdb608d997f13e633de45d /src
parent1a70cf53ff1890eaef5652975d0c16857ed9ecbb (diff)
downloadopenttd-45e788d524b4ce088b1f3e4ba27ed3a5340fdcda.tar.xz
(svn r9455) -Fix: the values for diff_custom, diff_level and snow_line in the .cfg were not properly checked.
Diffstat (limited to 'src')
-rw-r--r--src/settings.cpp7
-rw-r--r--src/settings_gui.cpp17
2 files changed, 22 insertions, 2 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index a0f6d1198..d82eec7d7 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1265,12 +1265,12 @@ static const SettingDesc _gameopt_settings[] = {
* and why not byte for example? */
SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 0, 3),
SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 4, SL_MAX_VERSION),
- SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 9, 0, 9, 0, STR_NULL, NULL),
+ SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 0, 0, 3, 0, STR_NULL, NULL),
SDT_OMANY(GameOptions, currency, SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
SDT_OMANY(GameOptions, units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL),
SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0, 20, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL),
SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0, 3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape),
- SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 1, 0, 56, 0, STR_NULL, NULL),
+ SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 7 * TILE_HEIGHT, 2 * TILE_HEIGHT, 13 * TILE_HEIGHT, 0, STR_NULL, NULL),
SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8, 0, 22, N, 0, 0, 0, "", STR_NULL, NULL, NULL),
SDT_CONDOMANY(GameOptions,autosave, SLE_UINT8,23, SL_MAX_VERSION, S, 0, 1, 4, "off|monthly|quarterly|half year|yearly", STR_NULL, NULL, NULL),
SDT_OMANY(GameOptions, road_side, SLE_UINT8, 0, 0, 1, 1, "left|right", STR_NULL, NULL, NULL),
@@ -1679,6 +1679,8 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
#endif /* ENABLE_NETWORK */
}
+extern void CheckDifficultyLevels();
+
/** Load the values from the configuration files */
void LoadFromConfig()
{
@@ -1687,6 +1689,7 @@ void LoadFromConfig()
_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
_grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
_news_display_opt = NewsDisplayLoadConfig(ini, "news_display");
+ CheckDifficultyLevels();
ini_free(ini);
}
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index a536ad396..bfe3d54f9 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -369,6 +369,23 @@ void SetDifficultyLevel(int mode, GameOptions *gm_opt)
}
}
+/**
+ * Checks the difficulty levels read from the configuration and
+ * forces them to be correct when invalid.
+ */
+void CheckDifficultyLevels()
+{
+ if (_opt_newgame.diff_level != 3) {
+ SetDifficultyLevel(_opt_newgame.diff_level, &_opt_newgame);
+ } else {
+ for (uint i = 0; i < GAME_DIFFICULTY_NUM; i++) {
+ int *diff = ((int*)&_opt_newgame.diff) + i;
+ *diff = clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max);
+ *diff -= *diff % _game_setting_info[i].step;
+ }
+ }
+}
+
extern void StartupEconomy();
enum {