rubidium@9491: /* $Id$ */ rubidium@9491: rubidium@9491: /** @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: 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: /** truelight@9529: * The name of the class, needed by several sub-processes. truelight@9529: */ truelight@9529: static const char *GetClassName() { return "AIVehicle"; } truelight@9529: truelight@9529: /** 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: /** rubidium@9491: * Builds a vehicle with the given engine at the given depot. rubidium@9491: * @param depot the depot where the vehicle will be build. rubidium@9491: * @param engine_id the engine to use for this vehicle. rubidium@9491: * @pre the tile at depot has a depot that can build the engine and rubidium@9491: * is owned by you. rubidium@9491: * @pre IsValidEngine(engine_id). rubidium@9491: * @return the VehicleID of the new vehicle, or an invalid VehicleID when truelight@9562: * it failed. Check the return value using IsValidVehicle. In test-mode truelight@9562: * 0 is returned if it was successful; any other value indicates failure. truelight@9563: * @note in test-mode it means you can't assign orders yet to this vehicle, truelight@9563: * as the vehicle isn't really built yet. Build it for real first before truelight@9563: * assigning orders. rubidium@9491: */ truebrain@9737: static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id); rubidium@9491: rubidium@9491: /** rubidium@9491: * Clones a vehicle at the given depot, copying or cloning it's orders. rubidium@9491: * @param depot the depot where the vehicle will be build. rubidium@9491: * @param vehicle_id the vehicle to use as example for the new vehicle. rubidium@9491: * @param share_orders should the orders be copied or shared? rubidium@9491: * @pre the tile at depot has a depot. rubidium@9491: * @pre IsValidVehicle(vehicle_id). rubidium@9491: * @return the VehicleID of the new vehicle, or an invalid VehicleID when truelight@9562: * it failed. Check the return value using IsValidVehicle. In test-mode truelight@9562: * 0 is returned if it was successful; any other value indicates failure. rubidium@9491: */ truebrain@9737: static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders); rubidium@9491: rubidium@9491: /** rubidium@9491: * Refits a vehicle to the given cargo type rubidium@9491: * @param vehicle_id the vehicle to refit rubidium@9491: * @param cargo the cargo to refit to rubidium@9491: * @pre IsValidVehicle(vehicle_id). rubidium@9491: * @pre AICargo::IsValidCargo(cargo) rubidium@9491: * @pre you must own the vehicle rubidium@9491: * @pre the vehicle must be stopped in the depot rubidium@9491: * @return true if and only if the refit succeeded. rubidium@9491: */ truebrain@9737: static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo); rubidium@9491: rubidium@9491: /** rubidium@9491: * Sells the given vehicle. rubidium@9491: * @param vehicle_id the vehicle to sell. rubidium@9491: * @pre IsValidVehicle(vehicle_id). rubidium@9491: * @pre you must own the vehicle rubidium@9491: * @pre the vehicle must be stopped in the depot rubidium@9491: * @return true if and only if the vehicle has been sold. rubidium@9491: */ truebrain@9737: static bool SellVehicle(VehicleID vehicle_id); rubidium@9491: rubidium@9491: /** rubidium@9491: * Sends the given vehicle to a depot. rubidium@9491: * @param vehicle_id the vehicle to send to a depot. rubidium@9491: * @pre IsValidVehicle(vehicle_id). rubidium@9491: * @return true if and only if the vehicle has been sent to a depot. rubidium@9491: */ truebrain@9737: static bool SendVehicleToDepot(VehicleID vehicle_id); rubidium@9491: rubidium@9491: /** truelight@9709: * Check if a vehicle is in a depot. truelight@9709: * @param vehicle_id the vehicle to check. truelight@9709: * @pre isValidVehicle(vehicle_id). truelight@9709: * @return true if and only if the vehicle is in a depot. truelight@9709: */ truebrain@9737: static bool IsInDepot(VehicleID vehicle_id); truelight@9709: truelight@9709: /** truelight@9709: * Check if a vehicle is in a depot and stopped. truelight@9709: * @param vehicle_id the vehicle to check. truelight@9709: * @pre isValidVehicle(vehicle_id). truelight@9709: * @return true if and only if the vehicle is in a depot and stopped. truelight@9709: */ truebrain@9737: static bool IsStoppedInDepot(VehicleID vehicle_id); truelight@9709: truelight@9709: /** rubidium@9491: * Starts or stops the given vehicle depending on the current state. rubidium@9491: * @param vehicle_id the vehicle to start/stop. rubidium@9491: * @pre IsValidVehicle(vehicle_id). rubidium@9491: * @return true if and only if the vehicle has been started or stopped. rubidium@9491: */ truebrain@9737: static bool StartStopVehicle(VehicleID vehicle_id); rubidium@9491: rubidium@9491: /** rubidium@9491: * Skips the current order of the given vehicle. rubidium@9491: * @param vehicle_id the vehicle to skip the order for. truelight@9706: * @param order_id the selected order to which we want to skip. truelight@9706: * @pre IsValidVehicleOrder(vehicle_id, order_id). rubidium@9491: * @return true if and only if the order has been skipped. rubidium@9491: */ truebrain@9737: static bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id); truelight@9615: truelight@9615: /** 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: /** 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@9699: * Get the name of a vehicle. truelight@9712: * @param vehicle_id the vehicle to get the name of. truelight@9699: * @pre IsValidVehicle(vehicle_id). truelight@9699: * @return the name the vehicle has. truelight@9699: */ truelight@9699: static char *GetName(VehicleID vehicle_id); truelight@9699: truelight@9699: /** 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: rubidium@9491: }; rubidium@9491: rubidium@9491: #endif /* AI_VEHICLE_HPP */