OpenTTD
clear_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 CLEAR_MAP_H
11 #define CLEAR_MAP_H
12 
13 #include "bridge_map.h"
14 #include "industry_type.h"
15 
24  CLEAR_SNOW = 4,
26 };
27 
28 
35 static inline bool IsSnowTile(TileIndex t)
36 {
37  assert(IsTileType(t, MP_CLEAR));
38  return HasBit(_m[t].m3, 4);
39 }
40 
48 {
49  assert(IsTileType(t, MP_CLEAR));
50  return (ClearGround)GB(_m[t].m5, 2, 3);
51 }
52 
60 {
61  if (IsSnowTile(t)) return CLEAR_SNOW;
62  return GetRawClearGround(t);
63 }
64 
71 static inline bool IsClearGround(TileIndex t, ClearGround ct)
72 {
73  return GetClearGround(t) == ct;
74 }
75 
76 
83 static inline uint GetClearDensity(TileIndex t)
84 {
85  assert(IsTileType(t, MP_CLEAR));
86  return GB(_m[t].m5, 0, 2);
87 }
88 
95 static inline void AddClearDensity(TileIndex t, int d)
96 {
97  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
98  _m[t].m5 += d;
99 }
100 
107 static inline void SetClearDensity(TileIndex t, uint d)
108 {
109  assert(IsTileType(t, MP_CLEAR));
110  SB(_m[t].m5, 0, 2, d);
111 }
112 
113 
120 static inline uint GetClearCounter(TileIndex t)
121 {
122  assert(IsTileType(t, MP_CLEAR));
123  return GB(_m[t].m5, 5, 3);
124 }
125 
132 static inline void AddClearCounter(TileIndex t, int c)
133 {
134  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
135  _m[t].m5 += c << 5;
136 }
137 
144 static inline void SetClearCounter(TileIndex t, uint c)
145 {
146  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
147  SB(_m[t].m5, 5, 3, c);
148 }
149 
150 
158 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
159 {
160  assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
161  _m[t].m5 = 0 << 5 | type << 2 | density;
162 }
163 
164 
171 static inline uint GetFieldType(TileIndex t)
172 {
173  assert(GetClearGround(t) == CLEAR_FIELDS);
174  return GB(_m[t].m3, 0, 4);
175 }
176 
183 static inline void SetFieldType(TileIndex t, uint f)
184 {
185  assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
186  SB(_m[t].m3, 0, 4, f);
187 }
188 
195 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
196 {
197  assert(GetClearGround(t) == CLEAR_FIELDS);
198  return(IndustryID) _m[t].m2;
199 }
200 
207 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
208 {
209  assert(GetClearGround(t) == CLEAR_FIELDS);
210  _m[t].m2 = i;
211 }
212 
213 
221 static inline uint GetFence(TileIndex t, DiagDirection side)
222 {
223  assert(IsClearGround(t, CLEAR_FIELDS));
224  switch (side) {
225  default: NOT_REACHED();
226  case DIAGDIR_SE: return GB(_m[t].m4, 2, 3);
227  case DIAGDIR_SW: return GB(_m[t].m4, 5, 3);
228  case DIAGDIR_NE: return GB(_m[t].m3, 5, 3);
229  case DIAGDIR_NW: return GB(_me[t].m6, 2, 3);
230  }
231 }
232 
240 static inline void SetFence(TileIndex t, DiagDirection side, uint h)
241 {
242  assert(IsClearGround(t, CLEAR_FIELDS));
243  switch (side) {
244  default: NOT_REACHED();
245  case DIAGDIR_SE: SB(_m[t].m4, 2, 3, h); break;
246  case DIAGDIR_SW: SB(_m[t].m4, 5, 3, h); break;
247  case DIAGDIR_NE: SB(_m[t].m3, 5, 3, h); break;
248  case DIAGDIR_NW: SB(_me[t].m6, 2, 3, h); break;
249  }
250 }
251 
252 
259 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
260 {
261  SetTileType(t, MP_CLEAR);
262  _m[t].m1 = 0;
264  _m[t].m2 = 0;
265  _m[t].m3 = 0;
266  _m[t].m4 = 0 << 5 | 0 << 2;
267  SetClearGroundDensity(t, g, density); // Sets m5
268  _me[t].m6 = 0;
269  _me[t].m7 = 0;
270  _me[t].m8 = 0;
271 }
272 
273 
280 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
281 {
282  SetTileType(t, MP_CLEAR);
283  _m[t].m1 = 0;
285  _m[t].m2 = industry;
286  _m[t].m3 = field_type;
287  _m[t].m4 = 0 << 5 | 0 << 2;
289  SB(_me[t].m6, 2, 4, 0);
290  _me[t].m7 = 0;
291  _me[t].m8 = 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:198
static bool IsSnowTile(TileIndex t)
Test if a tile is covered with snow.
Definition: clear_map.h:35
Northwest.
byte m7
Primarily used for newgrf support.
Definition: map_type.h:35
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:20
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Tile * _m
Tiles of the map.
Definition: map.cpp:30
byte m6
General purpose.
Definition: map_type.h:34
ClearGround
Ground types.
Definition: clear_map.h:19
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
static IndustryID GetIndustryIndexOfField(TileIndex t)
Get the industry (farm) that made the field.
Definition: clear_map.h:195
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:21
static uint GetFence(TileIndex t, DiagDirection side)
Is there a fence at the given border?
Definition: clear_map.h:221
static uint GetFieldType(TileIndex t)
Get the field type (production stage) of the field.
Definition: clear_map.h:171
The tile has no ownership.
Definition: company_type.h:25
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
static void MakeField(TileIndex t, uint field_type, IndustryID industry)
Make a (farm) field tile.
Definition: clear_map.h:280
Southeast.
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:31
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:158
byte m5
General purpose.
Definition: map_type.h:24
static void SetFieldType(TileIndex t, uint f)
Set the field type (production stage) of the field.
Definition: clear_map.h:183
Map accessor functions for bridges.
static void SetClearDensity(TileIndex t, uint d)
Set the density of a non-field clear tile.
Definition: clear_map.h:107
static ClearGround GetClearGround(TileIndex t)
Get the type of clear tile.
Definition: clear_map.h:59
static void AddClearDensity(TileIndex t, int d)
Increment the density of a non-field clear tile.
Definition: clear_map.h:95
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
Definition: clear_map.h:83
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:120
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
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:259
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:47
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
0-3
Definition: clear_map.h:24
static void AddClearCounter(TileIndex t, int c)
Increments the counter used to advance to the next clear density/field type.
Definition: clear_map.h:132
uint16 m8
General purpose.
Definition: map_type.h:36
static void SetIndustryIndexOfField(TileIndex t, IndustryID i)
Set the industry (farm) that made the field.
Definition: clear_map.h:207
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
static void SetClearCounter(TileIndex t, uint c)
Sets the counter used to advance to the next clear density/field type.
Definition: clear_map.h:144
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:240
Northeast, upper right on your monitor.
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:41
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:22
Southwest.
byte m4
General purpose.
Definition: map_type.h:23