OpenTTD: src/tile_map.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

tile_map.h
Go to the documentation of this file.
1 /* $Id: tile_map.h 26875 2014-09-21 11:18:10Z 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 TILE_MAP_H
13 #define TILE_MAP_H
14
15 #include "slope_type.h"
16 #include "map_func.h"
17 #include "core/bitmath_func.hpp"
18 #include "settings_type.h"
19
31 static inline uint TileHeight(TileIndex tile)
32 {
33 assert(tile < MapSize());
34 return _m[tile].height;
35 }
36
37 uint TileHeightOutsideMap(int x, int y);
38
49 static inline void SetTileHeight(TileIndex tile, uint height)
50 {
51 assert(tile < MapSize());
52 assert(height <= MAX_TILE_HEIGHT);
53 _m[tile].height = height;
54 }
55
64 static inline uint TilePixelHeight(TileIndex tile)
65 {
66 return TileHeight(tile) * TILE_HEIGHT;
67 }
68
76 static inline TileType GetTileType(TileIndex tile)
77 {
78 assert(tile < MapSize());
79 return (TileType)GB(_m[tile].type, 4, 4);
80 }
81
89 static inline bool IsInnerTile(TileIndex tile)
90 {
91 assert(tile < MapSize());
92
93 uint x = TileX(tile);
94 uint y = TileY(tile);
95
96 return x < MapMaxX() && y < MapMaxY() && ((x > 0 && y > 0) || !_settings_game.construction.freeform_edges);
97 }
98
111 static inline void SetTileType(TileIndex tile, TileType type)
112 {
113 assert(tile < MapSize());
114 /* VOID tiles (and no others) are exactly allowed at the lower left and right
115 * edges of the map. If _settings_game.construction.freeform_edges is true,
116 * the upper edges of the map are also VOID tiles. */
117 assert(IsInnerTile(tile) == (type != MP_VOID));
118 SB(_m[tile].type, 4, 4, type);
119 }
120
130 static inline bool IsTileType(TileIndex tile, TileType type)
131 {
132 return GetTileType(tile) == type;
133 }
134
141 static inline bool IsValidTile(TileIndex tile)
142 {
143 return tile < MapSize() && !IsTileType(tile, MP_VOID);
144 }
145
158 static inline Owner GetTileOwner(TileIndex tile)
159 {
160 assert(IsValidTile(tile));
161 assert(!IsTileType(tile, MP_HOUSE));
162 assert(!IsTileType(tile, MP_INDUSTRY));
163
164 return (Owner)GB(_m[tile].m1, 0, 5);
165 }
166
178 static inline void SetTileOwner(TileIndex tile, Owner owner)
179 {
180 assert(IsValidTile(tile));
181 assert(!IsTileType(tile, MP_HOUSE));
182 assert(!IsTileType(tile, MP_INDUSTRY));
183
184 SB(_m[tile].m1, 0, 5, owner);
185 }
186
194 static inline bool IsTileOwner(TileIndex tile, Owner owner)
195 {
196 return GetTileOwner(tile) == owner;
197 }
198
205 static inline void SetTropicZone(TileIndex tile, TropicZone type)
206 {
207 assert(tile < MapSize());
208 assert(!IsTileType(tile, MP_VOID) || type == TROPICZONE_NORMAL);
209 SB(_m[tile].type, 0, 2, type);
210 }
211
218 static inline TropicZone GetTropicZone(TileIndex tile)
219 {
220 assert(tile < MapSize());
221 return (TropicZone)GB(_m[tile].type, 0, 2);
222 }
223
230 static inline byte GetAnimationFrame(TileIndex t)
231 {
232 assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION));
233 return _me[t].m7;
234 }
235
242 static inline void SetAnimationFrame(TileIndex t, byte frame)
243 {
244 assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION));
245 _me[t].m7 = frame;
246 }
247
248 Slope GetTileSlope(TileIndex tile, int *h = NULL);
249 int GetTileZ(TileIndex tile);
250 int GetTileMaxZ(TileIndex tile);
251
252 bool IsTileFlat(TileIndex tile, int *h = NULL);
253
260 static inline Slope GetTilePixelSlope(TileIndex tile, int *h)
261 {
262 Slope s = GetTileSlope(tile, h);
263 if (h != NULL) *h *= TILE_HEIGHT;
264 return s;
265 }
266
267 Slope GetTilePixelSlopeOutsideMap(int x, int y, int *h);
268
274 static inline int GetTilePixelZ(TileIndex tile)
275 {
276 return GetTileZ(tile) * TILE_HEIGHT;
277 }
278
279 int GetTilePixelZOutsideMap(int x, int y);
280
286 static inline int GetTileMaxPixelZ(TileIndex tile)
287 {
288 return GetTileMaxZ(tile) * TILE_HEIGHT;
289 }
290
291 int GetTileMaxPixelZOutsideMap(int x, int y);
292
293
301 static inline uint TileHash(uint x, uint y)
302 {
303 uint hash = x >> 4;
304 hash ^= x >> 6;
305 hash ^= y >> 4;
306 hash -= y >> 6;
307 return hash;
308 }
309
319 static inline uint TileHash2Bit(uint x, uint y)
320 {
321 return GB(TileHash(x, y), 0, 2);
322 }
323
324 #endif /* TILE_MAP_H */