2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file tree_map.h Map accessors for tree tiles. */
14 #include "water_map.h"
17 * List of tree types along all landscape types.
19 * This enumeration contains a list of the different tree types along
20 * all landscape types. The values for the enumerations may be used for
21 * offsets from the grfs files. These points to the start of
22 * the tree list for a landscape. See the TREE_COUNT_* enumerations
23 * for the amount of different trees for a specific landscape.
26 TREE_TEMPERATE
= 0x00, ///< temperate tree
27 TREE_SUB_ARCTIC
= 0x0C, ///< tree on a sub_arctic landscape
28 TREE_RAINFOREST
= 0x14, ///< tree on the 'green part' on a sub-tropical map
29 TREE_CACTUS
= 0x1B, ///< a cactus for the 'desert part' on a sub-tropical map
30 TREE_SUB_TROPICAL
= 0x1C, ///< tree on a sub-tropical map, non-rainforest, non-desert
31 TREE_TOYLAND
= 0x20, ///< tree on a toyland map
32 TREE_INVALID
= 0xFF, ///< An invalid tree
35 /* Counts the number of tree types for each landscape.
37 * This list contains the counts of different tree types for each landscape. This list contains
38 * 5 entries instead of 4 (as there are only 4 landscape types) as the sub tropic landscape
39 * has two types of area, one for normal trees and one only for cacti.
41 static const uint TREE_COUNT_TEMPERATE
= TREE_SUB_ARCTIC
- TREE_TEMPERATE
; ///< number of tree types on a temperate map.
42 static const uint TREE_COUNT_SUB_ARCTIC
= TREE_RAINFOREST
- TREE_SUB_ARCTIC
; ///< number of tree types on a sub arctic map.
43 static const uint TREE_COUNT_RAINFOREST
= TREE_CACTUS
- TREE_RAINFOREST
; ///< number of tree types for the 'rainforest part' of a sub-tropic map.
44 static const uint TREE_COUNT_SUB_TROPICAL
= TREE_TOYLAND
- TREE_SUB_TROPICAL
; ///< number of tree types for the 'sub-tropic part' of a sub-tropic map.
45 static const uint TREE_COUNT_TOYLAND
= 9; ///< number of tree types on a toyland map.
48 * Enumeration for ground types of tiles with trees.
50 * This enumeration defines the ground types for tiles with trees on it.
53 TREE_GROUND_GRASS
= 0, ///< normal grass
54 TREE_GROUND_ROUGH
= 1, ///< some rough tile
55 TREE_GROUND_SNOW_DESERT
= 2, ///< a desert or snow tile, depend on landscape
56 TREE_GROUND_SHORE
= 3, ///< shore
57 TREE_GROUND_ROUGH_SNOW
= 4, ///< A snow tile that is rough underneath.
61 * Enumeration for tree growth stages.
63 * This enumeration defines the stages of tree growth for tiles with trees on it.
65 enum class TreeGrowthStage
: uint
{
66 Growing1
= 0, ///< First stage of growth
67 Growing2
= 1, ///< Second stage of growth
68 Growing3
= 2, ///< Third stage of growth
69 Grown
= 3, ///< Fully grown tree
70 Dying1
= 4, ///< First stage of dying
71 Dying2
= 5, ///< Second stage of dying
72 Dead
= 6, ///< Dead tree
76 * Returns the treetype of a tile.
78 * This function returns the treetype of a given tile. As there are more
79 * possible treetypes for a tile in a game as the enumeration #TreeType defines
80 * this function may be return a value which isn't catch by an entry of the
81 * enumeration #TreeType. But there is no problem known about it.
83 * @param t The tile to get the treetype from
84 * @return The treetype of the given tile with trees
85 * @pre Tile t must be of type MP_TREES
87 inline TreeType
GetTreeType(Tile t
)
89 assert(IsTileType(t
, MP_TREES
));
90 return (TreeType
)t
.m3();
94 * Returns the groundtype for tree tiles.
96 * This function returns the groundtype of a tile with trees.
98 * @param t The tile to get the groundtype from
99 * @return The groundtype of the tile
100 * @pre Tile must be of type MP_TREES
102 inline TreeGround
GetTreeGround(Tile t
)
104 assert(IsTileType(t
, MP_TREES
));
105 return (TreeGround
)GB(t
.m2(), 6, 3);
109 * Returns the 'density' of a tile with trees.
111 * This function returns the density of a tile which got trees. Note
112 * that this value doesn't count the number of trees on a tile, use
113 * #GetTreeCount instead. This function instead returns some kind of
114 * groundtype of the tile. As the map-array is finite in size and
115 * the information about the trees must be saved somehow other
116 * information about a tile must be saved somewhere encoded in the
117 * tile. So this function returns the density of a tile for sub arctic
118 * and sub tropical games. This means for sub arctic the type of snowline
119 * (0 to 3 for all 4 types of snowtiles) and for sub tropical the value
120 * 3 for a desert (and 0 for non-desert). The function name is not read as
121 * "get the tree density of a tile" but "get the density of a tile which got trees".
123 * @param t The tile to get the 'density'
124 * @pre Tile must be of type MP_TREES
127 inline uint
GetTreeDensity(Tile t
)
129 assert(IsTileType(t
, MP_TREES
));
130 return GB(t
.m2(), 4, 2);
134 * Set the density and ground type of a tile with trees.
136 * This functions saves the ground type and the density which belongs to it
139 * @param t The tile to set the density and ground type
140 * @param g The ground type to save
141 * @param d The density to save with
142 * @pre Tile must be of type MP_TREES
144 inline void SetTreeGroundDensity(Tile t
, TreeGround g
, uint d
)
146 assert(IsTileType(t
, MP_TREES
)); // XXX incomplete
149 SetWaterClass(t
, g
== TREE_GROUND_SHORE
? WATER_CLASS_SEA
: WATER_CLASS_INVALID
);
153 * Returns the number of trees on a tile.
155 * This function returns the number of trees of a tile (1-4).
156 * The tile must be contains at least one tree or be more specific: it must be
159 * @param t The index to get the number of trees
160 * @return The number of trees (1-4)
161 * @pre Tile must be of type MP_TREES
163 inline uint
GetTreeCount(Tile t
)
165 assert(IsTileType(t
, MP_TREES
));
166 return GB(t
.m5(), 6, 2) + 1;
170 * Add a amount to the tree-count value of a tile with trees.
172 * This function add a value to the tree-count value of a tile. This
173 * value may be negative to reduce the tree-counter. If the resulting
174 * value reach 0 it doesn't get converted to a "normal" tile.
176 * @param t The tile to change the tree amount
177 * @param c The value to add (or reduce) on the tree-count value
178 * @pre Tile must be of type MP_TREES
180 inline void AddTreeCount(Tile t
, int c
)
182 assert(IsTileType(t
, MP_TREES
)); // XXX incomplete
187 * Returns the tree growth stage.
189 * This function returns the tree growth stage of a tile with trees.
191 * @param t The tile to get the tree growth stage
192 * @return The tree growth stage
193 * @pre Tile must be of type MP_TREES
195 inline TreeGrowthStage
GetTreeGrowth(Tile t
)
197 assert(IsTileType(t
, MP_TREES
));
198 return static_cast<TreeGrowthStage
>(GB(t
.m5(), 0, 3));
202 * Add a value to the tree growth stage.
204 * This function adds a value to the tree grow stage of a tile.
206 * @param t The tile to add the value on
207 * @param a The value to add on the tree growth stage
208 * @pre Tile must be of type MP_TREES
210 inline void AddTreeGrowth(Tile t
, int a
)
212 assert(IsTileType(t
, MP_TREES
)); // XXX incomplete
217 * Sets the tree growth stage of a tile.
219 * This function sets the tree growth stage of a tile directly with
222 * @param t The tile to change the tree growth stage
223 * @param g The new value
224 * @pre Tile must be of type MP_TREES
226 inline void SetTreeGrowth(Tile t
, TreeGrowthStage g
)
228 assert(IsTileType(t
, MP_TREES
)); // XXX incomplete
229 SB(t
.m5(), 0, 3, static_cast<uint
>(g
));
235 * This functions change the tile to a tile with trees and all information which belongs to it.
237 * @param t The tile to make a tree-tile from
238 * @param type The type of the tree
239 * @param count the number of trees
240 * @param growth the growth stage
241 * @param ground the ground type
242 * @param density the density (not the number of trees)
244 inline void MakeTree(Tile t
, TreeType type
, uint count
, TreeGrowthStage growth
, TreeGround ground
, uint density
)
246 SetTileType(t
, MP_TREES
);
247 SetTileOwner(t
, OWNER_NONE
);
248 SetWaterClass(t
, ground
== TREE_GROUND_SHORE
? WATER_CLASS_SEA
: WATER_CLASS_INVALID
);
249 t
.m2() = ground
<< 6 | density
<< 4 | 0;
251 t
.m4() = 0 << 5 | 0 << 2;
252 t
.m5() = count
<< 6 | static_cast<uint
>(growth
);
257 #endif /* TREE_MAP_H */