changeset 16136:be5b3d5d2a03 draft

(svn r20832) -Feature: Allow to select a custom percentage of water in the map generation window (based on patch by CommanderZ).
author terkhen <terkhen@openttd.org>
date Mon, 20 Sep 2010 18:56:35 +0000
parents 1ac9cc3debac
children bcb0d63341e2
files src/genworld.h src/genworld_gui.cpp src/lang/english.txt src/saveload/saveload.cpp src/settings_type.h src/table/settings.h src/tgp.cpp
diffstat 7 files changed, 41 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/genworld.h
+++ b/src/genworld.h
@@ -33,6 +33,10 @@
 	GWM_HEIGHTMAP = 3, ///< Generate a newgame from a heightmap
 };
 
+static const int CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4; ///< Value for custom sea level in difficulty settings.
+static const int CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1;    ///< Minimum percentage a user can specify for custom sea level.
+static const int CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90;   ///< Maximum percentage a user can specify for custom sea level.
+
 typedef void GWDoneProc();  ///< Procedure called when the genworld process finishes
 typedef void GWAbortProc(); ///< Called when genworld is aborted
 
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -331,7 +331,7 @@
 }
 
 static const StringID _elevations[]  = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, INVALID_STRING_ID};
-static const StringID _sea_lakes[]   = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, INVALID_STRING_ID};
+static const StringID _sea_lakes[]   = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM, INVALID_STRING_ID};
 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 _tree_placer[] = {STR_CONFIG_SETTING_TREE_PLACER_NONE, STR_CONFIG_SETTING_TREE_PLACER_ORIGINAL, STR_CONFIG_SETTING_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
 static const StringID _rotation[]    = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
@@ -393,7 +393,16 @@
 			case GLAND_LANDSCAPE_PULLDOWN:  SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
 			case GLAND_TREE_PULLDOWN:       SetDParam(0, _tree_placer[_settings_newgame.game_creation.tree_placer]); break;
 			case GLAND_TERRAIN_PULLDOWN:    SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
-			case GLAND_WATER_PULLDOWN:      SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]); break;
+
+			case GLAND_WATER_PULLDOWN:
+				if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
+					SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
+					SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
+				} else {
+					SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
+				}
+				break;
+
 			case GLAND_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
 			case GLAND_VARIETY_PULLDOWN:    SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
 			case GLAND_BORDERS_RANDOM:      SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
@@ -488,7 +497,12 @@
 			case GLAND_LANDSCAPE_PULLDOWN:  strs = _landscape; break;
 			case GLAND_TREE_PULLDOWN:       strs = _tree_placer; break;
 			case GLAND_TERRAIN_PULLDOWN:    strs = _elevations; break;
-			case GLAND_WATER_PULLDOWN:      strs = _sea_lakes; break;
+			case GLAND_WATER_PULLDOWN:
+				strs = _sea_lakes;
+				SetDParam(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
+				*size = GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
+				break;
+
 			case GLAND_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
 			case GLAND_VARIETY_PULLDOWN:    strs = _variety; break;
 			case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
@@ -745,6 +759,11 @@
 			}
 
 			case GLAND_WATER_PULLDOWN: {
+				if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
+					this->widget_id = widget;
+					SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
+					ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, 50, this, CS_NUMERAL, QSF_NONE);
+				};
 				GameMode old_gm = _game_mode;
 				_game_mode = GM_MENU;
 				IConsoleSetSetting("difficulty.quantity_sea_lakes", index);
@@ -786,6 +805,10 @@
 			case GLAND_TOWN_PULLDOWN:
 				_settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
 				break;
+
+			case GLAND_WATER_PULLDOWN:
+				_settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
+				break;
 		}
 
 		this->InvalidateData();
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1045,6 +1045,8 @@
 STR_SEA_LEVEL_LOW                                               :Low
 STR_SEA_LEVEL_MEDIUM                                            :Medium
 STR_SEA_LEVEL_HIGH                                              :High
+STR_SEA_LEVEL_CUSTOM                                            :Custom
+STR_SEA_LEVEL_CUSTOM_PERCENTAGE                                 :Custom ({NUM}%)
 
 STR_DISASTER_NONE                                               :None
 STR_DISASTER_REDUCED                                            :Reduced
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -211,8 +211,9 @@
  *  146   20446
  *  147   20621
  *  148   20659
+ *  149   20832
  */
