rubidium@9491: /* $Id$ */ rubidium@9491: truebrain@9829: /** @file ai_vehicle.hpp Everything to query and build vehicles. */ rubidium@9491: rubidium@9491: #ifndef AI_VEHICLE_HPP rubidium@9491: #define AI_VEHICLE_HPP rubidium@9491: rubidium@9491: #include "ai_object.hpp" truebrain@9874: #include "ai_error.hpp" truebrain@10668: #include "ai_road.hpp" rubidium@9491: rubidium@9491: /** rubidium@9491: * Class that handles all vehicle related functions. rubidium@9491: */ rubidium@9491: class AIVehicle : public AIObject { rubidium@9491: public: truebrain@9829: static const char *GetClassName() { return "AIVehicle"; } truebrain@9829: truebrain@10096: /** truebrain@10096: * All vehicle related error messages. truebrain@10096: */ truebrain@9874: enum ErrorMessages { truebrain@9874: /** Base for vehicle related errors */ truebrain@9874: ERR_VEHICLE_BASE = AIError::ERR_CAT_VEHICLE << AIError::ERR_CAT_BIT_SIZE, truebrain@9874: truebrain@9874: /** Too many vehicles in the game, can't build any more. */ truebrain@9874: ERR_VEHICLE_TOO_MANY, // [STR_00E1_TOO_MANY_VEHICLES_IN_GAME] truebrain@9874: truebrain@9874: /** Vehicle is not available */ truebrain@9874: ERR_VEHICLE_NOT_AVAILABLE, // [STR_AIRCRAFT_NOT_AVAILABLE, STR_ROAD_VEHICLE_NOT_AVAILABLE, STR_SHIP_NOT_AVAILABLE, STR_RAIL_VEHICLE_NOT_AVAILABLE] truebrain@9874: truebrain@9874: /** Vehicle can't be build due to game settigns */ truebrain@9874: ERR_VEHICLE_BUILD_DISABLED, // [STR_A008_CAN_T_BUILD_AIRCRAFT, STR_980D_CAN_T_BUILD_SHIP, STR_9009_CAN_T_BUILD_ROAD_VEHICLE, STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE] truebrain@9874: truebrain@9874: /** Vehicle can't be build in the selected depot */ truebrain@9874: ERR_VEHICLE_WRONG_DEPOT, // [STR_DEPOT_WRONG_DEPOT_TYPE] truebrain@9874: truebrain@9874: /** Vehicle can't return to the depot */ truebrain@9874: ERR_VEHICLE_CANNOT_SEND_TO_DEPOT, // [STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT, STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT, STR_9819_CAN_T_SEND_SHIP_TO_DEPOT, STR_A012_CAN_T_SEND_AIRCRAFT_TO] truebrain@9874: truebrain@9874: /** Vehicle can't start / stop */ truebrain@9874: ERR_VEHICLE_CANNOT_START_STOP, // [STR_883B_CAN_T_STOP_START_TRAIN, STR_9015_CAN_T_STOP_START_ROAD_VEHICLE, STR_9818_CAN_T_STOP_START_SHIP, STR_A016_CAN_T_STOP_START_AIRCRAFT] truebrain@9874: truebrain@9874: /** Vehicle can't turn */ truebrain@9874: ERR_VEHICLE_CANNOT_TURN, // [STR_8869_CAN_T_REVERSE_DIRECTION, STR_9033_CAN_T_MAKE_VEHICLE_TURN] truebrain@9874: truebrain@9874: /** Vehicle can't be refit */ truebrain@9874: ERR_VEHICLE_CANNOT_REFIT, // [STR_RAIL_CAN_T_REFIT_VEHICLE, STR_REFIT_ROAD_VEHICLE_CAN_T, STR_9841_CAN_T_REFIT_SHIP, STR_A042_CAN_T_REFIT_AIRCRAFT] truebrain@9874: truebrain@9874: /** Vehicle is destroyed */ truebrain@9874: ERR_VEHICLE_IS_DESTROYED, // [STR_CAN_T_REFIT_DESTROYED_VEHICLE, STR_CAN_T_SELL_DESTROYED_VEHICLE] truebrain@9874: truebrain@9874: /** Vehicle is not in a depot */ truebrain@9874: ERR_VEHICLE_NOT_IN_DEPOT, // [STR_A01B_AIRCRAFT_MUST_BE_STOPPED, STR_9013_MUST_BE_STOPPED_INSIDE, STR_TRAIN_MUST_BE_STOPPED, STR_980B_SHIP_MUST_BE_STOPPED_IN] truebrain@9874: truebrain@9874: /** Vehicle is flying */ truebrain@9874: ERR_VEHICLE_IN_FLIGHT, // [STR_A017_AIRCRAFT_IS_IN_FLIGHT] truebrain@9874: truebrain@9874: /** Vehicle is without power */ truebrain@9874: ERR_VEHCILE_NO_POWER, // [STR_TRAIN_START_NO_CATENARY] truebrain@9874: truebrain@9874: }; truelight@9685: /** truelight@9685: * The type of a vehicle available in the game. Trams for example are truelight@9685: * road vehicles, as maglev is a rail vehicle. truelight@9685: */ truelight@9684: enum VehicleType { truelight@9684: /* Order IS important, as it now matches the internal state of the game for vehicle type */ truebrain@9838: VEHICLE_RAIL, //!< Rail type vehicle. truebrain@9838: VEHICLE_ROAD, //!< Road type vehicle (bus / truck). truebrain@9838: VEHICLE_WATER, //!< Water type vehicle. truebrain@9838: VEHICLE_AIR, //!< Air type vehicle. truebrain@9838: VEHICLE_INVALID = 0xFF, //!< Invalid vehicle type. truelight@9684: }; truelight@9684: rubidium@9491: /** rubidium@9491: * Checks whether the given vehicle is valid and owned by you. truebrain@9838: * @param vehicle_id The vehicle to check. truebrain@9838: * @return True if and only if the vehicle is valid. rubidium@9491: */ rubidium@9497: static bool IsValidVehicle(VehicleID vehicle_id); rubidium@9491: rubidium@9491: /** truelight@9699: * Set the name of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to set the name for. truebrain@9838: * @param name The name for the vehicle. truelight@9699: * @pre IsValidVehicle(vehicle_id). truelight@9699: * @pre Name has to be unique. truelight@9699: * @pre You have to own the vehicle. truebrain@9838: * @return True if and only if the name was changed. truelight@9699: */ truebrain@9737: static bool SetName(VehicleID vehicle_id, const char *name); truelight@9699: truelight@9699: /** truebrain@9829: * Get the name of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the name of. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The name the vehicle has. truebrain@9829: */ truebrain@9829: static char *GetName(VehicleID vehicle_id); truebrain@9829: truebrain@9829: /** truelight@9615: * Get the current location of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the location of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The tile the vehicle is currently on. truelight@9615: */ truelight@9615: static TileIndex GetLocation(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the engine-type of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the engine-type of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The engine type the vehicle has. truelight@9615: */ truelight@9615: static EngineID GetEngineType(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the unitnumber of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the unitnumber of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The unitnumber the vehicle has. truelight@9615: */ truelight@9615: static int32 GetUnitNumber(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the current age of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the age of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The current age the vehicle has. truebrain@9838: * @note The age is in days. truelight@9615: */ truelight@9615: static int32 GetAge(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truebrain@9838: * Get the maximum age of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the age of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The maximum age the vehicle has. truebrain@9838: * @note The age is in days. truelight@9615: */ truelight@9615: static int32 GetMaxAge(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truebrain@9838: * Get the age a vehicle has left (maximum - current). truebrain@9838: * @param vehicle_id The vehicle to get the age of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The age the vehicle has left. truebrain@9838: * @note The age is in days. truelight@9615: */ truelight@9615: static int32 GetAgeLeft(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truebrain@10187: * Get the current speed of a vehicle. truebrain@10187: * @param vehicle_id The vehicle to get the age of. truebrain@10187: * @pre IsValidVehicle(vehicle_id). truebrain@10187: * @return The current speed of the vehicle. truebrain@10187: * @note Speed is in km/h. truebrain@10187: */ truebrain@10187: static int32 GetCurrentSpeed(VehicleID vehicle_id); truebrain@10187: truebrain@10187: /** truebrain@9733: * Get the running cost of this vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the age of. truebrain@9733: * @pre IsValidVehicle(vehicle_id). truebrain@9733: * @return The running cost of the vehicle per year. truebrain@9838: * @note Cost is per year; divide by 364 to get per day. truebrain@9838: * @note This is not equal to AIEngine::GetRunningCost for Trains, because truebrain@9838: * wagons and second engines can add up in the calculation too. truebrain@9733: */ truebrain@9733: static Money GetRunningCost(VehicleID vehicle_id); truebrain@9733: truebrain@9733: /** truelight@9615: * Get the current profit of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the profit of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The current profit the vehicle has. truelight@9615: */ rubidium@10196: static Money GetProfitThisYear(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the profit of last year of a vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the profit of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The profit the vehicle had last year. truelight@9615: */ rubidium@10196: static Money GetProfitLastYear(VehicleID vehicle_id); truelight@9654: truelight@9684: /** truelight@9684: * Get the type of vehicle. truebrain@9838: * @param vehicle_id The vehicle to get the type of. truelight@9684: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return The vehicle type. truelight@9684: */ truelight@9684: static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id); truebrain@9737: truebrain@9829: /** truebrain@10668: * Get the RoadType of the vehicle. truebrain@10668: * @param vehicle_id The vhiecle to get the RoadType of. truebrain@10668: * @pre IsValidVehicle(vehicle_id). truebrain@10668: * @pre GetVehicleType(vehicle_id) == VEHICLE_ROAD. truebrain@10668: * @return The RoadType the vehicle has. truebrain@10668: */ truebrain@10668: static AIRoad::RoadType GetRoadType(VehicleID vehicle_id); truebrain@10668: truebrain@10668: /** truebrain@9829: * Check if a vehicle is in a depot. truebrain@9838: * @param vehicle_id The vehicle to check. truebrain@9838: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return True if and only if the vehicle is in a depot. truebrain@9829: */ truebrain@9829: static bool IsInDepot(VehicleID vehicle_id); truebrain@9829: truebrain@9829: /** truebrain@9829: * Check if a vehicle is in a depot and stopped. truebrain@9838: * @param vehicle_id The vehicle to check. truebrain@9838: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @return True if and only if the vehicle is in a depot and stopped. truebrain@9829: */ truebrain@9829: static bool IsStoppedInDepot(VehicleID vehicle_id); truebrain@9829: truebrain@9829: /** truebrain@9829: * Builds a vehicle with the given engine at the given depot. truebrain@9838: * @param depot The depot where the vehicle will be build. truebrain@9838: * @param engine_id The engine to use for this vehicle. truebrain@9838: * @pre The tile at depot has a depot that can build the engine and truebrain@9829: * is owned by you. truebrain@9829: * @pre IsValidEngine(engine_id). truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_TOO_MANY truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT truebrain@9838: * @return The VehicleID of the new vehicle, or an invalid VehicleID when truebrain@9829: * it failed. Check the return value using IsValidVehicle. In test-mode truebrain@9829: * 0 is returned if it was successful; any other value indicates failure. truebrain@9838: * @note In Test Mode it means you can't assign orders yet to this vehicle, truebrain@9829: * as the vehicle isn't really built yet. Build it for real first before truebrain@9829: * assigning orders. truebrain@9829: */ truebrain@9829: static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id); truebrain@9829: truebrain@9829: /** truebrain@9829: * Clones a vehicle at the given depot, copying or cloning it's orders. truebrain@9838: * @param depot The depot where the vehicle will be build. truebrain@9838: * @param vehicle_id The vehicle to use as example for the new vehicle. truebrain@9838: * @param share_orders Should the orders be copied or shared? truebrain@9838: * @pre The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_TOO_MANY truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_BUILD_DISABLED truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_WRONG_DEPOT truebrain@9838: * @return The VehicleID of the new vehicle, or an invalid VehicleID when truebrain@9829: * it failed. Check the return value using IsValidVehicle. In test-mode truebrain@9829: * 0 is returned if it was successful; any other value indicates failure. truebrain@9829: */ truebrain@9829: static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders); truebrain@9829: truebrain@9829: /** truebrain@9829: * Refits a vehicle to the given cargo type truebrain@9838: * @param vehicle_id The vehicle to refit truebrain@9838: * @param cargo The cargo to refit to. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @pre AICargo::IsValidCargo(cargo). truebrain@9838: * @pre You must own the vehicle. truebrain@9838: * @pre The vehicle must be stopped in the depot. truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_CANNOT_REFIT truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT truebrain@9838: * @return True if and only if the refit succeeded. truebrain@9829: */ truebrain@9829: static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); truebrain@9829: truebrain@9829: /** truebrain@9829: * Sells the given vehicle. truebrain@9838: * @param vehicle_id The vehicle to sell. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9838: * @pre You must own the vehicle. truebrain@9838: * @pre The vehicle must be stopped in the depot. truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT truebrain@9838: * @return True if and only if the vehicle has been sold. truebrain@9829: */ truebrain@9829: static bool SellVehicle(VehicleID vehicle_id); truebrain@9829: truebrain@9829: /** truebrain@9829: * Sends the given vehicle to a depot. truebrain@9838: * @param vehicle_id The vehicle to send to a depot. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT truebrain@9838: * @return True if and only if the vehicle has been sent to a depot. truebrain@9829: */ truebrain@9829: static bool SendVehicleToDepot(VehicleID vehicle_id); truebrain@9829: truebrain@9829: /** truebrain@9829: * Starts or stops the given vehicle depending on the current state. truebrain@9838: * @param vehicle_id The vehicle to start/stop. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9874: * @exception AIVehicle::ERR_VEHICLE_CANNOT_START_STOP truebrain@9874: * @exception (For aircraft only): AIVehicle::ERR_VEHICLE_IN_FLIGHT truebrain@9874: * @exception (For trains only): AIVehicle::ERR_VEHICLE_NO_POWER truebrain@9838: * @return True if and only if the vehicle has been started or stopped. truebrain@9829: */ truebrain@9829: static bool StartStopVehicle(VehicleID vehicle_id); truebrain@9829: truebrain@9829: /** truebrain@9829: * Skips the current order of the given vehicle. truebrain@9838: * @param vehicle_id The vehicle to skip the order for. truebrain@9838: * @param order_id The selected order to which we want to skip. truebrain@9829: * @pre IsValidVehicleOrder(vehicle_id, order_id). truebrain@9838: * @return True if and only if the order has been skipped. truebrain@9829: */ truebrain@9829: static bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id); rubidium@10189: rubidium@10189: /** rubidium@10189: * Get the maximum amount of a specific cargo the given vehicle can transport. rubidium@10189: * @param vehicle_id The vehicle to get the capacity of. rubidium@10189: * @param cargo The cargo to get the capacity for. rubidium@10189: * @pre IsValidVehicle(vehicle_id). rubidium@10189: * @pre AICargo::IsValidCargo(cargo). rubidium@10189: * @return The maximum amount of the given cargo the vehicle can transport. rubidium@10189: */ rubidium@10189: static int32 GetCapacity(VehicleID vehicle_id, CargoID cargo); rubidium@10189: rubidium@10189: /** rubidium@10189: * Get the amount of a specific cargo the given vehicle transports. rubidium@10189: * @param vehicle_id The vehicle to get the load amount of. rubidium@10189: * @param cargo The cargo to get the load amount for. rubidium@10189: * @pre IsValidVehicle(vehicle_id). rubidium@10189: * @pre AICargo::IsValidCargo(cargo). rubidium@10189: * @return The amount of the given cargo the vehicle currently transports. rubidium@10189: */ rubidium@10189: static int32 GetCargoLoad(VehicleID vehicle_id, CargoID cargo); rubidium@9491: }; rubidium@9491: rubidium@9491: #endif /* AI_VEHICLE_HPP */