summaryrefslogtreecommitdiff
path: root/src/genworld.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-03-24 10:29:01 +0100
committerPatric Stout <github@truebrain.nl>2021-03-26 12:22:32 +0100
commit422e132845255264314cd79aa14361d0df0905d7 (patch)
tree21452e883fa2a1bec4280625fb0ce7a6dfb168b8 /src/genworld.cpp
parent1a1049bc0db4e29402e950e56f3a6873c1f5a0ab (diff)
downloadopenttd-422e132845255264314cd79aa14361d0df0905d7.tar.xz
Feature: auto-detect map height limit based on generated map
This opens up the true power of the TGP terrain generator, as it is no longer constrainted by an arbitrary low map height limit, especially for extreme terrain types. In other words: on a 1kx1k map with "Alpinist" terrain type, the map is now really hilly with default settings. People can still manually limit the map height if they so wish, and after the terrain generation the limit is stored in the savegame as if the user set it. Cheats still allow you to change this value.
Diffstat (limited to 'src/genworld.cpp')
-rw-r--r--src/genworld.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/genworld.cpp b/src/genworld.cpp
index 0bd64f896..d357a1516 100644
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -33,6 +33,7 @@
#include "game/game_instance.hpp"
#include "string_func.h"
#include "thread.h"
+#include "tgp.h"
#include "safeguards.h"
@@ -285,6 +286,20 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
InitializeGame(_gw.size_x, _gw.size_y, true, reset_settings);
PrepareGenerateWorldProgress();
+ if (_settings_game.construction.map_height_limit == 0) {
+ uint estimated_height = 0;
+
+ if (_gw.mode == GWM_EMPTY && _game_mode != GM_MENU) {
+ estimated_height = _settings_game.game_creation.se_flat_world_height;
+ } else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
+ estimated_height = GetEstimationTGPMapHeight();
+ } else {
+ estimated_height = 0;
+ }
+
+ _settings_game.construction.map_height_limit = std::max(MAP_HEIGHT_LIMIT_AUTO_MINIMUM, std::min(MAX_MAP_HEIGHT_LIMIT, estimated_height + MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM));
+ }
+
/* Load the right landscape stuff, and the NewGRFs! */
GfxLoadSprites();
LoadStringWidthTable();