tron@2186: /* $Id$ */ tron@2186: glx@9574: /** @file tile.h */ glx@9574: tron@1209: #ifndef TILE_H tron@1209: #define TILE_H tron@926: tron@1394: #include "macros.h" rubidium@5838: #include "openttd.h" tron@1209: #include "map.h" tron@3636: #include "slope.h" tron@1035: rubidium@9694: /** Maximum allowed tile height */ rubidium@9694: #define MAX_TILE_HEIGHT 15 rubidium@9694: rubidium@9694: /** Maximum allowed snowline height */ rubidium@9694: #define MAX_SNOWLINE_HEIGHT (MAX_TILE_HEIGHT - 2) rubidium@9694: rubidium@9694: /** rubidium@9694: * The different type of a tile. rubidium@9694: * rubidium@9694: * Each tile belongs to one type, according whatever is build on it. rubidium@9694: * rubidium@9694: * @note A railway with a crossing street is marked as MP_ROAD. rubidium@9694: */ rubidium@6574: enum TileType { rubidium@9694: MP_CLEAR, ///< A tile without any structures, i.e. grass, rocks, farm fields etc. rubidium@9694: MP_RAILWAY, ///< A railway rubidium@9694: MP_ROAD, ///< A tile with road (or tram tracks) rubidium@9694: MP_HOUSE, ///< A house by a town rubidium@9694: MP_TREES, ///< Tile got trees rubidium@9694: MP_STATION, ///< A tile of a station rubidium@9694: MP_WATER, ///< Water tile rubidium@9694: MP_VOID, ///< Invisible tiles at the SW and SE border rubidium@9694: MP_INDUSTRY, ///< Part of an industry rubidium@9694: MP_TUNNELBRIDGE, ///< Tunnel entry/exit and bridge heads rubidium@9694: MP_UNMOVABLE, ///< Contains an object with cannot be removed like transmitters rubidium@6574: }; tron@1214: rubidium@9694: /** rubidium@9694: * Additional infos of a tile on a tropic game. rubidium@9694: * rubidium@9694: * Each non-water tile in a tropic game is either a rainforest tile or a rubidium@9694: * desert one. rubidium@9694: */ rubidium@6574: enum TropicZone { rubidium@9694: TROPICZONE_INVALID = 0, ///< Invalid tropiczone-type rubidium@9694: TROPICZONE_DESERT = 1, ///< Tile is desert rubidium@9694: TROPICZONE_RAINFOREST = 2, ///< Rainforest tile rubidium@6574: }; tron@1211: tron@3636: Slope GetTileSlope(TileIndex tile, uint *h); tron@1335: uint GetTileZ(TileIndex tile); tron@3773: uint GetTileMaxZ(TileIndex tile); tron@1335: rubidium@9694: /** rubidium@9694: * Returns the height of a tile rubidium@9694: * rubidium@9694: * This function returns the height of the northern corner of a tile. rubidium@9694: * This is saved in the global map-array. It does not take affect by rubidium@9694: * any slope-data of the tile. rubidium@9694: * rubidium@9694: * @param tile The tile to get the height from rubidium@9694: * @return the height of the tile rubidium@9694: * @pre tile < MapSize() rubidium@9694: */ tron@1044: static inline uint TileHeight(TileIndex tile) tron@1044: { tron@1044: assert(tile < MapSize()); tron@2049: return GB(_m[tile].type_height, 0, 4); tron@1044: } tron@1044: rubidium@9694: /** rubidium@9694: * Sets the height of a tile. rubidium@9694: * rubidium@9694: * This function sets the height of the northern corner of a tile. rubidium@9694: * rubidium@9694: * @param tile The tile to change the height rubidium@9694: * @param height The new height value of the tile rubidium@9694: * @pre tile < MapSize() rubidium@9694: * @pre heigth <= MAX_TILE_HEIGHT rubidium@9694: */ tron@1059: static inline void SetTileHeight(TileIndex tile, uint height) tron@1059: { tron@1059: assert(tile < MapSize()); rubidium@9694: assert(height <= MAX_TILE_HEIGHT); tron@2049: SB(_m[tile].type_height, 0, 4, height); tron@1059: } tron@1059: rubidium@9694: /** rubidium@9694: * Returns the height of a tile in pixels. rubidium@9694: * rubidium@9694: * This function returns the height of the northern corner of a tile in pixels. rubidium@9694: * rubidium@9694: * @param tile The tile to get the height rubidium@9694: * @return The height of the tile in pixel rubidium@9694: */ tron@1041: static inline uint TilePixelHeight(TileIndex tile) tron@1035: { tron@4077: return TileHeight(tile) * TILE_HEIGHT; tron@1035: } tron@1035: rubidium@9694: /** rubidium@9694: * Get the tiletype of a given tile. rubidium@9694: * rubidium@9694: * @param tile The tile to get the TileType rubidium@9694: * @return The tiletype of the tile rubidium@9694: * @pre tile < MapSize() rubidium@9694: */ tron@1214: static inline TileType GetTileType(TileIndex tile) tron@1035: { tron@1035: assert(tile < MapSize()); KUDr@3900: return (TileType)GB(_m[tile].type_height, 4, 4); tron@1035: } tron@1035: rubidium@9694: /** rubidium@9694: * Set the type of a tile rubidium@9694: * rubidium@9694: * This functions sets the type of a tile. If the type rubidium@9694: * MP_VOID is selected the tile must be at the south-west or rubidium@9694: * south-east edges of the map and vice versa. rubidium@9694: * rubidium@9694: * @param tile The tile to save the new type rubidium@9694: * @param type The type to save rubidium@9694: * @pre tile < MapSize() rubidium@9694: * @pre type MP_VOID <=> tile is on the south-east or south-west edge. rubidium@9694: */ tron@1214: static inline void SetTileType(TileIndex tile, TileType type) tron@1059: { tron@1059: assert(tile < MapSize()); tron@4010: /* VOID tiles (and no others) are exactly allowed at the lower left and right tron@4077: * edges of the map */ tron@4010: assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID)); tron@2049: SB(_m[tile].type_height, 4, 4, type); tron@1059: } tron@1059: rubidium@9694: /** rubidium@9694: * Checks if a tile is a give tiletype. rubidium@9694: * rubidium@9694: * This function checks if a tile got the given tiletype. rubidium@9694: * rubidium@9694: * @param tile The tile to check rubidium@9694: * @param type The type to check agains rubidium@9694: * @return true If the type matches agains the type of the tile rubidium@9694: */ tron@1214: static inline bool IsTileType(TileIndex tile, TileType type) tron@1035: { tron@1214: return GetTileType(tile) == type; tron@1035: } tron@1035: rubidium@9694: /** rubidium@9694: * Returns the owner of a tile rubidium@9694: * rubidium@9694: * This function returns the owner of a tile. This cannot used rubidium@9694: * for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY rubidium@9694: * as no player owned any of these buildings. rubidium@9694: * rubidium@9694: * @param tile The tile to check rubidium@9694: * @return The owner of the tile rubidium@9694: * @pre tile < MapSize() rubidium@9694: * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY rubidium@9694: */ tron@1333: static inline Owner GetTileOwner(TileIndex tile) matthijs@1330: { tron@1333: assert(tile < MapSize()); tron@1898: assert(!IsTileType(tile, MP_HOUSE)); tron@1898: assert(!IsTileType(tile, MP_VOID)); tron@1898: assert(!IsTileType(tile, MP_INDUSTRY)); tron@1898: KUDr@3900: return (Owner)_m[tile].m1; matthijs@1330: } matthijs@1330: rubidium@9694: /** rubidium@9694: * Sets the owner of a tile rubidium@9694: * rubidium@9694: * This function sets the owner status of a tile. Note that you cannot rubidium@9694: * set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY. rubidium@9694: * rubidium@9694: * @param tile The tile to change the owner status. rubidium@9694: * @param owner The new owner. rubidium@9694: * @pre tile < MapSize() rubidium@9694: * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY rubidium@9694: */ tron@1902: static inline void SetTileOwner(TileIndex tile, Owner owner) tron@1902: { tron@1902: assert(tile < MapSize()); tron@1902: assert(!IsTileType(tile, MP_HOUSE)); tron@1902: assert(!IsTileType(tile, MP_VOID)); tron@1902: assert(!IsTileType(tile, MP_INDUSTRY)); tron@1902: tron@2360: _m[tile].m1 = owner; tron@1902: } tron@1902: rubidium@9694: /** rubidium@9694: * Checks if a tile belongs to the given owner rubidium@9694: * rubidium@9694: * @param tile The tile to check rubidium@9694: * @param owner The owner to check agains rubidium@9694: * @return True if a tile belongs the the given owner rubidium@9694: */ matthijs@1330: static inline bool IsTileOwner(TileIndex tile, Owner owner) matthijs@1330: { matthijs@1330: return GetTileOwner(tile) == owner; matthijs@1330: } matthijs@1330: belugas@3379: /** belugas@3379: * Set the tropic zone belugas@3379: * @param tile the tile to set the zone of belugas@3379: * @param type the new type belugas@3379: * @pre assert(tile < MapSize()); belugas@3379: */ belugas@3379: static inline void SetTropicZone(TileIndex tile, TropicZone type) belugas@3379: { belugas@3379: assert(tile < MapSize()); belugas@5847: SB(_m[tile].m6, 0, 2, type); belugas@3379: } belugas@3379: belugas@3379: /** belugas@3379: * Get the tropic zone belugas@3379: * @param tile the tile to get the zone of belugas@3379: * @pre assert(tile < MapSize()); belugas@3379: * @return the zone type belugas@3379: */ belugas@3379: static inline TropicZone GetTropicZone(TileIndex tile) belugas@3379: { belugas@3379: assert(tile < MapSize()); belugas@5847: return (TropicZone)GB(_m[tile].m6, 0, 2); belugas@3379: } Darkvater@2436: #endif /* TILE_H */