OpenTTD Source
20240917-master-g9ab0a47812
|
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);
192 uint32_t r = Random();
193 int x =
GB(r, 0, 5) - 16;
194 int y =
GB(r, 8, 5) - 16;
195 uint dist =
abs(x) +
abs(y);
205 }
while (--num_groups);
220 uint32_t r = Random();
221 int x =
GB(r, 0, 5) - 16;
222 int y =
GB(r, 8, 5) - 16;
227 if (
abs(x) +
abs(y) > 16)
continue;
253 uint32_t r = Random();
282 uint32_t r = Random();
308 assert(_game_mode == GM_EDITOR);
313 for (; count > 0; count--) {
315 auto mkcoord = [&]() -> int32_t {
316 const uint32_t rand = InteractiveRandom();
317 const int32_t dist = GB<int32_t>(rand, 0, 8) + GB<int32_t>(rand, 8, 8) + GB<int32_t>(rand, 16, 8) + GB<int32_t>(rand, 24, 8);
318 const int32_t scu = dist * radius / 512;
321 const int32_t xofs = mkcoord();
322 const int32_t yofs = mkcoord();
362 default: NOT_REACHED();
374 for (; i != 0; i--) {
398 int limit = (c ==
nullptr ? INT32_MAX :
GB(c->
tree_limit, 16, 16));
407 msg = STR_ERROR_TREE_ALREADY_HERE;
413 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
423 cost.
AddCost(_price[PR_BUILD_TREES] * 2);
428 msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
435 msg = STR_ERROR_SITE_UNSUITABLE;
448 msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
454 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
464 if (ret.
Failed())
return ret;
475 if (t !=
nullptr)
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
494 cost.
AddCost(_price[PR_BUILD_TREES]);
499 msg = STR_ERROR_SITE_UNSUITABLE;
504 if (limit < 0)
break;
518 static void DrawTile_Trees(
TileInfo *ti)
540 assert(index <
lengthof(_tree_layout_sprite));
543 const TreePos *d = _tree_layout_xy[
GB(tmp, 2, 2)];
553 for (uint i = 0; i < trees; i++) {
568 for (; trees > 0; trees--) {
569 uint min = te[0].x + te[0].y;
572 for (uint i = 1; i < trees; i++) {
573 if ((uint)(te[i].x + te[i].y) < min) {
574 min = te[i].x + te[i].y;
579 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);
582 te[mi] = te[trees - 1];
589 static int GetSlopePixelZ_Trees(
TileIndex tile, uint x, uint y,
bool)
607 if (t !=
nullptr)
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
613 if (flags &
DC_EXEC) DoClearSquare(tile);
623 td->
str = STR_LAI_TREE_NAME_RAINFOREST;
625 td->
str = tt ==
TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
631 static void TileLoopTreesDesert(
TileIndex tile)
642 static const SoundFx forest_sounds[] = {
648 uint32_t r = Random();
658 static void TileLoopTreesAlps(
TileIndex tile)
669 uint density = std::min<uint>(k, 3);
678 uint32_t r = Random();
689 static bool CanPlantExtraTrees(
TileIndex tile)
696 static void TileLoop_Trees(
TileIndex tile)
702 case LT_TROPIC: TileLoopTreesDesert(tile);
break;
703 case LT_ARCTIC: TileLoopTreesAlps(tile);
break;
726 static const uint32_t TREE_UPDATE_FREQUENCY = 16;
727 if (cycle % TREE_UPDATE_FREQUENCY != TREE_UPDATE_FREQUENCY - 1)
return;
736 switch (
GB(Random(), 0, 3)) {
742 if (
GetTreeCount(tile) < 4 && CanPlantExtraTrees(tile)) {
750 if (!CanPlantExtraTrees(tile))
break;
774 if (!CanPlantExtraTrees(tile)) {
877 void InitializeTrees()
890 GetSlopePixelZ_Trees,
894 GetTileTrackStatus_Trees,
898 ChangeTileOwner_Trees,
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
@ TROPICZONE_DESERT
Tile is desert.
bool Chance16I(const uint32_t a, const uint32_t b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
static void PlaceTreeAtSameHeight(TileIndex tile, int height)
Place a tree at the same height as an existing tree.
void GenerateTrees()
Place new trees.
@ TP_NONE
No tree placer algorithm.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void MakeSnow(Tile t, uint density=0)
Make a snow tile.
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.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
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.
uint GetTreeCount(Tile t)
Returns the number of trees on a tile.
ExtraTreePlacement
Where to place trees while in-game?
Owner owner[4]
Name of the owner(s)
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
void AddTreeGrowth(Tile t, int a)
Add a value to the tree growth stage.
@ TREE_RAINFOREST
tree on the 'green part' on a sub-tropical map
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
@ SND_44_RAINFOREST_3
68 == 0x44 Tree ambient: rainforest ambient (3): monkeys
Owner
Enum for all companies/owners.
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...
@ DIR_END
Used to iterate.
@ TROPICZONE_RAINFOREST
Rainforest tile.
SpriteID sprite
The 'real' sprite.
void AddTreeCount(Tile t, int c)
Add a amount to the tree-count value of a tile with trees.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
DiagDirection
Enumeration for diagonal directions.
ClientSettings _settings_client
The current settings for this game.
int y
Y position of the tile in unit coordinates.
static const uint TREE_COUNT_TEMPERATE
number of tree types on a temperate map.
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
@ DC_EXEC
execute the given command
@ SND_39_ARCTIC_SNOW_2
57 == 0x39 Tree ambient: arctic snow (2): heavy wind
uint32_t PaletteID
The number of the palette.
void MakeTree(Tile t, TreeType type, uint count, TreeGrowthStage growth, TreeGround ground, uint density)
Make a tree-tile.
uint8_t landscape
the landscape we're currently in
Tile description for the 'land area information' tool.
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.
GameCreationSettings game_creation
settings used during the creation of a game (map)
bool IsCoast(Tile t)
Is it a coast tile?
Slope tileh
Slope of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
bool ambient
Play ambient, industry and town sounds.
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...
TransportType
Available types of transport.
@ TREE_GROUND_ROUGH
some rough tile
TreeGrowthStage
Enumeration for tree growth stages.
constexpr 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_SUB_ARCTIC
tree on a sub_arctic landscape
static const uint16_t EDITOR_TREE_DIV
Game editor tree generation divisor factor.
uint8_t dist_local_authority
distance for town local authority, default 20
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
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.
uint32_t tree_limit
Amount of trees we can (still) plant (times 65536).
@ Growing1
First stage of growth.
SoundSettings sound
sound effect settings
static constexpr int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
@ ETP_NO_SPREAD
Grow trees on tiles that have them but don't spread to new ones.
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, TreeGrowthStage growth)
Creates a tree tile Ground type and density is preserved.
@ TREE_CACTUS
a cactus for the 'desert part' on a sub-tropical map
ClearGround GetRawClearGround(Tile t)
Get the type of clear tile but never return CLEAR_SNOW.
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
bool Failed() const
Did this command fail?
@ ETP_SPREAD_RAINFOREST
Grow trees on tiles that have them, only spread to new ones in rainforests.
CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, uint8_t tree_to_plant, bool diagonal)
Plant a tree.
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
Place some trees in a radius around a tile.
static void PlaceTreeGroups(uint num_groups)
Creates a number of tree groups.
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.
EconomySettings economy
settings to change the economy
#define lengthof(array)
Return the length of an fixed size array.
Money GetCost() const
The costs as made up to this moment.
#define RandomTile()
Get a valid random tile.
uint8_t _trees_tick_ctr
Determines when to consider building more trees.
Owner GetTileOwner(Tile tile)
Returns the owner of a 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.
@ 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.
void SetTreeGroundDensity(Tile t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Set of callback functions for performing tile operations of a given tile type.
SoundFx
Sound effects from baseset.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
@ EXPENSES_OTHER
Other expenses.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
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.
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.
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.
uint8_t tree_placer
the tree placer algorithm
void SetTreeGrowth(Tile t, TreeGrowthStage g)
Sets the tree growth stage of a tile.
@ 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.
Slope
Enumeration for the slope-type.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
static debug_inline uint Size()
Get the size of the map.
void MakeShore(Tile t)
Helper function to make a coast tile.
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.
@ TP_ORIGINAL
The original algorithm.
static void PlaceTree(TileIndex tile, uint32_t r)
Make a random tree tile of the given tile.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Direction
Defines the 8 directions on the map.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
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 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.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
static const uint16_t DEFAULT_TREE_STEPS
Default number of attempts for placing trees.
constexpr T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
TreeGrowthStage GetTreeGrowth(Tile t)
Returns the tree growth stage.
@ TREE_TEMPERATE
temperate tree
int x
X position of the tile in unit coordinates.
@ 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.
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
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
TreeType GetTreeType(Tile t)
Returns the treetype of a tile.
@ TROPICZONE_NORMAL
Normal tropiczone.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
void SetTropicZone(Tile tile, TropicZone type)
Set the tropic zone.
uint8_t extra_tree_placement
(dis)allow building extra trees in-game
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
uint GetTreeDensity(Tile t)
Returns the 'density' of a tile with trees.
TileIndex RandomTileSeed(uint32_t r)
Get a random tile out of a given seed.
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 const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static const uint16_t DEFAULT_RAINFOREST_TREE_STEPS
Default number of attempts for placing extra trees at rainforest in tropic.
TreeType
List of tree types along all landscape types.
@ GWP_TREE
Generate trees.
@ EXPENSES_CONSTRUCTION
Construction costs.
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.