# ai_order.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_order.hpp 15684 2009-03-12 11:43:40Z yexo $ */
    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,
    00060
    00062     AIOF_NON_STOP_FLAGS    = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
    00064     AIOF_UNLOAD_FLAGS      = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
    00066     AIOF_LOAD_FLAGS        = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
    00067
    00069     AIOF_INVALID           = 0xFFFF,
    00070   };
    00071
    00075   enum OrderCondition {
    00076     /* Order _is_ important, as it's based on OrderConditionVariable in order_type.h. */
    00077     OC_LOAD_PERCENTAGE,
    00078     OC_RELIABILITY,
    00079     OC_MAX_SPEED,
    00080     OC_AGE,
    00081     OC_REQUIRES_SERVICE,
    00082     OC_UNCONDITIONALLY,
    00083     OC_INVALID = -1,
    00084   };
    00085
    00089   enum CompareFunction {
    00090     /* Order _is_ important, as it's based on OrderConditionComparator in order_type.h. */
    00091     CF_EQUALS,
    00092     CF_NOT_EQUALS,
    00093     CF_LESS_THAN,
    00094     CF_LESS_EQUALS,
    00095     CF_MORE_THAN,
    00096     CF_MORE_EQUALS,
    00097     CF_IS_TRUE,
    00098     CF_IS_FALSE,
    00099     CF_INVALID = -1,
    00100   };
    00101
    00103   enum OrderPosition {
    00104     ORDER_CURRENT = 0xFF,
    00105     ORDER_INVALID = -1,
    00106   };
    00107
    00115   static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
    00116
    00124   static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
    00125
    00136   static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
    00137
    00144   static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags);
    00145
    00152   static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
    00153
    00161   static int32 GetOrderCount(VehicleID vehicle_id);
    00162
    00176   static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
    00177
    00191   static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
    00192
    00201   static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
    00202
    00211   static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
    00212
    00221   static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
    00222
    00231   static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
    00232
    00243   static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00244
    00253   static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
    00254
    00263   static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
    00264
    00274   static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
    00275
    00288   static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
    00289
    00300   static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
    00301
    00315   static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
    00316
    00328   static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00329
    00338   static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
    00339
    00340 #ifndef DOXYGEN_SKIP
    00341
    00344   static bool _SetOrderFlags();
    00345 #endif /* DOXYGEN_SKIP */
    00346
    00357   static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
    00358
    00362   static bool ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
    00363
    00378   static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
    00379
    00388   static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
    00389
    00401   static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00402
    00413   static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00414
    00421   static bool UnshareOrders(VehicleID vehicle_id);
    00422 };
    00423 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags);
    00424
    00425 #endif /* AI_ORDER_HPP */