# ai_order.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_order.hpp 16902 2009-07-21 17:17:20Z rubidium $ */
    00002
    00005 #ifndef AI_ORDER_HPP
    00006 #define AI_ORDER_HPP
    00007
    00008 #include "ai_object.hpp"
    00009 #include "ai_error.hpp"
    00010
    00014 class AIOrder : public AIObject {
    00015 public:
    00016   static const char *GetClassName() { return "AIOrder"; }
    00017
    00021   enum ErrorMessages {
    00023     ERR_ORDER_BASE = AIError::ERR_CAT_ORDER << AIError::ERR_CAT_BIT_SIZE,
    00024
    00026     ERR_ORDER_TOO_MANY,                                  // [STR_8831_NO_MORE_SPACE_FOR_ORDERS]
    00027
    00029     ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,    // [STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO]
    00030   };
    00031
    00035   enum AIOrderFlags {
    00037     AIOF_NONE              = 0,
    00038
    00040     AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
    00042     AIOF_NON_STOP_DESTINATION  = 1 << 1,
    00043
    00045     AIOF_UNLOAD            = 1 << 2,
    00047     AIOF_TRANSFER          = 1 << 3,
    00049     AIOF_NO_UNLOAD         = 1 << 4,
    00050
    00052     AIOF_FULL_LOAD         = 2 << 5,
    00054     AIOF_FULL_LOAD_ANY     = 3 << 5,
    00056     AIOF_NO_LOAD           = 1 << 7,
    00057
    00059     AIOF_SERVICE_IF_NEEDED = 1 << 2,
    00061     AIOF_STOP_IN_DEPOT     = 1 << 3,
    00062
    00064     AIOF_NON_STOP_FLAGS    = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
    00066     AIOF_UNLOAD_FLAGS      = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
    00068     AIOF_LOAD_FLAGS        = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
    00070     AIOF_DEPOT_FLAGS       = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT,
    00071
    00073     AIOF_INVALID           = 0xFFFF,
    00074   };
    00075
    00079   enum OrderCondition {
    00080     /* Order _is_ important, as it's based on OrderConditionVariable in order_type.h. */
    00081     OC_LOAD_PERCENTAGE,
    00082     OC_RELIABILITY,
    00083     OC_MAX_SPEED,
    00084     OC_AGE,
    00085     OC_REQUIRES_SERVICE,
    00086     OC_UNCONDITIONALLY,
    00087     OC_INVALID = -1,
    00088   };
    00089
    00093   enum CompareFunction {
    00094     /* Order _is_ important, as it's based on OrderConditionComparator in order_type.h. */
    00095     CF_EQUALS,
    00096     CF_NOT_EQUALS,
    00097     CF_LESS_THAN,
    00098     CF_LESS_EQUALS,
    00099     CF_MORE_THAN,
    00100     CF_MORE_EQUALS,
    00101     CF_IS_TRUE,
    00102     CF_IS_FALSE,
    00103     CF_INVALID = -1,
    00104   };
    00105
    00107   enum OrderPosition {
    00108     ORDER_CURRENT = 0xFF,
    00109     ORDER_INVALID = -1,
    00110   };
    00111
    00119   static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
    00120
    00128   static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
    00129
    00137   static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
    00138
    00146   static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
    00147
    00155   static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
    00156
    00166   static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
    00167
    00178   static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
    00179
    00186   static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags);
    00187
    00194   static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
    00195
    00203   static int32 GetOrderCount(VehicleID vehicle_id);
    00204
    00218   static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
    00219
    00233   static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
    00234
    00243   static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
    00244
    00253   static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
    00254
    00263   static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
    00264
    00273   static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
    00274
    00285   static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00286
    00297   static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
    00298
    00309   static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
    00310
    00321   static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
    00322
    00335   static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
    00336
    00347   static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
    00348
    00362   static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
    00363
    00375   static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00376
    00385   static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
    00386
    00387 #ifndef DOXYGEN_SKIP
    00388
    00391   static bool _SetOrderFlags();
    00392 #endif /* DOXYGEN_SKIP */
    00393
    00404   static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
    00405
    00409   static bool ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
    00410
    00425   static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
    00426
    00435   static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
    00436
    00448   static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00449
    00460   static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00461
    00468   static bool UnshareOrders(VehicleID vehicle_id);
    00469 };
    00470 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags);
    00471
    00472 #endif /* AI_ORDER_HPP */