/* $Id$ */
/** @file ai_bridge.hpp Everything to query and build bridges. */
#ifndef AI_BRIDGE_HPP
#define AI_BRIDGE_HPP
#include "ai_object.hpp"
#include "ai_vehicle.hpp"
#include "ai_error.hpp"
#include "../../bridge.h"
/** In OpenTTD Core 'BridgeID' is called 'BridgeType', so map it to make this API more logic. */
typedef BridgeType BridgeID;
/**
* Class that handles all bridge related functions.
*/
class AIBridge : public AIObject {
public:
enum ErrorMessages {
/** Base for bridge related errors */
ERR_BRIDGE_BASE = AIError::ERR_CAT_BRIDGE << AIError::ERR_CAT_BIT_SIZE,
/**
* The bridge you want to build is not available yet,
* or it is not available for the requested length.
*/
ERR_BRIDGE_TYPE_UNAVAILABLE, // [STR_5015_CAN_T_BUILD_BRIDGE_HERE]
/** One (or more) of the bridge head(s) ends in water. */
ERR_BRIDGE_CANNOT_END_IN_WATER, // [STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH]
/** Slope of the land does not allow the required bridge head. */
ERR_BRIDGE_SLOPE_WRONG, // [STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION]
/** The bride heads need to be on the same height */
ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT, // [STR_BRIDGEHEADS_NOT_SAME_HEIGHT]
};
static const char *GetClassName() { return "AIBridge"; }
/**
* Checks whether the given bridge type is valid.
* @param bridge_id The bridge to check.
* @return True if and only if the bridge type is valid.
*/
static bool IsValidBridge(BridgeID bridge_id);
/**
* Checks whether the given tile is actually a bridge start or end tile.
* @param tile The tile to check.
* @pre AIMap::IsValidTile(tile).
* @return True if and only if the tile is the beginning or end of a bridge.
*/
static bool IsBridgeTile(TileIndex tile);
/**
* Get the name of a bridge.
* @param bridge_id The bridge to get the name of.
* @pre IsValidBridge(bridge_id).
* @return The name the bridge has.
*/
static char *GetName(BridgeID bridge_id);
/**
* Get the maximum speed of a bridge (in km/h).
* @param bridge_id The bridge to get the maximum speed of.
* @pre IsValidBridge(bridge_id).
* @return The maximum speed the bridge has.
*/
static uint32 GetMaxSpeed(BridgeID bridge_id);
/**
* Get the new cost of a bridge.
* @param bridge_id The bridge to get the new cost of.
* @param length The length of the bridge.
* @pre IsValidBridge(bridge_id).
* @return The new cost the bridge has.
*/
static uint32 GetPrice(BridgeID bridge_id, uint length);
/**
* Get the maximum length of a bridge.
* @param bridge_id The bridge to get the maximum length of.
* @pre IsValidBridge(bridge_id).
* @returns The maximum length the bridge has.
*/
static uint32 GetMaxLength(BridgeID bridge_id);
/**
* Get the minimum length of a bridge.
* @param bridge_id The bridge to get the minimum length of.
* @pre IsValidBridge(bridge_id).
* @returns The minimum length the bridge has.
*/
static uint32 GetMinLength(BridgeID bridge_id);
/**
* Get the year in which a bridge becomes available.
* @param bridge_id The bridge to get the year of availability of.
* @pre IsValidBridge(bridge_id).
* @returns The year of availability the bridge has.
* @note Years are like 2010, -10 (10 B.C.), 1950, ..
*/
static int32 GetYearAvailable(BridgeID bridge_id);
/**
* Build a bridge from one tile to the other.
* @param vehicle_type The vehicle-type of bridge to build.
* @param bridge_id The bridge-type to build.
* @param start Where to start the bridge.
* @param end Where to end the bridge.
* @pre AIMap::IsValidTile(start).
* @pre AIMap::IsValidTile(end).
* @pre 'start' and 'end' are in a straight line, i.e.
* AIMap::GetTileX(start) == AIMap::GetTileX(end) or
* AIMap::GetTileY(start) == AIMap::GetTileY(end).
* @pre 'vehicle_type' is either AIVehicle::VEHICLE_RAIL or AIVehicle::VEHICLE_ROAD.
* @exception AIError::ERR_ALREADY_BUILT
* @exception AIError::ERR_AREA_NOT_CLEAR
* @exception AIBridge::ERR_BRIDGE_TYPE_UNAVAILABLE
* @exception AIBridge::ERR_BRIDGE_CANNOT_END_IN_WATER
* @exception AIBridge::ERR_BRIDGE_SLOPE_WRONG
* @exception AIBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT
* @return Whether the bridge has been/can be build or not.
*/
static bool BuildBridge(AIVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end);
/**
* Removes a bridge, by executing it on either the start or end tile.
* @param tile An end or start tile of the bridge.
* @pre AIMap::IsValidTile(tile).
* @return Whether the bridge has been/can be removed or not.
*/
static bool RemoveBridge(TileIndex tile);
};
#endif /* AI_BRIDGE_HPP */