rubidium@9500: /* $Id$ */ rubidium@9500: rubidium@9500: /** @file ai_order.hpp Everything to query and build Orders */ rubidium@9500: rubidium@9500: #ifndef AI_ORDER_HPP rubidium@9500: #define AI_ORDER_HPP rubidium@9500: rubidium@9500: #include "ai_object.hpp" rubidium@9500: rubidium@9500: /** rubidium@9500: * Class that handles all order related functions. rubidium@9500: */ rubidium@9500: class AIOrder : public AIObject { rubidium@9500: public: rubidium@9500: /** truelight@9529: * The name of the class, needed by several sub-processes. truelight@9529: */ truelight@9529: static const char *GetClassName() { return "AIOrder"; } truelight@9529: truelight@9529: /** rubidium@9500: * Flags that can be used to modify the behaviour of orders. rubidium@9500: */ rubidium@9500: enum AIOrderFlags { rubidium@9500: /** Just go to the station/depot, stop unload if possible and load if needed. */ rubidium@9500: AIOF_NONE = 0, rubidium@9500: rubidium@9500: /** Transfer instead of deliver the goods; only for stations. */ rubidium@9500: AIOF_TRANSFER = 1 << 0, rubidium@9548: /** Always unload the vehicle; only for stations. Cannot be set when AIOF_FULL_LOAD is set. */ rubidium@9500: AIOF_UNLOAD = 1 << 1, rubidium@9548: /** Wait till the the vehicle is fully loaded; only for stations. Cannot be set when AIOF_UNLOAD is set. */ rubidium@9500: AIOF_FULL_LOAD = 1 << 2, rubidium@9500: rubidium@9500: /** Service the vehicle when needed, otherwise skip this order; only for depots. */ rubidium@9500: AIOF_SERVICE_IF_NEEDED = 1 << 2, rubidium@9500: rubidium@9500: /** Do not stop at the stations that are passed when going to the destination. */ rubidium@9500: AIOF_NON_STOP = 1 << 3, rubidium@9500: rubidium@9500: /** For marking invalid order flags */ rubidium@9500: AIOF_INVALID = 0xFFFF, rubidium@9500: }; rubidium@9500: rubidium@9500: /** rubidium@9500: * Checks whether the given order id is valid for the given vehicle. rubidium@9500: * @param vehicle_id the vehicle to check the order index for. rubidium@9500: * @param order_id the order index to check. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @return true if and only if the order_id is valid for the given vehicle. rubidium@9500: */ rubidium@9500: static bool IsValidVehicleOrder(VehicleID vehicle_id, uint32 order_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Checks whether the given order flags are valid for the given destination. rubidium@9500: * @param destination the destination of the order. rubidium@9500: * @param order_flags the flags given to the order. rubidium@9500: * @return true if and only if the order_flags are valid for the given location. rubidium@9500: */ rubidium@9500: static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags); rubidium@9500: rubidium@9500: /** rubidium@9500: * Returns the number of orders for the given vehicle. rubidium@9500: * @param vehicle_id the vehicle to get the order count of. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @return the number of orders for the given vehicle or a negative rubidium@9500: * value when the vehicle does not exist. rubidium@9500: */ truebrain@9737: static int32 GetNumberOfOrders(VehicleID vehicle_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Gets the destination of the given order for the given vehicle. rubidium@9500: * @param vehicle_id the vehicle to get the destination for. rubidium@9500: * @param order_id the order to get the destination for. rubidium@9500: * @pre IsValidVehicleOrder(vehicle_id, order_id). rubidium@9500: * @return the destination tile of the order. rubidium@9500: */ truebrain@9737: static TileIndex GetOrderDestination(VehicleID vehicle_id, uint32 order_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Gets the AIOrderFlags of the given order for the given vehicle. rubidium@9500: * @param vehicle_id the vehicle to get the destination for. rubidium@9500: * @param order_id the order to get the destination for. rubidium@9500: * @pre IsValidVehicleOrder(vehicle_id, order_id). rubidium@9500: * @return the AIOrderFlags of the order. rubidium@9500: */ truebrain@9737: static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, uint32 order_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Appends an order to the end of the vehicle's order list. rubidium@9500: * @param vehicle_id the vehicle to append the order to. rubidium@9500: * @param destination the destination of the order. rubidium@9500: * @param order_flags the flags given to the order. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @pre AreOrderFlagsValid(destination, order_flags). rubidium@9500: * @return true if and only if the order was appended. rubidium@9500: */ truebrain@9737: static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags); rubidium@9500: rubidium@9500: /** rubidium@9500: * Inserts an order before the given order_id into the vehicle's order list. rubidium@9500: * @param vehicle_id the vehicle to add the order to. rubidium@9500: * @param order_id the order to place the new order before. rubidium@9500: * @param destination the destination of the order. rubidium@9500: * @param order_flags the flags given to the order. rubidium@9500: * @pre IsValidVehicleOrder(vehicle_id, order_id). rubidium@9500: * @pre AreOrderFlagsValid(destination, order_flags). rubidium@9500: * @return true if and only if the order was inserted. rubidium@9500: */ truebrain@9737: static bool InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrderFlags order_flags); rubidium@9500: rubidium@9500: /** rubidium@9500: * Removes an order from the vehicle's order list. rubidium@9500: * @param vehicle_id the vehicle to remove the order from. rubidium@9500: * @param order_id the order to remove from the order list. rubidium@9500: * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_id). rubidium@9500: * @return true if and only if the order was removed. rubidium@9500: */ truebrain@9737: static bool RemoveOrder(VehicleID vehicle_id, uint32 order_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Changes the order flags of the given order. rubidium@9500: * @param vehicle_id the vehicle to change the order of. rubidium@9500: * @param order_id the order to change. rubidium@9500: * @param order_flags the new flags given to the order. rubidium@9500: * @pre IsValidVehicleOrder(vehicle_id, order_id). rubidium@9500: * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags). rubidium@9500: * @return true if and only if the order was changed. rubidium@9500: */ truebrain@9737: static bool ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrderFlags order_flags); rubidium@9500: rubidium@9500: /** truelight@9707: * Move an order inside the orderlist truelight@9707: * @param vehicle_id the vehicle to move the orders. truelight@9707: * @param order_id_move the order to move. truelight@9707: * @param order_id_target the target order truelight@9707: * @pre IsValidVehicleOrder(vehicle_id, order_id_move). truelight@9707: * @pre IsValidVehicleOrder(vehicle_id, order_id_target). truelight@9707: * @return true if and only if the order was moved. truelight@9707: * @note If the order is moved to a lower place (e.g. from 7 to 2) truelight@9707: * the target order is moved upwards (e.g. 3). If the order is moved truelight@9707: * to a higher place (e.g. from 7 to 9) the target will be moved truelight@9707: * downwards (e.g. 8). truelight@9707: */ truebrain@9737: static bool MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target); truelight@9707: truelight@9707: /** rubidium@9500: * Copies the orders from another vehicle. The orders of the main rubidium@9500: * vehicle are going to be the orders of the changed vehicle. rubidium@9500: * @param vehicle_id the vehicle to copy the orders to. rubidium@9500: * @param main_vehicle_id the vehicle to copy the orders from. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @pre AIVehicle::IsValidVehicle(main_vehicle_id). rubidium@9500: * @return true if and only if the copying succeeded. rubidium@9500: */ truebrain@9737: static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Shares the orders between two vehicles. The orders of the main rubidium@9500: * vehicle are going to be the orders of the changed vehicle. rubidium@9500: * @param vehicle_id the vehicle to add to the shared order list. rubidium@9500: * @param main_vehicle_id the vehicle to share the orders with. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @pre AIVehicle::IsValidVehicle(main_vehicle_id). rubidium@9500: * @return true if and only if the sharing succeeded. rubidium@9500: */ truebrain@9737: static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id); rubidium@9500: rubidium@9500: /** rubidium@9500: * Removes the given vehicle from a shared orders list. rubidium@9500: * @param vehicle_id the vehicle to remove from the shared order list. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @return true if and only if the unsharing succeeded. rubidium@9500: */ truebrain@9737: static bool UnshareOrders(VehicleID vehicle_id); rubidium@9500: }; rubidium@9500: DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags); rubidium@9500: rubidium@9500: #endif /* AI_ORDER_HPP */