tile_map.h

Go to the documentation of this file.
00001 /* $Id: tile_map.h 17248 2009-08-21 20:21:05Z 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 "tile_type.h"
00016 #include "slope_type.h"
00017 #include "company_type.h"
00018 #include "map_func.h"
00019 #include "core/bitmath_func.hpp"
00020 #include "settings_type.h"
00021 
00033 static inline uint TileHeight(TileIndex tile)
00034 {
00035   assert(tile < MapSize());
00036   return GB(_m[tile].type_height, 0, 4);
00037 }
00038 
00049 static inline void SetTileHeight(TileIndex tile, uint height)
00050 {
00051   assert(tile < MapSize());
00052   assert(height <= MAX_TILE_HEIGHT);
00053   SB(_m[tile].type_height, 0, 4, height);
00054 }
00055 
00064 static inline uint TilePixelHeight(TileIndex tile)
00065 {
00066   return TileHeight(tile) * TILE_HEIGHT;
00067 }
00068 
00076 static inline TileType GetTileType(TileIndex tile)
00077 {
00078   assert(tile < MapSize());
00079   return (TileType)GB(_m[tile].type_height, 4, 4);
00080 }
00081 
00094 static inline void SetTileType(TileIndex tile, TileType type)
00095 {
00096   assert(tile < MapSize());
00097   /* VOID tiles (and no others) are exactly allowed at the lower left and right
00098    * edges of the map. If _settings_game.construction.freeform_edges is true,
00099    * the upper edges of the map are also VOID tiles. */
00100   assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
00101   SB(_m[tile].type_height, 4, 4, type);
00102 }
00103 
00113 static inline bool IsTileType(TileIndex tile, TileType type)
00114 {
00115   return GetTileType(tile) == type;
00116 }
00117 
00124 static inline bool IsValidTile(TileIndex tile)
00125 {
00126   return tile < MapSize() && !IsTileType(tile, MP_VOID);
00127 }
00128 
00141 static inline Owner GetTileOwner(TileIndex tile)
00142 {
00143   assert(IsValidTile(tile));
00144   assert(!IsTileType(tile, MP_HOUSE));
00145   assert(!IsTileType(tile, MP_INDUSTRY));
00146 
00147   return (Owner)_m[tile].m1;
00148 }
00149 
00161 static inline void SetTileOwner(TileIndex tile, Owner owner)
00162 {
00163   assert(IsValidTile(tile));
00164   assert(!IsTileType(tile, MP_HOUSE));
00165   assert(!IsTileType(tile, MP_INDUSTRY));
00166 
00167   _m[tile].m1 = owner;
00168 }
00169 
00177 static inline bool IsTileOwner(TileIndex tile, Owner owner)
00178 {
00179   return GetTileOwner(tile) == owner;
00180 }
00181 
00188 static inline void SetTropicZone(TileIndex tile, TropicZone type)
00189 {
00190   assert(tile < MapSize());
00191   SB(_m[tile].m6, 0, 2, type);
00192 }
00193 
00200 static inline TropicZone GetTropicZone(TileIndex tile)
00201 {
00202   assert(tile < MapSize());
00203   return (TropicZone)GB(_m[tile].m6, 0, 2);
00204 }
00205 
00206 Slope GetTileSlope(TileIndex tile, uint *h);
00207 uint GetTileZ(TileIndex tile);
00208 uint GetTileMaxZ(TileIndex tile);
00209 
00210 #endif /* TILE_TYPE_H */

Generated on Tue Jan 5 21:02:59 2010 for OpenTTD by  doxygen 1.5.6