tile_map.h

Go to the documentation of this file.
00001 /* $Id$ */
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)GB(_m[tile].m1, 0, 5);
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   SB(_m[tile].m1, 0, 5, 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 
00211 static inline byte GetAnimationFrame(TileIndex t)
00212 {
00213   assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION));
00214   return _me[t].m7;
00215 }
00216 
00223 static inline void SetAnimationFrame(TileIndex t, byte frame)
00224 {
00225   assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION));
00226   _me[t].m7 = frame;
00227 }
00228 
00229 Slope GetTileSlope(TileIndex tile, uint *h);
00230 uint GetTileZ(TileIndex tile);
00231 uint GetTileMaxZ(TileIndex tile);
00232 
00233 
00241 static inline uint TileHash(uint x, uint y)
00242 {
00243   uint hash = x >> 4;
00244   hash ^= x >> 6;
00245   hash ^= y >> 4;
00246   hash -= y >> 6;
00247   return hash;
00248 }
00249 
00259 static inline uint TileHash2Bit(uint x, uint y)
00260 {
00261   return GB(TileHash(x, y), 0, 2);
00262 }
00263 
00264 #endif /* TILE_MAP_H */

Generated on Thu Apr 14 00:48:21 2011 for OpenTTD by  doxygen 1.6.1