# tile_map.h

Go to the documentation of this file.

    00001 /* $Id: tile_map.h 18809 2010-01-15 16:41:15Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    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   /* VOID tiles (and no others) are exactly allowed at the lower left and right
    00096    * edges of the map. If _settings_game.construction.freeform_edges is true,
    00097    * the upper edges of the map are also VOID tiles. */
    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)_m[tile].m1;
    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   _m[tile].m1 = 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   SB(_m[tile].m6, 0, 2, type);
    00190 }
    00191
    00198 static inline TropicZone GetTropicZone(TileIndex tile)
    00199 {
    00200   assert(tile < MapSize());
    00201   return (TropicZone)GB(_m[tile].m6, 0, 2);
    00202 }
    00203
    00204 Slope GetTileSlope(TileIndex tile, uint *h);
    00205 uint GetTileZ(TileIndex tile);
    00206 uint GetTileMaxZ(TileIndex tile);
    00207
    00208 #endif /* TILE_TYPE_H */