00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef SCRIPT_ORDER_HPP
00013 #define SCRIPT_ORDER_HPP
00014
00015 #include "script_error.hpp"
00016 #include "script_vehicle.hpp"
00017
00022 class ScriptOrder : public ScriptObject {
00023 public:
00027 enum ErrorMessages {
00029 ERR_ORDER_BASE = ScriptError::ERR_CAT_ORDER << ScriptError::ERR_CAT_BIT_SIZE,
00030
00032 ERR_ORDER_TOO_MANY,
00033
00035 ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,
00036
00037
00038 ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE,
00039 };
00040
00044 enum ScriptOrderFlags {
00046 AIOF_NONE = 0,
00047
00049 AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
00051 AIOF_NON_STOP_DESTINATION = 1 << 1,
00052
00054 AIOF_UNLOAD = 1 << 2,
00056 AIOF_TRANSFER = 1 << 3,
00058 AIOF_NO_UNLOAD = 1 << 4,
00059
00061 AIOF_FULL_LOAD = 2 << 5,
00063 AIOF_FULL_LOAD_ANY = 3 << 5,
00065 AIOF_NO_LOAD = 1 << 7,
00066
00068 AIOF_SERVICE_IF_NEEDED = 1 << 2,
00070 AIOF_STOP_IN_DEPOT = 1 << 3,
00072 AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
00073
00075 AIOF_NON_STOP_FLAGS = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
00077 AIOF_UNLOAD_FLAGS = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
00079 AIOF_LOAD_FLAGS = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
00081 AIOF_DEPOT_FLAGS = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
00082
00084 AIOF_INVALID = 0xFFFF,
00085 };
00086
00090 enum OrderCondition {
00091
00092 OC_LOAD_PERCENTAGE,
00093 OC_RELIABILITY,
00094 OC_MAX_SPEED,
00095 OC_AGE,
00096 OC_REQUIRES_SERVICE,
00097 OC_UNCONDITIONALLY,
00098 OC_REMAINING_LIFETIME,
00099 OC_INVALID = -1,
00100 };
00101
00105 enum CompareFunction {
00106
00107 CF_EQUALS,
00108 CF_NOT_EQUALS,
00109 CF_LESS_THAN,
00110 CF_LESS_EQUALS,
00111 CF_MORE_THAN,
00112 CF_MORE_EQUALS,
00113 CF_IS_TRUE,
00114 CF_IS_FALSE,
00115 CF_INVALID = -1,
00116 };
00117
00125 enum OrderPosition {
00126 ORDER_CURRENT = 0xFF,
00127 ORDER_INVALID = -1,
00128 };
00129
00131 enum StopLocation {
00132 STOPLOCATION_NEAR,
00133 STOPLOCATION_MIDDLE,
00134 STOPLOCATION_FAR,
00135 STOPLOCATION_INVALID = -1,
00136 };
00137
00145 static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
00146
00154 static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
00155
00163 static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
00164
00172 static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
00173
00181 static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
00182
00193 static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
00194
00202 static bool IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position);
00203
00213 static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
00214
00225 static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
00226
00233 static bool AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags);
00234
00241 static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
00242
00250 static int32 GetOrderCount(VehicleID vehicle_id);
00251
00265 static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
00266
00280 static ScriptOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
00281
00290 static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
00291
00300 static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
00301
00310 static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
00311
00320 static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
00321
00331 static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
00332
00346 static CargoID GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position);
00347
00358 static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00359
00370 static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
00371
00382 static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
00383
00394 static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
00395
00407 static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
00408
00419 static bool SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo);
00420
00433 static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags);
00434
00445 static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
00446
00460 static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrderFlags order_flags);
00461
00473 static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00474
00483 static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
00484
00489 static bool _SetOrderFlags();
00490
00502 static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, ScriptOrderFlags order_flags);
00503
00518 static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
00519
00528 static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
00529
00542 static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00543
00555 static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00556
00563 static bool UnshareOrders(VehicleID vehicle_id);
00564
00573 static uint GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile);
00574 };
00575 DECLARE_ENUM_AS_BIT_SET(ScriptOrder::ScriptOrderFlags)
00576
00577 #endif