summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-09-20 18:56:35 +0000
committerterkhen <terkhen@openttd.org>2010-09-20 18:56:35 +0000
commite90930e5722a43741deef77de9c562283549faf1 (patch)
tree113c2207950441246ceea53c85e7d3a1aacfc0f7 /src
parentb916c5d8c177526690489da4b758187184dff464 (diff)
downloadopenttd-e90930e5722a43741deef77de9c562283549faf1.tar.xz
(svn r20832) -Feature: Allow to select a custom percentage of water in the map generation window (based on patch by CommanderZ).
Diffstat (limited to 'src')
-rw-r--r--src/genworld.h4
-rw-r--r--src/genworld_gui.cpp29
-rw-r--r--src/lang/english.txt2
-rw-r--r--src/saveload/saveload.cpp3
-rw-r--r--src/settings_type.h1
-rw-r--r--src/table/settings.h3
-rw-r--r--src/tgp.cpp7
7 files changed, 41 insertions, 8 deletions
diff --git a/src/genworld.h b/src/genworld.h
index 2b701ad45..0fd6b4231 100644
--- a/src/genworld.h
+++ b/src/genworld.h
@@ -33,6 +33,10 @@ enum GenWorldMode {
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
diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp
index 053b59ec5..47efaa317 100644
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -331,7 +331,7 @@ static DropDownList *BuildMapsizeDropDown()
}
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 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
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 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
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 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
}
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 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
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();
diff --git a/src/lang/english.txt b/src/lang/english.txt
index edb604fba..4e9e97464 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1045,6 +1045,8 @@ STR_SEA_LEVEL_VERY_LOW :Very Low
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
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 903892faf..101cc412e 100644
--- 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
diff --git a/src/settings_type.h b/src/settings_type.h
index f353d6da2..e12507938 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -179,6 +179,7 @@ struct GameCreationSettings {
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 */
diff --git a/src/table/settings.h b/src/table/settings.h
index 52bff244f..579d2bb8f 100644
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -352,7 +352,7 @@ const SettingDesc _settings[] = {
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 @@ const SettingDesc _settings[] = {
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),
diff --git a/src/tgp.cpp b/src/tgp.cpp
index 368fd3af0..5e7bf6092 100644
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -647,7 +647,7 @@ static void HeightMapCurves(uint level)
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 @@ static void HeightMapAdjustWaterLevel(amplitude_t water_percent, height_t h_max_
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 HeightMapSmoothSlopes(height_t dh_max)
*/
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;