# tile_map.h

Go to the documentation of this file.

    00001 /* $Id: tile_map.h 12303 2008-02-28 00:10:08Z glx $ */
    00002
    00005 #ifndef TILE_MAP_H
    00006 #define TILE_MAP_H
    00007
    00008 #include "tile_type.h"
    00009 #include "slope_type.h"
    00010 #include "player_type.h"
    00011 #include "map_func.h"
    00012 #include "core/bitmath_func.hpp"
    00013
    00025 static inline uint TileHeight(TileIndex tile)
    00026 {
    00027   assert(tile < MapSize());
    00028   return GB(_m[tile].type_height, 0, 4);
    00029 }
    00030
    00041 static inline void SetTileHeight(TileIndex tile, uint height)
    00042 {
    00043   assert(tile < MapSize());
    00044   assert(height <= MAX_TILE_HEIGHT);
    00045   SB(_m[tile].type_height, 0, 4, height);
    00046 }
    00047
    00056 static inline uint TilePixelHeight(TileIndex tile)
    00057 {
    00058   return TileHeight(tile) * TILE_HEIGHT;
    00059 }
    00060
    00068 static inline TileType GetTileType(TileIndex tile)
    00069 {
    00070   assert(tile < MapSize());
    00071   return (TileType)GB(_m[tile].type_height, 4, 4);
    00072 }
    00073
    00086 static inline void SetTileType(TileIndex tile, TileType type)
    00087 {
    00088   assert(tile < MapSize());
    00089   /* VOID tiles (and no others) are exactly allowed at the lower left and right
    00090    * edges of the map */
    00091   assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID));
    00092   SB(_m[tile].type_height, 4, 4, type);
    00093 }
    00094
    00104 static inline bool IsTileType(TileIndex tile, TileType type)
    00105 {
    00106   return GetTileType(tile) == type;
    00107 }
    00108
    00115 static inline bool IsValidTile(TileIndex tile)
    00116 {
    00117   return tile < MapSize() && !IsTileType(tile, MP_VOID);
    00118 }
    00119
    00132 static inline Owner GetTileOwner(TileIndex tile)
    00133 {
    00134   assert(IsValidTile(tile));
    00135   assert(!IsTileType(tile, MP_HOUSE));
    00136   assert(!IsTileType(tile, MP_INDUSTRY));
    00137
    00138   return (Owner)_m[tile].m1;
    00139 }
    00140
    00152 static inline void SetTileOwner(TileIndex tile, Owner owner)
    00153 {
    00154   assert(IsValidTile(tile));
    00155   assert(!IsTileType(tile, MP_HOUSE));
    00156   assert(!IsTileType(tile, MP_INDUSTRY));
    00157
    00158   _m[tile].m1 = owner;
    00159 }
    00160
    00168 static inline bool IsTileOwner(TileIndex tile, Owner owner)
    00169 {
    00170   return GetTileOwner(tile) == owner;
    00171 }
    00172
    00179 static inline void SetTropicZone(TileIndex tile, TropicZone type)
    00180 {
    00181   assert(tile < MapSize());
    00182   SB(_m[tile].m6, 0, 2, type);
    00183 }
    00184
    00191 static inline TropicZone GetTropicZone(TileIndex tile)
    00192 {
    00193   assert(tile < MapSize());
    00194   return (TropicZone)GB(_m[tile].m6, 0, 2);
    00195 }
    00196
    00197 Slope GetTileSlope(TileIndex tile, uint *h);
    00198 uint GetTileZ(TileIndex tile);
    00199 uint GetTileMaxZ(TileIndex tile);
    00200
    00201 #endif /* TILE_TYPE_H */