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" truelight@9654: #include "../../vehicle.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 engine type is valid and buildable by you. rubidium@9491: * @param engine_id the engine to check. rubidium@9491: * @return true if and only if the engine type is valid. rubidium@9491: */ rubidium@9497: static bool IsValidEngine(EngineID engine_id); rubidium@9491: 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: /** rubidium@9491: * Find the best road vehicle for this job, given a minimum reliability. rubidium@9491: * @param cargo the cargo the vehicle has to transport. rubidium@9491: * @param min_reliability the minimum reliability of the vehicle, rubidium@9491: * between 0 and 100. truelight@9672: * @param max_cost the maximum cost for the vehicle. rubidium@9491: * @pre AICargo::IsValidCargo(cargo). rubidium@9491: * @pre min_reliability is between 0 and 100. rubidium@9522: * @return the engine with the best characteristics, or an invalid engine rubidium@9522: * when no engine was found given the cargo and reliability. Check the rubidium@9522: * return value using IsValidEngine. rubidium@9491: */ truelight@9672: EngineID FindBestRoadVehicle(CargoID cargo, uint8 min_reliability, uint max_cost); rubidium@9491: rubidium@9491: /** truelight@9654: * Find the best aircraft for this job, given a minimum reliability. truelight@9654: * @param cargo the cargo the vehicle has to transport. truelight@9654: * @param min_reliability the minimum reliability of the vehicle, truelight@9654: * between 0 and 100. truelight@9672: * @param max_cost the maximum cost for the vehicle. truelight@9654: * @pre AICargo::IsValidCargo(cargo). truelight@9654: * @pre min_reliability is between 0 and 100. truelight@9654: * @return the engine with the best characteristics, or an invalid engine truelight@9654: * when no engine was found given the cargo and reliability. Check the truelight@9654: * return value using IsValidEngine. truelight@9654: */ truelight@9691: EngineID FindBestAirVehicle(CargoID cargo, uint8 min_reliability, uint max_cost); truelight@9691: truelight@9691: /** truelight@9691: * Find the best ship for this job, given a minimum reliability. truelight@9691: * @param cargo the cargo the vehicle has to transport. truelight@9691: * @param min_reliability the minimum reliability of the vehicle, truelight@9691: * between 0 and 100. truelight@9691: * @param max_cost the maximum cost for the vehicle. truelight@9691: * @pre AICargo::IsValidCargo(cargo). truelight@9691: * @pre min_reliability is between 0 and 100. truelight@9691: * @return the engine with the best characteristics, or an invalid engine truelight@9691: * when no engine was found given the cargo and reliability. Check the truelight@9691: * return value using IsValidEngine. truelight@9691: */ truelight@9691: EngineID FindBestWaterVehicle(CargoID cargo, uint8 min_reliability, uint max_cost); truelight@9654: truelight@9654: /** 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: */ truelight@9550: 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: */ rubidium@9491: 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: */ rubidium@9491: 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: */ rubidium@9491: bool SellVehicle(VehicleID vehicle_id); rubidium@9491: 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: */ rubidium@9491: bool SendVehicleToDepot(VehicleID vehicle_id); rubidium@9491: rubidium@9491: /** 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: */ rubidium@9491: 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. rubidium@9491: * @pre IsValidVehicle(vehicle_id). rubidium@9491: * @return true if and only if the order has been skipped. rubidium@9491: */ rubidium@9491: bool SkipVehicleOrder(VehicleID vehicle_id); truelight@9615: truelight@9615: /** 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: /** 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); truelight@9684: truelight@9654: private: truelight@9684: EngineID FindBestVehicle(CargoID cargo, uint8 min_reliability, AIVehicle::VehicleType veh_type, uint max_cost); rubidium@9491: }; rubidium@9491: rubidium@9491: #endif /* AI_VEHICLE_HPP */