OpenTTD
clear_map.h
Go to the documentation of this file.
1 /* $Id: clear_map.h 27037 2014-10-23 17:13:44Z 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 CLEAR_MAP_H
13 #define CLEAR_MAP_H
14 
15 #include "bridge_map.h"
16 #include "industry_type.h"
17 
26  CLEAR_SNOW = 4,
28 };
29 
30 
37 static inline bool IsSnowTile(TileIndex t)
38 {
39  assert(IsTileType(t, MP_CLEAR));
40  return HasBit(_m[t].m3, 4);
41 }
42 
50 {
51  assert(IsTileType(t, MP_CLEAR));
52  return (ClearGround)GB(_m[t].m5, 2, 3);
53 }
54 
62 {
63  if (IsSnowTile(t)) return CLEAR_SNOW;
64  return GetRawClearGround(t);
65 }
66 
73 static inline bool IsClearGround(TileIndex t, ClearGround ct)
74 {
75  return GetClearGround(t) == ct;
76 }
77 
78 
85 static inline uint GetClearDensity(TileIndex t)
86 {
87  assert(IsTileType(t, MP_CLEAR));
88  return GB(_m[t].m5, 0, 2);
89 }
90 
97 static inline void AddClearDensity(TileIndex t, int d)
98 {
99  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
100  _m[t].m5 += d;
101 }
102 
109 static inline void SetClearDensity(TileIndex t, uint d)
110 {
111  assert(IsTileType(t, MP_CLEAR));
112  SB(_m[t].m5, 0, 2, d);
113 }
114 
115 
122 static inline uint GetClearCounter(TileIndex t)
123 {
124  assert(IsTileType(t, MP_CLEAR));
125  return GB(_m[t].m5, 5, 3);
126 }
127 
134 static inline void AddClearCounter(TileIndex t, int c)
135 {
136  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
137  _m[t].m5 += c << 5;
138 }
139 
146 static inline void SetClearCounter(TileIndex t, uint c)
147 {
148  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
149  SB(_m[t].m5, 5, 3, c);
150 }
151 
152 
160 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
161 {
162  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
163  _m[t].m5 = 0 << 5 | type << 2 | density;
164 }
165 
166 
173 static inline uint GetFieldType(TileIndex t)
174 {
175  assert(GetClearGround(t) == CLEAR_FIELDS);
176  return GB(_m[t].m3, 0, 4);
177 }
178 
185 static inline void SetFieldType(TileIndex t, uint f)
186 {
187  assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
188  SB(_m[t].m3, 0, 4, f);
189 }
190 
197 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
198 {
199  assert(GetClearGround(t) == CLEAR_FIELDS);
200  return(IndustryID) _m[t].m2;
201 }
202 
209 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
210 {
211  assert(GetClearGround(t) == CLEAR_FIELDS);
212  _m[t].m2 = i;
213 }
214 
215 
223 static inline uint GetFence(TileIndex t, DiagDirection side)
224 {
225  assert(IsClearGround(t, CLEAR_FIELDS));
226  switch (side) {
227  default: NOT_REACHED();
228  case DIAGDIR_SE: return GB(_m[t].m4, 2, 3);
229  case DIAGDIR_SW: return GB(_m[t].m4, 5, 3);
230  case DIAGDIR_NE: return GB(_m[t].m3, 5, 3);
231  case DIAGDIR_NW: return GB(_me[t].m6, 2, 3);
232  }
233 }
234 
242 static inline void SetFence(TileIndex t, DiagDirection side, uint h)
243 {
244  assert(IsClearGround(t, CLEAR_FIELDS));
245  switch (side) {
246  default: NOT_REACHED();
247  case DIAGDIR_SE: SB(_m[t].m4, 2, 3, h); break;
248  case DIAGDIR_SW: SB(_m[t].m4, 5, 3, h); break;
249  case DIAGDIR_NE: SB(_m[t].m3, 5, 3, h); break;
250  case DIAGDIR_NW: SB(_me[t].m6, 2, 3, h); break;
251  }
252 }
253 
254 
261 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
262 {
263  SetTileType(t, MP_CLEAR);
264  _m[t].m1 = 0;
266  _m[t].m2 = 0;
267  _m[t].m3 = 0;
268  _m[t].m4 = 0 << 5 | 0 << 2;
269  SetClearGroundDensity(t, g, density); // Sets m5
270  _me[t].m6 = 0;
271  _me[t].m7 = 0;
272 }
273 
274 
281 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
282 {
283  SetTileType(t, MP_CLEAR);
284  _m[t].m1 = 0;
286  _m[t].m2 = industry;
287  _m[t].m3 = field_type;
288  _m[t].m4 = 0 << 5 | 0 << 2;
290  SB(_me[t].m6, 2, 4, 0);
291  _me[t].m7 = 0;
292 }
293 
300 static inline void MakeSnow(TileIndex t, uint density = 0)
301 {
302  assert(GetClearGround(t) != CLEAR_SNOW);
303  SetBit(_m[t].m3, 4);
304  if (GetRawClearGround(t) == CLEAR_FIELDS) {
305  SetClearGroundDensity(t, CLEAR_GRASS, density);
306  } else {
307  SetClearDensity(t, density);
308  }
309 }
310 
316 static inline void ClearSnow(TileIndex t)
317 {
318  assert(GetClearGround(t) == CLEAR_SNOW);
319  ClrBit(_m[t].m3, 4);
320  SetClearDensity(t, 3);
321 }
322 
323 #endif /* CLEAR_MAP_H */
Types related to the industry.
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
static bool IsSnowTile(TileIndex t)
Test if a tile is covered with snow.
Definition: clear_map.h:37
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
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Tile * _m
Tiles of the map.
Definition: map.cpp:32
Northeast, upper right on your monitor.
byte m6
General purpose.
Definition: map_type.h:36
ClearGround
Ground types.
Definition: clear_map.h:21
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:73
static IndustryID GetIndustryIndexOfField(TileIndex t)
Get the industry (farm) that made the field.
Definition: clear_map.h:197
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.
byte m1
Primarily used for ownership information.
Definition: map_type.h:23
static uint GetFence(TileIndex t, DiagDirection side)
Is there a fence at the given border?
Definition: clear_map.h:223
static uint GetFieldType(TileIndex t)
Get the field type (production stage) of the field.
Definition: clear_map.h:173
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
static void MakeField(TileIndex t, uint field_type, IndustryID industry)
Make a (farm) field tile.
Definition: clear_map.h:281
Southeast.
Southwest.
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
static void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
Sets ground type and density in one go, also sets the counter to 0.
Definition: clear_map.h:160
byte m5
General purpose.
Definition: map_type.h:26
static void SetFieldType(TileIndex t, uint f)
Set the field type (production stage) of the field.
Definition: clear_map.h:185
Map accessor functions for bridges.
The tile has no ownership.
Definition: company_type.h:27
Northwest.
static void SetClearDensity(TileIndex t, uint d)
Set the density of a non-field clear tile.
Definition: clear_map.h:109
DiagDirection
Enumeration for diagonal directions.
static ClearGround GetClearGround(TileIndex t)
Get the type of clear tile.
Definition: clear_map.h:61
static void AddClearDensity(TileIndex t, int d)
Increment the density of a non-field clear tile.
Definition: clear_map.h:97
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
Definition: clear_map.h:85
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
static uint GetClearCounter(TileIndex t)
Get the counter used to advance to the next clear density/field type.
Definition: clear_map.h:122
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
static void MakeSnow(TileIndex t, uint density=0)
Make a snow tile.
Definition: clear_map.h:300
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:261
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
Definition: clear_map.h:49
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
0-3
Definition: clear_map.h:26
static void AddClearCounter(TileIndex t, int c)
Increments the counter used to advance to the next clear density/field type.
Definition: clear_map.h:134
static void SetIndustryIndexOfField(TileIndex t, IndustryID i)
Set the industry (farm) that made the field.
Definition: clear_map.h:209
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static void SetClearCounter(TileIndex t, uint c)
Sets the counter used to advance to the next clear density/field type.
Definition: clear_map.h:146
static void SetFence(TileIndex t, DiagDirection side, uint h)
Sets the type of fence (and whether there is one) for the given border.
Definition: clear_map.h:242
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:43
static void ClearSnow(TileIndex t)
Clear the snow from a tile and return it to its previous type.
Definition: clear_map.h:316
byte m3
General purpose.
Definition: map_type.h:24
byte m4
General purpose.
Definition: map_type.h:25