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 */