Go to the documentation of this file.
29 #include "table/strings.h"
79 default:
return false;
117 default: NOT_REACHED();
120 MakeTree(tile, treetype, count, growth, ground, density);
196 int x =
GB(r, 0, 5) - 16;
197 int y =
GB(r, 8, 5) - 16;
198 uint dist =
abs(x) +
abs(y);
208 }
while (--num_groups);
224 int x =
GB(r, 0, 5) - 16;
225 int y =
GB(r, 8, 5) - 16;
230 if (
abs(x) +
abs(y) > 16)
continue;
315 for (; count > 0; count--) {
317 auto mkcoord = [&]() -> int32 {
318 const uint32 rand = InteractiveRandom();
319 const int32 dist = GB<int32>(rand, 0, 8) + GB<int32>(rand, 8, 8) + GB<int32>(rand, 16, 8) + GB<int32>(rand, 24, 8);
320 const int32 scu = dist * radius / 512;
323 const int32 xofs = mkcoord();
324 const int32 yofs = mkcoord();
364 default: NOT_REACHED();
376 for (; i != 0; i--) {
400 int limit = (c ==
nullptr ? INT32_MAX :
GB(c->
tree_limit, 16, 16));
409 msg = STR_ERROR_TREE_ALREADY_HERE;
415 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
425 cost.
AddCost(_price[PR_BUILD_TREES] * 2);
430 msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
437 msg = STR_ERROR_SITE_UNSUITABLE;
450 msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
456 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
466 if (ret.
Failed())
return ret;
477 if (t !=
nullptr)
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
487 PlantTreesOnTile(current_tile, treetype, 0, _game_mode == GM_EDITOR ? 3 : 0);
496 cost.
AddCost(_price[PR_BUILD_TREES]);
501 msg = STR_ERROR_SITE_UNSUITABLE;
506 if (limit < 0)
break;
520 static void DrawTile_Trees(
TileInfo *ti)
542 assert(index <
lengthof(_tree_layout_sprite));
545 const TreePos *d = _tree_layout_xy[
GB(tmp, 2, 2)];
555 for (uint i = 0; i < trees; i++) {
570 for (; trees > 0; trees--) {
571 uint min = te[0].x + te[0].y;
574 for (uint i = 1; i < trees; i++) {
575 if ((uint)(te[i].x + te[i].y) < min) {
576 min = te[i].x + te[i].y;
581 AddSortableSpriteToDraw(te[mi].sprite, te[mi].pal, ti->
x + te[mi].x, ti->
y + te[mi].y, 16 - te[mi].x, 16 - te[mi].y, 0x30, z,
IsTransparencySet(
TO_TREES), -te[mi].x, -te[mi].y);
584 te[mi] = te[trees - 1];
591 static int GetSlopePixelZ_Trees(
TileIndex tile, uint x, uint y)
610 if (t !=
nullptr)
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
616 if (flags &
DC_EXEC) DoClearSquare(tile);
626 td->
str = STR_LAI_TREE_NAME_RAINFOREST;
628 td->
str = tt ==
TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
634 static void TileLoopTreesDesert(
TileIndex tile)
645 static const SoundFx forest_sounds[] = {
661 static void TileLoopTreesAlps(
TileIndex tile)
672 uint density = std::min<uint>(k, 3);
692 static bool CanPlantExtraTrees(
TileIndex tile)
699 static void TileLoop_Trees(
TileIndex tile)
705 case LT_TROPIC: TileLoopTreesDesert(tile);
break;
706 case LT_ARCTIC: TileLoopTreesAlps(tile);
break;
738 switch (
GB(Random(), 0, 3)) {
744 if (
GetTreeCount(tile) < 4 && CanPlantExtraTrees(tile)) {
752 if (!CanPlantExtraTrees(tile))
break;
776 if (!CanPlantExtraTrees(tile)) {
846 if (skip < 16 && (
_tick_counter & (16 / skip - 1)) != 0)
return;
879 void InitializeTrees()
892 GetSlopePixelZ_Trees,
896 GetTileTrackStatus_Trees,
900 ChangeTileOwner_Trees,
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
static TreeType GetTreeType(TileIndex t)
Returns the treetype of a tile.
@ TROPICZONE_DESERT
Tile is desert.
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Iterator to iterate over a diagonal area of the map.
static void PlaceTreeAtSameHeight(TileIndex tile, int height)
Place a tree at the same height as an existing tree.
Direction
Defines the 8 directions on the map.
void GenerateTrees()
Place new trees.
@ TP_NONE
No tree placer algorithm.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
uint8 extra_tree_placement
(dis)allow building extra trees in-game
uint x
X position of the tile in unit coordinates.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Tile information, used while rendering the tile.
byte landscape
the landscape we're currently in
static uint GetTreeGrowth(TileIndex t)
Returns the tree growth status.
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
@ EXPENSES_OTHER
Other expenses.
ExtraTreePlacement
Where to place trees while in-game?
Owner owner[4]
Name of the owner(s)
static void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
static void SetTreeGrowth(TileIndex t, uint g)
Sets the tree growth status of a tile.
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
@ TREE_RAINFOREST
tree on the 'green part' on a sub-tropical map
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
@ SND_44_RAINFOREST_3
68 == 0x44 Tree ambient: rainforest ambient (3): monkeys
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
@ TROPICZONE_RAINFOREST
Rainforest tile.
SpriteID sprite
The 'real' sprite.
static uint GetTreeDensity(TileIndex t)
Returns the 'density' of a tile with trees.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
static const uint16 DEFAULT_TREE_STEPS
Default number of attempts for placing trees.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
uint y
Y position of the tile in unit coordinates.
ClientSettings _settings_client
The current settings for this game.
static bool IsCoast(TileIndex t)
Is it a coast tile?
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
static const uint TREE_COUNT_TEMPERATE
number of tree types on a temperate map.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
@ SND_39_ARCTIC_SNOW_2
57 == 0x39 Tree ambient: arctic snow (2): heavy wind
Tile description for the 'land area information' tool.
static const uint16 EDITOR_TREE_DIV
Game editor tree generation divisor factor.
DoCommandFlag
List of flags for a command.
Foundation
Enumeration for Foundations.
void PlaceTreesRandomly()
Place some trees randomly.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
static ClearGround GetClearGround(TileIndex t)
Get the type of clear tile.
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
static void SetTreeCounter(TileIndex t, uint c)
Set the tick counter for a tree-tile.
static uint CountBits(T value)
Counts the number of set bits in a variable.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static uint GetTreeCounter(TileIndex t)
Get the tick counter of a tree tile.
Slope tileh
Slope of the tile.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
bool ambient
Play ambient, industry and town sounds.
static uint GetTreeCount(TileIndex t)
Returns the number of trees on a tile.
Slope
Enumeration for the slope-type.
Iterator to iterate over a tile area (rectangle) of the map.
@ TREE_GROUND_ROUGH
some rough tile
@ TREE_SUB_ARCTIC
tree on a sub_arctic landscape
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
static uint MapSize()
Get the size of the map.
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
@ EXPENSES_CONSTRUCTION
Construction costs.
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Common return value for all commands.
byte GetSnowLine()
Get the current snow line, either variable or static.
static void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
SoundSettings sound
sound effect settings
byte _trees_tick_ctr
Determines when to consider building more trees.
Base class for tile iterators.
@ ETP_NO_SPREAD
Grow trees on tiles that have them but don't spread to new ones.
TransportType
Available types of transport.
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
@ TREE_CACTUS
a cactus for the 'desert part' on a sub-tropical map
bool Failed() const
Did this command fail?
@ ETP_SPREAD_RAINFOREST
Grow trees on tiles that have them, only spread to new ones in rainforests.
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
Place some trees in a radius around a tile.
static void PlaceTree(TileIndex tile, uint32 r)
Make a random tree tile of the given tile.
static void PlaceTreeGroups(uint num_groups)
Creates a number of tree groups.
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
@ TREE_INVALID
An invalid tree.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ TP_IMPROVED
A 'improved' algorithm.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
EconomySettings economy
settings to change the economy
static TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Money GetCost() const
The costs as made up to this moment.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
#define RandomTile()
Get a valid random tile.
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
@ TREE_TOYLAND
tree on a toyland map
@ SND_34_ARCTIC_SNOW_1
52 == 0x34 Tree ambient: arctic snow (1): wind
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
DiagDirection
Enumeration for diagonal directions.
@ ETP_NO_GROWTH_NO_SPREAD
Don't grow trees and don't spread them at all.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Set of callback functions for performing tile operations of a given tile type.
SoundFx
Sound effects from baseset.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
@ TREE_GROUND_GRASS
normal grass
@ ETP_SPREAD_ALL
Grow trees and spread them without restrictions.
@ MP_TREES
Tile got trees.
byte dist_local_authority
distance for town local authority, default 20
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
@ TREE_SUB_TROPICAL
tree on a sub-tropical map, non-rainforest, non-desert
static const uint TREE_COUNT_RAINFOREST
number of tree types for the 'rainforest part' of a sub-tropic map.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CompanyID _current_company
Company currently doing an action.
TreeGround
Enumeration for ground types of tiles with trees.
static const uint TREE_COUNT_TOYLAND
number of tree types on a toyland map.
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
Get a random TreeType for the given tile based on a given seed.
static void MakeSnow(TileIndex t, uint density=0)
Make a snow tile.
static uint ScaleByMapSize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
static void AddTreeGrowth(TileIndex t, int a)
Add a value to the tree growth status.
@ MP_VOID
Invisible tiles at the SW and SE border.
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
static const uint TREE_COUNT_SUB_TROPICAL
number of tree types for the 'sub-tropic part' of a sub-tropic map.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
TreePlacer
List of tree placer algorithm.
static const uint16 DEFAULT_RAINFOREST_TREE_STEPS
Default number of attempts for placing extra trees at rainforest in tropic.
uint32 PaletteID
The number of the palette.
static int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
@ TP_ORIGINAL
The original algorithm.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
static void AddTreeCount(TileIndex t, int c)
Add a amount to the tree-count value of a tile with trees.
static void MakeShore(TileIndex t)
Helper function to make a coast tile.
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
Creates a tree tile Ground type and density is preserved.
StringID str
Description of the tile.
Combination of a palette sprite and a 'real' sprite.
bool DecrementTreeCounter()
Decrement the tree tick counter.
@ SND_48_RAINFOREST_4
72 == 0x48 Tree ambient: rainforest ambient (4): bird (2)
static void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
Make a tree-tile.
static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
Tests if a tile can be converted to MP_TREES This is true for clear ground without farms or rocks.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
#define lengthof(x)
Return the length of an fixed size array.
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, byte tree_to_plant, bool diagonal)
Plant a tree.
byte tree_placer
the tree placer algorithm
@ TREE_TEMPERATE
temperate tree
static void AddTreeCounter(TileIndex t, int a)
Add a value on the tick counter of a tree-tile.
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
PaletteID pal
The palette (use PAL_NONE) if not needed)
TileIndex tile
Tile index.
@ SND_42_RAINFOREST_1
66 == 0x42 Tree ambient: rainforest ambient (1): bird (1)
ConstructionSettings construction
construction of things in-game
static const uint TREE_COUNT_SUB_ARCTIC
number of tree types on a sub arctic map.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ SND_43_RAINFOREST_2
67 == 0x43 Tree ambient: rainforest ambient (2): lion
@ TROPICZONE_NORMAL
Normal tropiczone.
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
uint64 _tick_counter
Ever incrementing tick counter for setting off various events.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
static TileIndex RandomTileSeed(uint32 r)
Get a random tile out of a given seed.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
TreeType
List of tree types along all landscape types.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
static void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
@ GWP_TREE
Generate trees.
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.