(svn r9446) [NoAI] -Add: simple script to make changing/adding classes to export a little simpler.
/* $Id$ */
/** @file ai_map.hpp Everything to query map metadata */
#ifndef AI_MAP_HPP
#define AI_MAP_HPP
#include "ai_object.hpp"
/**
* Class that handles all map related functions.
*/
class AIMap : public AIObject {
public:
/**
* Checks whether the given tile is valid.
* @param t the tile to check.
* @return true is the tile it within the boundaries of the map.
*/
bool IsValidTile(TileIndex t);
/**
* Gets the number of tiles in the map.
* @return the size of the map in tiles.
* @post return value is always positive.
*/
TileIndex GetMapSize();
/**
* Gets the amount of tiles along the SW and NE border.
* @return the length along the SW and NE borders.
* @post return value is always positive.
*/
uint32 GetMapSizeX();
/**
* Gets the amount of tiles along the SE and NW border.
* @return the length along the SE and NW borders.
* @post return value is always positive.
*/
uint32 GetMapSizeY();
/**
* Gets the place along the SW/NE border (X-value).
* @param t the tile to get the X-value of.
* @pre t has to be valid (use IsValidTile(t)).
* @return the X-value.
* @post return value is lower than GetMapSizeX().
*/
uint32 GetTileX(TileIndex t);
/**
* Gets the place along the SE/NW border (Y-value).
* @param t the tile to get the Y-value of.
* @pre t has to be valid (use IsValidTile(t)).
* @return the Y-value.
* @post return value is lower than GetMapSizeY().
*/
uint32 GetTileY(TileIndex t);
/**
* Gets the TileIndex given a x,y-coordinate.
* @param x the X coordinate.
* @param y the Y coordinate.
* @pre x has to be lower than GetMapSizeX().
* @pre y has to be lower than GetMapSizeY().
* @return the TileIndex for the given x,y coordinate.
*/
TileIndex GetTileIndex(uint32 x, uint32 y);
/**
* Calculates the Manhattan distance; the difference of
* the X and Y added together.
* @param t1 the start.
* @param t2 the destination.
* @pre t1 has to be valid (use IsValidTile(t1)).
* @pre t2 has to be valid (use IsValidTile(t2)).
* @return the Manhattan distance.
*/
uint32 DistanceManhattan(TileIndex t1, TileIndex t2);
/**
* Calculates the distance between xy1 and xy2 via 1D calculation.
* (so the distance between X or the distance between Y, depending
* on which one is bigger).
* @param t1 the start.
* @param t2 the destination.
* @pre t1 has to be valid (use IsValidTile(t1)).
* @pre t2 has to be valid (use IsValidTile(t2)).
* @return the maximum distance of X and Y.
*/
uint32 DistanceMax(TileIndex t1, TileIndex t2);
/**
* The squared distance between the two tiles.
* This is the distance is the length of the shortest straight
* line between both points.
* @param t1 the start.
* @param t2 the destination.
* @pre t1 has to be valid (use IsValidTile(t1)).
* @pre t2 has to be valid (use IsValidTile(t2)).
* @return the distance.
*/
uint32 DistanceSquare(TileIndex t1, TileIndex t2);
/**
* Calculates the shortest distance to the edge.
* @param t from where the distance has to be calculated.
* @pre t has to be valid (use IsValidTile(t)).
* @return the distances to the closest edge.
*/
uint32 DistanceFromEdge(TileIndex t);
/**
* Destroy everything on the given tile.
* @param t the tile to destroy the stuff of.
* @pre t has to be valid (use IsValidTile(t)).
* @return true if and only if the destruction succeeded
*/
bool DemolishTile(TileIndex t);
};
#ifdef DEFINE_SQUIRREL_CLASS
namespace SQConvert {
/* Allow AIMap to be used as Squirrel parameter */
template <> AIMap *GetParam(ForceType<AIMap *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIMap *)instance; }
}; // namespace SQConvert
void SQAIMapRegister(Squirrel *engine) {
DefSQClass <AIMap> SQAIMap("AIMap");
SQAIMap.PreRegister(engine);
SQAIMap.AddConstructor(engine);
SQAIMap.DefSQFunction(engine, &AIMap::IsValidTile, "IsValidTile");
SQAIMap.DefSQFunction(engine, &AIMap::GetMapSize, "GetMapSize");
SQAIMap.DefSQFunction(engine, &AIMap::GetMapSizeX, "GetMapSizeX");
SQAIMap.DefSQFunction(engine, &AIMap::GetMapSizeY, "GetMapSizeY");
SQAIMap.DefSQFunction(engine, &AIMap::GetTileX, "GetTileX");
SQAIMap.DefSQFunction(engine, &AIMap::GetTileY, "GetTileY");
SQAIMap.DefSQFunction(engine, &AIMap::GetTileIndex, "GetTileIndex");
SQAIMap.DefSQFunction(engine, &AIMap::DistanceManhattan, "DistanceManhattan");
SQAIMap.DefSQFunction(engine, &AIMap::DistanceMax, "DistanceMax");
SQAIMap.DefSQFunction(engine, &AIMap::DistanceSquare, "DistanceSquare");
SQAIMap.DefSQFunction(engine, &AIMap::DistanceFromEdge, "DistanceFromEdge");
SQAIMap.DefSQFunction(engine, &AIMap::DemolishTile, "DemolishTile");
SQAIMap.PostRegister(engine);
}
#endif /* DEFINE_SQUIRREL_CLASS */
#endif /* AI_MAP_HPP */