00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef AI_ORDER_HPP
00013 #define AI_ORDER_HPP
00014
00015 #include "ai_object.hpp"
00016 #include "ai_error.hpp"
00017
00021 class AIOrder : public AIObject {
00022 public:
00024 static const char *GetClassName() { return "AIOrder"; }
00025
00029 enum ErrorMessages {
00031 ERR_ORDER_BASE = AIError::ERR_CAT_ORDER << AIError::ERR_CAT_BIT_SIZE,
00032
00034 ERR_ORDER_TOO_MANY,
00035
00037 ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,
00038 };
00039
00043 enum AIOrderFlags {
00045 AIOF_NONE = 0,
00046
00048 AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
00050 AIOF_NON_STOP_DESTINATION = 1 << 1,
00051
00053 AIOF_UNLOAD = 1 << 2,
00055 AIOF_TRANSFER = 1 << 3,
00057 AIOF_NO_UNLOAD = 1 << 4,
00058
00060 AIOF_FULL_LOAD = 2 << 5,
00062 AIOF_FULL_LOAD_ANY = 3 << 5,
00064 AIOF_NO_LOAD = 1 << 7,
00065
00067 AIOF_SERVICE_IF_NEEDED = 1 << 2,
00069 AIOF_STOP_IN_DEPOT = 1 << 3,
00071 AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
00072
00074 AIOF_NON_STOP_FLAGS = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
00076 AIOF_UNLOAD_FLAGS = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
00078 AIOF_LOAD_FLAGS = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
00080 AIOF_DEPOT_FLAGS = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
00081
00083 AIOF_INVALID = 0xFFFF,
00084 };
00085
00089 enum OrderCondition {
00090
00091 OC_LOAD_PERCENTAGE,
00092 OC_RELIABILITY,
00093 OC_MAX_SPEED,
00094 OC_AGE,
00095 OC_REQUIRES_SERVICE,
00096 OC_UNCONDITIONALLY,
00097 OC_INVALID = -1,
00098 };
00099
00103 enum CompareFunction {
00104
00105 CF_EQUALS,
00106 CF_NOT_EQUALS,
00107 CF_LESS_THAN,
00108 CF_LESS_EQUALS,
00109 CF_MORE_THAN,
00110 CF_MORE_EQUALS,
00111 CF_IS_TRUE,
00112 CF_IS_FALSE,
00113 CF_INVALID = -1,
00114 };
00115
00117 enum OrderPosition {
00118 ORDER_CURRENT = 0xFF,
00119 ORDER_INVALID = -1,
00120 };
00121
00123 enum StopLocation {
00124 STOPLOCATION_NEAR,
00125 STOPLOCATION_MIDDLE,
00126 STOPLOCATION_FAR,
00127 STOPLOCATION_INVALID = -1,
00128 };
00129
00137 static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
00138
00146 static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
00147
00155 static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
00156
00164 static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
00165
00173 static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
00174
00185 static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
00186
00196 static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
00197
00208 static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
00209
00216 static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags);
00217
00224 static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
00225
00233 static int32 GetOrderCount(VehicleID vehicle_id);
00234
00248 static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
00249
00263 static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
00264
00273 static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
00274
00283 static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
00284
00293 static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
00294
00303 static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
00304
00314 static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
00315
00326 static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00327
00338 static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
00339
00350 static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
00351
00362 static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
00363
00375 static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
00376
00389 static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
00390
00401 static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
00402
00416 static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
00417
00429 static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00430
00439 static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
00440
00441 #ifndef DOXYGEN_SKIP
00442
00445 static bool _SetOrderFlags();
00446 #endif
00447
00458 static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
00459
00474 static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
00475
00484 static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
00485
00497 static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00498
00509 static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00510
00517 static bool UnshareOrders(VehicleID vehicle_id);
00518 };
00519 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags)
00520
00521 #endif