rubidium@9723: /* $Id$ */ rubidium@9723: rubidium@9723: /** @file tile_map.h Map writing/reading functions for tiles. */ rubidium@9723: rubidium@9723: #ifndef TILE_MAP_H rubidium@9723: #define TILE_MAP_H rubidium@9723: rubidium@9723: #include "tile_type.h" rubidium@9723: #include "slope_type.h" rubidium@9724: #include "player_type.h" rubidium@9723: #include "map_func.h" rubidium@9723: #include "core/bitmath_func.hpp" rubidium@9723: rubidium@9723: /** rubidium@9723: * Returns the height of a tile rubidium@9723: * rubidium@9723: * This function returns the height of the northern corner of a tile. rubidium@9723: * This is saved in the global map-array. It does not take affect by rubidium@9723: * any slope-data of the tile. rubidium@9723: * rubidium@9723: * @param tile The tile to get the height from rubidium@9723: * @return the height of the tile rubidium@9723: * @pre tile < MapSize() rubidium@9723: */ rubidium@9723: static inline uint TileHeight(TileIndex tile) rubidium@9723: { rubidium@9723: assert(tile < MapSize()); rubidium@9723: return GB(_m[tile].type_height, 0, 4); rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Sets the height of a tile. rubidium@9723: * rubidium@9723: * This function sets the height of the northern corner of a tile. rubidium@9723: * rubidium@9723: * @param tile The tile to change the height rubidium@9723: * @param height The new height value of the tile rubidium@9723: * @pre tile < MapSize() rubidium@9723: * @pre heigth <= MAX_TILE_HEIGHT rubidium@9723: */ rubidium@9723: static inline void SetTileHeight(TileIndex tile, uint height) rubidium@9723: { rubidium@9723: assert(tile < MapSize()); rubidium@9723: assert(height <= MAX_TILE_HEIGHT); rubidium@9723: SB(_m[tile].type_height, 0, 4, height); rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Returns the height of a tile in pixels. rubidium@9723: * rubidium@9723: * This function returns the height of the northern corner of a tile in pixels. rubidium@9723: * rubidium@9723: * @param tile The tile to get the height rubidium@9723: * @return The height of the tile in pixel rubidium@9723: */ rubidium@9723: static inline uint TilePixelHeight(TileIndex tile) rubidium@9723: { rubidium@9723: return TileHeight(tile) * TILE_HEIGHT; rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Get the tiletype of a given tile. rubidium@9723: * rubidium@9723: * @param tile The tile to get the TileType rubidium@9723: * @return The tiletype of the tile rubidium@9723: * @pre tile < MapSize() rubidium@9723: */ rubidium@9723: static inline TileType GetTileType(TileIndex tile) rubidium@9723: { rubidium@9723: assert(tile < MapSize()); rubidium@9723: return (TileType)GB(_m[tile].type_height, 4, 4); rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Set the type of a tile rubidium@9723: * rubidium@9723: * This functions sets the type of a tile. If the type rubidium@9723: * MP_VOID is selected the tile must be at the south-west or rubidium@9723: * south-east edges of the map and vice versa. rubidium@9723: * rubidium@9723: * @param tile The tile to save the new type rubidium@9723: * @param type The type to save rubidium@9723: * @pre tile < MapSize() rubidium@9723: * @pre type MP_VOID <=> tile is on the south-east or south-west edge. rubidium@9723: */ rubidium@9723: static inline void SetTileType(TileIndex tile, TileType type) rubidium@9723: { rubidium@9723: assert(tile < MapSize()); rubidium@9723: /* VOID tiles (and no others) are exactly allowed at the lower left and right rubidium@9723: * edges of the map */ rubidium@9723: assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID)); rubidium@9723: SB(_m[tile].type_height, 4, 4, type); rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Checks if a tile is a give tiletype. rubidium@9723: * rubidium@9723: * This function checks if a tile got the given tiletype. rubidium@9723: * rubidium@9723: * @param tile The tile to check rubidium@9723: * @param type The type to check agains rubidium@9723: * @return true If the type matches agains the type of the tile rubidium@9723: */ rubidium@9723: static inline bool IsTileType(TileIndex tile, TileType type) rubidium@9723: { rubidium@9723: return GetTileType(tile) == type; rubidium@9723: } rubidium@9723: rubidium@9723: /** glx@9800: * Checks if a tile is valid glx@9800: * glx@9800: * @param tile The tile to check glx@9800: * @return True if the tile is on the map and not one of MP_VOID. glx@9800: */ glx@9800: static inline bool IsValidTile(TileIndex tile) glx@9800: { glx@9800: return tile < MapSize() && !IsTileType(tile, MP_VOID); glx@9800: } glx@9800: glx@9800: /** rubidium@9723: * Returns the owner of a tile rubidium@9723: * rubidium@9723: * This function returns the owner of a tile. This cannot used rubidium@9723: * for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY rubidium@9723: * as no player owned any of these buildings. rubidium@9723: * rubidium@9723: * @param tile The tile to check rubidium@9723: * @return The owner of the tile glx@9800: * @pre IsValidTile(tile) glx@9800: * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY rubidium@9723: */ rubidium@9723: static inline Owner GetTileOwner(TileIndex tile) rubidium@9723: { glx@9800: assert(IsValidTile(tile)); rubidium@9723: assert(!IsTileType(tile, MP_HOUSE)); rubidium@9723: assert(!IsTileType(tile, MP_INDUSTRY)); rubidium@9723: rubidium@9723: return (Owner)_m[tile].m1; rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Sets the owner of a tile rubidium@9723: * rubidium@9723: * This function sets the owner status of a tile. Note that you cannot rubidium@9723: * set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY. rubidium@9723: * rubidium@9723: * @param tile The tile to change the owner status. rubidium@9723: * @param owner The new owner. glx@9800: * @pre IsValidTile(tile) glx@9800: * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY rubidium@9723: */ rubidium@9723: static inline void SetTileOwner(TileIndex tile, Owner owner) rubidium@9723: { glx@9800: assert(IsValidTile(tile)); rubidium@9723: assert(!IsTileType(tile, MP_HOUSE)); rubidium@9723: assert(!IsTileType(tile, MP_INDUSTRY)); rubidium@9723: rubidium@9723: _m[tile].m1 = owner; rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Checks if a tile belongs to the given owner rubidium@9723: * rubidium@9723: * @param tile The tile to check rubidium@9723: * @param owner The owner to check agains rubidium@9723: * @return True if a tile belongs the the given owner rubidium@9723: */ rubidium@9723: static inline bool IsTileOwner(TileIndex tile, Owner owner) rubidium@9723: { rubidium@9723: return GetTileOwner(tile) == owner; rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Set the tropic zone rubidium@9723: * @param tile the tile to set the zone of rubidium@9723: * @param type the new type glx@9800: * @pre tile < MapSize() rubidium@9723: */ rubidium@9723: static inline void SetTropicZone(TileIndex tile, TropicZone type) rubidium@9723: { rubidium@9723: assert(tile < MapSize()); rubidium@9723: SB(_m[tile].m6, 0, 2, type); rubidium@9723: } rubidium@9723: rubidium@9723: /** rubidium@9723: * Get the tropic zone rubidium@9723: * @param tile the tile to get the zone of glx@9800: * @pre tile < MapSize() rubidium@9723: * @return the zone type rubidium@9723: */ rubidium@9723: static inline TropicZone GetTropicZone(TileIndex tile) rubidium@9723: { rubidium@9723: assert(tile < MapSize()); rubidium@9723: return (TropicZone)GB(_m[tile].m6, 0, 2); rubidium@9723: } rubidium@9723: rubidium@9723: Slope GetTileSlope(TileIndex tile, uint *h); rubidium@9723: uint GetTileZ(TileIndex tile); rubidium@9723: uint GetTileMaxZ(TileIndex tile); rubidium@9723: rubidium@9723: #endif /* TILE_TYPE_H */