# tile_map.h

Go to the documentation of this file.

    00001 /* $Id: tile_map.h 15190 2009-01-21 02:31:55Z Yexo $ */
    00002
    00005 #ifndef TILE_MAP_H
    00006 #define TILE_MAP_H
    00007
    00008 #include "tile_type.h"
    00009 #include "slope_type.h"
    00010 #include "company_type.h"
    00011 #include "map_func.h"
    00012 #include "core/bitmath_func.hpp"
    00013 #include "settings_type.h"
    00014
    00026 static inline uint TileHeight(TileIndex tile)
    00027 {
    00028   assert(tile < MapSize());
    00029   return GB(_m[tile].type_height, 0, 4);
    00030 }
    00031
    00042 static inline void SetTileHeight(TileIndex tile, uint height)
    00043 {
    00044   assert(tile < MapSize());
    00045   assert(height <= MAX_TILE_HEIGHT);
    00046   SB(_m[tile].type_height, 0, 4, height);
    00047 }
    00048
    00057 static inline uint TilePixelHeight(TileIndex tile)
    00058 {
    00059   return TileHeight(tile) * TILE_HEIGHT;
    00060 }
    00061
    00069 static inline TileType GetTileType(TileIndex tile)
    00070 {
    00071   assert(tile < MapSize());
    00072   return (TileType)GB(_m[tile].type_height, 4, 4);
    00073 }
    00074
    00087 static inline void SetTileType(TileIndex tile, TileType type)
    00088 {
    00089   assert(tile < MapSize());
    00090   /* VOID tiles (and no others) are exactly allowed at the lower left and right
    00091    * edges of the map. If _settings_game.construction.freeform_edges is true,
    00092    * the upper edges of the map are also VOID tiles. */
    00093   assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
    00094   SB(_m[tile].type_height, 4, 4, type);
    00095 }
    00096
    00106 static inline bool IsTileType(TileIndex tile, TileType type)
    00107 {
    00108   return GetTileType(tile) == type;
    00109 }
    00110
    00117 static inline bool IsValidTile(TileIndex tile)
    00118 {
    00119   return tile < MapSize() && !IsTileType(tile, MP_VOID);
    00120 }
    00121
    00134 static inline Owner GetTileOwner(TileIndex tile)
    00135 {
    00136   assert(IsValidTile(tile));
    00137   assert(!IsTileType(tile, MP_HOUSE));
    00138   assert(!IsTileType(tile, MP_INDUSTRY));
    00139
    00140   return (Owner)_m[tile].m1;
    00141 }
    00142
    00154 static inline void SetTileOwner(TileIndex tile, Owner owner)
    00155 {
    00156   assert(IsValidTile(tile));
    00157   assert(!IsTileType(tile, MP_HOUSE));
    00158   assert(!IsTileType(tile, MP_INDUSTRY));
    00159
    00160   _m[tile].m1 = owner;
    00161 }
    00162
    00170 static inline bool IsTileOwner(TileIndex tile, Owner owner)
    00171 {
    00172   return GetTileOwner(tile) == owner;
    00173 }
    00174
    00181 static inline void SetTropicZone(TileIndex tile, TropicZone type)
    00182 {
    00183   assert(tile < MapSize());
    00184   SB(_m[tile].m6, 0, 2, type);
    00185 }
    00186
    00193 static inline TropicZone GetTropicZone(TileIndex tile)
    00194 {
    00195   assert(tile < MapSize());
    00196   return (TropicZone)GB(_m[tile].m6, 0, 2);
    00197 }
    00198
    00199 Slope GetTileSlope(TileIndex tile, uint *h);
    00200 uint GetTileZ(TileIndex tile);
    00201 uint GetTileMaxZ(TileIndex tile);
    00202
    00203 #endif /* TILE_TYPE_H */