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" rubidium@9723: #include "../../vehicle_type.h" 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: 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 */ truelight@9684: VEHICLE_RAIL, truelight@9684: VEHICLE_ROAD, truelight@9684: VEHICLE_WATER, truelight@9684: VEHICLE_AIR, truelight@9684: VEHICLE_INVALID = 0xFF, truelight@9684: }; truelight@9684: rubidium@9491: /** rubidium@9491: * Checks whether the given vehicle is valid and owned by you. rubidium@9491: * @param vehicle_id the vehicle to check. rubidium@9491: * @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. truelight@9699: * @param vehicle_id the vehicle to set the name for. truelight@9699: * @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. truelight@9699: * @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@9829: * @param vehicle_id the vehicle to get the name of. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9829: * @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. truelight@9615: * @param vehicle_id the vehicle to get the location of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @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. truelight@9615: * @param vehicle_id the vehicle to get the engine-type of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @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. truelight@9615: * @param vehicle_id the vehicle to get the unitnumber of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @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. truelight@9615: * @note age is in days. truelight@9615: * @param vehicle_id the vehicle to get the age of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @return the current age the vehicle has. truelight@9615: */ truelight@9615: static int32 GetAge(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the max age of a vehicle. truelight@9615: * @note age is in days. truelight@9615: * @param vehicle_id the vehicle to get the age of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @return the max age the vehicle has. truelight@9615: */ truelight@9615: static int32 GetMaxAge(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the age a vehicle has left (max - current). truelight@9615: * @note age is in days. truelight@9615: * @param vehicle_id the vehicle to get the age of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @return the age the vehicle has left. truelight@9615: */ truelight@9615: static int32 GetAgeLeft(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truebrain@9733: * Get the running cost of this vehicle. truebrain@9733: * @note cost is per year; divide by 364 to get per day. truebrain@9733: * @note this is not equal to AIEngine::GetRunningCost for Trains, because truebrain@9733: * wagons and second engines can add up in the calculation too. truebrain@9733: * @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@9733: */ truebrain@9733: static Money GetRunningCost(VehicleID vehicle_id); truebrain@9733: truebrain@9733: /** truelight@9615: * Get the current profit of a vehicle. truelight@9615: * @param vehicle_id the vehicle to get the profit of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @return the current profit the vehicle has. truelight@9615: */ truelight@9615: static int32 GetProfitThisYear(VehicleID vehicle_id); truelight@9615: truelight@9615: /** truelight@9615: * Get the profit of last year of a vehicle. truelight@9615: * @param vehicle_id the vehicle to get the profit of. truelight@9615: * @pre IsValidVehicle(vehicle_id). truelight@9615: * @return the profit the vehicle had last year. truelight@9615: */ truelight@9615: static int32 GetProfitLastYear(VehicleID vehicle_id); truelight@9654: truelight@9684: /** truelight@9684: * Get the type of vehicle. truelight@9684: * @param vehicle_id the vehicle to get the type of. truelight@9684: * @pre IsValidVehicle(vehicle_id). truelight@9684: * @return the vehicle type. truelight@9684: */ truelight@9684: static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id); truebrain@9737: truebrain@9829: /** truebrain@9829: * Check if a vehicle is in a depot. truebrain@9829: * @param vehicle_id the vehicle to check. truebrain@9829: * @pre isValidVehicle(vehicle_id). truebrain@9829: * @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@9829: * @param vehicle_id the vehicle to check. truebrain@9829: * @pre isValidVehicle(vehicle_id). truebrain@9829: * @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@9829: * @param depot the depot where the vehicle will be build. truebrain@9829: * @param engine_id the engine to use for this vehicle. truebrain@9829: * @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@9829: * @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: * @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@9829: * @param depot the depot where the vehicle will be build. truebrain@9829: * @param vehicle_id the vehicle to use as example for the new vehicle. truebrain@9829: * @param share_orders should the orders be copied or shared? truebrain@9829: * @pre the tile at depot has a depot. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9829: * @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@9829: * @param vehicle_id the vehicle to refit truebrain@9829: * @param cargo the cargo to refit to truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9829: * @pre AICargo::IsValidCargo(cargo) truebrain@9829: * @pre you must own the vehicle truebrain@9829: * @pre the vehicle must be stopped in the depot truebrain@9829: * @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@9829: * @param vehicle_id the vehicle to sell. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9829: * @pre you must own the vehicle truebrain@9829: * @pre the vehicle must be stopped in the depot truebrain@9829: * @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@9829: * @param vehicle_id the vehicle to send to a depot. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9829: * @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@9829: * @param vehicle_id the vehicle to start/stop. truebrain@9829: * @pre IsValidVehicle(vehicle_id). truebrain@9829: * @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@9829: * @param vehicle_id the vehicle to skip the order for. truebrain@9829: * @param order_id the selected order to which we want to skip. truebrain@9829: * @pre IsValidVehicleOrder(vehicle_id, order_id). truebrain@9829: * @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@9491: }; rubidium@9491: rubidium@9491: #endif /* AI_VEHICLE_HPP */