rubidium@9500: /* $Id$ */ rubidium@9500: truebrain@9829: /** @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@10093: #include "ai_error.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: truelight@9529: static const char *GetClassName() { return "AIOrder"; } truelight@9529: truebrain@10096: /** truebrain@10096: * All order related error messages. truebrain@10096: */ rubidium@10093: enum ErrorMessages { rubidium@10093: /** Base for all order related errors */ rubidium@10093: ERR_ORDER_BASE = AIError::ERR_CAT_ORDER << AIError::ERR_CAT_BIT_SIZE, rubidium@10093: rubidium@10093: /** No more space for orders */ rubidium@10093: ERR_ORDER_TOO_MANY, // [STR_8831_NO_MORE_SPACE_FOR_ORDERS] rubidium@10093: rubidium@10093: /** Destination of new order is to far away from the previous order */ rubidium@10093: ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION, // [STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO] rubidium@10093: }; rubidium@10093: 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@10181: /** Do not stop at the stations that are passed when going to the destination. Only for trains and road vehicles. */ truebrain@10149: AIOF_NON_STOP_INTERMEDIATE = 1 << 0, rubidium@10181: /** Do not stop at the destionation station. Only for trains and road vehicles. */ truebrain@10149: AIOF_NON_STOP_DESTINATION = 1 << 1, rubidium@10146: rubidium@10146: /** Always unload the vehicle; only for stations. Cannot be set when AIOF_TRANSFER or AIOF_NO_UNLOAD is set. */ rubidium@10146: AIOF_UNLOAD = 1 << 2, rubidium@10146: /** Transfer instead of deliver the goods; only for stations. Cannot be set when AIOF_UNLOAD or AIOF_NO_UNLOAD is set. */ rubidium@10146: AIOF_TRANSFER = 1 << 3, rubidium@10146: /** Never unload the vehicle; only for stations. Cannot be set when AIOF_UNLOAD, AIOF_TRANSFER or AIOF_NO_LOAD is set. */ rubidium@10146: AIOF_NO_UNLOAD = 1 << 4, rubidium@10146: rubidium@10146: /** Wait till the vehicle is fully loaded; only for stations. Cannot be set when AIOF_NO_LOAD is set. */ rubidium@10146: AIOF_FULL_LOAD = 2 << 5, rubidium@10146: /** Wait till at least one cargo of the vehicle is fully loaded; only for stations. Cannot be set when AIOF_NO_LOAD is set. */ rubidium@10146: AIOF_FULL_LOAD_ANY = 3 << 5, rubidium@10146: /** Do not load any cargo; only for stations. Cannot be set when AIOF_NO_UNLOAD, AIOF_FULL_LOAD or AIOF_FULL_LOAD_ANY is set. */ rubidium@10146: AIOF_NO_LOAD = 1 << 7, 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@10146: /** All flags related to non-stop settings. */ truebrain@10149: AIOF_NON_STOP_FLAGS = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION, rubidium@10146: /** All flags related to unloading. */ rubidium@10146: AIOF_UNLOAD_FLAGS = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD, rubidium@10146: /** All flags related to loading. */ rubidium@10146: AIOF_LOAD_FLAGS = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD, 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. truebrain@9838: * @param vehicle_id The vehicle to check the order index for. truebrain@9838: * @param order_id The order index to check. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). truebrain@9838: * @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. truebrain@9838: * @param destination The destination of the order. truebrain@9838: * @param order_flags The flags given to the order. truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to get the order count of. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to get the destination for. truebrain@9838: * @param order_id The order to get the destination for. rubidium@9500: * @pre IsValidVehicleOrder(vehicle_id, order_id). truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to get the destination for. truebrain@9838: * @param order_id The order to get the destination for. rubidium@9500: * @pre IsValidVehicleOrder(vehicle_id, order_id). truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to append the order to. truebrain@9838: * @param destination The destination of the order. truebrain@9838: * @param order_flags The flags given to the order. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). rubidium@9500: * @pre AreOrderFlagsValid(destination, order_flags). rubidium@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10093: * @exception AIOrder::ERR_ORDER_NO_MORE_SPACE rubidium@10093: * @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to add the order to. truebrain@9838: * @param order_id The order to place the new order before. truebrain@9838: * @param destination The destination of the order. truebrain@9838: * @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@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10093: * @exception AIOrder::ERR_ORDER_NO_MORE_SPACE rubidium@10093: * @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to remove the order from. truebrain@9838: * @param order_id The order to remove from the order list. rubidium@9500: * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_id). rubidium@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to change the order of. truebrain@9838: * @param order_id The order to change. truebrain@9838: * @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@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY truebrain@9838: * @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 truebrain@9838: * @param vehicle_id The vehicle to move the orders. truebrain@9838: * @param order_id_move The order to move. truebrain@9838: * @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). rubidium@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY truebrain@9838: * @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: /** truebrain@9838: * Copies the orders from another vehicle. The orders of the main vehicle truebrain@9838: * are going to be the orders of the changed vehicle. truebrain@9838: * @param vehicle_id The vehicle to copy the orders to. truebrain@9838: * @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@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY rubidium@10093: * @exception AIOrder::ERR_ORDER_NO_MORE_SPACE truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to add to the shared order list. truebrain@9838: * @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@10093: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY truebrain@9838: * @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. truebrain@9838: * @param vehicle_id The vehicle to remove from the shared order list. rubidium@9500: * @pre AIVehicle::IsValidVehicle(vehicle_id). truebrain@9838: * @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 */