tron@2186: /* $Id$ */ tron@2186: tron@1209: #ifndef TILE_H tron@1209: #define TILE_H tron@926: tron@1394: #include "macros.h" tron@1209: #include "map.h" tron@1035: matthijs@1944: typedef enum TileTypes { tron@1214: MP_CLEAR, tron@1214: MP_RAILWAY, tron@1214: MP_STREET, tron@1214: MP_HOUSE, tron@1214: MP_TREES, tron@1214: MP_STATION, tron@1214: MP_WATER, tron@1214: MP_VOID, // invisible tiles at the SW and SE border tron@1214: MP_INDUSTRY, tron@1214: MP_TUNNELBRIDGE, ludde@2125: MP_UNMOVABLE, tron@1214: } TileType; tron@1214: matthijs@1942: /* Direction as commonly used in v->direction, 8 way. */ matthijs@1942: typedef enum Directions { matthijs@1942: DIR_N = 0, matthijs@1942: DIR_NE = 1, /* Northeast, upper right on your monitor */ matthijs@1942: DIR_E = 2, matthijs@1942: DIR_SE = 3, matthijs@1942: DIR_S = 4, matthijs@1942: DIR_SW = 5, matthijs@1942: DIR_W = 6, matthijs@1942: DIR_NW = 7, matthijs@1942: DIR_END, matthijs@1942: INVALID_DIR = 0xFF, matthijs@1942: } Direction; matthijs@1749: matthijs@1942: /* Direction commonly used as the direction of entering and leaving tiles, 4-way */ matthijs@1942: typedef enum DiagonalDirections { matthijs@1942: DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */ matthijs@1942: DIAGDIR_SE = 1, matthijs@1942: DIAGDIR_SW = 2, matthijs@1942: DIAGDIR_NW = 3, matthijs@1942: DIAGDIR_END, matthijs@1942: INVALID_DIAGDIR = 0xFF, matthijs@1942: } DiagDirection; matthijs@1749: tron@1211: void SetMapExtraBits(TileIndex tile, byte flags); tron@1211: uint GetMapExtraBits(TileIndex tile); tron@1211: celestar@9942: uint GetTileh(uint n, uint w, uint e, uint s, uint *h); tron@1335: uint GetTileSlope(TileIndex tile, uint *h); tron@1335: uint GetTileZ(TileIndex tile); tron@1335: tron@1394: static inline bool CorrectZ(uint tileh) tron@1394: { tron@1394: /* tile height must be corrected if the north corner is not raised, but tron@1394: * any other corner is. These are the cases 1 till 7 */ tron@1394: return IS_INT_INSIDE(tileh, 1, 8); tron@1394: } tron@1394: tron@1044: static inline uint TileHeight(TileIndex tile) tron@1044: { tron@1044: assert(tile < MapSize()); tron@2049: return GB(_m[tile].type_height, 0, 4); tron@1044: } tron@1044: celestar@2085: static inline bool IsSteepTileh(uint tileh) celestar@2085: { celestar@2085: return (tileh & 0x10); celestar@2085: } celestar@2085: tron@1059: static inline void SetTileHeight(TileIndex tile, uint height) tron@1059: { tron@1059: assert(tile < MapSize()); tron@1059: assert(height < 16); tron@2049: SB(_m[tile].type_height, 0, 4, height); tron@1059: } tron@1059: tron@1041: static inline uint TilePixelHeight(TileIndex tile) tron@1035: { tron@1044: return TileHeight(tile) * 8; tron@1035: } tron@1035: tron@1214: static inline TileType GetTileType(TileIndex tile) tron@1035: { tron@1035: assert(tile < MapSize()); tron@2049: return GB(_m[tile].type_height, 4, 4); tron@1035: } tron@1035: tron@1214: static inline void SetTileType(TileIndex tile, TileType type) tron@1059: { tron@1059: assert(tile < MapSize()); matthijs@2900: /* Allow only MP_VOID to be set to border tiles. This code is put here since matthijs@2900: * it seems there is a bug that violates this somewhere. (Formely know as matthijs@2900: * the "old ship pf" bug, which presented a case in which this broke). It matthijs@2900: * can be removed as soon as the bug is squashed. */ matthijs@2900: assert((TileX(tile) < MapMaxX() && TileY(tile) < MapMaxY()) || type == MP_VOID); tron@2049: SB(_m[tile].type_height, 4, 4, type); tron@1059: } tron@1059: tron@1214: static inline bool IsTileType(TileIndex tile, TileType type) tron@1035: { tron@1214: return GetTileType(tile) == type; tron@1035: } tron@1035: ludde@2125: static inline bool IsTunnelTile(TileIndex tile) ludde@2125: { tron@2493: return IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0; ludde@2125: } ludde@2125: tron@1333: static inline Owner GetTileOwner(TileIndex tile) matthijs@1330: { tron@1333: assert(tile < MapSize()); tron@1898: assert(!IsTileType(tile, MP_HOUSE)); tron@1898: assert(!IsTileType(tile, MP_VOID)); tron@1898: assert(!IsTileType(tile, MP_INDUSTRY)); tron@1898: tron@2360: return _m[tile].m1; matthijs@1330: } matthijs@1330: tron@1902: static inline void SetTileOwner(TileIndex tile, Owner owner) tron@1902: { tron@1902: assert(tile < MapSize()); tron@1902: assert(!IsTileType(tile, MP_HOUSE)); tron@1902: assert(!IsTileType(tile, MP_VOID)); tron@1902: assert(!IsTileType(tile, MP_INDUSTRY)); tron@1902: tron@2360: _m[tile].m1 = owner; tron@1902: } tron@1902: matthijs@1330: static inline bool IsTileOwner(TileIndex tile, Owner owner) matthijs@1330: { matthijs@1330: return GetTileOwner(tile) == owner; matthijs@1330: } matthijs@1330: Darkvater@2436: #endif /* TILE_H */