Change: Let AI developers edit non-editable AI/Game Script Parameters (#8895)
[openttd-github.git] / src / tree_map.h
blobe8f68d825d9ccf0a52e034d46fefd5d996f08b1c
1 /*
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/>.
6 */
8 /** @file tree_map.h Map accessors for tree tiles. */
10 #ifndef TREE_MAP_H
11 #define TREE_MAP_H
13 #include "tile_map.h"
14 #include "water_map.h"
16 /**
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.
25 enum TreeType {
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.
47 /**
48 * Enumeration for ground types of tiles with trees.
50 * This enumeration defines the ground types for tiles with trees on it.
52 enum TreeGround {
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 /**
62 * Returns the treetype of a tile.
64 * This function returns the treetype of a given tile. As there are more
65 * possible treetypes for a tile in a game as the enumeration #TreeType defines
66 * this function may be return a value which isn't catch by an entry of the
67 * enumeration #TreeType. But there is no problem known about it.
69 * @param t The tile to get the treetype from
70 * @return The treetype of the given tile with trees
71 * @pre Tile t must be of type MP_TREES
73 static inline TreeType GetTreeType(TileIndex t)
75 assert(IsTileType(t, MP_TREES));
76 return (TreeType)_m[t].m3;
79 /**
80 * Returns the groundtype for tree tiles.
82 * This function returns the groundtype of a tile with trees.
84 * @param t The tile to get the groundtype from
85 * @return The groundtype of the tile
86 * @pre Tile must be of type MP_TREES
88 static inline TreeGround GetTreeGround(TileIndex t)
90 assert(IsTileType(t, MP_TREES));
91 return (TreeGround)GB(_m[t].m2, 6, 3);
94 /**
95 * Returns the 'density' of a tile with trees.
97 * This function returns the density of a tile which got trees. Note
98 * that this value doesn't count the number of trees on a tile, use
99 * #GetTreeCount instead. This function instead returns some kind of
100 * groundtype of the tile. As the map-array is finite in size and
101 * the information about the trees must be saved somehow other
102 * information about a tile must be saved somewhere encoded in the
103 * tile. So this function returns the density of a tile for sub arctic
104 * and sub tropical games. This means for sub arctic the type of snowline
105 * (0 to 3 for all 4 types of snowtiles) and for sub tropical the value
106 * 3 for a desert (and 0 for non-desert). The function name is not read as
107 * "get the tree density of a tile" but "get the density of a tile which got trees".
109 * @param t The tile to get the 'density'
110 * @pre Tile must be of type MP_TREES
111 * @see GetTreeCount
113 static inline uint GetTreeDensity(TileIndex t)
115 assert(IsTileType(t, MP_TREES));
116 return GB(_m[t].m2, 4, 2);
120 * Set the density and ground type of a tile with trees.
122 * This functions saves the ground type and the density which belongs to it
123 * for a given tile.
125 * @param t The tile to set the density and ground type
126 * @param g The ground type to save
127 * @param d The density to save with
128 * @pre Tile must be of type MP_TREES
130 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
132 assert(IsTileType(t, MP_TREES)); // XXX incomplete
133 SB(_m[t].m2, 4, 2, d);
134 SB(_m[t].m2, 6, 3, g);
135 SetWaterClass(t, g == TREE_GROUND_SHORE ? WATER_CLASS_SEA : WATER_CLASS_INVALID);
139 * Returns the number of trees on a tile.
141 * This function returns the number of trees of a tile (1-4).
142 * The tile must be contains at least one tree or be more specific: it must be
143 * of type MP_TREES.
145 * @param t The index to get the number of trees
146 * @return The number of trees (1-4)
147 * @pre Tile must be of type MP_TREES
149 static inline uint GetTreeCount(TileIndex t)
151 assert(IsTileType(t, MP_TREES));
152 return GB(_m[t].m5, 6, 2) + 1;
156 * Add a amount to the tree-count value of a tile with trees.
158 * This function add a value to the tree-count value of a tile. This
159 * value may be negative to reduce the tree-counter. If the resulting
160 * value reach 0 it doesn't get converted to a "normal" tile.
162 * @param t The tile to change the tree amount
163 * @param c The value to add (or reduce) on the tree-count value
164 * @pre Tile must be of type MP_TREES
166 static inline void AddTreeCount(TileIndex t, int c)
168 assert(IsTileType(t, MP_TREES)); // XXX incomplete
169 _m[t].m5 += c << 6;
173 * Returns the tree growth status.
175 * This function returns the tree growth status of a tile with trees.
177 * @param t The tile to get the tree growth status
178 * @return The tree growth status
179 * @pre Tile must be of type MP_TREES
181 static inline uint GetTreeGrowth(TileIndex t)
183 assert(IsTileType(t, MP_TREES));
184 return GB(_m[t].m5, 0, 3);
188 * Add a value to the tree growth status.
190 * This function adds a value to the tree grow status of a tile.
192 * @param t The tile to add the value on
193 * @param a The value to add on the tree growth status
194 * @pre Tile must be of type MP_TREES
196 static inline void AddTreeGrowth(TileIndex t, int a)
198 assert(IsTileType(t, MP_TREES)); // XXX incomplete
199 _m[t].m5 += a;
203 * Sets the tree growth status of a tile.
205 * This function sets the tree growth status of a tile directly with
206 * the given value.
208 * @param t The tile to change the tree growth status
209 * @param g The new value
210 * @pre Tile must be of type MP_TREES
212 static inline void SetTreeGrowth(TileIndex t, uint g)
214 assert(IsTileType(t, MP_TREES)); // XXX incomplete
215 SB(_m[t].m5, 0, 3, g);
219 * Get the tick counter of a tree tile.
221 * Returns the saved tick counter of a given tile.
223 * @param t The tile to get the counter value from
224 * @pre Tile must be of type MP_TREES
226 static inline uint GetTreeCounter(TileIndex t)
228 assert(IsTileType(t, MP_TREES));
229 return GB(_m[t].m2, 0, 4);
233 * Add a value on the tick counter of a tree-tile
235 * This function adds a value on the tick counter of a tree-tile.
237 * @param t The tile to add the value on
238 * @param a The value to add on the tick counter
239 * @pre Tile must be of type MP_TREES
241 static inline void AddTreeCounter(TileIndex t, int a)
243 assert(IsTileType(t, MP_TREES)); // XXX incomplete
244 _m[t].m2 += a;
248 * Set the tick counter for a tree-tile
250 * This function sets directly the tick counter for a tree-tile.
252 * @param t The tile to set the tick counter
253 * @param c The new tick counter value
254 * @pre Tile must be of type MP_TREES
256 static inline void SetTreeCounter(TileIndex t, uint c)
258 assert(IsTileType(t, MP_TREES)); // XXX incomplete
259 SB(_m[t].m2, 0, 4, c);
263 * Make a tree-tile.
265 * This functions change the tile to a tile with trees and all information which belongs to it.
267 * @param t The tile to make a tree-tile from
268 * @param type The type of the tree
269 * @param count the number of trees
270 * @param growth the growth status
271 * @param ground the ground type
272 * @param density the density (not the number of trees)
274 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
276 SetTileType(t, MP_TREES);
277 SetTileOwner(t, OWNER_NONE);
278 SetWaterClass(t, ground == TREE_GROUND_SHORE ? WATER_CLASS_SEA : WATER_CLASS_INVALID);
279 _m[t].m2 = ground << 6 | density << 4 | 0;
280 _m[t].m3 = type;
281 _m[t].m4 = 0 << 5 | 0 << 2;
282 _m[t].m5 = count << 6 | growth;
283 SB(_me[t].m6, 2, 4, 0);
284 _me[t].m7 = 0;
287 #endif /* TREE_MAP_H */