# tile_map.h

Go to the documentation of this file.

    00001 /* $Id: tile_map.h 19857 2010-05-18 21:44:47Z 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   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
    00205 Slope GetTileSlope(TileIndex tile, uint *h);
    00206 uint GetTileZ(TileIndex tile);
    00207 uint GetTileMaxZ(TileIndex tile);
    00208
    00209 #endif /* TILE_TYPE_H */