28 #include "table/strings.h" 77 default:
return false;
115 default: NOT_REACHED();
118 MakeTree(tile, treetype, count, growth, ground, density);
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);
221 int x =
GB(r, 0, 5) - 16;
222 int y =
GB(r, 8, 5) - 16;
227 if (
abs(x) +
abs(y) > 16)
continue;
309 default: NOT_REACHED();
321 for (; i != 0; i--) {
339 const byte tree_to_plant =
GB(p1, 0, 8);
346 int limit = (c == NULL ? INT32_MAX :
GB(c->
tree_limit, 16, 16));
353 if (_game_mode != GM_EDITOR &&
GetTreeCount(tile) == 4) {
354 msg = STR_ERROR_TREE_ALREADY_HERE;
360 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
370 cost.
AddCost(_price[PR_BUILD_TREES] * 2);
375 msg = STR_ERROR_CAN_T_BUILD_ON_WATER;
382 msg = STR_ERROR_SITE_UNSUITABLE;
395 msg = STR_ERROR_TREE_WRONG_TERRAIN_FOR_TREE_TYPE;
401 msg = STR_ERROR_TREE_PLANT_LIMIT_REACHED;
411 if (ret.
Failed())
return ret;
422 if (t != NULL)
ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
425 if (flags & DC_EXEC) {
441 cost.
AddCost(_price[PR_BUILD_TREES]);
446 msg = STR_ERROR_SITE_UNSUITABLE;
451 if (limit < 0)
break;
465 static void DrawTile_Trees(
TileInfo *ti)
487 assert(index <
lengthof(_tree_layout_sprite));
490 const TreePos *d = _tree_layout_xy[
GB(tmp, 2, 2)];
500 for (uint i = 0; i < trees; i++) {
515 for (; trees > 0; trees--) {
516 uint
min = te[0].x + te[0].y;
519 for (uint i = 1; i < trees; i++) {
520 if ((uint)(te[i].x + te[i].y) < min) {
521 min = te[i].x + te[i].y;
526 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);
529 te[mi] = te[trees - 1];
536 static int GetSlopePixelZ_Trees(
TileIndex tile, uint x, uint y)
555 if (t != NULL)
ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
561 if (flags &
DC_EXEC) DoClearSquare(tile);
571 td->
str = STR_LAI_TREE_NAME_RAINFOREST;
573 td->
str = tt ==
TREE_CACTUS ? STR_LAI_TREE_NAME_CACTUS_PLANTS : STR_LAI_TREE_NAME_TREES;
579 static void TileLoopTreesDesert(
TileIndex tile)
590 static const SoundFx forest_sounds[] = {
606 static void TileLoopTreesAlps(
TileIndex tile)
617 uint density = min<uint>(k, 3);
628 SndPlayTileFx((r & 0x80000000) ? SND_39_HEAVY_WIND : SND_34_WIND, tile);
637 static void TileLoop_Trees(
TileIndex tile)
643 case LT_TROPIC: TileLoopTreesDesert(tile);
break;
644 case LT_ARCTIC: TileLoopTreesAlps(tile);
break;
673 switch (
GB(Random(), 0, 3)) {
791 void InitializeTrees()
804 GetSlopePixelZ_Trees,
808 GetTileTrackStatus_Trees,
812 ChangeTileOwner_Trees,
static const uint TREE_COUNT_TEMPERATE
number of tree types on a temperate map.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
uint32 PaletteID
The number of the palette.
#define RandomTile()
Get a valid random tile.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const uint TREE_COUNT_SUB_TROPICAL
number of tree types for the 'sub-tropic part' of a sub-tropic map.
void GenerateTrees()
Place new trees.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
static void AddTreeCounter(TileIndex t, int a)
Add a value on the tick counter of a tree-tile.
Tile information, used while rendering the tile.
static const uint TREE_COUNT_TOYLAND
number of tree types on a toyland map.
static void SetTreeCounter(TileIndex t, uint c)
Set the tick counter for a tree-tile.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
void PlaceTreesRandomly()
Place some trees randomly.
byte landscape
the landscape we're currently in
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
EconomySettings economy
settings to change the economy
ExtraTreePlacement
Where to place trees while in-game?
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
static uint GetTreeCounter(TileIndex t)
Get the tick counter of a tree tile.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
static void MakeShore(TileIndex t)
Helper function to make a coast tile.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Slope tileh
Slope of the 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...
A snow tile that is rough underneath.
byte tree_placer
the tree placer algorithm
static void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
static void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
Make a tree-tile.
Combination of a palette sprite and a 'real' sprite.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
A 'improved' algorithm.
Tile description for the 'land area information' tool.
bool ambient
Play ambient, industry and town sounds.
static const uint TREE_COUNT_RAINFOREST
number of tree types for the 'rainforest part' of a sub-tropic map.
TreePlacer
List of tree placer algorithm.
Map accessors for tree tiles.
byte dist_local_authority
distance for town local authority, default 20
Functions related to world/map generation.
Money GetCost() const
The costs as made up to this moment.
static TreeType GetTreeType(TileIndex t)
Returns the treetype of a tile.
Common return value for all commands.
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
static void AmbientSoundEffect(TileIndex tile)
Play an ambient sound effect for an empty tile.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Owner owner[4]
Name of the owner(s)
Direction
Defines the 8 directions on the map.
static uint GetTreeGrowth(TileIndex t)
Returns the tree growth status.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Functions related to (drawing on) viewports.
Pseudo random number generator.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
static void SetTreeGrowth(TileIndex t, uint g)
Sets the tree growth status of a tile.
uint x
X position of the tile in unit coordinates.
Foundation
Enumeration for Foundations.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
TileIndex tile
Tile index.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static bool IsCoast(TileIndex t)
Is it a coast tile?
SoundSettings sound
sound effect settings
Sprites to use and how to display them for tree tiles.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
No tree placer algorithm.
DoCommandFlag
List of flags for a command.
static TreeType GetRandomTreeType(TileIndex tile, uint seed)
Get a random TreeType for the given tile based on a given seed.
ClientSettings _settings_client
The current settings for this game.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
static const uint16 DEFAULT_RAINFOREST_TREE_STEPS
Default number of attempts for placing extra trees at rainforest in tropic.
A number of safeguards to prevent using unsafe methods.
static void PlaceTreeAtSameHeight(TileIndex tile, int height)
Place a tree at the same height as an existing tree.
static void PlaceTreeGroups(uint num_groups)
Creates a number of tree groups.
uint y
Y position of the tile in unit coordinates.
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
static bool IsSlopeWithOneCornerRaised(Slope s)
Tests if a specific slope has exactly one corner raised.
Represents the covered area of e.g.
Tables with sprites for clear land and fences.
static uint GetTreeDensity(TileIndex t)
Returns the 'density' of a tile with trees.
tree on a sub_arctic landscape
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
Creates a tree tile Ground type and density is preserved.
DiagDirection
Enumeration for diagonal directions.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
static ClearGround GetClearGround(TileIndex t)
Get the type of clear tile.
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
a desert or snow tile, depend on landscape
bool Failed() const
Did this command fail?
a cactus for the 'desert part' on a sub-tropical map
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.
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
#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. ...
Functions related to clear (MP_CLEAR) land.
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
static TileIndex RandomTileSeed(uint32 r)
Get a random tile out of a given seed.
execute the given command
static int GetSlopeMaxPixelZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height) ...
static void AddTreeCount(TileIndex t, int c)
Add a amount to the tree-count value of a tile with trees.
Functions related to companies.
static void PlaceTree(TileIndex tile, uint32 r)
Make a random tree tile of the given tile.
static uint MapSize()
Get the size of the map.
Functions related to generic callbacks.
Place trees on all tiles.
Place trees only on rainforest tiles.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
CompanyByte _current_company
Company currently doing an action.
Set of callback functions for performing tile operations of a given tile type.
uint32 TileIndex
The index/ID of a Tile.
Map accessors for 'clear' tiles.
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
static uint GetTreeCount(TileIndex t)
Returns the number of trees on a tile.
static void MakeSnow(TileIndex t, uint density=0)
Make a snow tile.
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
The tile has no foundation, the slope remains unchanged.
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
Slope
Enumeration for the slope-type.
Functions related to OTTD's landscape.
static TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
static uint CountBits(T value)
Counts the number of set bits in a variable.
Functions related to commands.
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.
TreeType
List of tree types along all landscape types.
byte GetSnowLine()
Get the current snow line, either variable or static.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
static void AddTreeGrowth(TileIndex t, int a)
Add a value to the tree growth status.
static uint SlopeToSpriteOffset(Slope s)
Returns the Sprite offset for a given Slope.
ConstructionSettings construction
construction of things in-game
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
StringID str
Description of the tile.
byte _trees_tick_ctr
Determines when to consider building more trees.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
GameCreationSettings game_creation
settings used during the creation of a game (map)
A tile without any structures, i.e. grass, rocks, farm fields etc.
tree on a sub-tropical map, non-rainforest, non-desert
TreeGround
Enumeration for ground types of tiles with trees.
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...
static const uint TREE_COUNT_SUB_ARCTIC
number of tree types on a sub arctic map.
Owner
Enum for all companies/owners.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
tree on the 'green part' on a sub-tropical map
Functions related to water (management)
SpriteID sprite
The 'real' sprite.
CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Plant a tree.
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
static T Delta(const T a, const T b)
Returns the (absolute) difference between two (scalar) variables.
static const uint16 EDITOR_TREE_DIV
Game editor tree generation divisor factor.
SoundFx
Sound effects from baseset.
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...
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 void SetTropicZone(TileIndex tile, TropicZone type)
Set the tropic zone.
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
Changes town rating of the current company.
uint8 extra_tree_placement
(dis)allow building extra trees in-game
static const uint16 DEFAULT_TREE_STEPS
Default number of attempts for placing trees.
PaletteID pal
The palette (use PAL_NONE) if not needed)