-extern const uint16 SAVEGAME_VERSION = 148; ///< current savegame version of OpenTTD
+extern const uint16 SAVEGAME_VERSION = 149; ///< current savegame version of OpenTTD
 
 SavegameType _savegame_type; ///< type of savegame we are loading
 
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -179,6 +179,7 @@
 	byte   water_borders;                    ///< bitset of the borders that are water
 	uint16 custom_town_number;               ///< manually entered number of towns
 	byte   variety;                          ///< variety level applied to TGP
+	byte   custom_sea_level;                 ///< manually entered percentage of water in the map
 };
 
 /** Settings related to construction in-game */
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -352,7 +352,7 @@
 	 SDT_CONDVAR(GameSettings, difficulty.subsidy_multiplier,        SLE_UINT8, 97, SL_MAX_VERSION, 0, 0,     2,     0,      3,  1, STR_SUBSIDY_X1_5,                          DifficultyChange),
 	 SDT_CONDVAR(GameSettings, difficulty.construction_cost,         SLE_UINT8, 97, SL_MAX_VERSION, 0,NS,     0,     0,      2,  1, STR_SEA_LEVEL_LOW,                         DifficultyChange),
 	 SDT_CONDVAR(GameSettings, difficulty.terrain_type,              SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     1,     0,      3,  1, STR_TERRAIN_TYPE_VERY_FLAT,                DifficultyChange),
-	 SDT_CONDVAR(GameSettings, difficulty.quantity_sea_lakes,        SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     0,     0,      3,  1, STR_SEA_LEVEL_VERY_LOW,                    DifficultyChange),
+	 SDT_CONDVAR(GameSettings, difficulty.quantity_sea_lakes,        SLE_UINT8, 97, SL_MAX_VERSION, 0,NG,     0,     0,      4,  1, STR_SEA_LEVEL_VERY_LOW,                    DifficultyChange),
 	 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),
@@ -540,6 +540,7 @@
 	 SDT_CONDVAR(GameSettings, game_creation.water_borders,                   SLE_UINT8,111, SL_MAX_VERSION, 0, 0,    15,                     0,      16, 0, STR_NULL,                                 NULL),
 	 SDT_CONDVAR(GameSettings, game_creation.custom_town_number,             SLE_UINT16,115, SL_MAX_VERSION, 0, 0,     1,                     1,    5000, 0, STR_NULL,                                 NULL),
 	 SDT_CONDVAR(GameSettings, construction.extra_tree_placement,             SLE_UINT8,132, SL_MAX_VERSION, 0,MS,     2,                     0,       2, 0, STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT,  NULL),
+	 SDT_CONDVAR(GameSettings, game_creation.custom_sea_level,                SLE_UINT8,149, SL_MAX_VERSION, 0, 0,     1,                     2,      90, 0, STR_NULL,                                 NULL),
 
  SDT_CONDOMANY(GameSettings, locale.currency,                               SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 0, CUSTOM_CURRENCY_ID, _locale_currencies, STR_NULL, RedrawScreen, NULL),
  SDT_CONDOMANY(GameSettings, locale.units,                                  SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 1, 2, _locale_units,                       STR_NULL, RedrawScreen, NULL),
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -647,7 +647,7 @@
 static void HeightMapAdjustWaterLevel(amplitude_t water_percent, height_t h_max_new)
 {
 	height_t h_min, h_max, h_avg, h_water_level;
-	int water_tiles, desired_water_tiles;
+	int64 water_tiles, desired_water_tiles;
 	height_t *h;
 	int *hist;
 
@@ -659,7 +659,7 @@
 	hist = HeightMapMakeHistogram(h_min, h_max, hist_buf);
 
 	/* How many water tiles do we want? */
-	desired_water_tiles = (int)(((int64)water_percent) * (int64)(_height_map.size_x * _height_map.size_y)) >> amplitude_decimal_bits;
+	desired_water_tiles = A2I(((int64)water_percent) * (int64)(_height_map.size_x * _height_map.size_y));
 
 	/* Raise water_level and accumulate values from histogram until we reach required number of water tiles */
 	for (h_water_level = h_min, water_tiles = 0; h_water_level < h_max; h_water_level++) {
@@ -847,7 +847,8 @@
  */
 static void HeightMapNormalize()
 {
-	const amplitude_t water_percent = _water_percent[_settings_game.difficulty.quantity_sea_lakes];
+	int sea_level_setting = _settings_game.difficulty.quantity_sea_lakes;
+	const amplitude_t water_percent = sea_level_setting != CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY ? _water_percent[sea_level_setting] : _settings_game.game_creation.custom_sea_level * 1024 / 100;
 	const height_t h_max_new = I2H(_max_height[_settings_game.difficulty.terrain_type]);
 	const height_t roughness = 7 + 3 * _settings_game.game_creation.tgen_smoothness;