diff --git a/src/landscape.cpp b/src/landscape.cpp index b87e917a1e..51032adeb4 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1436,7 +1436,7 @@ static void CreateRivers() /** * Calculate what height would be needed to cover N% of the landmass. * - * The function allows both snow and desert/tropic line to be calculated. It + * The function allows snow, alpine tree line, and desert/tropic line to be calculated. It * tries to find the closests height which covers N% of the landmass; it can * be below or above it. * @@ -1536,6 +1536,14 @@ static void CalculateSnowLine() _settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u); } +/** + * Calculate the elevation line from which trees do not grow. + */ +void CalculateTreeLine() +{ + _settings_game.game_creation.tree_line_height = CalculateCoverageLine(_settings_game.game_creation.alpine_coverage, 0); +} + /** * Calculate the line (in height) between desert and tropic. * @return The height of the line between desert and tropic. @@ -1635,6 +1643,7 @@ bool GenerateLandscape(uint8_t mode) switch (_settings_game.game_creation.landscape) { case LT_ARCTIC: CalculateSnowLine(); + CalculateTreeLine(); break; case LT_TROPIC: { diff --git a/src/landscape.h b/src/landscape.h index 98221c5019..bb7c63eb2b 100644 --- a/src/landscape.h +++ b/src/landscape.h @@ -32,6 +32,7 @@ uint8_t GetSnowLine(); uint8_t HighestSnowLine(); uint8_t LowestSnowLine(); void ClearSnowLine(); +void CalculateTreeLine(); int GetSlopeZInCorner(Slope tileh, Corner corner); std::tuple GetFoundationSlope(TileIndex tile); diff --git a/src/lang/english.txt b/src/lang/english.txt index cbb10cf08b..d89f2d3d2b 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1567,6 +1567,10 @@ STR_CONFIG_SETTING_SNOW_COVERAGE :Snow coverage: STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT :Choose the approximate amount of snow on the sub-arctic landscape. Snow also affects industry generation and town growth requirements. Only used during map generation. Sea level and coast tiles never have snow STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE :{NUM}% +STR_CONFIG_SETTING_ALPINE_COVERAGE :Alpine coverage: {STRING2} +STR_CONFIG_SETTING_ALPINE_COVERAGE_HELPTEXT :Choose the approximate amount of alpine terrain on the sub-arctic landscape. Alpine terrain is above the elevation where trees grow +STR_CONFIG_SETTING_ALPINE_COVERAGE_VALUE :{NUM}% + STR_CONFIG_SETTING_DESERT_COVERAGE :Desert coverage: {STRING2} STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT :Choose the approximate amount of desert on the tropical landscape. Desert also affects industry generation and town growth requirements. Only used during map generation STR_CONFIG_SETTING_DESERT_COVERAGE_VALUE :{NUM}% @@ -5184,6 +5188,7 @@ STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE :{WHITE}Can't bu # Tree related errors STR_ERROR_TREE_ALREADY_HERE :{WHITE}... tree already here STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE :{WHITE}... wrong terrain for tree type +STR_ERROR_TREE_ABOVE_TREELINE :{WHITE}... can't plant trees above alpine tree line STR_ERROR_CAN_T_PLANT_TREE_HERE :{WHITE}Can't plant tree here... # Bridge related errors diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 6da28e6db5..d7d94afe2f 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2255,6 +2255,7 @@ static SettingsContainer &GetSettingsTree() { trees->Add(new SettingEntry("game_creation.tree_placer")); trees->Add(new SettingEntry("construction.extra_tree_placement")); + trees->Add(new SettingEntry("game_creation.alpine_coverage")); } } diff --git a/src/settings_type.h b/src/settings_type.h index 239a845a90..8107cff857 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -346,6 +346,8 @@ struct GameCreationSettings { uint8_t oil_refinery_limit; ///< distance oil refineries allowed from map edge uint8_t snow_line_height; ///< the configured snow line height (deduced from "snow_coverage") uint8_t snow_coverage; ///< the amount of snow coverage on the map + uint8_t tree_line_height; ///< the configured tree line height (deduced from "alpine_coverage") + uint8_t alpine_coverage; ///< the amount of alpine land on the map (no trees at high elevations) uint8_t desert_coverage; ///< the amount of desert coverage on the map uint8_t heightmap_height; ///< highest mountain for heightmap (towards what it scales) uint8_t tgen_smoothness; ///< how rough is the terrain from 0-3 diff --git a/src/table/settings/world_settings.ini b/src/table/settings/world_settings.ini index 6b5d1466e0..05e3ec850c 100644 --- a/src/table/settings/world_settings.ini +++ b/src/table/settings/world_settings.ini @@ -109,6 +109,19 @@ strhelp = STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT strval = STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE cat = SC_BASIC +[SDT_VAR] +var = game_creation.alpine_coverage +type = SLE_UINT8 +def = DEF_ALPINE_COVERAGE +min = 0 +max = 100 +interval = 10 +str = STR_CONFIG_SETTING_ALPINE_COVERAGE +strhelp = STR_CONFIG_SETTING_ALPINE_COVERAGE_HELPTEXT +strval = STR_CONFIG_SETTING_ALPINE_COVERAGE_VALUE +post_cb = [](auto) { CalculateTreeLine(); } +cat = SC_BASIC + [SDT_VAR] var = game_creation.desert_coverage type = SLE_UINT8 diff --git a/src/tile_type.h b/src/tile_type.h index d1a7a3eb93..cb9070d048 100644 --- a/src/tile_type.h +++ b/src/tile_type.h @@ -34,6 +34,7 @@ static const uint DEF_SNOWLINE_HEIGHT = 10; ///< Default snow static const uint MAX_SNOWLINE_HEIGHT = (MAX_TILE_HEIGHT - 2); ///< Maximum allowed snowline height static const uint DEF_SNOW_COVERAGE = 40; ///< Default snow coverage. +static const uint DEF_ALPINE_COVERAGE = 0; ///< Default alpine coverage. static const uint DEF_DESERT_COVERAGE = 50; ///< Default desert coverage. diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 1a58c6c2e1..070031220a 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -61,6 +61,7 @@ static const uint16_t EDITOR_TREE_DIV = 5; ///< Game editor tr /** * Tests if a tile can be converted to MP_TREES * This is true for clear ground without farms or rocks. + * This test also considers the tree line in the subarctic climate. * * @param tile the tile of interest * @param allow_desert Allow planting trees on CLEAR_DESERT? @@ -68,6 +69,9 @@ static const uint16_t EDITOR_TREE_DIV = 5; ///< Game editor tr */ static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert) { + /* Trees do not grow in alpine terrain, above the tree line. */ + if (_settings_game.game_creation.landscape == LT_ARCTIC && GetTileZ(tile) >= _settings_game.game_creation.tree_line_height) return false; + switch (GetTileType(tile)) { case MP_WATER: return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile)); @@ -436,6 +440,12 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti continue; } + /* Trees do not grow in alpine terrain, above the tree line. */ + if (_settings_game.game_creation.landscape == LT_ARCTIC && GetTileZ(current_tile) >= _settings_game.game_creation.tree_line_height) { + msg = STR_ERROR_TREE_ABOVE_TREELINE; + continue; + } + TreeType treetype = (TreeType)tree_to_plant; /* Be a bit picky about which trees go where. */ if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && (