(svn r27953) -Cleanup: Adjust other languages for r27952
[openttd.git] / src / tree_map.h
blobe614099fc9b0df862e6a04d6b567c2f6177fd3bb
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 */
10 /** @file tree_map.h Map accessors for tree tiles. */
12 #ifndef TREE_MAP_H
13 #define TREE_MAP_H
15 #include "tile_map.h"
17 /**
18 * List of tree types along all landscape types.
20 * This enumeration contains a list of the different tree types along
21 * all landscape types. The values for the enumerations may be used for
22 * offsets from the grfs files. These points to the start of
23 * the tree list for a landscape. See the TREE_COUNT_* enumerations
24 * for the amount of different trees for a specific landscape.
26 enum TreeType {
27 TREE_TEMPERATE = 0x00, ///< temperate tree
28 TREE_SUB_ARCTIC = 0x0C, ///< tree on a sub_arctic landscape
29 TREE_RAINFOREST = 0x14, ///< tree on the 'green part' on a sub-tropical map
30 TREE_CACTUS = 0x1B, ///< a cactus for the 'desert part' on a sub-tropical map
31 TREE_SUB_TROPICAL = 0x1C, ///< tree on a sub-tropical map, non-rainforest, non-desert
32 TREE_TOYLAND = 0x20, ///< tree on a toyland map
33 TREE_INVALID = 0xFF, ///< An invalid tree
36 /* Counts the number of tree types for each landscape.
38 * This list contains the counts of different tree types for each landscape. This list contains
39 * 5 entries instead of 4 (as there are only 4 landscape types) as the sub tropic landscape
40 * has two types of area, one for normal trees and one only for cacti.
42 static const uint TREE_COUNT_TEMPERATE = TREE_SUB_ARCTIC - TREE_TEMPERATE; ///< number of tree types on a temperate map.
43 static const uint TREE_COUNT_SUB_ARCTIC = TREE_RAINFOREST - TREE_SUB_ARCTIC; ///< number of tree types on a sub arctic map.
44 static const uint TREE_COUNT_RAINFOREST = TREE_CACTUS - TREE_RAINFOREST; ///< number of tree types for the 'rainforest part' of a sub-tropic map.
45 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.
46 static const uint TREE_COUNT_TOYLAND = 9; ///< number of tree types on a toyland map.
48 /**
49 * Enumeration for ground types of tiles with trees.
51 * This enumeration defines the ground types for tiles with trees on it.
53 enum TreeGround {
54 TREE_GROUND_GRASS = 0, ///< normal grass
55 TREE_GROUND_ROUGH = 1, ///< some rough tile
56 TREE_GROUND_SNOW_DESERT = 2, ///< a desert or snow tile, depend on landscape
57 TREE_GROUND_SHORE = 3, ///< shore
58 TREE_GROUND_ROUGH_SNOW = 4, ///< A snow tile that is rough underneath.
62 /**
63 * Returns the treetype of a tile.
65 * This function returns the treetype of a given tile. As there are more
66 * possible treetypes for a tile in a game as the enumeration #TreeType defines
67 * this function may be return a value which isn't catch by an entry of the
68 * enumeration #TreeType. But there is no problem known about it.
70 * @param t The tile to get the treetype from
71 * @return The treetype of the given tile with trees
72 * @pre Tile t must be of type MP_TREES
74 static inline TreeType GetTreeType(TileIndex t)
76 assert(IsTileType(t, MP_TREES));
77 return (TreeType)_m[t].m3;
80 /**
81 * Returns the groundtype for tree tiles.
83 * This function returns the groundtype of a tile with trees.
85 * @param t The tile to get the groundtype from
86 * @return The groundtype of the tile
87 * @pre Tile must be of type MP_TREES
89 static inline TreeGround GetTreeGround(TileIndex t)
91 assert(IsTileType(t, MP_TREES));
92 return (TreeGround)GB(_m[t].m2, 6, 3);
95 /**
96 * Returns the 'density' of a tile with trees.
98 * This function returns the density of a tile which got trees. Note
99 * that this value doesn't count the number of trees on a tile, use
100 * #GetTreeCount instead. This function instead returns some kind of
101 * groundtype of the tile. As the map-array is finite in size and
102 * the informations about the trees must be saved somehow other
103 * informations about a tile must be saved somewhere encoded in the
104 * tile. So this function returns the density of a tile for sub arctic
105 * and sub tropical games. This means for sub arctic the type of snowline
106 * (0 to 3 for all 4 types of snowtiles) and for sub tropical the value
107 * 3 for a desert (and 0 for non-desert). The function name is not read as
108 * "get the tree density of a tile" but "get the density of a tile which got trees".
110 * @param t The tile to get the 'density'
111 * @pre Tile must be of type MP_TREES
112 * @see GetTreeCount
114 static inline uint GetTreeDensity(TileIndex t)
116 assert(IsTileType(t, MP_TREES));
117 return GB(_m[t].m2, 4, 2);
121 * Set the density and ground type of a tile with trees.
123 * This functions saves the ground type and the density which belongs to it
124 * for a given tile.
126 * @param t The tile to set the density and ground type
127 * @param g The ground type to save
128 * @param d The density to save with
129 * @pre Tile must be of type MP_TREES
131 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
133 assert(IsTileType(t, MP_TREES)); // XXX incomplete
134 SB(_m[t].m2, 4, 2, d);
135 SB(_m[t].m2, 6, 3, g);
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 informations 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 _m[t].m2 = ground << 6 | density << 4 | 0;
279 _m[t].m3 = type;
280 _m[t].m4 = 0 << 5 | 0 << 2;
281 _m[t].m5 = count << 6 | growth;
282 SB(_me[t].m6, 2, 4, 0);
283 _me[t].m7 = 0;
286 #endif /* TREE_MAP_H */