Merge remote-tracking branch 'upstream/master'
This commit is contained in:
257
src/tree_cmd.cpp
257
src/tree_cmd.cpp
@@ -20,6 +20,7 @@
|
||||
#include "sound_func.h"
|
||||
#include "water.h"
|
||||
#include "company_base.h"
|
||||
#include "core/geometry_type.hpp"
|
||||
#include "core/random_func.hpp"
|
||||
#include "newgrf_generic.h"
|
||||
#include "timer/timer_game_tick.h"
|
||||
@@ -39,14 +40,14 @@
|
||||
*
|
||||
* This enumeration defines all possible tree placer algorithm in the game.
|
||||
*/
|
||||
enum TreePlacer {
|
||||
enum TreePlacer : uint8_t {
|
||||
TP_NONE, ///< No tree placer algorithm
|
||||
TP_ORIGINAL, ///< The original algorithm
|
||||
TP_IMPROVED, ///< A 'improved' algorithm
|
||||
};
|
||||
|
||||
/** Where to place trees while in-game? */
|
||||
enum ExtraTreePlacement {
|
||||
enum ExtraTreePlacement : uint8_t {
|
||||
ETP_NO_SPREAD, ///< Grow trees on tiles that have them but don't spread to new ones
|
||||
ETP_SPREAD_RAINFOREST, ///< Grow trees on tiles that have them, only spread to new ones in rainforests
|
||||
ETP_SPREAD_ALL, ///< Grow trees and spread them without restrictions
|
||||
@@ -75,7 +76,7 @@ static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
|
||||
return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile));
|
||||
|
||||
case MP_CLEAR:
|
||||
return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && GetRawClearGround(tile) != CLEAR_ROCKS &&
|
||||
return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && !IsClearGround(tile, CLEAR_ROCKS) &&
|
||||
(allow_desert || !IsClearGround(tile, CLEAR_DESERT));
|
||||
|
||||
default: return false;
|
||||
@@ -107,15 +108,20 @@ static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, Tree
|
||||
ClearNeighbourNonFloodingStates(tile);
|
||||
break;
|
||||
|
||||
case MP_CLEAR:
|
||||
switch (GetClearGround(tile)) {
|
||||
case CLEAR_GRASS: ground = TREE_GROUND_GRASS; break;
|
||||
case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break;
|
||||
case CLEAR_SNOW: ground = GetRawClearGround(tile) == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; break;
|
||||
default: ground = TREE_GROUND_SNOW_DESERT; break;
|
||||
case MP_CLEAR: {
|
||||
ClearGround clearground = GetClearGround(tile);
|
||||
if (IsSnowTile(tile)) {
|
||||
ground = clearground == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT;
|
||||
} else {
|
||||
switch (clearground) {
|
||||
case CLEAR_GRASS: ground = TREE_GROUND_GRASS; break;
|
||||
case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break;
|
||||
default: ground = TREE_GROUND_SNOW_DESERT; break;
|
||||
}
|
||||
}
|
||||
if (GetClearGround(tile) != CLEAR_ROUGH) density = GetClearDensity(tile);
|
||||
if (clearground != CLEAR_ROUGH) density = GetClearDensity(tile);
|
||||
break;
|
||||
}
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
@@ -137,13 +143,13 @@ static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, Tree
|
||||
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
|
||||
{
|
||||
switch (_settings_game.game_creation.landscape) {
|
||||
case LT_TEMPERATE:
|
||||
case LandscapeType::Temperate:
|
||||
return static_cast<TreeType>(seed * TREE_COUNT_TEMPERATE / 256 + TREE_TEMPERATE);
|
||||
|
||||
case LT_ARCTIC:
|
||||
case LandscapeType::Arctic:
|
||||
return static_cast<TreeType>(seed * TREE_COUNT_SUB_ARCTIC / 256 + TREE_SUB_ARCTIC);
|
||||
|
||||
case LT_TROPIC:
|
||||
case LandscapeType::Tropic:
|
||||
switch (GetTropicZone(tile)) {
|
||||
case TROPICZONE_NORMAL: return static_cast<TreeType>(seed * TREE_COUNT_SUB_TROPICAL / 256 + TREE_SUB_TROPICAL);
|
||||
case TROPICZONE_DESERT: return static_cast<TreeType>((seed > 12) ? TREE_INVALID : TREE_CACTUS);
|
||||
@@ -180,6 +186,110 @@ static void PlaceTree(TileIndex tile, uint32_t r)
|
||||
}
|
||||
}
|
||||
|
||||
struct BlobHarmonic {
|
||||
int amplitude;
|
||||
float phase;
|
||||
int frequency;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a star-shaped polygon originating from (0, 0) as defined by the given harmonics.
|
||||
* The shape is placed into a pre-allocated span so the caller controls allocation.
|
||||
* @param radius The maximum radius of the polygon. May be smaller, but will not be larger.
|
||||
* @param harmonics Harmonics data for the polygon.
|
||||
* @param[out] shape Shape to fill with points.
|
||||
*/
|
||||
static void CreateStarShapedPolygon(int radius, std::span<const BlobHarmonic> harmonics, std::span<Point> shape)
|
||||
{
|
||||
float theta = 0;
|
||||
float step = (M_PI * 2) / std::size(shape);
|
||||
|
||||
/* Divide a circle into a number of equally spaced divisions. */
|
||||
for (Point &vertex : shape) {
|
||||
|
||||
/* Add up the values of each harmonic at this segment.*/
|
||||
float deviation = std::accumulate(std::begin(harmonics), std::end(harmonics), 0.f, [theta](float d, const BlobHarmonic &harmonic) -> float {
|
||||
return d + sinf((theta + harmonic.phase) * harmonic.frequency) * harmonic.amplitude;
|
||||
});
|
||||
|
||||
/* Smooth out changes. */
|
||||
float adjusted_radius = (radius / 2.f) + (deviation / 2);
|
||||
|
||||
/* Add to the final polygon. */
|
||||
vertex.x = cosf(theta) * adjusted_radius;
|
||||
vertex.y = sinf(theta) * adjusted_radius;
|
||||
|
||||
/* Proceed to the next segment. */
|
||||
theta += step;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a random star-shaped polygon originating from (0, 0).
|
||||
* The shape is placed into a pre-allocated span so the caller controls allocation.
|
||||
* @param radius The maximum radius of the blob. May be smaller, but will not be larger.
|
||||
* @param[out] shape Shape to fill with polygon points.
|
||||
*/
|
||||
static void CreateRandomStarShapedPolygon(int radius, std::span<Point> shape)
|
||||
{
|
||||
/* Valid values for the phase of blob harmonics are between 0 and Tau. we can get a value in the correct range
|
||||
* from Random() by dividing the maximum possible value by the desired maximum, and then dividing the random
|
||||
* value by the result. */
|
||||
static constexpr float PHASE_DIVISOR = static_cast<float>(INT32_MAX / M_PI * 2);
|
||||
|
||||
/* These values are ones found in testing that result in suitable-looking polygons that did not self-intersect
|
||||
* and fit within a square of radius * radius dimensions. */
|
||||
std::initializer_list<BlobHarmonic> harmonics = {
|
||||
{radius / 2, Random() / PHASE_DIVISOR, 1},
|
||||
{radius / 4, Random() / PHASE_DIVISOR, 2},
|
||||
{radius / 8, Random() / PHASE_DIVISOR, 3},
|
||||
{radius / 16, Random() / PHASE_DIVISOR, 4},
|
||||
};
|
||||
|
||||
CreateStarShapedPolygon(radius, harmonics, shape);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given coordinates lie within a triangle.
|
||||
* @param x X coordinate relative to centre of shape.
|
||||
* @param y Y coordinate relative to centre of shape.
|
||||
* @param v1 First vertex of triangle.
|
||||
* @param v2 Second vertex of triangle.
|
||||
* @param v3 Third vertex of triangle.
|
||||
* @returns true if the given coordinates lie within a triangle.
|
||||
*/
|
||||
static bool IsPointInTriangle(int x, int y, const Point &v1, const Point &v2, const Point &v3)
|
||||
{
|
||||
const int s = ((v1.x - v3.x) * (y - v3.y)) - ((v1.y - v3.y) * (x - v3.x));
|
||||
const int t = ((v2.x - v1.x) * (y - v1.y)) - ((v2.y - v1.y) * (x - v1.x));
|
||||
|
||||
if ((s < 0) != (t < 0) && s != 0 && t != 0) return false;
|
||||
|
||||
const int d = (v3.x - v2.x) * (y - v2.y) - (v3.y - v2.y) * (x - v2.x);
|
||||
return (d < 0) == (s + t <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given coordinates lie within a star shaped polygon.
|
||||
* Breaks the polygon into a series of triangles around the centre point (0, 0) and then tests the coordinates against each triangle until a match is found (or not).
|
||||
* @param x X coordinate relative to centre of shape.
|
||||
* @param y Y coordinate relative to centre of shape.
|
||||
* @param shape The shape to check against.
|
||||
* @returns true if the given coordinates lie within the star shaped polygon.
|
||||
*/
|
||||
static bool IsPointInStarShapedPolygon(int x, int y, std::span<Point> shape)
|
||||
{
|
||||
for (auto it = std::begin(shape); it != std::end(shape); /* nothing */) {
|
||||
const Point &v1 = *it;
|
||||
++it;
|
||||
const Point &v2 = (it == std::end(shape)) ? shape.front() : *it;
|
||||
|
||||
if (IsPointInTriangle(x, y, v1, v2, {0, 0})) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a number of tree groups.
|
||||
* The number of trees in each group depends on how many trees are actually placed around the given tile.
|
||||
@@ -188,21 +298,30 @@ static void PlaceTree(TileIndex tile, uint32_t r)
|
||||
*/
|
||||
static void PlaceTreeGroups(uint num_groups)
|
||||
{
|
||||
static constexpr uint GROVE_SEGMENTS = 16; ///< How many segments make up the tree group.
|
||||
static constexpr uint GROVE_RADIUS = 16; ///< Maximum radius of tree groups.
|
||||
|
||||
/* Shape in which trees may be contained. Array is here to reduce allocations. */
|
||||
std::array<Point, GROVE_SEGMENTS> grove;
|
||||
|
||||
do {
|
||||
TileIndex center_tile = RandomTile();
|
||||
|
||||
for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
|
||||
uint32_t r = Random();
|
||||
int x = GB(r, 0, 5) - 16;
|
||||
int y = GB(r, 8, 5) - 16;
|
||||
uint dist = abs(x) + abs(y);
|
||||
TileIndex cur_tile = TileAddWrap(center_tile, x, y);
|
||||
CreateRandomStarShapedPolygon(GROVE_RADIUS, grove);
|
||||
|
||||
for (uint i = 0; i < DEFAULT_TREE_STEPS; i++) {
|
||||
IncreaseGeneratingWorldProgress(GWP_TREE);
|
||||
|
||||
if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
|
||||
PlaceTree(cur_tile, r);
|
||||
}
|
||||
uint32_t r = Random();
|
||||
int x = GB(r, 0, 5) - GROVE_RADIUS;
|
||||
int y = GB(r, 8, 5) - GROVE_RADIUS;
|
||||
TileIndex cur_tile = TileAddWrap(center_tile, x, y);
|
||||
|
||||
if (cur_tile == INVALID_TILE) continue;
|
||||
if (!CanPlantTreesOnTile(cur_tile, true)) continue;
|
||||
if (!IsPointInStarShapedPolygon(x, y, grove)) continue;
|
||||
|
||||
PlaceTree(cur_tile, r);
|
||||
}
|
||||
|
||||
} while (--num_groups);
|
||||
@@ -249,6 +368,7 @@ static void PlaceTreeAtSameHeight(TileIndex tile, int height)
|
||||
void PlaceTreesRandomly()
|
||||
{
|
||||
int i, j, ht;
|
||||
uint8_t max_height = _settings_game.construction.map_height_limit;
|
||||
|
||||
i = Map::ScaleBySize(DEFAULT_TREE_STEPS);
|
||||
if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
|
||||
@@ -269,7 +389,9 @@ void PlaceTreesRandomly()
|
||||
/* The higher we get, the more trees we plant */
|
||||
j = GetTileZ(tile) * 2;
|
||||
/* Above snowline more trees! */
|
||||
if (_settings_game.game_creation.landscape == LT_ARCTIC && ht > GetSnowLine()) j *= 3;
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Arctic && ht > GetSnowLine()) j *= 3;
|
||||
/* Scale generation by maximum map height. */
|
||||
if (max_height > MAP_HEIGHT_LIMIT_ORIGINAL) j = j * MAP_HEIGHT_LIMIT_ORIGINAL / max_height;
|
||||
while (j--) {
|
||||
PlaceTreeAtSameHeight(tile, ht);
|
||||
}
|
||||
@@ -277,7 +399,7 @@ void PlaceTreesRandomly()
|
||||
} while (--i);
|
||||
|
||||
/* place extra trees at rainforest area */
|
||||
if (_settings_game.game_creation.landscape == LT_TROPIC) {
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Tropic) {
|
||||
i = Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
|
||||
if (_game_mode == GM_EDITOR) i /= EDITOR_TREE_DIV;
|
||||
|
||||
@@ -360,15 +482,15 @@ void GenerateTrees()
|
||||
if (_settings_game.game_creation.tree_placer == TP_NONE) return;
|
||||
|
||||
switch (_settings_game.game_creation.tree_placer) {
|
||||
case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break;
|
||||
case TP_IMPROVED: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 4 : 2; break;
|
||||
case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LandscapeType::Arctic ? 15 : 6; break;
|
||||
case TP_IMPROVED: i = _settings_game.game_creation.landscape == LandscapeType::Arctic ? 4 : 2; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
total = Map::ScaleBySize(DEFAULT_TREE_STEPS);
|
||||
if (_settings_game.game_creation.landscape == LT_TROPIC) total += Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Tropic) total += Map::ScaleBySize(DEFAULT_RAINFOREST_TREE_STEPS);
|
||||
total *= i;
|
||||
uint num_groups = (_settings_game.game_creation.landscape != LT_TOYLAND) ? Map::ScaleBySize(GB(Random(), 0, 5) + 25) : 0;
|
||||
uint num_groups = (_settings_game.game_creation.landscape != LandscapeType::Toyland) ? Map::ScaleBySize(GB(Random(), 0, 5) + 25) : 0;
|
||||
total += num_groups * DEFAULT_TREE_STEPS;
|
||||
SetGeneratingWorldProgress(GWP_TREE, total);
|
||||
|
||||
@@ -388,14 +510,14 @@ void GenerateTrees()
|
||||
* @param diagonal Whether to use the Orthogonal (false) or Diagonal (true) iterator.
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, uint8_t tree_to_plant, bool diagonal)
|
||||
CommandCost CmdPlantTree(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, uint8_t tree_to_plant, bool diagonal)
|
||||
{
|
||||
StringID msg = INVALID_STRING_ID;
|
||||
CommandCost cost(EXPENSES_OTHER);
|
||||
|
||||
if (start_tile >= Map::Size()) return CMD_ERROR;
|
||||
/* Check the tree type within the current climate */
|
||||
if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
|
||||
if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[to_underlying(_settings_game.game_creation.landscape)], _tree_count_by_landscape[to_underlying(_settings_game.game_creation.landscape)])) return CMD_ERROR;
|
||||
|
||||
Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
|
||||
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
|
||||
@@ -417,7 +539,7 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
|
||||
break;
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
AddTreeCount(current_tile, 1);
|
||||
MarkTileDirtyByTile(current_tile);
|
||||
if (c != nullptr) c->tree_limit -= 1 << 16;
|
||||
@@ -441,12 +563,12 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
|
||||
|
||||
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 && (
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Tropic && treetype != TREE_INVALID && (
|
||||
/* No cacti outside the desert */
|
||||
(treetype == TREE_CACTUS && GetTropicZone(current_tile) != TROPICZONE_DESERT) ||
|
||||
/* No rain forest trees outside the rain forest, except in the editor mode where it makes those tiles rain forest tile */
|
||||
/* No rainforest trees outside the rainforest, except in the editor mode where it makes those tiles rainforest tile */
|
||||
(IsInsideMM(treetype, TREE_RAINFOREST, TREE_CACTUS) && GetTropicZone(current_tile) != TROPICZONE_RAINFOREST && _game_mode != GM_EDITOR) ||
|
||||
/* And no subtropical trees in the desert/rain forest */
|
||||
/* And no subtropical trees in the desert/rainforest */
|
||||
(IsInsideMM(treetype, TREE_SUB_TROPICAL, TREE_TOYLAND) && GetTropicZone(current_tile) != TROPICZONE_NORMAL))) {
|
||||
msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
|
||||
continue;
|
||||
@@ -460,12 +582,12 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
|
||||
|
||||
if (IsTileType(current_tile, MP_CLEAR)) {
|
||||
/* Remove fields or rocks. Note that the ground will get barrened */
|
||||
switch (GetRawClearGround(current_tile)) {
|
||||
switch (GetClearGround(current_tile)) {
|
||||
case CLEAR_FIELDS:
|
||||
case CLEAR_ROCKS: {
|
||||
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
cost.AddCost(ret.GetCost());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -478,7 +600,7 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti
|
||||
if (t != nullptr) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
if (treetype == TREE_INVALID) {
|
||||
treetype = GetRandomTreeType(current_tile, GB(Random(), 24, 8));
|
||||
if (treetype == TREE_INVALID) treetype = TREE_CACTUS;
|
||||
@@ -603,7 +725,7 @@ static Foundation GetFoundation_Trees(TileIndex, Slope)
|
||||
return FOUNDATION_NONE;
|
||||
}
|
||||
|
||||
static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
|
||||
static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlags flags)
|
||||
{
|
||||
uint num;
|
||||
|
||||
@@ -615,22 +737,22 @@ static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
|
||||
num = GetTreeCount(tile);
|
||||
if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
|
||||
|
||||
if (flags & DC_EXEC) DoClearSquare(tile);
|
||||
if (flags.Test(DoCommandFlag::Execute)) DoClearSquare(tile);
|
||||
|
||||
return CommandCost(EXPENSES_CONSTRUCTION, num * _price[PR_CLEAR_TREES]);
|
||||
}
|
||||
|
||||
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
|
||||
static void GetTileDesc_Trees(TileIndex tile, TileDesc &td)
|
||||
{
|
||||
TreeType tt = GetTreeType(tile);
|
||||
|
||||
if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) {
|
||||
td->str = STR_LAI_TREE_NAME_RAINFOREST;
|
||||
td.str = STR_LAI_TREE_NAME_RAINFOREST;
|
||||
} else {
|
||||
td->str = tt == TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
|
||||
td.str = tt == TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
|
||||
}
|
||||
|
||||
td->owner[0] = GetTileOwner(tile);
|
||||
td.owner[0] = GetTileOwner(tile);
|
||||
}
|
||||
|
||||
static void TileLoopTreesDesert(TileIndex tile)
|
||||
@@ -693,7 +815,7 @@ static void TileLoopTreesAlps(TileIndex tile)
|
||||
|
||||
static bool CanPlantExtraTrees(TileIndex tile)
|
||||
{
|
||||
return ((_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_RAINFOREST) ?
|
||||
return ((_settings_game.game_creation.landscape == LandscapeType::Tropic && GetTropicZone(tile) == TROPICZONE_RAINFOREST) ?
|
||||
(_settings_game.construction.extra_tree_placement == ETP_SPREAD_ALL || _settings_game.construction.extra_tree_placement == ETP_SPREAD_RAINFOREST) :
|
||||
_settings_game.construction.extra_tree_placement == ETP_SPREAD_ALL);
|
||||
}
|
||||
@@ -704,8 +826,9 @@ static void TileLoop_Trees(TileIndex tile)
|
||||
TileLoop_Water(tile);
|
||||
} else {
|
||||
switch (_settings_game.game_creation.landscape) {
|
||||
case LT_TROPIC: TileLoopTreesDesert(tile); break;
|
||||
case LT_ARCTIC: TileLoopTreesAlps(tile); break;
|
||||
case LandscapeType::Tropic: TileLoopTreesDesert(tile); break;
|
||||
case LandscapeType::Arctic: TileLoopTreesAlps(tile); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -733,7 +856,7 @@ static void TileLoop_Trees(TileIndex tile)
|
||||
|
||||
switch (GetTreeGrowth(tile)) {
|
||||
case TreeGrowthStage::Grown: // regular sized tree
|
||||
if (_settings_game.game_creation.landscape == LT_TROPIC &&
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Tropic &&
|
||||
GetTreeType(tile) != TREE_CACTUS &&
|
||||
GetTropicZone(tile) == TROPICZONE_DESERT) {
|
||||
AddTreeGrowth(tile, 1);
|
||||
@@ -796,7 +919,7 @@ static void TileLoop_Trees(TileIndex tile)
|
||||
break;
|
||||
}
|
||||
default: // snow or desert
|
||||
if (_settings_game.game_creation.landscape == LT_TROPIC) {
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Tropic) {
|
||||
MakeClear(tile, CLEAR_DESERT, GetTreeDensity(tile));
|
||||
} else {
|
||||
uint density = GetTreeDensity(tile);
|
||||
@@ -833,15 +956,29 @@ bool DecrementTreeCounter()
|
||||
return old_trees_tick_ctr <= _trees_tick_ctr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Place a random tree on a random tile.
|
||||
* @param rainforest If set the random tile must be in a rainforest zone.
|
||||
*/
|
||||
static void PlantRandomTree(bool rainforest)
|
||||
{
|
||||
uint32_t r = Random();
|
||||
TileIndex tile = RandomTileSeed(r);
|
||||
|
||||
if (rainforest && GetTropicZone(tile) != TROPICZONE_RAINFOREST) return;
|
||||
if (!CanPlantTreesOnTile(tile, false)) return;
|
||||
|
||||
TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
|
||||
if (tree == TREE_INVALID) return;
|
||||
|
||||
PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1);
|
||||
}
|
||||
|
||||
void OnTick_Trees()
|
||||
{
|
||||
/* Don't spread trees if that's not allowed */
|
||||
if (_settings_game.construction.extra_tree_placement == ETP_NO_SPREAD || _settings_game.construction.extra_tree_placement == ETP_NO_GROWTH_NO_SPREAD) return;
|
||||
|
||||
uint32_t r;
|
||||
TileIndex tile;
|
||||
TreeType tree;
|
||||
|
||||
/* Skip some tree ticks for map sizes below 256 * 256. 64 * 64 is 16 times smaller, so
|
||||
* this is the maximum number of ticks that are skipped. Number of ticks to skip is
|
||||
* inversely proportional to map size, so that is handled to create a mask. */
|
||||
@@ -849,24 +986,16 @@ void OnTick_Trees()
|
||||
if (skip < 16 && (TimerGameTick::counter & (16 / skip - 1)) != 0) return;
|
||||
|
||||
/* place a tree at a random rainforest spot */
|
||||
if (_settings_game.game_creation.landscape == LT_TROPIC) {
|
||||
if (_settings_game.game_creation.landscape == LandscapeType::Tropic) {
|
||||
for (uint c = Map::ScaleBySize(1); c > 0; c--) {
|
||||
if ((r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
|
||||
CanPlantTreesOnTile(tile, false) &&
|
||||
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
|
||||
PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1);
|
||||
}
|
||||
PlantRandomTree(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!DecrementTreeCounter() || _settings_game.construction.extra_tree_placement == ETP_SPREAD_RAINFOREST) return;
|
||||
|
||||
/* place a tree at a random spot */
|
||||
r = Random();
|
||||
tile = RandomTileSeed(r);
|
||||
if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
|
||||
PlantTreesOnTile(tile, tree, 0, TreeGrowthStage::Growing1);
|
||||
}
|
||||
PlantRandomTree(false);
|
||||
}
|
||||
|
||||
static TrackStatus GetTileTrackStatus_Trees(TileIndex, TransportType, uint, DiagDirection)
|
||||
@@ -884,7 +1013,7 @@ void InitializeTrees()
|
||||
_trees_tick_ctr = 0;
|
||||
}
|
||||
|
||||
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, int, Slope)
|
||||
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlags flags, int, Slope)
|
||||
{
|
||||
return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user