OpenTTD
tree_map.h
Go to the documentation of this file.
1 /* $Id$ */
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 #include "water_map.h"
17 
27 enum TreeType {
28  TREE_TEMPERATE = 0x00,
29  TREE_SUB_ARCTIC = 0x0C,
30  TREE_RAINFOREST = 0x14,
31  TREE_CACTUS = 0x1B,
33  TREE_TOYLAND = 0x20,
34  TREE_INVALID = 0xFF,
35 };
36 
37 /* Counts the number of tree types for each landscape.
38  *
39  * This list contains the counts of different tree types for each landscape. This list contains
40  * 5 entries instead of 4 (as there are only 4 landscape types) as the sub tropic landscape
41  * has two types of area, one for normal trees and one only for cacti.
42  */
47 static const uint TREE_COUNT_TOYLAND = 9;
48 
54 enum TreeGround {
60 };
61 
62 
75 static inline TreeType GetTreeType(TileIndex t)
76 {
77  assert(IsTileType(t, MP_TREES));
78  return (TreeType)_m[t].m3;
79 }
80 
91 {
92  assert(IsTileType(t, MP_TREES));
93  return (TreeGround)GB(_m[t].m2, 6, 3);
94 }
95 
115 static inline uint GetTreeDensity(TileIndex t)
116 {
117  assert(IsTileType(t, MP_TREES));
118  return GB(_m[t].m2, 4, 2);
119 }
120 
132 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
133 {
134  assert(IsTileType(t, MP_TREES)); // XXX incomplete
135  SB(_m[t].m2, 4, 2, d);
136  SB(_m[t].m2, 6, 3, g);
138 }
139 
151 static inline uint GetTreeCount(TileIndex t)
152 {
153  assert(IsTileType(t, MP_TREES));
154  return GB(_m[t].m5, 6, 2) + 1;
155 }
156 
168 static inline void AddTreeCount(TileIndex t, int c)
169 {
170  assert(IsTileType(t, MP_TREES)); // XXX incomplete
171  _m[t].m5 += c << 6;
172 }
173 
183 static inline uint GetTreeGrowth(TileIndex t)
184 {
185  assert(IsTileType(t, MP_TREES));
186  return GB(_m[t].m5, 0, 3);
187 }
188 
198 static inline void AddTreeGrowth(TileIndex t, int a)
199 {
200  assert(IsTileType(t, MP_TREES)); // XXX incomplete
201  _m[t].m5 += a;
202 }
203 
214 static inline void SetTreeGrowth(TileIndex t, uint g)
215 {
216  assert(IsTileType(t, MP_TREES)); // XXX incomplete
217  SB(_m[t].m5, 0, 3, g);
218 }
219 
228 static inline uint GetTreeCounter(TileIndex t)
229 {
230  assert(IsTileType(t, MP_TREES));
231  return GB(_m[t].m2, 0, 4);
232 }
233 
243 static inline void AddTreeCounter(TileIndex t, int a)
244 {
245  assert(IsTileType(t, MP_TREES)); // XXX incomplete
246  _m[t].m2 += a;
247 }
248 
258 static inline void SetTreeCounter(TileIndex t, uint c)
259 {
260  assert(IsTileType(t, MP_TREES)); // XXX incomplete
261  SB(_m[t].m2, 0, 4, c);
262 }
263 
276 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
277 {
278  SetTileType(t, MP_TREES);
281  _m[t].m2 = ground << 6 | density << 4 | 0;
282  _m[t].m3 = type;
283  _m[t].m4 = 0 << 5 | 0 << 2;
284  _m[t].m5 = count << 6 | growth;
285  SB(_me[t].m6, 2, 4, 0);
286  _me[t].m7 = 0;
287 }
288 
289 #endif /* TREE_MAP_H */
static const uint TREE_COUNT_TEMPERATE
number of tree types on a temperate map.
Definition: tree_map.h:43
static const uint TREE_COUNT_SUB_TROPICAL
number of tree types for the &#39;sub-tropic part&#39; of a sub-tropic map.
Definition: tree_map.h:46
static void AddTreeCounter(TileIndex t, int a)
Add a value on the tick counter of a tree-tile.
Definition: tree_map.h:243
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:200
static const uint TREE_COUNT_TOYLAND
number of tree types on a toyland map.
Definition: tree_map.h:47
static void SetTreeCounter(TileIndex t, uint c)
Set the tick counter for a tree-tile.
Definition: tree_map.h:258
static uint GetTreeCounter(TileIndex t)
Get the tick counter of a tree tile.
Definition: tree_map.h:228
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
Tile * _m
Tiles of the map.
Definition: map.cpp:32
A snow tile that is rough underneath.
Definition: tree_map.h:59
static void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Definition: tree_map.h:132
static void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
Make a tree-tile.
Definition: tree_map.h:276
static const uint TREE_COUNT_RAINFOREST
number of tree types for the &#39;rainforest part&#39; of a sub-tropic map.
Definition: tree_map.h:45
static TreeType GetTreeType(TileIndex t)
Returns the treetype of a tile.
Definition: tree_map.h:75
static void SetWaterClass(TileIndex t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:118
some rough tile
Definition: tree_map.h:56
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
An invalid tree.
Definition: tree_map.h:34
static uint GetTreeGrowth(TileIndex t)
Returns the tree growth status.
Definition: tree_map.h:183
static void SetTreeGrowth(TileIndex t, uint g)
Sets the tree growth status of a tile.
Definition: tree_map.h:214
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
Map accessors for water tiles.
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
byte m5
General purpose.
Definition: map_type.h:26
static uint GetTreeDensity(TileIndex t)
Returns the &#39;density&#39; of a tile with trees.
Definition: tree_map.h:115
tree on a sub_arctic landscape
Definition: tree_map.h:29
The tile has no ownership.
Definition: company_type.h:27
a desert or snow tile, depend on landscape
Definition: tree_map.h:57
a cactus for the &#39;desert part&#39; on a sub-tropical map
Definition: tree_map.h:31
temperate tree
Definition: tree_map.h:28
static void AddTreeCount(TileIndex t, int c)
Add a amount to the tree-count value of a tile with trees.
Definition: tree_map.h:168
Tile got trees.
Definition: tile_type.h:47
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:90
static uint GetTreeCount(TileIndex t)
Returns the number of trees on a tile.
Definition: tree_map.h:151
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:133
tree on a toyland map
Definition: tree_map.h:33
TreeType
List of tree types along all landscape types.
Definition: tree_map.h:27
static void AddTreeGrowth(TileIndex t, int a)
Add a value to the tree growth status.
Definition: tree_map.h:198
normal grass
Definition: tree_map.h:55
tree on a sub-tropical map, non-rainforest, non-desert
Definition: tree_map.h:32
TreeGround
Enumeration for ground types of tiles with trees.
Definition: tree_map.h:54
Map writing/reading functions for tiles.
static const uint TREE_COUNT_SUB_ARCTIC
number of tree types on a sub arctic map.
Definition: tree_map.h:44
tree on the &#39;green part&#39; on a sub-tropical map
Definition: tree_map.h:30
byte m3
General purpose.
Definition: map_type.h:24
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:53
byte m4
General purpose.
Definition: map_type.h:25