2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file script_order.hpp Everything to query and build orders. */
10 #ifndef SCRIPT_ORDER_HPP
11 #define SCRIPT_ORDER_HPP
13 #include "script_vehicle.hpp"
14 #include "../../order_type.h"
17 * Class that handles all order related functions.
20 class ScriptOrder
: public ScriptObject
{
23 * All order related error messages.
25 * @see ScriptErrorType
28 /** Base for all order related errors */
29 ERR_ORDER_BASE
= ScriptError::ERR_CAT_ORDER
<< ScriptError::ERR_CAT_BIT_SIZE
,
31 /** No more space for orders */
32 ERR_ORDER_TOO_MANY
, // [STR_ERROR_NO_MORE_SPACE_FOR_ORDERS]
34 /** Destination of new order is too far away from the previous order */
35 ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
, // [STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION]
37 /** Aircraft has not enough range to copy/share orders. */
38 ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
, // [STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE]
42 * Flags that can be used to modify the behaviour of orders.
44 enum ScriptOrderFlags
{
45 /** Just go to the station/depot, stop unload if possible and load if needed. */
48 /** Do not stop at the stations that are passed when going to the destination. Only for trains and road vehicles. */
49 OF_NON_STOP_INTERMEDIATE
= 1 << 0,
50 /** Do not stop at the destination station. Only for trains and road vehicles. */
51 OF_NON_STOP_DESTINATION
= 1 << 1,
53 /** Always unload the vehicle; only for stations. Cannot be set when OF_TRANSFER or OF_NO_UNLOAD is set. */
55 /** Transfer instead of deliver the goods; only for stations. Cannot be set when OF_UNLOAD or OF_NO_UNLOAD is set. */
57 /** Never unload the vehicle; only for stations. Cannot be set when OF_UNLOAD, OF_TRANSFER or OF_NO_LOAD is set. */
58 OF_NO_UNLOAD
= 1 << 4,
60 /** Wt till the vehicle is fully loaded; only for stations. Cannot be set when OF_NO_LOAD is set. */
61 OF_FULL_LOAD
= 2 << 5,
62 /** Wt till at least one cargo of the vehicle is fully loaded; only for stations. Cannot be set when OF_NO_LOAD is set. */
63 OF_FULL_LOAD_ANY
= 3 << 5,
64 /** Do not load any cargo; only for stations. Cannot be set when OF_NO_UNLOAD, OF_FULL_LOAD or OF_FULL_LOAD_ANY is set. */
67 /** Service the vehicle when needed, otherwise skip this order; only for depots. */
68 OF_SERVICE_IF_NEEDED
= 1 << 2,
69 /** Stop in the depot instead of only go there for servicing; only for depots. */
70 OF_STOP_IN_DEPOT
= 1 << 3,
71 /** Go to nearest depot. */
72 OF_GOTO_NEAREST_DEPOT
= 1 << 8,
74 /** All flags related to non-stop settings. */
75 OF_NON_STOP_FLAGS
= OF_NON_STOP_INTERMEDIATE
| OF_NON_STOP_DESTINATION
,
76 /** All flags related to unloading. */
77 OF_UNLOAD_FLAGS
= OF_TRANSFER
| OF_UNLOAD
| OF_NO_UNLOAD
,
78 /** All flags related to loading. */
79 OF_LOAD_FLAGS
= OF_FULL_LOAD
| OF_FULL_LOAD_ANY
| OF_NO_LOAD
,
80 /** All flags related to depots. */
81 OF_DEPOT_FLAGS
= OF_SERVICE_IF_NEEDED
| OF_STOP_IN_DEPOT
| OF_GOTO_NEAREST_DEPOT
,
83 /** For marking invalid order flags */
88 * All conditions a conditional order can depend on.
91 /* Note: these values represent part of the in-game OrderConditionVariable enum */
92 OC_LOAD_PERCENTAGE
= ::OCV_LOAD_PERCENTAGE
, ///< Skip based on the amount of load, value is in tons.
93 OC_RELIABILITY
= ::OCV_RELIABILITY
, ///< Skip based on the reliability, value is percent (0..100).
94 OC_MAX_RELIABILITY
= ::OCV_MAX_RELIABILITY
, ///< Skip based on the maximum reliability. Value in percent
95 OC_MAX_SPEED
= ::OCV_MAX_SPEED
, ///< Skip based on the maximum speed, value is in OpenTTD's internal speed unit, see ScriptEngine::GetMaxSpeed.
96 OC_AGE
= ::OCV_AGE
, ///< Skip based on the age, value is in calender-years. @see \ref ScriptCalendarTime
97 OC_REQUIRES_SERVICE
= ::OCV_REQUIRES_SERVICE
, ///< Skip when the vehicle requires service, no value.
98 OC_UNCONDITIONALLY
= ::OCV_UNCONDITIONALLY
, ///< Always skip, no compare function, no value.
99 OC_REMAINING_LIFETIME
= ::OCV_REMAINING_LIFETIME
, ///< Skip based on the remaining lifetime in calendar-years. @see \ref ScriptCalendarTime
101 /* Custom added value, only valid for this API */
102 OC_INVALID
= -1, ///< An invalid condition, do not use.
106 * Comparators for conditional orders.
108 enum CompareFunction
{
109 /* Note: these values represent part of the in-game OrderConditionComparator enum */
110 CF_EQUALS
= ::OCC_EQUALS
, ///< Skip if both values are equal
111 CF_NOT_EQUALS
= ::OCC_NOT_EQUALS
, ///< Skip if both values are not equal
112 CF_LESS_THAN
= ::OCC_LESS_THAN
, ///< Skip if the value is less than the limit
113 CF_LESS_EQUALS
= ::OCC_LESS_EQUALS
, ///< Skip if the value is less or equal to the limit
114 CF_MORE_THAN
= ::OCC_MORE_THAN
, ///< Skip if the value is more than the limit
115 CF_MORE_EQUALS
= ::OCC_MORE_EQUALS
, ///< Skip if the value is more or equal to the limit
116 CF_IS_TRUE
= ::OCC_IS_TRUE
, ///< Skip if the variable is true
117 CF_IS_FALSE
= ::OCC_IS_FALSE
, ///< Skip if the variable is false
119 /* Custom added value, only valid for this API */
120 CF_INVALID
= -1, ///< Invalid compare function, do not use.
124 * Index in the list of orders for a vehicle. The first order has index 0, the second
125 * order index 1, etc. The current order can be queried by using ORDER_CURRENT. Do not
126 * use ORDER_INVALID yourself, it's used as return value by for example ResolveOrderPosition.
127 * @note Automatic orders are hidden from scripts, so OrderPosition 0 will always be the first
131 ORDER_CURRENT
= 0xFF, ///< Constant that gets resolved to the current order.
132 ORDER_INVALID
= -1, ///< An invalid order.
135 /** Where to stop trains in a station that's longer than the train */
137 STOPLOCATION_NEAR
, ///< Stop the train as soon as it's completely in the station
138 STOPLOCATION_MIDDLE
, ///< Stop the train in the middle of the station
139 STOPLOCATION_FAR
, ///< Stop the train at the far end of the station
140 STOPLOCATION_INVALID
= -1, ///< An invalid stop location
144 * Checks whether the given order id is valid for the given vehicle.
145 * @param vehicle_id The vehicle to check the order index for.
146 * @param order_position The order index to check.
147 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
148 * @return True if and only if the order_position is valid for the given vehicle.
150 static bool IsValidVehicleOrder(VehicleID vehicle_id
, OrderPosition order_position
);
153 * Checks whether the given order is a goto-station order.
154 * @param vehicle_id The vehicle to check.
155 * @param order_position The order index to check.
156 * @pre IsValidVehicleOrder(vehicle_id, order_position).
157 * @return True if and only if the order is a goto-station order.
159 static bool IsGotoStationOrder(VehicleID vehicle_id
, OrderPosition order_position
);
162 * Checks whether the given order is a goto-depot order.
163 * @param vehicle_id The vehicle to check.
164 * @param order_position The order index to check.
165 * @pre IsValidVehicleOrder(vehicle_id, order_position).
166 * @return True if and only if the order is a goto-depot order.
168 static bool IsGotoDepotOrder(VehicleID vehicle_id
, OrderPosition order_position
);
171 * Checks whether the given order is a goto-waypoint order.
172 * @param vehicle_id The vehicle to check.
173 * @param order_position The order index to check.
174 * @pre IsValidVehicleOrder(vehicle_id, order_position).
175 * @return True if and only if the order is a goto-waypoint order.
177 static bool IsGotoWaypointOrder(VehicleID vehicle_id
, OrderPosition order_position
);
180 * Checks whether the given order is a conditional order.
181 * @param vehicle_id The vehicle to check.
182 * @param order_position The order index to check.
183 * @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
184 * @return True if and only if the order is a conditional order.
186 static bool IsConditionalOrder(VehicleID vehicle_id
, OrderPosition order_position
);
189 * Checks whether the given order is a void order.
190 * A void order is an order that used to be a goto station, depot or waypoint order but
191 * its destination got removed. In OpenTTD these orders as shown as "(Invalid Order)"
192 * in the order list of a vehicle.
193 * @param vehicle_id The vehicle to check.
194 * @param order_position The order index to check.
195 * @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
196 * @return True if and only if the order is a void order.
198 static bool IsVoidOrder(VehicleID vehicle_id
, OrderPosition order_position
);
201 * Checks whether the given order has a valid refit cargo.
202 * @param vehicle_id The vehicle to check.
203 * @param order_position The order index to check.
204 * @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
205 * @return True if and only if the order is has a valid refit cargo.
207 static bool IsRefitOrder(VehicleID vehicle_id
, OrderPosition order_position
);
210 * Checks whether the current order is part of the orderlist.
211 * @param vehicle_id The vehicle to check.
212 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
213 * @return True if and only if the current order is part of the order list.
214 * @note If the order is a non-'non-stop' order, and the vehicle is currently
215 * (un)loading at a station that is not the final destination, this function
216 * will still return true.
218 static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id
);
221 * Resolves the given order index to the correct index for the given vehicle.
222 * If the order index was ORDER_CURRENT it will be resolved to the index of
223 * the current order (as shown in the order list). If the order with the
224 * given index does not exist it will return ORDER_INVALID.
225 * @param vehicle_id The vehicle to check the order index for.
226 * @param order_position The order index to resolve.
227 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
228 * @return The resolved order index.
230 static OrderPosition
ResolveOrderPosition(VehicleID vehicle_id
, OrderPosition order_position
);
233 * Checks whether the given order flags are valid for the given destination.
234 * @param destination The destination of the order.
235 * @param order_flags The flags given to the order.
236 * @return True if and only if the order_flags are valid for the given location.
238 static bool AreOrderFlagsValid(TileIndex destination
, ScriptOrderFlags order_flags
);
241 * Checks whether the given combination of condition and compare function is valid.
242 * @param condition The condition to check.
243 * @param compare The compare function to check.
244 * @return True if and only if the combination of condition and compare function is valid.
246 static bool IsValidConditionalOrder(OrderCondition condition
, CompareFunction compare
);
249 * Returns the number of orders for the given vehicle.
250 * @param vehicle_id The vehicle to get the order count of.
251 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
252 * @return The number of orders for the given vehicle or a negative
253 * value when the vehicle does not exist.
255 static SQInteger
GetOrderCount(VehicleID vehicle_id
);
258 * Gets the destination of the given order for the given vehicle.
259 * @param vehicle_id The vehicle to get the destination for.
260 * @param order_position The order to get the destination for.
261 * @pre IsValidVehicleOrder(vehicle_id, order_position).
262 * @pre order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position).
263 * @note Giving ORDER_CURRENT as order_position will give the order that is
264 * currently being executed by the vehicle. This is not necessarily the
265 * current order as given by ResolveOrderPosition (the current index in the
266 * order list) as manual or autoservicing depot orders do not show up
267 * in the orderlist, but they can be the current order of a vehicle.
268 * @return The destination tile of the order.
270 static TileIndex
GetOrderDestination(VehicleID vehicle_id
, OrderPosition order_position
);
273 * Gets the ScriptOrderFlags of the given order for the given vehicle.
274 * @param vehicle_id The vehicle to get the destination for.
275 * @param order_position The order to get the destination for.
276 * @pre IsValidVehicleOrder(vehicle_id, order_position).
277 * @pre order_position == ORDER_CURRENT || (!IsConditionalOrder(vehicle_id, order_position) && !IsVoidOrder(vehicle_id, order_position)).
278 * @note Giving ORDER_CURRENT as order_position will give the order that is
279 * currently being executed by the vehicle. This is not necessarily the
280 * current order as given by ResolveOrderPosition (the current index in the
281 * order list) as manual or autoservicing depot orders do not show up
282 * in the orderlist, but they can be the current order of a vehicle.
283 * @return The ScriptOrderFlags of the order.
285 static ScriptOrderFlags
GetOrderFlags(VehicleID vehicle_id
, OrderPosition order_position
);
288 * Gets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle.
289 * @param vehicle_id The vehicle to get the OrderPosition for.
290 * @param order_position The order to get the OrderPosition for.
291 * @pre IsValidVehicleOrder(vehicle_id, order_position).
292 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
293 * @return The target of the conditional jump.
295 static OrderPosition
GetOrderJumpTo(VehicleID vehicle_id
, OrderPosition order_position
);
298 * Gets the OrderCondition of the given order for the given vehicle.
299 * @param vehicle_id The vehicle to get the condition type for.
300 * @param order_position The order to get the condition type for.
301 * @pre IsValidVehicleOrder(vehicle_id, order_position).
302 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
303 * @return The OrderCondition of the order.
305 static OrderCondition
GetOrderCondition(VehicleID vehicle_id
, OrderPosition order_position
);
308 * Gets the CompareFunction of the given order for the given vehicle.
309 * @param vehicle_id The vehicle to get the compare function for.
310 * @param order_position The order to get the compare function for.
311 * @pre IsValidVehicleOrder(vehicle_id, order_position).
312 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
313 * @return The CompareFunction of the order.
315 static CompareFunction
GetOrderCompareFunction(VehicleID vehicle_id
, OrderPosition order_position
);
318 * Gets the value to compare against of the given order for the given vehicle.
319 * @param vehicle_id The vehicle to get the value for.
320 * @param order_position The order to get the value for.
321 * @pre IsValidVehicleOrder(vehicle_id, order_position).
322 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
323 * @return The value to compare against of the order.
325 static SQInteger
GetOrderCompareValue(VehicleID vehicle_id
, OrderPosition order_position
);
328 * Gets the stoplocation of the given order for the given train.
329 * @param vehicle_id The vehicle to get the value for.
330 * @param order_position The order to get the value for.
331 * @pre IsValidVehicleOrder(vehicle_id, order_position).
332 * @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL.
333 * @pre IsGotoStationOrder(vehicle_id, order_position).
334 * @return The relative position where the train will stop inside a station.
336 static StopLocation
GetStopLocation(VehicleID vehicle_id
, OrderPosition order_position
);
339 * Gets the refit cargo type of the given order for the given vehicle.
340 * @param vehicle_id The vehicle to get the refit cargo for.
341 * @param order_position The order to get the refit cargo for.
342 * @pre IsValidVehicleOrder(vehicle_id, order_position).
343 * @pre order_position == ORDER_CURRENT || IsGotoStationOrder(vehicle_id, order_position) || IsGotoDepotOrder(vehicle_id, order_position).
344 * @note Giving ORDER_CURRENT as order_position will give the order that is
345 * currently being executed by the vehicle. This is not necessarily the
346 * current order as given by ResolveOrderPosition (the current index in the
347 * order list) as manual or autoservicing depot orders do not show up
348 * in the orderlist, but they can be the current order of a vehicle.
349 * @return The refit cargo of the order or CT_NO_REFIT if no refit is set.
351 static CargoID
GetOrderRefit(VehicleID vehicle_id
, OrderPosition order_position
);
354 * Sets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle.
355 * @param vehicle_id The vehicle to set the OrderPosition for.
356 * @param order_position The order to set the OrderPosition for.
357 * @param jump_to The order to jump to if the check succeeds.
358 * @pre IsValidVehicleOrder(vehicle_id, order_position).
359 * @pre IsValidVehicleOrder(vehicle_id, jump_to).
360 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
361 * @game @pre ScriptCompanyMode::IsValid().
362 * @return Whether the order has been/can be changed.
364 static bool SetOrderJumpTo(VehicleID vehicle_id
, OrderPosition order_position
, OrderPosition jump_to
);
367 * Sets the OrderCondition of the given order for the given vehicle.
368 * @param vehicle_id The vehicle to set the condition type for.
369 * @param order_position The order to set the condition type for.
370 * @param condition The condition to compare on.
371 * @pre IsValidVehicleOrder(vehicle_id, order_position).
372 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
373 * @pre condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY.
374 * @game @pre ScriptCompanyMode::IsValid().
375 * @return Whether the order has been/can be changed.
377 static bool SetOrderCondition(VehicleID vehicle_id
, OrderPosition order_position
, OrderCondition condition
);
380 * Sets the CompareFunction of the given order for the given vehicle.
381 * @param vehicle_id The vehicle to set the compare function for.
382 * @param order_position The order to set the compare function for.
383 * @param compare The new compare function of the order.
384 * @pre IsValidVehicleOrder(vehicle_id, order_position).
385 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
386 * @pre compare >= CF_EQUALS && compare <= CF_IS_FALSE.
387 * @game @pre ScriptCompanyMode::IsValid().
388 * @return Whether the order has been/can be changed.
390 static bool SetOrderCompareFunction(VehicleID vehicle_id
, OrderPosition order_position
, CompareFunction compare
);
393 * Sets the value to compare against of the given order for the given vehicle.
394 * @param vehicle_id The vehicle to set the value for.
395 * @param order_position The order to set the value for.
396 * @param value The value to compare against.
397 * @pre IsValidVehicleOrder(vehicle_id, order_position).
398 * @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
399 * @pre value >= 0 && value < 2048.
400 * @game @pre ScriptCompanyMode::IsValid().
401 * @return Whether the order has been/can be changed.
403 static bool SetOrderCompareValue(VehicleID vehicle_id
, OrderPosition order_position
, SQInteger value
);
406 * Sets the stoplocation of the given order for the given train.
407 * @param vehicle_id The vehicle to get the value for.
408 * @param order_position The order to get the value for.
409 * @param stop_location The relative position where a train will stop inside a station.
410 * @pre IsValidVehicleOrder(vehicle_id, order_position).
411 * @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL.
412 * @pre IsGotoStationOrder(vehicle_id, order_position).
413 * @pre stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR
414 * @game @pre ScriptCompanyMode::IsValid().
415 * @return Whether the order has been/can be changed.
417 static bool SetStopLocation(VehicleID vehicle_id
, OrderPosition order_position
, StopLocation stop_location
);
420 * Sets the refit cargo type of the given order for the given vehicle.
421 * @param vehicle_id The vehicle to set the refit cargo for.
422 * @param order_position The order to set the refit cargo for.
423 * @param refit_cargo The cargo to refit to. The refit can be cleared by passing CT_NO_REFIT.
424 * @pre IsValidVehicleOrder(vehicle_id, order_position).
425 * @pre IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT).
426 * @pre ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT
427 * @game @pre ScriptCompanyMode::IsValid().
428 * @return Whether the order has been/can be changed.
430 static bool SetOrderRefit(VehicleID vehicle_id
, OrderPosition order_position
, CargoID refit_cargo
);
433 * Appends an order to the end of the vehicle's order list.
434 * @param vehicle_id The vehicle to append the order to.
435 * @param destination The destination of the order.
436 * @param order_flags The flags given to the order.
437 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
438 * @pre AreOrderFlagsValid(destination, order_flags).
439 * @game @pre ScriptCompanyMode::IsValid().
440 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
441 * @exception ScriptOrder::ERR_ORDER_TOO_MANY
442 * @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
443 * @return True if and only if the order was appended.
445 static bool AppendOrder(VehicleID vehicle_id
, TileIndex destination
, ScriptOrderFlags order_flags
);
448 * Appends a conditional order to the end of the vehicle's order list.
449 * @param vehicle_id The vehicle to append the order to.
450 * @param jump_to The OrderPosition to jump to if the condition is true.
451 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
452 * @pre IsValidVehicleOrder(vehicle_id, jump_to).
453 * @game @pre ScriptCompanyMode::IsValid().
454 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
455 * @exception ScriptOrder::ERR_ORDER_TOO_MANY
456 * @return True if and only if the order was appended.
458 static bool AppendConditionalOrder(VehicleID vehicle_id
, OrderPosition jump_to
);
461 * Inserts an order before the given order_position into the vehicle's order list.
462 * @param vehicle_id The vehicle to add the order to.
463 * @param order_position The order to place the new order before.
464 * @param destination The destination of the order.
465 * @param order_flags The flags given to the order.
466 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id)
467 * @pre IsValidVehicleOrder(vehicle_id, order_position).
468 * @pre AreOrderFlagsValid(destination, order_flags).
469 * @game @pre ScriptCompanyMode::IsValid().
470 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
471 * @exception ScriptOrder::ERR_ORDER_TOO_MANY
472 * @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
473 * @return True if and only if the order was inserted.
475 static bool InsertOrder(VehicleID vehicle_id
, OrderPosition order_position
, TileIndex destination
, ScriptOrderFlags order_flags
);
478 * Appends a conditional order before the given order_position into the vehicle's order list.
479 * @param vehicle_id The vehicle to add the order to.
480 * @param order_position The order to place the new order before.
481 * @param jump_to The OrderPosition to jump to if the condition is true.
482 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
483 * @pre IsValidVehicleOrder(vehicle_id, order_position).
484 * @pre IsValidVehicleOrder(vehicle_id, jump_to).
485 * @game @pre ScriptCompanyMode::IsValid().
486 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
487 * @exception ScriptOrder::ERR_ORDER_TOO_MANY
488 * @return True if and only if the order was inserted.
490 static bool InsertConditionalOrder(VehicleID vehicle_id
, OrderPosition order_position
, OrderPosition jump_to
);
493 * Removes an order from the vehicle's order list.
494 * @param vehicle_id The vehicle to remove the order from.
495 * @param order_position The order to remove from the order list.
496 * @pre IsValidVehicleOrder(vehicle_id, order_position).
497 * @game @pre ScriptCompanyMode::IsValid().
498 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
499 * @return True if and only if the order was removed.
501 static bool RemoveOrder(VehicleID vehicle_id
, OrderPosition order_position
);
504 * Internal function to help SetOrderFlags.
507 static bool _SetOrderFlags();
510 * Changes the order flags of the given order.
511 * @param vehicle_id The vehicle to change the order of.
512 * @param order_position The order to change.
513 * @param order_flags The new flags given to the order.
514 * @pre IsValidVehicleOrder(vehicle_id, order_position).
515 * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
516 * @pre (order_flags & OF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & OF_GOTO_NEAREST_DEPOT).
517 * @game @pre ScriptCompanyMode::IsValid().
518 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
519 * @return True if and only if the order was changed.
521 static bool SetOrderFlags(VehicleID vehicle_id
, OrderPosition order_position
, ScriptOrderFlags order_flags
);
524 * Move an order inside the orderlist
525 * @param vehicle_id The vehicle to move the orders.
526 * @param order_position_move The order to move.
527 * @param order_position_target The target order
528 * @pre IsValidVehicleOrder(vehicle_id, order_position_move).
529 * @pre IsValidVehicleOrder(vehicle_id, order_position_target).
530 * @pre order_position_move != order_position_target.
531 * @game @pre ScriptCompanyMode::IsValid().
532 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
533 * @return True if and only if the order was moved.
534 * @note If the order is moved to a lower place (e.g. from 7 to 2)
535 * the target order is moved upwards (e.g. 3). If the order is moved
536 * to a higher place (e.g. from 7 to 9) the target will be moved
537 * downwards (e.g. 8).
539 static bool MoveOrder(VehicleID vehicle_id
, OrderPosition order_position_move
, OrderPosition order_position_target
);
542 * Make a vehicle execute next_order instead of its current order.
543 * @param vehicle_id The vehicle that should skip some orders.
544 * @param next_order The order the vehicle should skip to.
545 * @pre IsValidVehicleOrder(vehicle_id, next_order).
546 * @game @pre ScriptCompanyMode::IsValid().
547 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
548 * @return True if and only the current order was changed.
550 static bool SkipToOrder(VehicleID vehicle_id
, OrderPosition next_order
);
553 * Copies the orders from another vehicle. The orders of the main vehicle
554 * are going to be the orders of the changed vehicle.
555 * @param vehicle_id The vehicle to copy the orders to.
556 * @param main_vehicle_id The vehicle to copy the orders from.
557 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
558 * @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
559 * @game @pre ScriptCompanyMode::IsValid().
560 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
561 * @exception ScriptOrder::ERR_ORDER_TOO_MANY
562 * @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
563 * @return True if and only if the copying succeeded.
565 static bool CopyOrders(VehicleID vehicle_id
, VehicleID main_vehicle_id
);
568 * Shares the orders between two vehicles. The orders of the main
569 * vehicle are going to be the orders of the changed vehicle.
570 * @param vehicle_id The vehicle to add to the shared order list.
571 * @param main_vehicle_id The vehicle to share the orders with.
572 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
573 * @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
574 * @game @pre ScriptCompanyMode::IsValid().
575 * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
576 * @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
577 * @return True if and only if the sharing succeeded.
579 static bool ShareOrders(VehicleID vehicle_id
, VehicleID main_vehicle_id
);
582 * Removes the given vehicle from a shared orders list.
583 * After unsharing orders, the orders list of the vehicle is empty.
584 * @param vehicle_id The vehicle to remove from the shared order list.
585 * @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
586 * @game @pre ScriptCompanyMode::IsValid().
587 * @return True if and only if the unsharing succeeded.
589 static bool UnshareOrders(VehicleID vehicle_id
);
592 * Get the distance between two points for a vehicle type.
593 * Use this function to compute the distance between two tiles wrt. a vehicle type.
594 * These vehicle-type specific distances are independent from other map distances, you may
595 * use the result of this function to compare it with the result of
596 * ScriptEngine::GetMaximumOrderDistance or ScriptVehicle::GetMaximumOrderDistance.
597 * @param vehicle_type The vehicle type to get the distance for.
598 * @param origin_tile Origin, can be any tile or a tile of a specific station.
599 * @param dest_tile Destination, can be any tile or a tile of a specific station.
600 * @return The distance between the origin and the destination for a
601 * vehicle of the given vehicle type.
602 * @note The unit of the order distances is unspecified and should
603 * not be compared with map distances
604 * @see ScriptEngine::GetMaximumOrderDistance and ScriptVehicle::GetMaximumOrderDistance
606 static SQInteger
GetOrderDistance(ScriptVehicle::VehicleType vehicle_type
, TileIndex origin_tile
, TileIndex dest_tile
);
608 DECLARE_ENUM_AS_BIT_SET(ScriptOrder::ScriptOrderFlags
)
610 #endif /* SCRIPT_ORDER_HPP */