OpenTTD
town_map.h
Go to the documentation of this file.
1 /* $Id: town_map.h 26878 2014-09-21 11:23:33Z 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 TOWN_MAP_H
13 #define TOWN_MAP_H
14 
15 #include "road_map.h"
16 #include "house.h"
17 
24 static inline TownID GetTownIndex(TileIndex t)
25 {
26  assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
27  return _m[t].m2;
28 }
29 
36 static inline void SetTownIndex(TileIndex t, TownID index)
37 {
38  assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
39  _m[t].m2 = index;
40 }
41 
50 {
51  assert(IsTileType(t, MP_HOUSE));
52  return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
53 }
54 
61 static inline HouseID GetHouseType(TileIndex t)
62 {
64 }
65 
72 static inline void SetHouseType(TileIndex t, HouseID house_id)
73 {
74  assert(IsTileType(t, MP_HOUSE));
75  _m[t].m4 = GB(house_id, 0, 8);
76  SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
77 }
78 
84 static inline bool LiftHasDestination(TileIndex t)
85 {
86  return HasBit(_me[t].m7, 0);
87 }
88 
95 static inline void SetLiftDestination(TileIndex t, byte dest)
96 {
97  SetBit(_me[t].m7, 0);
98  SB(_me[t].m7, 1, 3, dest);
99 }
100 
106 static inline byte GetLiftDestination(TileIndex t)
107 {
108  return GB(_me[t].m7, 1, 3);
109 }
110 
117 static inline void HaltLift(TileIndex t)
118 {
119  SB(_me[t].m7, 0, 4, 0);
120 }
121 
127 static inline byte GetLiftPosition(TileIndex t)
128 {
129  return GB(_me[t].m6, 2, 6);
130 }
131 
137 static inline void SetLiftPosition(TileIndex t, byte pos)
138 {
139  SB(_me[t].m6, 2, 6, pos);
140 }
141 
147 static inline bool IsHouseCompleted(TileIndex t)
148 {
149  assert(IsTileType(t, MP_HOUSE));
150  return HasBit(_m[t].m3, 7);
151 }
152 
158 static inline void SetHouseCompleted(TileIndex t, bool status)
159 {
160  assert(IsTileType(t, MP_HOUSE));
161  SB(_m[t].m3, 7, 1, !!status);
162 }
163 
185 static inline byte GetHouseBuildingStage(TileIndex t)
186 {
187  assert(IsTileType(t, MP_HOUSE));
188  return IsHouseCompleted(t) ? (byte)TOWN_HOUSE_COMPLETED : GB(_m[t].m5, 3, 2);
189 }
190 
197 static inline byte GetHouseConstructionTick(TileIndex t)
198 {
199  assert(IsTileType(t, MP_HOUSE));
200  return IsHouseCompleted(t) ? 0 : GB(_m[t].m5, 0, 3);
201 }
202 
210 static inline void IncHouseConstructionTick(TileIndex t)
211 {
212  assert(IsTileType(t, MP_HOUSE));
213  AB(_m[t].m5, 0, 5, 1);
214 
215  if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
216  /* House is now completed.
217  * Store the year of construction as well, for newgrf house purpose */
218  SetHouseCompleted(t, true);
219  }
220 }
221 
228 static inline void ResetHouseAge(TileIndex t)
229 {
230  assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t));
231  _m[t].m5 = 0;
232 }
233 
239 static inline void IncrementHouseAge(TileIndex t)
240 {
241  assert(IsTileType(t, MP_HOUSE));
242  if (IsHouseCompleted(t) && _m[t].m5 < 0xFF) _m[t].m5++;
243 }
244 
251 static inline Year GetHouseAge(TileIndex t)
252 {
253  assert(IsTileType(t, MP_HOUSE));
254  return IsHouseCompleted(t) ? _m[t].m5 : 0;
255 }
256 
264 static inline void SetHouseRandomBits(TileIndex t, byte random)
265 {
266  assert(IsTileType(t, MP_HOUSE));
267  _m[t].m1 = random;
268 }
269 
277 static inline byte GetHouseRandomBits(TileIndex t)
278 {
279  assert(IsTileType(t, MP_HOUSE));
280  return _m[t].m1;
281 }
282 
290 static inline void SetHouseTriggers(TileIndex t, byte triggers)
291 {
292  assert(IsTileType(t, MP_HOUSE));
293  SB(_m[t].m3, 0, 5, triggers);
294 }
295 
303 static inline byte GetHouseTriggers(TileIndex t)
304 {
305  assert(IsTileType(t, MP_HOUSE));
306  return GB(_m[t].m3, 0, 5);
307 }
308 
315 static inline byte GetHouseProcessingTime(TileIndex t)
316 {
317  assert(IsTileType(t, MP_HOUSE));
318  return GB(_me[t].m6, 2, 6);
319 }
320 
327 static inline void SetHouseProcessingTime(TileIndex t, byte time)
328 {
329  assert(IsTileType(t, MP_HOUSE));
330  SB(_me[t].m6, 2, 6, time);
331 }
332 
338 static inline void DecHouseProcessingTime(TileIndex t)
339 {
340  assert(IsTileType(t, MP_HOUSE));
341  _me[t].m6 -= 1 << 2;
342 }
343 
354 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
355 {
356  assert(IsTileType(t, MP_CLEAR));
357 
358  SetTileType(t, MP_HOUSE);
359  _m[t].m1 = random_bits;
360  _m[t].m2 = tid;
361  _m[t].m3 = 0;
362  SetHouseType(t, type);
364  _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
365  SetAnimationFrame(t, 0);
366  SetHouseProcessingTime(t, HouseSpec::Get(type)->processing_time);
367 }
368 
369 #endif /* TOWN_MAP_H */