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
49 static inline HouseID GetCleanHouseType(TileIndex t)
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 {
63 return GetTranslatedHouseID(GetCleanHouseType(t));
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);
363 SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
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 */
GetHouseAge
static Year GetHouseAge(TileIndex t)
Get the age of the house.
Definition: town_map.h:251
SetAnimationFrame
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
Definition: tile_map.h:255
TOWN_HOUSE_COMPLETED
static const byte TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition: house.h:25
AB
static T AB(T &x, const uint8 s, const uint8 n, const U i)
Add i to n bits of x starting at bit s.
Definition: bitmath_func.hpp:85
road_map.h
Map accessors for roads.
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:123
MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:45
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:32
MakeHouseTile
static void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
Make the tile a house.
Definition: town_map.h:354
GetHouseRandomBits
static byte GetHouseRandomBits(TileIndex t)
Get the random bits for this house.
Definition: town_map.h:277
TileExtended::m6
byte m6
General purpose.
Definition: map_type.h:36
GetTranslatedHouseID
static HouseID GetTranslatedHouseID(HouseID hid)
Do HouseID translation for NewGRFs.
Definition: house.h:140
LiftHasDestination
static bool LiftHasDestination(TileIndex t)
Check if the lift of this animated house has a destination.
Definition: town_map.h:84
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
HouseID
uint16 HouseID
OpenTTD ID of house types.
Definition: house_type.h:15
GetLiftDestination
static byte GetLiftDestination(TileIndex t)
Get the current destination for this lift.
Definition: town_map.h:106
SB
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.
Definition: bitmath_func.hpp:60
Tile::m1
byte m1
Primarily used for ownership information.
Definition: map_type.h:23
SetHouseType
static void SetHouseType(TileIndex t, HouseID house_id)
Set the house type.
Definition: town_map.h:72
GetHouseBuildingStage
static byte GetHouseBuildingStage(TileIndex t)
House Construction Scheme.
Definition: town_map.h:185
IsHouseCompleted
static bool IsHouseCompleted(TileIndex t)
Get the completion of this house.
Definition: town_map.h:147
GetHouseConstructionTick
static byte GetHouseConstructionTick(TileIndex t)
Gets the construction stage of a house.
Definition: town_map.h:197
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
GetCleanHouseType
static HouseID GetCleanHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array without doing any NewGRF rela...
Definition: town_map.h:49
house.h
definition of HouseSpec and accessors
GetTownIndex
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Definition: town_map.h:24
DecHouseProcessingTime
static void DecHouseProcessingTime(TileIndex t)
Decrease the amount of time remaining before the tile loop processes this tile.
Definition: town_map.h:338
SetHouseRandomBits
static void SetHouseRandomBits(TileIndex t, byte random)
Set the random bits for this house.
Definition: town_map.h:264
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
GetLiftPosition
static byte GetLiftPosition(TileIndex t)
Get the position of the lift on this animated house.
Definition: town_map.h:127
GetHouseProcessingTime
static byte GetHouseProcessingTime(TileIndex t)
Get the amount of time remaining before the tile loop processes this tile.
Definition: town_map.h:315
Tile::m5
byte m5
General purpose.
Definition: map_type.h:26
SetHouseProcessingTime
static void SetHouseProcessingTime(TileIndex t, byte time)
Set the amount of time remaining before the tile loop processes this tile.
Definition: town_map.h:327
IncHouseConstructionTick
static void IncHouseConstructionTick(TileIndex t)
Sets the increment stage of a house It is working with the whole counter + stage 5 bits...
Definition: town_map.h:210
SetHouseCompleted
static void SetHouseCompleted(TileIndex t, bool status)
Mark this house as been completed.
Definition: town_map.h:158
SetLiftDestination
static void SetLiftDestination(TileIndex t, byte dest)
Set the new destination of the lift for this animated house, and activate the LiftHasDestination bit...
Definition: town_map.h:95
HaltLift
static void HaltLift(TileIndex t)
Stop the lift of this animated house from moving.
Definition: town_map.h:117
GetHouseTriggers
static byte GetHouseTriggers(TileIndex t)
Get the already activated triggers bits for this house.
Definition: town_map.h:303
SetLiftPosition
static void SetLiftPosition(TileIndex t, byte pos)
Set the position of the lift on this animated house.
Definition: town_map.h:137
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
GetHouseType
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
Definition: town_map.h:61
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:34
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
ResetHouseAge
static void ResetHouseAge(TileIndex t)
Sets the age of the house to zero.
Definition: town_map.h:228
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:43
MP_HOUSE
A house by a town.
Definition: tile_type.h:46
SetHouseTriggers
static void SetHouseTriggers(TileIndex t, byte triggers)
Set the activated triggers bits for this house.
Definition: town_map.h:290
SetTownIndex
static void SetTownIndex(TileIndex t, TownID index)
Set the town index for a road or house tile.
Definition: town_map.h:36
Tile::m3
byte m3
General purpose.
Definition: map_type.h:24
IsRoadDepot
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Definition: road_map.h:89
IncrementHouseAge
static void IncrementHouseAge(TileIndex t)
Increments the age of the house.
Definition: town_map.h:239
Tile::m4
byte m4
General purpose.
Definition: map_type.h:25