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