OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

tree_map.h
Go to the documentation of this file.
1 /* $Id: tree_map.h 26878 2014-09-21 11:23:33Z rubidium $ */
2
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 */
9
12 #ifndef TREE_MAP_H
13 #define TREE_MAP_H
14
15 #include "tile_map.h"
16
26 enum TreeType {
27 TREE_TEMPERATE = 0x00,
28 TREE_SUB_ARCTIC = 0x0C,
29 TREE_RAINFOREST = 0x14,
30 TREE_CACTUS = 0x1B,
31 TREE_SUB_TROPICAL = 0x1C,
32 TREE_TOYLAND = 0x20,
33 TREE_INVALID = 0xFF,
34 };
35
36 /* Counts the number of tree types for each landscape.
37 *
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.
41 */
42 static const uint TREE_COUNT_TEMPERATE = TREE_SUB_ARCTIC - TREE_TEMPERATE;
43 static const uint TREE_COUNT_SUB_ARCTIC = TREE_RAINFOREST - TREE_SUB_ARCTIC;
44 static const uint TREE_COUNT_RAINFOREST = TREE_CACTUS - TREE_RAINFOREST;
45 static const uint TREE_COUNT_SUB_TROPICAL = TREE_TOYLAND - TREE_SUB_TROPICAL;
46 static const uint TREE_COUNT_TOYLAND = 9;
47
53 enum TreeGround {
54 TREE_GROUND_GRASS = 0,
55 TREE_GROUND_ROUGH = 1,
56 TREE_GROUND_SNOW_DESERT = 2,
57 TREE_GROUND_SHORE = 3,
58 TREE_GROUND_ROUGH_SNOW = 4,
59 };
60
61
74 static inline TreeType GetTreeType(TileIndex t)
75 {
76 assert(IsTileType(t, MP_TREES));
77 return (TreeType)_m[t].m3;
78 }
79
89 static inline TreeGround GetTreeGround(TileIndex t)
90 {
91 assert(IsTileType(t, MP_TREES));
92 return (TreeGround)GB(_m[t].m2, 6, 3);
93 }
94
114 static inline uint GetTreeDensity(TileIndex t)
115 {
116 assert(IsTileType(t, MP_TREES));
117 return GB(_m[t].m2, 4, 2);
118 }
119
131 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
132 {
133 assert(IsTileType(t, MP_TREES)); // XXX incomplete
134 SB(_m[t].m2, 4, 2, d);
135 SB(_m[t].m2, 6, 3, g);
136 }
137
149 static inline uint GetTreeCount(TileIndex t)
150 {
151 assert(IsTileType(t, MP_TREES));
152 return GB(_m[t].m5, 6, 2) + 1;
153 }
154
166 static inline void AddTreeCount(TileIndex t, int c)
167 {
168 assert(IsTileType(t, MP_TREES)); // XXX incomplete
169 _m[t].m5 += c << 6;
170 }
171
181 static inline uint GetTreeGrowth(TileIndex t)
182 {
183 assert(IsTileType(t, MP_TREES));
184 return GB(_m[t].m5, 0, 3);
185 }
186
196 static inline void AddTreeGrowth(TileIndex t, int a)
197 {
198 assert(IsTileType(t, MP_TREES)); // XXX incomplete
199 _m[t].m5 += a;
200 }
201
212 static inline void SetTreeGrowth(TileIndex t, uint g)
213 {
214 assert(IsTileType(t, MP_TREES)); // XXX incomplete
215 SB(_m[t].m5, 0, 3, g);
216 }
217
226 static inline uint GetTreeCounter(TileIndex t)
227 {
228 assert(IsTileType(t, MP_TREES));
229 return GB(_m[t].m2, 0, 4);
230 }
231
241 static inline void AddTreeCounter(TileIndex t, int a)
242 {
243 assert(IsTileType(t, MP_TREES)); // XXX incomplete
244 _m[t].m2 += a;
245 }
246
256 static inline void SetTreeCounter(TileIndex t, uint c)
257 {
258 assert(IsTileType(t, MP_TREES)); // XXX incomplete
259 SB(_m[t].m2, 0, 4, c);
260 }
261
274 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
275 {
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;
284 }
285
286 #endif /* TREE_MAP_H */