(svn r9455) -Fix: the values for diff_custom, diff_level and snow_line in the .cfg were not properly checked.
authorrubidium
Sun, 25 Mar 2007 19:21:22 +0000
changeset 6704 1d7e67bc3f7c
parent 6703 9ddfcb1849e4
child 6705 d3fb7785c0a4
(svn r9455) -Fix: the values for diff_custom, diff_level and snow_line in the .cfg were not properly checked.
src/settings.cpp
src/settings_gui.cpp
--- a/src/settings.cpp	Sun Mar 25 16:09:36 2007 +0000
+++ b/src/settings.cpp	Sun Mar 25 19:21:22 2007 +0000
@@ -1265,12 +1265,12 @@
 	 * 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 @@
 #endif /* ENABLE_NETWORK */
 }
 
+extern void CheckDifficultyLevels();
+
 /** Load the values from the configuration files */
 void LoadFromConfig()
 {
@@ -1687,6 +1689,7 @@
 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
 	_news_display_opt  = NewsDisplayLoadConfig(ini, "news_display");
+	CheckDifficultyLevels();
 	ini_free(ini);
 }
 
--- a/src/settings_gui.cpp	Sun Mar 25 16:09:36 2007 +0000
+++ b/src/settings_gui.cpp	Sun Mar 25 19:21:22 2007 +0000
@@ -369,6 +369,23 @@
 	}
 }
 
+/**
+ * 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 {