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 #include "../../order_type.h"
00018
00023 class ScriptOrder : public ScriptObject {
00024 public:
00028 enum ErrorMessages {
00030 ERR_ORDER_BASE = ScriptError::ERR_CAT_ORDER << ScriptError::ERR_CAT_BIT_SIZE,
00031
00033 ERR_ORDER_TOO_MANY,
00034
00036 ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,
00037
00038
00039 ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE,
00040 };
00041
00045 enum ScriptOrderFlags {
00047 AIOF_NONE = 0,
00048
00050 AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
00052 AIOF_NON_STOP_DESTINATION = 1 << 1,
00053
00055 AIOF_UNLOAD = 1 << 2,
00057 AIOF_TRANSFER = 1 << 3,
00059 AIOF_NO_UNLOAD = 1 << 4,
00060
00062 AIOF_FULL_LOAD = 2 << 5,
00064 AIOF_FULL_LOAD_ANY = 3 << 5,
00066 AIOF_NO_LOAD = 1 << 7,
00067
00069 AIOF_SERVICE_IF_NEEDED = 1 << 2,
00071 AIOF_STOP_IN_DEPOT = 1 << 3,
00073 AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
00074
00076 AIOF_NON_STOP_FLAGS = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
00078 AIOF_UNLOAD_FLAGS = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
00080 AIOF_LOAD_FLAGS = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
00082 AIOF_DEPOT_FLAGS = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
00083
00085 AIOF_INVALID = 0xFFFF,
00086 };
00087
00091 enum OrderCondition {
00092
00093 OC_LOAD_PERCENTAGE = ::OCV_LOAD_PERCENTAGE,
00094 OC_RELIABILITY = ::OCV_RELIABILITY,
00095 OC_MAX_SPEED = ::OCV_MAX_SPEED,
00096 OC_AGE = ::OCV_AGE,
00097 OC_REQUIRES_SERVICE = ::OCV_REQUIRES_SERVICE,
00098 OC_UNCONDITIONALLY = ::OCV_UNCONDITIONALLY,
00099 OC_REMAINING_LIFETIME = ::OCV_REMAINING_LIFETIME,
00100
00101
00102 OC_INVALID = -1,
00103 };
00104
00108 enum CompareFunction {
00109
00110 CF_EQUALS = ::OCC_EQUALS,
00111 CF_NOT_EQUALS = ::OCC_NOT_EQUALS,
00112 CF_LESS_THAN = ::OCC_LESS_THAN,
00113 CF_LESS_EQUALS = ::OCC_LESS_EQUALS,
00114 CF_MORE_THAN = ::OCC_MORE_THAN,
00115 CF_MORE_EQUALS = ::OCC_MORE_EQUALS,
00116 CF_IS_TRUE = ::OCC_IS_TRUE,
00117 CF_IS_FALSE = ::OCC_IS_FALSE,
00118
00119
00120 CF_INVALID = -1,
00121 };
00122
00130 enum OrderPosition {
00131 ORDER_CURRENT = 0xFF,
00132 ORDER_INVALID = -1,
00133 };
00134
00136 enum StopLocation {
00137 STOPLOCATION_NEAR,
00138 STOPLOCATION_MIDDLE,
00139 STOPLOCATION_FAR,
00140 STOPLOCATION_INVALID = -1,
00141 };
00142
00150 static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
00151
00159 static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
00160
00168 static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
00169
00177 static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
00178
00186 static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
00187
00198 static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
00199
00207 static bool IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position);
00208
00218 static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
00219
00230 static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
00231
00238 static bool AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags);
00239
00246 static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
00247
00255 static int32 GetOrderCount(VehicleID vehicle_id);
00256
00270 static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
00271
00285 static ScriptOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
00286
00295 static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
00296
00305 static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
00306
00315 static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
00316
00325 static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
00326
00336 static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
00337
00351 static CargoID GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position);
00352
00363 static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00364
00375 static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
00376
00387 static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
00388
00399 static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
00400
00412 static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
00413
00424 static bool SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo);
00425
00438 static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags);
00439
00450 static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
00451
00465 static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrderFlags order_flags);
00466
00478 static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00479
00488 static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
00489
00494 static bool _SetOrderFlags();
00495
00507 static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, ScriptOrderFlags order_flags);
00508
00523 static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
00524
00533 static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
00534
00547 static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00548
00560 static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00561
00568 static bool UnshareOrders(VehicleID vehicle_id);
00569
00578 static uint GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile);
00579 };
00580 DECLARE_ENUM_AS_BIT_SET(ScriptOrder::ScriptOrderFlags)
00581
00582 #endif