00001
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,
00027
00029 ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,
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
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
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
00295 static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
00296
00305 static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
00306
00316 static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
00317
00330 static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
00331
00342 static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
00343
00357 static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
00358
00370 static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00371
00380 static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
00381
00382 #ifndef DOXYGEN_SKIP
00383
00386 static bool _SetOrderFlags();
00387 #endif
00388
00399 static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
00400
00404 static bool ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
00405
00420 static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
00421
00430 static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
00431
00443 static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00444
00455 static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00456
00463 static bool UnshareOrders(VehicleID vehicle_id);
00464 };
00465 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags);
00466
00467 #endif