truelight@9617: /* $Id$ */ truelight@9617: truebrain@9829: /** @file ai_tile.hpp Everything to query and manipulate tiles. */ truelight@9617: truelight@9617: #ifndef AI_TILE_HPP truelight@9617: #define AI_TILE_HPP truelight@9617: truelight@9617: #include "ai_abstractlist.hpp" rubidium@10089: #include "ai_error.hpp" truelight@9617: truelight@9617: /** truelight@9617: * Class that handles all tile related functions. truelight@9617: */ truelight@9617: class AITile : public AIObject { truelight@9617: public: truebrain@9829: static const char *GetClassName() { return "AITile"; } truebrain@9829: truelight@9617: /** rubidium@10089: * Error messages related to modifying tiles. rubidium@10089: */ rubidium@10089: enum ErrorMessages { rubidium@10089: rubidium@10089: /** Base for tile related errors */ rubidium@10089: ERR_TILE_BASE = AIError::ERR_CAT_TILE << AIError::ERR_CAT_BIT_SIZE, rubidium@10089: rubidium@10089: /** Tile can't be raised any higher */ rubidium@10094: ERR_TILE_TOO_HIGH, // [STR_1003_ALREADY_AT_SEA_LEVEL] rubidium@10089: rubidium@10089: /** Tile can't be lowered any lower */ rubidium@10094: ERR_TILE_TOO_LOW, // [STR_1003_ALREADY_AT_SEA_LEVEL] rubidium@10089: }; rubidium@10089: rubidium@10089: /** truelight@9708: * Enumeration for the slope-type (from slopes.h). truelight@9708: * truebrain@9838: * This enumeration use the chars N, E, S, W corresponding the truebrain@9838: * direction North, East, South and West. The top corner of a tile truebrain@9838: * is the north-part of the tile. truelight@9708: */ truelight@9708: enum Slope { truebrain@9838: SLOPE_FLAT = 0x00, //!< A flat tile truebrain@9838: SLOPE_W = 0x01, //!< The west corner of the tile is raised truebrain@9838: SLOPE_S = 0x02, //!< The south corner of the tile is raised truebrain@9838: SLOPE_E = 0x04, //!< The east corner of the tile is raised truebrain@9838: SLOPE_N = 0x08, //!< The north corner of the tile is raised truebrain@9838: SLOPE_STEEP = 0x10, //!< Indicates the slope is steep truebrain@9838: SLOPE_NW = SLOPE_N | SLOPE_W, //!< North and west corner are raised truebrain@9838: SLOPE_SW = SLOPE_S | SLOPE_W, //!< South and west corner are raised truebrain@9838: SLOPE_SE = SLOPE_S | SLOPE_E, //!< South and east corner are raised truebrain@9838: SLOPE_NE = SLOPE_N | SLOPE_E, //!< North and east corner are raised truebrain@9838: SLOPE_EW = SLOPE_E | SLOPE_W, //!< East and west corner are raised truebrain@9838: SLOPE_NS = SLOPE_N | SLOPE_S, //!< North and south corner are raised truebrain@9838: SLOPE_ELEVATED = SLOPE_N | SLOPE_E | SLOPE_S | SLOPE_W, //!< All corner are raised, similar to SLOPE_FLAT truebrain@9838: SLOPE_NWS = SLOPE_N | SLOPE_W | SLOPE_S, //!< North, west and south corner are raised truebrain@9838: SLOPE_WSE = SLOPE_W | SLOPE_S | SLOPE_E, //!< West, south and east corner are raised truebrain@9838: SLOPE_SEN = SLOPE_S | SLOPE_E | SLOPE_N, //!< South, east and north corner are raised truebrain@9838: SLOPE_ENW = SLOPE_E | SLOPE_N | SLOPE_W, //!< East, north and west corner are raised truebrain@9838: SLOPE_STEEP_W = SLOPE_STEEP | SLOPE_NWS, //!< A steep slope falling to east (from west) truebrain@9838: SLOPE_STEEP_S = SLOPE_STEEP | SLOPE_WSE, //!< A steep slope falling to north (from south) truebrain@9838: SLOPE_STEEP_E = SLOPE_STEEP | SLOPE_SEN, //!< A steep slope falling to west (from east) truebrain@9838: SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW //!< A steep slope falling to south (from north) truelight@9708: }; truelight@9708: truelight@9708: /** truebrain@9838: * Check if this tile is buildable, i.e. no things on it that needs truebrain@9838: * demolishing. truebrain@9838: * @param tile The tile to check on. truebrain@9838: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if it is buildable, false if not. truelight@9617: * @note Road and rail are considered buildable. truelight@9617: */ truelight@9617: static bool IsBuildable(TileIndex tile); truelight@9617: truelight@9617: /** truebrain@9838: * Check if this tile is buildable in a rectangle around a tile, with the truebrain@9838: * entry in the list as top-left. truebrain@9838: * @param tile The tile to check on. truebrain@9838: * @param width The width of the rectangle. truebrain@9838: * @param height The height of the rectangle. truebrain@9814: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if it is buildable, false if not. truebrain@9842: * @note Road and rail are considered buildable. truebrain@9814: */ truebrain@9814: static bool IsBuildableRectangle(TileIndex tile, uint width, uint height); truebrain@9814: truebrain@9814: /** truelight@9698: * Check if a tile is water. truebrain@9838: * @param tile The tile to check on. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return True if it is water, false if not. truelight@9698: */ truelight@9698: static bool IsWater(TileIndex tile); truelight@9698: truelight@9698: /** truelight@9617: * Get the slope of a tile. truebrain@9838: * @param tile The tile to check on. truebrain@9801: * @pre AIMap::IsValidTile(tile). truelight@9617: * @return 0 means flat, others indicate internal state of slope. truelight@9617: */ truelight@9617: static int32 GetSlope(TileIndex tile); truelight@9617: truelight@9617: /** truelight@9700: * Get the height of the tile. truebrain@9838: * @param tile The tile to check on. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return The height of the tile, ranging from 0 to 15. truelight@9700: */ truelight@9700: static int32 GetHeight(TileIndex tile); truelight@9700: truelight@9700: /** truelight@9617: * Check how much cargo this tile accepts. truebrain@9771: * It creates a radius around the tile, and adds up all acceptance of this truebrain@9771: * cargo. truebrain@9838: * @param tile The tile to check on. truebrain@9838: * @param cargo_type The cargo to check the acceptance of. truebrain@9838: * @param width The width of the station. truebrain@9838: * @param height The height of the station. truebrain@9838: * @param radius The radius of the station. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return Value below 8 means no acceptance; the more the better. truelight@9617: */ truelight@9658: static int32 GetCargoAcceptance(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius); truelight@9708: truelight@9708: /** truebrain@9771: * Checks how many tiles in the radius produces this cargo. truebrain@9771: * It creates a radius around the tile, and adds up all tiles that produce truebrain@9771: * this cargo. truebrain@9838: * @param tile The tile to check on. truebrain@9838: * @param cargo_type The cargo to check the production of. truebrain@9838: * @param width The width of the station. truebrain@9838: * @param height The height of the station. truebrain@9838: * @param radius The radius of the station. truebrain@9801: * @pre AIMap::IsValidTile(tile). truebrain@9838: * @return The tiles that produce this cargo within radius of the tile. truebrain@9838: * @note Town(houses) are not included in the value. glx@9729: */ truebrain@9735: static int32 GetCargoProduction(TileIndex tile, CargoID cargo_type, uint width, uint height, uint radius); glx@9729: glx@9729: /** truebrain@9814: * Get the manhattan distance from the tile to the tile. truebrain@9814: * @param tile_from The tile to get the distance to. truebrain@9814: * @param tile_to The tile to get the distance to. truebrain@9814: * @return The distance between the two tiles. truebrain@9814: */ truebrain@9814: static int32 GetDistanceManhattanToTile(TileIndex tile_from, TileIndex tile_to); truebrain@9814: truebrain@9814: /** truebrain@9814: * Get the square distance from the tile to the tile. truebrain@9814: * @param tile_from The tile to get the distance to. truebrain@9814: * @param tile_to The tile to get the distance to. truebrain@9814: * @return The distance between the two tiles. truebrain@9814: */ truebrain@9814: static int32 GetDistanceSquareToTile(TileIndex tile_from, TileIndex tile_to); truebrain@9814: truebrain@9814: /** truelight@9708: * Raise the given corners of the tile. The corners can be combined, truelight@9708: * for example: SLOPE_N | SLOPE_W (= SLOPE_NW) truebrain@9838: * @param tile The tile to raise. truebrain@9838: * @param slope Corners to raise (SLOPE_xxx). truebrain@9801: * @pre AIMap::IsValidTile(tile). rubidium@10094: * @exception AIError::ERR_AREA_NOT_CLEAR rubidium@10094: * @exception AIError::ERR_TOO_CLOSE_TO_EDGE rubidium@10094: * @exception AITile::ERR_TILE_TOO_HIGH truelight@9708: * @return 0 means failed, 1 means success. truelight@9708: */ truebrain@9737: static bool RaiseTile(TileIndex tile, int32 slope); truelight@9708: truelight@9708: /** truelight@9708: * Lower the given corners of the tile. The corners can be combined, truelight@9708: * for example: SLOPE_N | SLOPE_W (= SLOPE_NW) truebrain@9838: * @param tile The tile to lower. truebrain@9838: * @param slope Corners to lower (SLOPE_xxx). truebrain@9801: * @pre AIMap::IsValidTile(tile). rubidium@10094: * @exception AIError::ERR_AREA_NOT_CLEAR rubidium@10094: * @exception AIError::ERR_TOO_CLOSE_TO_EDGE rubidium@10094: * @exception AITile::ERR_TILE_TOO_LOW truelight@9708: * @return 0 means failed, 1 means success. truelight@9708: */ truebrain@9737: static bool LowerTile(TileIndex tile, int32 slope); truelight@9708: truebrain@9834: /** truebrain@9834: * Destroy everything on the given tile. truebrain@9838: * @param tile The tile to demolish. truebrain@9834: * @pre AIMap::IsValidTile(tile). rubidium@10094: * @exception AIError::ERR_AREA_NOT_CLEAR truebrain@9838: * @return True if and only if the tile was demolished. truebrain@9834: */ truebrain@9834: static bool DemolishTile(TileIndex tile); truelight@9617: }; truelight@9617: truelight@9617: #endif /* AI_TILE_HPP */