1
0
Fork 0

Feature: Alpine tree line in subarctic climate

pull/12774/head
Tyler Trahan 2024-06-09 15:36:02 -04:00
parent 59b92793a2
commit 7e9162f89d
8 changed files with 43 additions and 1 deletions

View File

@ -1436,7 +1436,7 @@ static void CreateRivers()
/** /**
* Calculate what height would be needed to cover N% of the landmass. * 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 * tries to find the closests height which covers N% of the landmass; it can
* be below or above it. * 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); _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. * Calculate the line (in height) between desert and tropic.
* @return The height of the line 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) { switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC: case LT_ARCTIC:
CalculateSnowLine(); CalculateSnowLine();
CalculateTreeLine();
break; break;
case LT_TROPIC: { case LT_TROPIC: {

View File

@ -32,6 +32,7 @@ uint8_t GetSnowLine();
uint8_t HighestSnowLine(); uint8_t HighestSnowLine();
uint8_t LowestSnowLine(); uint8_t LowestSnowLine();
void ClearSnowLine(); void ClearSnowLine();
void CalculateTreeLine();
int GetSlopeZInCorner(Slope tileh, Corner corner); int GetSlopeZInCorner(Slope tileh, Corner corner);
std::tuple<Slope, int> GetFoundationSlope(TileIndex tile); std::tuple<Slope, int> GetFoundationSlope(TileIndex tile);

View File

@ -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_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_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 :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_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}% 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 # Tree related errors
STR_ERROR_TREE_ALREADY_HERE :{WHITE}... tree already here 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_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... STR_ERROR_CAN_T_PLANT_TREE_HERE :{WHITE}Can't plant tree here...
# Bridge related errors # Bridge related errors

View File

@ -2255,6 +2255,7 @@ static SettingsContainer &GetSettingsTree()
{ {
trees->Add(new SettingEntry("game_creation.tree_placer")); trees->Add(new SettingEntry("game_creation.tree_placer"));
trees->Add(new SettingEntry("construction.extra_tree_placement")); trees->Add(new SettingEntry("construction.extra_tree_placement"));
trees->Add(new SettingEntry("game_creation.alpine_coverage"));
} }
} }

View File

@ -346,6 +346,8 @@ struct GameCreationSettings {
uint8_t oil_refinery_limit; ///< distance oil refineries allowed from map edge 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_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 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 desert_coverage; ///< the amount of desert coverage on the map
uint8_t heightmap_height; ///< highest mountain for heightmap (towards what it scales) uint8_t heightmap_height; ///< highest mountain for heightmap (towards what it scales)
uint8_t tgen_smoothness; ///< how rough is the terrain from 0-3 uint8_t tgen_smoothness; ///< how rough is the terrain from 0-3

View File

@ -109,6 +109,19 @@ strhelp = STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT
strval = STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE strval = STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE
cat = SC_BASIC 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] [SDT_VAR]
var = game_creation.desert_coverage var = game_creation.desert_coverage
type = SLE_UINT8 type = SLE_UINT8

View File

@ -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 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_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. static const uint DEF_DESERT_COVERAGE = 50; ///< Default desert coverage.

View File

@ -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 * Tests if a tile can be converted to MP_TREES
* This is true for clear ground without farms or rocks. * 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 tile the tile of interest
* @param allow_desert Allow planting trees on CLEAR_DESERT? * @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) 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)) { switch (GetTileType(tile)) {
case MP_WATER: case MP_WATER:
return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile)); return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile));
@ -436,6 +440,12 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
continue; 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; TreeType treetype = (TreeType)tree_to_plant;
/* Be a bit picky about which trees go where. */ /* Be a bit picky about which trees go where. */
if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && ( if (_settings_game.game_creation.landscape == LT_TROPIC && treetype != TREE_INVALID && (