tron@2186: /* $Id$ */ tron@2186: rubidium@8108: /** @file tile_map.h Map writing/reading functions for tiles. */ truelight@7313: rubidium@8108: #ifndef TILE_MAP_H rubidium@8108: #define TILE_MAP_H tron@1214: rubidium@8108: #include "tile_type.h" rubidium@8108: #include "slope_type.h" rubidium@8254: #include "player_type.h" rubidium@8139: #include "map_func.h" rubidium@8113: #include "core/bitmath_func.hpp" tron@1335: rubidium@7365: /** rubidium@7365: * Returns the height of a tile rubidium@7365: * rubidium@7365: * This function returns the height of the northern corner of a tile. rubidium@7365: * This is saved in the global map-array. It does not take affect by rubidium@7365: * any slope-data of the tile. rubidium@7365: * rubidium@7365: * @param tile The tile to get the height from rubidium@7365: * @return the height of the tile rubidium@7365: * @pre tile < MapSize() rubidium@7365: */ 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@7365: /** rubidium@7365: * Sets the height of a tile. rubidium@7365: * rubidium@7365: * This function sets the height of the northern corner of a tile. rubidium@7365: * rubidium@7365: * @param tile The tile to change the height rubidium@7365: * @param height The new height value of the tile rubidium@7365: * @pre tile < MapSize() rubidium@7365: * @pre heigth <= MAX_TILE_HEIGHT rubidium@7365: */ tron@1059: static inline void SetTileHeight(TileIndex tile, uint height) tron@1059: { tron@1059: assert(tile < MapSize()); rubidium@7365: assert(height <= MAX_TILE_HEIGHT); tron@2049: SB(_m[tile].type_height, 0, 4, height); tron@1059: } tron@1059: rubidium@7365: /** rubidium@7365: * Returns the height of a tile in pixels. rubidium@7365: * rubidium@7365: * This function returns the height of the northern corner of a tile in pixels. rubidium@7365: * rubidium@7365: * @param tile The tile to get the height rubidium@7365: * @return The height of the tile in pixel rubidium@7365: */ tron@1041: static inline uint TilePixelHeight(TileIndex tile) tron@1035: { tron@4077: return TileHeight(tile) * TILE_HEIGHT; tron@1035: } tron@1035: rubidium@7365: /** rubidium@7365: * Get the tiletype of a given tile. rubidium@7365: * rubidium@7365: * @param tile The tile to get the TileType rubidium@7365: * @return The tiletype of the tile rubidium@7365: * @pre tile < MapSize() rubidium@7365: */ 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@7365: /** rubidium@7365: * Set the type of a tile rubidium@7365: * rubidium@7365: * This functions sets the type of a tile. If the type rubidium@7365: * MP_VOID is selected the tile must be at the south-west or rubidium@7365: * south-east edges of the map and vice versa. rubidium@7365: * rubidium@7365: * @param tile The tile to save the new type rubidium@7365: * @param type The type to save rubidium@7365: * @pre tile < MapSize() rubidium@7365: * @pre type MP_VOID <=> tile is on the south-east or south-west edge. rubidium@7365: */ 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@7365: /** rubidium@7365: * Checks if a tile is a give tiletype. rubidium@7365: * rubidium@7365: * This function checks if a tile got the given tiletype. rubidium@7365: * rubidium@7365: * @param tile The tile to check rubidium@7365: * @param type The type to check agains rubidium@7365: * @return true If the type matches agains the type of the tile rubidium@7365: */ tron@1214: static inline bool IsTileType(TileIndex tile, TileType type) tron@1035: { tron@1214: return GetTileType(tile) == type; tron@1035: } tron@1035: rubidium@7365: /** glx@8651: * Checks if a tile is valid glx@8651: * glx@8651: * @param tile The tile to check glx@8651: * @return True if the tile is on the map and not one of MP_VOID. glx@8651: */ glx@8651: static inline bool IsValidTile(TileIndex tile) glx@8651: { glx@8651: return tile < MapSize() && !IsTileType(tile, MP_VOID); glx@8651: } glx@8651: glx@8651: /** rubidium@7365: * Returns the owner of a tile rubidium@7365: * rubidium@7365: * This function returns the owner of a tile. This cannot used rubidium@7365: * for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY rubidium@7365: * as no player owned any of these buildings. rubidium@7365: * rubidium@7365: * @param tile The tile to check rubidium@7365: * @return The owner of the tile glx@8651: * @pre IsValidTile(tile) glx@8651: * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY rubidium@7365: */ tron@1333: static inline Owner GetTileOwner(TileIndex tile) matthijs@1330: { glx@8651: assert(IsValidTile(tile)); tron@1898: assert(!IsTileType(tile, MP_HOUSE)); tron@1898: assert(!IsTileType(tile, MP_INDUSTRY)); tron@1898: KUDr@3900: return (Owner)_m[tile].m1; matthijs@1330: } matthijs@1330: rubidium@7365: /** rubidium@7365: * Sets the owner of a tile rubidium@7365: * rubidium@7365: * This function sets the owner status of a tile. Note that you cannot rubidium@7365: * set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY. rubidium@7365: * rubidium@7365: * @param tile The tile to change the owner status. rubidium@7365: * @param owner The new owner. glx@8651: * @pre IsValidTile(tile) glx@8651: * @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY rubidium@7365: */ tron@1902: static inline void SetTileOwner(TileIndex tile, Owner owner) tron@1902: { glx@8651: assert(IsValidTile(tile)); tron@1902: assert(!IsTileType(tile, MP_HOUSE)); tron@1902: assert(!IsTileType(tile, MP_INDUSTRY)); tron@1902: tron@2360: _m[tile].m1 = owner; tron@1902: } tron@1902: rubidium@7365: /** rubidium@7365: * Checks if a tile belongs to the given owner rubidium@7365: * rubidium@7365: * @param tile The tile to check rubidium@7365: * @param owner The owner to check agains rubidium@7365: * @return True if a tile belongs the the given owner rubidium@7365: */ 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 glx@8651: * @pre tile < MapSize() belugas@3379: */ belugas@3379: static inline void SetTropicZone(TileIndex tile, TropicZone type) belugas@3379: { belugas@3379: assert(tile < MapSize()); belugas@5596: 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 glx@8651: * @pre 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@5596: return (TropicZone)GB(_m[tile].m6, 0, 2); belugas@3379: } rubidium@8108: rubidium@8108: Slope GetTileSlope(TileIndex tile, uint *h); rubidium@8108: uint GetTileZ(TileIndex tile); rubidium@8108: uint GetTileMaxZ(TileIndex tile); rubidium@8108: rubidium@8108: #endif /* TILE_TYPE_H */