00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef TILE_MAP_H
00013 #define TILE_MAP_H
00014
00015 #include "slope_type.h"
00016 #include "map_func.h"
00017 #include "core/bitmath_func.hpp"
00018 #include "settings_type.h"
00019
00031 static inline uint TileHeight(TileIndex tile)
00032 {
00033 assert(tile < MapSize());
00034 return GB(_m[tile].type_height, 0, 4);
00035 }
00036
00047 static inline void SetTileHeight(TileIndex tile, uint height)
00048 {
00049 assert(tile < MapSize());
00050 assert(height <= MAX_TILE_HEIGHT);
00051 SB(_m[tile].type_height, 0, 4, height);
00052 }
00053
00062 static inline uint TilePixelHeight(TileIndex tile)
00063 {
00064 return TileHeight(tile) * TILE_HEIGHT;
00065 }
00066
00074 static inline TileType GetTileType(TileIndex tile)
00075 {
00076 assert(tile < MapSize());
00077 return (TileType)GB(_m[tile].type_height, 4, 4);
00078 }
00079
00092 static inline void SetTileType(TileIndex tile, TileType type)
00093 {
00094 assert(tile < MapSize());
00095
00096
00097
00098 assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
00099 SB(_m[tile].type_height, 4, 4, type);
00100 }
00101
00111 static inline bool IsTileType(TileIndex tile, TileType type)
00112 {
00113 return GetTileType(tile) == type;
00114 }
00115
00122 static inline bool IsValidTile(TileIndex tile)
00123 {
00124 return tile < MapSize() && !IsTileType(tile, MP_VOID);
00125 }
00126
00139 static inline Owner GetTileOwner(TileIndex tile)
00140 {
00141 assert(IsValidTile(tile));
00142 assert(!IsTileType(tile, MP_HOUSE));
00143 assert(!IsTileType(tile, MP_INDUSTRY));
00144
00145 return (Owner)GB(_m[tile].m1, 0, 5);
00146 }
00147
00159 static inline void SetTileOwner(TileIndex tile, Owner owner)
00160 {
00161 assert(IsValidTile(tile));
00162 assert(!IsTileType(tile, MP_HOUSE));
00163 assert(!IsTileType(tile, MP_INDUSTRY));
00164
00165 SB(_m[tile].m1, 0, 5, owner);
00166 }
00167
00175 static inline bool IsTileOwner(TileIndex tile, Owner owner)
00176 {
00177 return GetTileOwner(tile) == owner;
00178 }
00179
00186 static inline void SetTropicZone(TileIndex tile, TropicZone type)
00187 {
00188 assert(tile < MapSize());
00189 assert(!IsTileType(tile, MP_VOID) || type == TROPICZONE_NORMAL);
00190 SB(_m[tile].m6, 0, 2, type);
00191 }
00192
00199 static inline TropicZone GetTropicZone(TileIndex tile)
00200 {
00201 assert(tile < MapSize());
00202 return (TropicZone)GB(_m[tile].m6, 0, 2);
00203 }
00204
00211 static inline byte GetAnimationFrame(TileIndex t)
00212 {
00213 assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION));
00214 return _me[t].m7;
00215 }
00216
00223 static inline void SetAnimationFrame(TileIndex t, byte frame)
00224 {
00225 assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION));
00226 _me[t].m7 = frame;
00227 }
00228
00229 Slope GetTileSlope(TileIndex tile, int *h = NULL);
00230 int GetTileZ(TileIndex tile);
00231 int GetTileMaxZ(TileIndex tile);
00232
00239 static inline Slope GetTilePixelSlope(TileIndex tile, int *h)
00240 {
00241 Slope s = GetTileSlope(tile, h);
00242 if (h != NULL) *h *= TILE_HEIGHT;
00243 return s;
00244 }
00245
00251 static inline int GetTilePixelZ(TileIndex tile)
00252 {
00253 return GetTileZ(tile) * TILE_HEIGHT;
00254 }
00255
00261 static inline int GetTileMaxPixelZ(TileIndex tile)
00262 {
00263 return GetTileMaxZ(tile) * TILE_HEIGHT;
00264 }
00265
00266
00274 static inline uint TileHash(uint x, uint y)
00275 {
00276 uint hash = x >> 4;
00277 hash ^= x >> 6;
00278 hash ^= y >> 4;
00279 hash -= y >> 6;
00280 return hash;
00281 }
00282
00292 static inline uint TileHash2Bit(uint x, uint y)
00293 {
00294 return GB(TileHash(x, y), 0, 2);
00295 }
00296
00297 #endif