rubidium@9379: /* $Id$ */ rubidium@9379: truelight@9388: /** @file ai_map.hpp Everything to query 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: rubidium@9379: /** truelight@9529: * The name of the class, needed by several sub-processes. truelight@9529: */ truelight@9529: static const char *GetClassName() { return "AIMap"; } truelight@9529: truelight@9529: /** truelight@9448: * Checks whether the given tile is valid. truelight@9448: * @param t the tile to check. truelight@9448: * @return true is the tile it within the boundaries of the map. rubidium@9379: */ rubidium@9379: bool IsValidTile(TileIndex t); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the number of tiles in the map. truelight@9448: * @return the size of the map in tiles. truelight@9448: * @post return value is always positive. rubidium@9379: */ rubidium@9379: TileIndex GetMapSize(); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the amount of tiles along the SW and NE border. truelight@9448: * @return the length along the SW and NE borders. truelight@9448: * @post return value is always positive. rubidium@9379: */ rubidium@9379: uint32 GetMapSizeX(); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the amount of tiles along the SE and NW border. truelight@9448: * @return the length along the SE and NW borders. truelight@9448: * @post return value is always positive. rubidium@9379: */ rubidium@9379: uint32 GetMapSizeY(); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the place along the SW/NE border (X-value). truelight@9448: * @param t the tile to get the X-value of. truelight@9448: * @pre t has to be valid (use IsValidTile(t)). truelight@9448: * @return the X-value. truelight@9448: * @post return value is lower than GetMapSizeX(). rubidium@9379: */ rubidium@9379: uint32 GetTileX(TileIndex t); rubidium@9379: rubidium@9379: /** truelight@9448: * Gets the place along the SE/NW border (Y-value). truelight@9448: * @param t the tile to get the Y-value of. truelight@9448: * @pre t has to be valid (use IsValidTile(t)). truelight@9448: * @return the Y-value. truelight@9448: * @post return value is lower than GetMapSizeY(). rubidium@9379: */ rubidium@9379: uint32 GetTileY(TileIndex t); rubidium@9489: rubidium@9489: /** rubidium@9502: * Gets the TileIndex given a x,y-coordinate. rubidium@9502: * @param x the X coordinate. rubidium@9502: * @param y the Y coordinate. rubidium@9502: * @pre x has to be lower than GetMapSizeX(). rubidium@9502: * @pre y has to be lower than GetMapSizeY(). rubidium@9502: * @return the TileIndex for the given x,y coordinate. rubidium@9502: */ rubidium@9502: TileIndex GetTileIndex(uint32 x, uint32 y); rubidium@9502: rubidium@9502: /** rubidium@9489: * Calculates the Manhattan distance; the difference of rubidium@9489: * the X and Y added together. rubidium@9489: * @param t1 the start. rubidium@9489: * @param t2 the destination. rubidium@9489: * @pre t1 has to be valid (use IsValidTile(t1)). rubidium@9489: * @pre t2 has to be valid (use IsValidTile(t2)). rubidium@9489: * @return the Manhattan distance. rubidium@9489: */ rubidium@9489: uint32 DistanceManhattan(TileIndex t1, TileIndex t2); rubidium@9489: rubidium@9489: /** rubidium@9489: * Calculates the distance between xy1 and xy2 via 1D calculation. rubidium@9489: * (so the distance between X or the distance between Y, depending rubidium@9489: * on which one is bigger). rubidium@9489: * @param t1 the start. rubidium@9489: * @param t2 the destination. rubidium@9489: * @pre t1 has to be valid (use IsValidTile(t1)). rubidium@9489: * @pre t2 has to be valid (use IsValidTile(t2)). rubidium@9489: * @return the maximum distance of X and Y. rubidium@9489: */ rubidium@9489: uint32 DistanceMax(TileIndex t1, TileIndex t2); rubidium@9489: rubidium@9489: /** rubidium@9489: * The squared distance between the two tiles. rubidium@9489: * This is the distance is the length of the shortest straight rubidium@9489: * line between both points. rubidium@9489: * @param t1 the start. rubidium@9489: * @param t2 the destination. rubidium@9489: * @pre t1 has to be valid (use IsValidTile(t1)). rubidium@9489: * @pre t2 has to be valid (use IsValidTile(t2)). rubidium@9489: * @return the distance. rubidium@9489: */ rubidium@9489: uint32 DistanceSquare(TileIndex t1, TileIndex t2); rubidium@9489: rubidium@9489: /** rubidium@9489: * Calculates the shortest distance to the edge. rubidium@9489: * @param t from where the distance has to be calculated. rubidium@9489: * @pre t has to be valid (use IsValidTile(t)). rubidium@9489: * @return the distances to the closest edge. rubidium@9489: */ rubidium@9489: uint32 DistanceFromEdge(TileIndex t); rubidium@9489: rubidium@9489: /** rubidium@9489: * Destroy everything on the given tile. rubidium@9489: * @param t the tile to destroy the stuff of. rubidium@9489: * @pre t has to be valid (use IsValidTile(t)). rubidium@9489: * @return true if and only if the destruction succeeded rubidium@9489: */ rubidium@9489: bool DemolishTile(TileIndex t); rubidium@9379: }; rubidium@9379: truelight@9425: #ifdef DEFINE_SQUIRREL_CLASS rubidium@9524: namespace SQConvert { rubidium@9524: /* Allow AIMap to be used as Squirrel parameter */ rubidium@9524: template <> AIMap *GetParam(ForceType, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIMap *)instance; } rubidium@9524: }; // namespace SQConvert rubidium@9524: truelight@9422: void SQAIMapRegister(Squirrel *engine) { truelight@9387: DefSQClass SQAIMap("AIMap"); truelight@9397: SQAIMap.PreRegister(engine); truelight@9404: SQAIMap.AddConstructor(engine); rubidium@9526: rubidium@9532: SQAIMap.DefSQStaticMethod(engine, &AIMap::GetClassName, "GetClassName"); rubidium@9532: truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::IsValidTile, "IsValidTile"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::GetMapSize, "GetMapSize"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::GetMapSizeX, "GetMapSizeX"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::GetMapSizeY, "GetMapSizeY"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::GetTileX, "GetTileX"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::GetTileY, "GetTileY"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::GetTileIndex, "GetTileIndex"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::DistanceManhattan, "DistanceManhattan"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::DistanceMax, "DistanceMax"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::DistanceSquare, "DistanceSquare"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::DistanceFromEdge, "DistanceFromEdge"); truelight@9530: SQAIMap.DefSQMethod(engine, &AIMap::DemolishTile, "DemolishTile"); rubidium@9526: truelight@9397: SQAIMap.PostRegister(engine); truelight@9387: } rubidium@9520: #endif /* DEFINE_SQUIRREL_CLASS */ truelight@9387: rubidium@9379: #endif /* AI_MAP_HPP */