rubidium@9379: /* $Id$ */ rubidium@9379: truebrain@9829: /** @file ai_map.hpp Everything to query and manipulate map metadata. */ rubidium@9379: rubidium@9379: #ifndef AI_MAP_HPP rubidium@9379: #define AI_MAP_HPP rubidium@9379: rubidium@9379: #include "ai_object.hpp" rubidium@9379: truelight@9448: /** truelight@9448: * Class that handles all map related functions. truelight@9448: */ rubidium@9379: class AIMap : public AIObject { rubidium@9379: public: truelight@9529: static const char *GetClassName() { return "AIMap"; } truelight@9529: truelight@9529: /** truelight@9448: * Checks whether the given tile is valid. truebrain@9836: * @param tile The tile to check. truebrain@9836: * @return True is the tile it within the boundaries of the map. rubidium@9379: */ truebrain@9836: static bool IsValidTile(TileIndex tile); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the number of tiles in the map. truebrain@9836: * @return The size of the map in tiles. truebrain@9836: * @post Return value is always positive. rubidium@9379: */ truelight@9655: static TileIndex GetMapSize(); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the amount of tiles along the SW and NE border. truebrain@9836: * @return The length along the SW and NE borders. truebrain@9836: * @post Return value is always positive. rubidium@9379: */ truelight@9655: static uint32 GetMapSizeX(); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the amount of tiles along the SE and NW border. truebrain@9836: * @return The length along the SE and NW borders. truebrain@9836: * @post Return value is always positive. rubidium@9379: */ truelight@9655: static uint32 GetMapSizeY(); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the place along the SW/NE border (X-value). truebrain@9836: * @param tile The tile to get the X-value of. truebrain@9836: * @pre IsValidTile(tile). truebrain@9836: * @return The X-value. truebrain@9836: * @post Return value is always lower than GetMapSizeX(). rubidium@9379: */ truebrain@9836: static uint32 GetTileX(TileIndex tile); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the place along the SE/NW border (Y-value). truebrain@9836: * @param tile The tile to get the Y-value of. truebrain@9836: * @pre IsValidTile(tile). truebrain@9836: * @return The Y-value. truebrain@9836: * @post Return value is always lower than GetMapSizeY(). rubidium@9379: */ truebrain@9836: static uint32 GetTileY(TileIndex tile); rubidium@9489: rubidium@9489: /** rubidium@9502: * Gets the TileIndex given a x,y-coordinate. truebrain@9836: * @param x The X coordinate. truebrain@9836: * @param y The Y coordinate. truebrain@9836: * @pre x < GetMapSizeX(). truebrain@9836: * @pre y < GetMapSizeY(). truebrain@9836: * @return The TileIndex for the given (x,y) coordinate. rubidium@9502: */ truelight@9655: static TileIndex GetTileIndex(uint32 x, uint32 y); rubidium@9502: rubidium@9502: /** rubidium@9489: * Calculates the Manhattan distance; the difference of truebrain@9836: * the X and Y added together. truebrain@9836: * @param tile_from The start tile. truebrain@9836: * @param tile_to The destination tile. truebrain@9836: * @pre IsValidTile(tile_from). truebrain@9836: * @pre IsValidTile(tile_to). truebrain@9836: * @return The Manhattan distance between the tiles. rubidium@9489: */ truebrain@9836: static uint32 DistanceManhattan(TileIndex tile_from, TileIndex tile_to); rubidium@9489: rubidium@9489: /** truebrain@9836: * Calculates the distance between two tiles via 1D calculation. truebrain@9836: * This means the distance between X or the distance between Y, depending truebrain@9836: * on which one is bigger. truebrain@9836: * @param tile_from The start tile. truebrain@9836: * @param tile_to The destination tile. truebrain@9836: * @pre IsValidTile(tile_from). truebrain@9836: * @pre IsValidTile(tile_to). truebrain@9836: * @return The maximum distance between the tiles. rubidium@9489: */ truebrain@9836: static uint32 DistanceMax(TileIndex tile_from, TileIndex tile_to); rubidium@9489: rubidium@9489: /** rubidium@9489: * The squared distance between the two tiles. truebrain@9836: * This is the distance is the length of the shortest straight line truebrain@9836: * between both points. truebrain@9836: * @param tile_from The start tile. truebrain@9836: * @param tile_to The destination tile. truebrain@9836: * @pre IsValidTile(tile_from). truebrain@9836: * @pre IsValidTile(tile_to). truebrain@9836: * @return The squared distance between the tiles. rubidium@9489: */ truebrain@9836: static uint32 DistanceSquare(TileIndex tile_from, TileIndex tile_to); rubidium@9489: rubidium@9489: /** rubidium@9489: * Calculates the shortest distance to the edge. truebrain@9836: * @param tile From where the distance has to be calculated. truebrain@9836: * @pre IsValidTile(tile). truebrain@9836: * @return The distances to the closest edge. rubidium@9489: */ truebrain@9836: static uint32 DistanceFromEdge(TileIndex tile); rubidium@9379: }; rubidium@9379: rubidium@9379: #endif /* AI_MAP_HPP */