src/ai/api/ai_map.hpp
author truebrain
Wed, 26 Mar 2008 15:17:40 +0000
branchnoai
changeset 9823 0b7f816cf46f
parent 9737 ee408edf3851
child 9829 80fbe02a4184
permissions -rw-r--r--
(svn r12431) [NoAI] -Add: added AIEventSubsidiaryOffer, which keeps you informed about new Subsidiaries
/* $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:
	/**
	 * The name of the class, needed by several sub-processes.
	 */
	static const char *GetClassName() { return "AIMap"; }

	/**
	 * 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.
	 */
	static 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.
	 */
	static 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.
	 */
	static 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.
	 */
	static 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().
	 */
	static 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().
	 */
	static 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.
	 */
	static 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.
	 */
	static 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.
	 */
	static 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.
	 */
	static 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.
	 */
	static 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
	 */
	static bool DemolishTile(TileIndex t);
};

#endif /* AI_MAP_HPP */