src/ai/api/ai_tile.hpp
author truebrain
Wed, 26 Mar 2008 15:17:40 +0000
branchnoai
changeset 9823 0b7f816cf46f
parent 9814 be51ea0adc29
child 9829 80fbe02a4184
permissions -rw-r--r--
(svn r12431) [NoAI] -Add: added AIEventSubsidiaryOffer, which keeps you informed about new Subsidiaries
/* $Id$ */

/** @file ai_tile.hpp tile related functions */

#ifndef AI_TILE_HPP
#define AI_TILE_HPP

#include "ai_abstractlist.hpp"

/**
 * Class that handles all tile related functions.
 */
class AITile : public AIObject {
public:
	/**
	 * Enumeration for the slope-type (from slopes.h).
	 *
	 * This enumeration use the chars N,E,S,W corresponding the
	 * direction north, east, south and west. The top corner of a tile
	 * is the north-part of the tile. The whole slope is encoded with
	 * 5 bits, 4 bits for each corner and 1 bit for a steep-flag.
	 */
	enum Slope {
		SLOPE_FLAT     = 0x00,                                  ///< a flat tile
		SLOPE_W        = 0x01,                                  ///< the west corner of the tile is raised
		SLOPE_S        = 0x02,                                  ///< the south corner of the tile is raised
		SLOPE_E        = 0x04,                                  ///< the east corner of the tile is raised
		SLOPE_N        = 0x08,                                  ///< the north corner of the tile is raised
		SLOPE_STEEP    = 0x10,                                  ///< indicates the slope is steep
		SLOPE_NW       = SLOPE_N | SLOPE_W,                     ///< north and west corner are raised
		SLOPE_SW       = SLOPE_S | SLOPE_W,                     ///< south and west corner are raised
		SLOPE_SE       = SLOPE_S | SLOPE_E,                     ///< south and east corner are raised
		SLOPE_NE       = SLOPE_N | SLOPE_E,                     ///< north and east corner are raised
		SLOPE_EW       = SLOPE_E | SLOPE_W,                     ///< east and west corner are raised
		SLOPE_NS       = SLOPE_N | SLOPE_S,                     ///< north and south corner are raised
		SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, ///< all corner are raised, similar to SLOPE_FLAT
		SLOPE_NWS      = SLOPE_N | SLOPE_W | SLOPE_S,           ///< north, west and south corner are raised
		SLOPE_WSE      = SLOPE_W | SLOPE_S | SLOPE_E,           ///< west, south and east corner are raised
		SLOPE_SEN      = SLOPE_S | SLOPE_E | SLOPE_N,           ///< south, east and north corner are raised
		SLOPE_ENW      = SLOPE_E | SLOPE_N | SLOPE_W,           ///< east, north and west corner are raised
		SLOPE_STEEP_W  = SLOPE_STEEP | SLOPE_NWS,               ///< a steep slope falling to east (from west)
		SLOPE_STEEP_S  = SLOPE_STEEP | SLOPE_WSE,               ///< a steep slope falling to north (from south)
		SLOPE_STEEP_E  = SLOPE_STEEP | SLOPE_SEN,               ///< a steep slope falling to west (from east)
		SLOPE_STEEP_N  = SLOPE_STEEP | SLOPE_ENW                ///< a steep slope falling to south (from north)
	};

	/**
	 * The name of the class, needed by several sub-processes.
	 */
	static const char *GetClassName() { return "AITile"; }

	/**
	 * Check if this tile is buildable (e.g.: no things on it that needs removing).
	 * @note Road and rail are considered buildable.
	 * @param tile the tile to check on.
	 * @pre AIMap::IsValidTile(tile).
	 * @return true if it is buildable, false if not.
	 */
	static bool IsBuildable(TileIndex tile);

	/**
	 	 * Check if this tile is buildable in a rectangle around a tile, with the entry in the list as top-left.
	 * @note Road and rail are considered buildable.
	 * @param tile the tile to check on.
	 * @param width the width of the rectangle.
	 * @param height the height of the rectangle.
	 * @pre AIMap::IsValidTile(tile).
	 * @return true if it is buildable, false if not.
	 */
	static bool IsBuildableRectangle(TileIndex tile, uint width, uint height);

	/**
	 * Check if a tile is water.
	 * @param tile the tile to check on.
	 * @pre AIMap::IsValidTile(tile).
	 * @return true if it is water, false if not.
	 */
	static bool IsWater(TileIndex tile);

	/**
	 * Get the slope of a tile.
	 * @param tile the tile to check on.
	 * @pre AIMap::IsValidTile(tile).
	 * @return 0 means flat, others indicate internal state of slope.
	 */
	static int32 GetSlope(TileIndex tile);

	/**
	 * Get the height of the tile.
	 * @param tile the tile to check on.
	 * @pre AIMap::IsValidTile(tile).
	 * @return the height of the tile, ranging from 0 to 15.
	 */
	static int32 GetHeight(TileIndex tile);

	/**
	 * Check how much cargo this tile accepts.
	 *  It creates a radius around the tile, and adds up all acceptance of this
	 *   cargo.
	 * @param tile the tile to check on.
	 * @param cargo_type the cargo to check the acceptance of.
	 * @param width the width of the station.
	 * @param height the height of the station.
	 * @param radius the radius of the station.
	 * @pre AIMap::IsValidTile(tile).
	 * @return value below 8 means no acceptance; the more the better.
	 */
	static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius);

	/**
	 * Checks how many tiles in the radius produces this cargo.
	 *  It creates a radius around the tile, and adds up all tiles that produce
	 *  this cargo.
	 * @param tile the tile to check on.
	 * @param cargo_type the cargo to check the production of.
	 * @param width the width of the station.
	 * @param height the height of the station.
	 * @param radius the radius of the station.
	 * @pre AIMap::IsValidTile(tile).
	 * @return the tiles that produce this cargo within radius of the tile.
	 * @note town(houses) are not included in the value.
	 */
	static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius);

	/**
	 * Get the manhattan distance from the tile to the tile.
	 * @param tile_from The tile to get the distance to.
	 * @param tile_to The tile to get the distance to.
	 * @return The distance between the two tiles.
	 */
	static int32 GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to);

	/**
	 * Get the square distance from the tile to the tile.
	 * @param tile_from The tile to get the distance to.
	 * @param tile_to The tile to get the distance to.
	 * @return The distance between the two tiles.
	 */
	static int32 GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to);

	/**
	 * Raise the given corners of the tile. The corners can be combined,
	 *  for example: SLOPE_N | SLOPE_W (= SLOPE_NW)
	 * @param tile the tile to raise.
	 * @param slope corners to raise (SLOPE_xxx).
	 * @pre AIMap::IsValidTile(tile).
	 * @return 0 means failed, 1 means success.
	 */
	static bool RaiseTile(TileIndex tile, int32 slope);

	/**
	 * Lower the given corners of the tile. The corners can be combined,
	 *  for example: SLOPE_N | SLOPE_W (= SLOPE_NW)
	 * @param tile the tile to lower.
	 * @param slope corners to lower (SLOPE_xxx).
	 * @pre AIMap::IsValidTile(tile).
	 * @return 0 means failed, 1 means success.
	 */
	static bool LowerTile(TileIndex tile, int32 slope);

};

#endif /* AI_TILE_HPP */