OpenTTD Source  14.0-beta3
tree_map.h
Go to the documentation of this file.
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  */
7 
10 #ifndef TREE_MAP_H
11 #define TREE_MAP_H
12 
13 #include "tile_map.h"
14 #include "water_map.h"
15 
25 enum TreeType {
26  TREE_TEMPERATE = 0x00,
27  TREE_SUB_ARCTIC = 0x0C,
28  TREE_RAINFOREST = 0x14,
29  TREE_CACTUS = 0x1B,
31  TREE_TOYLAND = 0x20,
32  TREE_INVALID = 0xFF,
33 };
34 
35 /* Counts the number of tree types for each landscape.
36  *
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.
40  */
45 static const uint TREE_COUNT_TOYLAND = 9;
46 
52 enum TreeGround {
58 };
59 
60 
74 {
75  assert(IsTileType(t, MP_TREES));
76  return (TreeType)t.m3();
77 }
78 
89 {
90  assert(IsTileType(t, MP_TREES));
91  return (TreeGround)GB(t.m2(), 6, 3);
92 }
93 
113 inline uint GetTreeDensity(Tile t)
114 {
115  assert(IsTileType(t, MP_TREES));
116  return GB(t.m2(), 4, 2);
117 }
118 
130 inline void SetTreeGroundDensity(Tile t, TreeGround g, uint d)
131 {
132  assert(IsTileType(t, MP_TREES)); // XXX incomplete
133  SB(t.m2(), 4, 2, d);
134  SB(t.m2(), 6, 3, g);
136 }
137 
149 inline uint GetTreeCount(Tile t)
150 {
151  assert(IsTileType(t, MP_TREES));
152  return GB(t.m5(), 6, 2) + 1;
153 }
154 
166 inline void AddTreeCount(Tile t, int c)
167 {
168  assert(IsTileType(t, MP_TREES)); // XXX incomplete
169  t.m5() += c << 6;
170 }
171 
181 inline uint GetTreeGrowth(Tile t)
182 {
183  assert(IsTileType(t, MP_TREES));
184  return GB(t.m5(), 0, 3);
185 }
186 
196 inline void AddTreeGrowth(Tile t, int a)
197 {
198  assert(IsTileType(t, MP_TREES)); // XXX incomplete
199  t.m5() += a;
200 }
201 
212 inline void SetTreeGrowth(Tile t, uint g)
213 {
214  assert(IsTileType(t, MP_TREES)); // XXX incomplete
215  SB(t.m5(), 0, 3, g);
216 }
217 
230 inline void MakeTree(Tile t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
231 {
232  SetTileType(t, MP_TREES);
235  t.m2() = ground << 6 | density << 4 | 0;
236  t.m3() = type;
237  t.m4() = 0 << 5 | 0 << 2;
238  t.m5() = count << 6 | growth;
239  SB(t.m6(), 2, 4, 0);
240  t.m7() = 0;
241 }
242 
243 #endif /* TREE_MAP_H */
GetTreeGround
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
GetTreeCount
uint GetTreeCount(Tile t)
Returns the number of trees on a tile.
Definition: tree_map.h:149
AddTreeGrowth
void AddTreeGrowth(Tile t, int a)
Add a value to the tree growth status.
Definition: tree_map.h:196
TREE_RAINFOREST
@ TREE_RAINFOREST
tree on the 'green part' on a sub-tropical map
Definition: tree_map.h:28
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
TREE_GROUND_SHORE
@ TREE_GROUND_SHORE
shore
Definition: tree_map.h:56
AddTreeCount
void AddTreeCount(Tile t, int c)
Add a amount to the tree-count value of a tile with trees.
Definition: tree_map.h:166
Tile::m6
debug_inline byte & m6()
General purpose.
Definition: map_func.h:173
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
Tile::m5
debug_inline byte & m5()
General purpose.
Definition: map_func.h:161
TREE_COUNT_TEMPERATE
static const uint TREE_COUNT_TEMPERATE
number of tree types on a temperate map.
Definition: tree_map.h:41
Tile::m4
debug_inline byte & m4()
General purpose.
Definition: map_func.h:149
WATER_CLASS_INVALID
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:51
TREE_GROUND_ROUGH
@ TREE_GROUND_ROUGH
some rough tile
Definition: tree_map.h:54
Tile::m7
debug_inline byte & m7()
Primarily used for newgrf support.
Definition: map_func.h:185
TREE_SUB_ARCTIC
@ TREE_SUB_ARCTIC
tree on a sub_arctic landscape
Definition: tree_map.h:27
GetTreeGrowth
uint GetTreeGrowth(Tile t)
Returns the tree growth status.
Definition: tree_map.h:181
tile_map.h
Tile::m2
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition: map_func.h:125
TREE_CACTUS
@ TREE_CACTUS
a cactus for the 'desert part' on a sub-tropical map
Definition: tree_map.h:29
TREE_INVALID
@ TREE_INVALID
An invalid tree.
Definition: tree_map.h:32
SetWaterClass
void SetWaterClass(Tile t, WaterClass wc)
Set the water class at a tile.
Definition: water_map.h:127
TREE_TOYLAND
@ TREE_TOYLAND
tree on a toyland map
Definition: tree_map.h:31
SetTreeGroundDensity
void SetTreeGroundDensity(Tile t, TreeGround g, uint d)
Set the density and ground type of a tile with trees.
Definition: tree_map.h:130
SetTileOwner
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
WATER_CLASS_SEA
@ WATER_CLASS_SEA
Sea.
Definition: water_map.h:48
TREE_GROUND_GRASS
@ TREE_GROUND_GRASS
normal grass
Definition: tree_map.h:53
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
water_map.h
TREE_SUB_TROPICAL
@ TREE_SUB_TROPICAL
tree on a sub-tropical map, non-rainforest, non-desert
Definition: tree_map.h:30
TREE_COUNT_RAINFOREST
static const uint TREE_COUNT_RAINFOREST
number of tree types for the 'rainforest part' of a sub-tropic map.
Definition: tree_map.h:43
TreeGround
TreeGround
Enumeration for ground types of tiles with trees.
Definition: tree_map.h:52
TREE_COUNT_TOYLAND
static const uint TREE_COUNT_TOYLAND
number of tree types on a toyland map.
Definition: tree_map.h:45
TREE_COUNT_SUB_TROPICAL
static const uint TREE_COUNT_SUB_TROPICAL
number of tree types for the 'sub-tropic part' of a sub-tropic map.
Definition: tree_map.h:44
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
SetTileType
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
SetTreeGrowth
void SetTreeGrowth(Tile t, uint g)
Sets the tree growth status of a tile.
Definition: tree_map.h:212
TREE_TEMPERATE
@ TREE_TEMPERATE
temperate tree
Definition: tree_map.h:26
MakeTree
void MakeTree(Tile t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
Make a tree-tile.
Definition: tree_map.h:230
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
TREE_GROUND_SNOW_DESERT
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
Definition: tree_map.h:55
TREE_COUNT_SUB_ARCTIC
static const uint TREE_COUNT_SUB_ARCTIC
number of tree types on a sub arctic map.
Definition: tree_map.h:42
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GetTreeType
TreeType GetTreeType(Tile t)
Returns the treetype of a tile.
Definition: tree_map.h:73
Tile::m3
debug_inline byte & m3()
General purpose.
Definition: map_func.h:137
GetTreeDensity
uint GetTreeDensity(Tile t)
Returns the 'density' of a tile with trees.
Definition: tree_map.h:113
TreeType
TreeType
List of tree types along all landscape types.
Definition: tree_map.h:25
TREE_GROUND_ROUGH_SNOW
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
Definition: tree_map.h:57