OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
26 #include "table/strings.h"
76 default:
return false;
114 default: NOT_REACHED();
117 MakeTree(tile, treetype, count, growth, ground, density);
192 int x =
GB(r, 0, 5) - 16;
193 int y =
GB(r, 8, 5) - 16;
194 uint dist =
abs(x) +
abs(y);
204 }
while (--num_groups);
220 int x =
GB(r, 0, 5) - 16;
221 int y =
GB(r, 8, 5) - 16;
226 if (
abs(x) +
abs(y) > 16)
continue;
310 for (; count > 0; count--) {
312 auto mkcoord = [&]() -> int32 {
313 const uint32 rand = InteractiveRandom();
314 const int32 dist = GB<int32>(rand, 0, 8) + GB<int32>(rand, 8, 8) + GB<int32>(rand, 16, 8) + GB<int32>(rand, 24, 8);
315 const int32 scu = dist * radius / 512;
318 const int32 xofs = mkcoord();
319 const int32 yofs = mkcoord();
353 default: NOT_REACHED();
365 for (; i != 0; i--) {
383 const byte tree_to_plant =
GB(p1, 0, 8);
390 int limit = (c ==
nullptr ? INT32_MAX :
GB(c->
tree_limit, 16, 16));
398 msg = STR_ERROR_TREE_ALREADY_HERE;
404 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
414 cost.
AddCost(_price[PR_BUILD_TREES] * 2);
419 msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
426 msg = STR_ERROR_SITE_UNSUITABLE;
439 msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
445 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
455 if (ret.
Failed())
return ret;
466 if (t !=
nullptr)
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
485 cost.
AddCost(_price[PR_BUILD_TREES]);
490 msg = STR_ERROR_SITE_UNSUITABLE;
495 if (limit < 0)
break;
509 static void DrawTile_Trees(
TileInfo *ti)
531 assert(index <
lengthof(_tree_layout_sprite));
534 const TreePos *d = _tree_layout_xy[
GB(tmp, 2, 2)];
544 for (uint i = 0; i < trees; i++) {
559 for (; trees > 0; trees--) {
560 uint min = te[0].x + te[0].y;
563 for (uint i = 1; i < trees; i++) {
564 if ((uint)(te[i].x + te[i].y) < min) {
565 min = te[i].x + te[i].y;
570 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);
573 te[mi] = te[trees - 1];
580 static int GetSlopePixelZ_Trees(
TileIndex tile, uint x, uint y)
599 if (t !=
nullptr)
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
605 if (flags &
DC_EXEC) DoClearSquare(tile);
615 td->
str = STR_LAI_TREE_NAME_RAINFOREST;
617 td->
str = tt ==
TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
623 static void TileLoopTreesDesert(
TileIndex tile)
634 static const SoundFx forest_sounds[] = {
650 static void TileLoopTreesAlps(
TileIndex tile)
661 uint density = std::min<uint>(k, 3);
681 static bool CanPlantExtraTrees(
TileIndex tile)
688 static void TileLoop_Trees(
TileIndex tile)
694 case LT_TROPIC: TileLoopTreesDesert(tile);
break;
695 case LT_ARCTIC: TileLoopTreesAlps(tile);
break;
727 switch (
GB(Random(), 0, 3)) {
733 if (
GetTreeCount(tile) < 4 && CanPlantExtraTrees(tile)) {
741 if (!CanPlantExtraTrees(tile))
break;
765 if (!CanPlantExtraTrees(tile)) {
843 void InitializeTrees()
856 GetSlopePixelZ_Trees,
860 GetTileTrackStatus_Trees,
864 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.
uint32 TileIndex
The index/ID of a Tile.
@ TROPICZONE_DESERT
Tile is desert.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
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.
@ 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 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.
TransportType
Available types of transport.
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.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
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.
@ 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.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
SoundSettings sound
sound effect settings
byte _trees_tick_ctr
Determines when to consider building more trees.
@ ETP_NO_SPREAD
Grow trees on tiles that have them but don't spread to new ones.
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.
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...
Represents the covered area of e.g.
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.
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count)
Place some trees in a radius around a tile.
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.
Slope
Enumeration for the slope-type.
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
@ 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.
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.
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Plant a tree.
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.
@ 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.
#define lengthof(x)
Return the length of an fixed size array.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
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.
@ CMD_LANDSCAPE_CLEAR
demolish a tile
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.