2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-29 23:07:38 +00:00
|
|
|
/** @file script_order.hpp Everything to query and build orders. */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-29 23:07:38 +00:00
|
|
|
#ifndef SCRIPT_ORDER_HPP
|
|
|
|
#define SCRIPT_ORDER_HPP
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "script_error.hpp"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class that handles all order related functions.
|
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
class ScriptOrder : public ScriptObject {
|
2009-01-12 17:11:45 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* All order related error messages.
|
|
|
|
*/
|
|
|
|
enum ErrorMessages {
|
|
|
|
/** Base for all order related errors */
|
2011-11-29 23:15:35 +00:00
|
|
|
ERR_ORDER_BASE = ScriptError::ERR_CAT_ORDER << ScriptError::ERR_CAT_BIT_SIZE,
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/** No more space for orders */
|
2009-04-21 23:40:56 +00:00
|
|
|
ERR_ORDER_TOO_MANY, // [STR_ERROR_NO_MORE_SPACE_FOR_ORDERS]
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/** Destination of new order is to far away from the previous order */
|
2009-04-21 23:40:56 +00:00
|
|
|
ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION, // [STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION]
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flags that can be used to modify the behaviour of orders.
|
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
enum ScriptOrderFlags {
|
2009-01-12 17:11:45 +00:00
|
|
|
/** Just go to the station/depot, stop unload if possible and load if needed. */
|
|
|
|
AIOF_NONE = 0,
|
|
|
|
|
|
|
|
/** Do not stop at the stations that are passed when going to the destination. Only for trains and road vehicles. */
|
|
|
|
AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
|
|
|
|
/** Do not stop at the destionation station. Only for trains and road vehicles. */
|
|
|
|
AIOF_NON_STOP_DESTINATION = 1 << 1,
|
|
|
|
|
|
|
|
/** Always unload the vehicle; only for stations. Cannot be set when AIOF_TRANSFER or AIOF_NO_UNLOAD is set. */
|
|
|
|
AIOF_UNLOAD = 1 << 2,
|
|
|
|
/** Transfer instead of deliver the goods; only for stations. Cannot be set when AIOF_UNLOAD or AIOF_NO_UNLOAD is set. */
|
|
|
|
AIOF_TRANSFER = 1 << 3,
|
|
|
|
/** Never unload the vehicle; only for stations. Cannot be set when AIOF_UNLOAD, AIOF_TRANSFER or AIOF_NO_LOAD is set. */
|
|
|
|
AIOF_NO_UNLOAD = 1 << 4,
|
|
|
|
|
|
|
|
/** Wait till the vehicle is fully loaded; only for stations. Cannot be set when AIOF_NO_LOAD is set. */
|
|
|
|
AIOF_FULL_LOAD = 2 << 5,
|
|
|
|
/** Wait till at least one cargo of the vehicle is fully loaded; only for stations. Cannot be set when AIOF_NO_LOAD is set. */
|
|
|
|
AIOF_FULL_LOAD_ANY = 3 << 5,
|
|
|
|
/** Do not load any cargo; only for stations. Cannot be set when AIOF_NO_UNLOAD, AIOF_FULL_LOAD or AIOF_FULL_LOAD_ANY is set. */
|
|
|
|
AIOF_NO_LOAD = 1 << 7,
|
|
|
|
|
|
|
|
/** Service the vehicle when needed, otherwise skip this order; only for depots. */
|
|
|
|
AIOF_SERVICE_IF_NEEDED = 1 << 2,
|
2009-04-20 23:49:27 +00:00
|
|
|
/** Stop in the depot instead of only go there for servicing; only for depots. */
|
|
|
|
AIOF_STOP_IN_DEPOT = 1 << 3,
|
2009-12-16 21:31:21 +00:00
|
|
|
/** Go to nearest depot. */
|
2009-12-28 12:12:57 +00:00
|
|
|
AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/** All flags related to non-stop settings. */
|
|
|
|
AIOF_NON_STOP_FLAGS = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
|
|
|
|
/** All flags related to unloading. */
|
|
|
|
AIOF_UNLOAD_FLAGS = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
|
|
|
|
/** All flags related to loading. */
|
|
|
|
AIOF_LOAD_FLAGS = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
|
2009-04-20 23:49:27 +00:00
|
|
|
/** All flags related to depots. */
|
2009-12-16 21:31:21 +00:00
|
|
|
AIOF_DEPOT_FLAGS = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/** For marking invalid order flags */
|
|
|
|
AIOF_INVALID = 0xFFFF,
|
|
|
|
};
|
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* All conditions a conditional order can depend on.
|
|
|
|
*/
|
|
|
|
enum OrderCondition {
|
|
|
|
/* Order _is_ important, as it's based on OrderConditionVariable in order_type.h. */
|
2011-08-31 22:41:10 +00:00
|
|
|
OC_LOAD_PERCENTAGE, ///< Skip based on the amount of load, value is in tons.
|
|
|
|
OC_RELIABILITY, ///< Skip based on the reliability, value is percent (0..100).
|
2011-11-29 23:15:35 +00:00
|
|
|
OC_MAX_SPEED, ///< Skip based on the maximum speed, value is in OpenTTD's internal speed unit, see ScriptEngine::GetMaxSpeed.
|
2011-08-31 22:41:10 +00:00
|
|
|
OC_AGE, ///< Skip based on the age, value is in years.
|
|
|
|
OC_REQUIRES_SERVICE, ///< Skip when the vehicle requires service, no value.
|
|
|
|
OC_UNCONDITIONALLY, ///< Always skip, no compare function, no value.
|
|
|
|
OC_REMAINING_LIFETIME, ///< Skip based on the remaining lifetime
|
|
|
|
OC_INVALID = -1, ///< An invalid condition, do not use.
|
2009-02-19 23:12:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comparators for conditional orders.
|
|
|
|
*/
|
|
|
|
enum CompareFunction {
|
|
|
|
/* Order _is_ important, as it's based on OrderConditionComparator in order_type.h. */
|
2010-08-01 19:36:36 +00:00
|
|
|
CF_EQUALS, ///< Skip if both values are equal
|
|
|
|
CF_NOT_EQUALS, ///< Skip if both values are not equal
|
|
|
|
CF_LESS_THAN, ///< Skip if the value is less than the limit
|
|
|
|
CF_LESS_EQUALS, ///< Skip if the value is less or equal to the limit
|
|
|
|
CF_MORE_THAN, ///< Skip if the value is more than the limit
|
|
|
|
CF_MORE_EQUALS, ///< Skip if the value is more or equal to the limit
|
|
|
|
CF_IS_TRUE, ///< Skip if the variable is true
|
|
|
|
CF_IS_FALSE, ///< Skip if the variable is false
|
|
|
|
CF_INVALID = -1, ///< Invalid compare function, do not use.
|
2009-02-19 23:12:57 +00:00
|
|
|
};
|
|
|
|
|
2011-01-23 13:08:50 +00:00
|
|
|
/**
|
|
|
|
* Index in the list of orders for a vehicle. The first order has index 0, the second
|
|
|
|
* order index 1, etc. The current order can be queried by using ORDER_CURRENT. Do not
|
|
|
|
* use ORDER_INVALID yourself, it's used as return value by for example ResolveOrderPosition.
|
|
|
|
* @note Automatic orders are hidden from AIs, so OrderPosition 0 will always be the first
|
|
|
|
* manual order.
|
|
|
|
*/
|
2009-01-12 17:11:45 +00:00
|
|
|
enum OrderPosition {
|
2010-08-01 19:36:36 +00:00
|
|
|
ORDER_CURRENT = 0xFF, ///< Constant that gets resolved to the current order.
|
|
|
|
ORDER_INVALID = -1, ///< An invalid order.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2010-05-09 18:13:36 +00:00
|
|
|
/** Where to stop trains in a station that's longer than the train */
|
2010-02-04 23:18:19 +00:00
|
|
|
enum StopLocation {
|
2010-08-01 19:36:36 +00:00
|
|
|
STOPLOCATION_NEAR, ///< Stop the train as soon as it's completely in the station
|
|
|
|
STOPLOCATION_MIDDLE, ///< Stop the train in the middle of the station
|
|
|
|
STOPLOCATION_FAR, ///< Stop the train at the far end of the station
|
|
|
|
STOPLOCATION_INVALID = -1, ///< An invalid stop location
|
2010-02-04 23:18:19 +00:00
|
|
|
};
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given order id is valid for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to check the order index for.
|
|
|
|
* @param order_position The order index to check.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the order_position is valid for the given vehicle.
|
|
|
|
*/
|
|
|
|
static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2009-04-26 16:14:53 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given order is a goto-station order.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
|
|
|
* @param order_position The order index to check.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @return True if and only if the order is a goto-station order.
|
|
|
|
*/
|
|
|
|
static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given order is a goto-depot order.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
|
|
|
* @param order_position The order index to check.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @return True if and only if the order is a goto-depot order.
|
|
|
|
*/
|
|
|
|
static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given order is a goto-waypoint order.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
|
|
|
* @param order_position The order index to check.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @return True if and only if the order is a goto-waypoint order.
|
|
|
|
*/
|
|
|
|
static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given order is a conditional order.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
|
|
|
* @param order_position The order index to check.
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @return True if and only if the order is a conditional order.
|
|
|
|
*/
|
|
|
|
static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2010-08-06 19:04:21 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given order is a void order.
|
|
|
|
* A void order is an order that used to be a goto station, depot or waypoint order but
|
|
|
|
* its destination got removed. In OpenTTD these orders as shown as "(Invalid Order)"
|
|
|
|
* in the order list of a vehicle.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
|
|
|
* @param order_position The order index to check.
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @return True if and only if the order is a void order.
|
|
|
|
*/
|
|
|
|
static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2011-11-05 15:31:21 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given order has a valid refit cargo.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
|
|
|
* @param order_position The order index to check.
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @return True if and only if the order is has a valid refit cargo.
|
|
|
|
*/
|
|
|
|
static bool IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2009-04-26 16:14:53 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the current order is part of the orderlist.
|
|
|
|
* @param vehicle_id The vehicle to check.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-04-26 16:14:53 +00:00
|
|
|
* @return True if and only if the current order is part of the order list.
|
|
|
|
* @note If the order is a non-'non-stop' order, and the vehicle is currently
|
|
|
|
* (un)loading at a station that is not the final destination, this function
|
|
|
|
* will still return true.
|
|
|
|
*/
|
|
|
|
static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Resolves the given order index to the correct index for the given vehicle.
|
2009-02-19 09:01:34 +00:00
|
|
|
* If the order index was ORDER_CURRENT it will be resolved to the index of
|
2009-01-12 17:11:45 +00:00
|
|
|
* the current order (as shown in the order list). If the order with the
|
2009-01-16 00:05:26 +00:00
|
|
|
* given index does not exist it will return ORDER_INVALID.
|
2009-01-12 17:11:45 +00:00
|
|
|
* @param vehicle_id The vehicle to check the order index for.
|
|
|
|
* @param order_position The order index to resolve.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return The resolved order index.
|
|
|
|
*/
|
|
|
|
static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given order flags are valid for the given destination.
|
|
|
|
* @param destination The destination of the order.
|
|
|
|
* @param order_flags The flags given to the order.
|
|
|
|
* @return True if and only if the order_flags are valid for the given location.
|
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
static bool AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* Checks whether the given combination of condition and compare function is valid.
|
|
|
|
* @param condition The condition to check.
|
|
|
|
* @param compare The compare function to check.
|
|
|
|
* @return True if and only if the combination of condition and compare function is valid.
|
|
|
|
*/
|
|
|
|
static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of orders for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the order count of.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return The number of orders for the given vehicle or a negative
|
|
|
|
* value when the vehicle does not exist.
|
|
|
|
*/
|
|
|
|
static int32 GetOrderCount(VehicleID vehicle_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the destination of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the destination for.
|
|
|
|
* @param order_position The order to get the destination for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
2009-02-19 23:12:57 +00:00
|
|
|
* @pre order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position).
|
2009-02-19 09:01:34 +00:00
|
|
|
* @note Giving ORDER_CURRENT as order_position will give the order that is
|
2009-01-12 17:11:45 +00:00
|
|
|
* currently being executed by the vehicle. This is not necessarily the
|
|
|
|
* current order as given by ResolveOrderPosition (the current index in the
|
|
|
|
* order list) as manual or autoservicing depot orders do not show up
|
|
|
|
* in the orderlist, but they can be the current order of a vehicle.
|
|
|
|
* @return The destination tile of the order.
|
|
|
|
*/
|
|
|
|
static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
2011-11-29 23:15:35 +00:00
|
|
|
* Gets the ScriptOrderFlags of the given order for the given vehicle.
|
2009-01-12 17:11:45 +00:00
|
|
|
* @param vehicle_id The vehicle to get the destination for.
|
|
|
|
* @param order_position The order to get the destination for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
2010-08-06 19:04:21 +00:00
|
|
|
* @pre order_position == ORDER_CURRENT || (!IsConditionalOrder(vehicle_id, order_position) && !IsVoidOrder(vehicle_id, order_position)).
|
2009-02-19 09:01:34 +00:00
|
|
|
* @note Giving ORDER_CURRENT as order_position will give the order that is
|
2009-01-12 17:11:45 +00:00
|
|
|
* currently being executed by the vehicle. This is not necessarily the
|
|
|
|
* current order as given by ResolveOrderPosition (the current index in the
|
|
|
|
* order list) as manual or autoservicing depot orders do not show up
|
|
|
|
* in the orderlist, but they can be the current order of a vehicle.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @return The ScriptOrderFlags of the order.
|
2009-01-12 17:11:45 +00:00
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
static ScriptOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* Gets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the OrderPosition for.
|
|
|
|
* @param order_position The order to get the OrderPosition for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
|
|
|
* @return The target of the conditional jump.
|
|
|
|
*/
|
|
|
|
static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the OrderCondition of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the condition type for.
|
|
|
|
* @param order_position The order to get the condition type for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
|
|
|
* @return The OrderCondition of the order.
|
|
|
|
*/
|
|
|
|
static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the CompareFunction of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the compare function for.
|
|
|
|
* @param order_position The order to get the compare function for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
|
|
|
* @return The CompareFunction of the order.
|
|
|
|
*/
|
|
|
|
static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value to compare against of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the value for.
|
|
|
|
* @param order_position The order to get the value for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
|
|
|
* @return The value to compare against of the order.
|
|
|
|
*/
|
|
|
|
static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2010-02-04 23:18:19 +00:00
|
|
|
/**
|
|
|
|
* Gets the stoplocation of the given order for the given train.
|
|
|
|
* @param vehicle_id The vehicle to get the value for.
|
|
|
|
* @param order_position The order to get the value for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL.
|
2010-02-04 23:18:19 +00:00
|
|
|
* @pre IsGotoStationOrder(vehicle_id, order_position).
|
|
|
|
* @return The relative position where the train will stop inside a station.
|
|
|
|
*/
|
|
|
|
static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2011-11-05 15:31:21 +00:00
|
|
|
/**
|
|
|
|
* Gets the refit cargo type of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to get the refit cargo for.
|
|
|
|
* @param order_position The order to get the refit cargo for.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position == ORDER_CURRENT || IsGotoStationOrder(vehicle_id, order_position) || IsGotoDepotOrder(vehicle_id, order_position).
|
|
|
|
* @note Giving ORDER_CURRENT as order_position will give the order that is
|
|
|
|
* currently being executed by the vehicle. This is not necessarily the
|
|
|
|
* current order as given by ResolveOrderPosition (the current index in the
|
|
|
|
* order list) as manual or autoservicing depot orders do not show up
|
|
|
|
* in the orderlist, but they can be the current order of a vehicle.
|
|
|
|
* @return The refit cargo of the order or CT_NO_REFIT if no refit is set.
|
|
|
|
*/
|
|
|
|
static CargoID GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* Sets the OrderPosition to jump to if the check succeeds of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to set the OrderPosition for.
|
|
|
|
* @param order_position The order to set the OrderPosition for.
|
|
|
|
* @param jump_to The order to jump to if the check succeeds.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
|
|
|
* @return Whether the order has been/can be changed.
|
|
|
|
*/
|
|
|
|
static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the OrderCondition of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to set the condition type for.
|
|
|
|
* @param order_position The order to set the condition type for.
|
2009-06-03 18:47:08 +00:00
|
|
|
* @param condition The condition to compare on.
|
2009-02-19 23:12:57 +00:00
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
2009-06-03 18:47:08 +00:00
|
|
|
* @pre condition >= OC_LOAD_PERCENTAGE && condition <= OC_UNCONDITIONALLY.
|
2009-02-19 23:12:57 +00:00
|
|
|
* @return Whether the order has been/can be changed.
|
|
|
|
*/
|
|
|
|
static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the CompareFunction of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to set the compare function for.
|
|
|
|
* @param order_position The order to set the compare function for.
|
2009-06-03 18:47:08 +00:00
|
|
|
* @param compare The new compare function of the order.
|
2009-02-19 23:12:57 +00:00
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
2009-06-03 18:47:08 +00:00
|
|
|
* @pre compare >= CF_EQUALS && compare <= CF_IS_FALSE.
|
2009-02-19 23:12:57 +00:00
|
|
|
* @return Whether the order has been/can be changed.
|
|
|
|
*/
|
|
|
|
static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value to compare against of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to set the value for.
|
|
|
|
* @param order_position The order to set the value for.
|
2009-06-03 18:47:08 +00:00
|
|
|
* @param value The value to compare against.
|
2009-02-19 23:12:57 +00:00
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position).
|
|
|
|
* @pre value >= 0 && value < 2048.
|
|
|
|
* @return Whether the order has been/can be changed.
|
|
|
|
*/
|
|
|
|
static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
|
|
|
|
|
2010-02-04 23:18:19 +00:00
|
|
|
/**
|
|
|
|
* Sets the stoplocation of the given order for the given train.
|
|
|
|
* @param vehicle_id The vehicle to get the value for.
|
|
|
|
* @param order_position The order to get the value for.
|
2010-02-05 16:11:23 +00:00
|
|
|
* @param stop_location The relative position where a train will stop inside a station.
|
2010-02-04 23:18:19 +00:00
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::GetVehicleType(vehicle_id) == ScriptVehicle::VT_RAIL.
|
2010-02-04 23:18:19 +00:00
|
|
|
* @pre IsGotoStationOrder(vehicle_id, order_position).
|
2010-02-05 16:11:23 +00:00
|
|
|
* @pre stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR
|
2010-02-04 23:18:19 +00:00
|
|
|
* @return Whether the order has been/can be changed.
|
|
|
|
*/
|
|
|
|
static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
|
|
|
|
|
2011-11-05 15:31:21 +00:00
|
|
|
/**
|
|
|
|
* Sets the refit cargo type of the given order for the given vehicle.
|
|
|
|
* @param vehicle_id The vehicle to set the refit cargo for.
|
|
|
|
* @param order_position The order to set the refit cargo for.
|
|
|
|
* @param refit_cargo The cargo to refit to. The refit can be cleared by passing CT_NO_REFIT.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT
|
2011-11-05 15:31:21 +00:00
|
|
|
* @return Whether the order has been/can be changed.
|
|
|
|
*/
|
|
|
|
static bool SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Appends an order to the end of the vehicle's order list.
|
|
|
|
* @param vehicle_id The vehicle to append the order to.
|
|
|
|
* @param destination The destination of the order.
|
|
|
|
* @param order_flags The flags given to the order.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-01-12 17:11:45 +00:00
|
|
|
* @pre AreOrderFlagsValid(destination, order_flags).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the order was appended.
|
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* Appends a conditional order to the end of the vehicle's order list.
|
|
|
|
* @param vehicle_id The vehicle to append the order to.
|
|
|
|
* @param jump_to The OrderPosition to jump to if the condition is true.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-02-19 23:12:57 +00:00
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
2009-02-19 23:12:57 +00:00
|
|
|
* @return True if and only if the order was appended.
|
|
|
|
*/
|
|
|
|
static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Inserts an order before the given order_position into the vehicle's order list.
|
|
|
|
* @param vehicle_id The vehicle to add the order to.
|
|
|
|
* @param order_position The order to place the new order before.
|
|
|
|
* @param destination The destination of the order.
|
|
|
|
* @param order_flags The flags given to the order.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre AreOrderFlagsValid(destination, order_flags).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the order was inserted.
|
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrderFlags order_flags);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-02-19 23:12:57 +00:00
|
|
|
/**
|
|
|
|
* Appends a conditional order before the given order_position into the vehicle's order list.
|
|
|
|
* @param vehicle_id The vehicle to add the order to.
|
|
|
|
* @param order_position The order to place the new order before.
|
|
|
|
* @param jump_to The OrderPosition to jump to if the condition is true.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
2009-02-19 23:12:57 +00:00
|
|
|
* @return True if and only if the order was inserted.
|
|
|
|
*/
|
|
|
|
static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Removes an order from the vehicle's order list.
|
|
|
|
* @param vehicle_id The vehicle to remove the order from.
|
|
|
|
* @param order_position The order to remove from the order list.
|
2009-03-12 11:43:40 +00:00
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the order was removed.
|
|
|
|
*/
|
|
|
|
static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
|
|
|
|
|
2011-11-12 18:48:21 +00:00
|
|
|
#ifndef DOXYGEN_AI_DOCS
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
2009-03-04 23:12:48 +00:00
|
|
|
* Internal function to help SetOrderFlags.
|
2009-01-12 17:11:45 +00:00
|
|
|
*/
|
2009-03-04 23:12:48 +00:00
|
|
|
static bool _SetOrderFlags();
|
2011-11-12 18:48:21 +00:00
|
|
|
#endif /* DOXYGEN_AI_DOCS */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the order flags of the given order.
|
|
|
|
* @param vehicle_id The vehicle to change the order of.
|
|
|
|
* @param order_position The order to change.
|
|
|
|
* @param order_flags The new flags given to the order.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
|
|
|
* @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
|
2011-02-06 12:15:17 +00:00
|
|
|
* @pre (order_flags & AIOF_GOTO_NEAREST_DEPOT) == (GetOrderFlags(vehicle_id, order_position) & AIOF_GOTO_NEAREST_DEPOT).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the order was changed.
|
|
|
|
*/
|
2011-11-29 23:15:35 +00:00
|
|
|
static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, ScriptOrderFlags order_flags);
|
2009-03-04 23:12:48 +00:00
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Move an order inside the orderlist
|
|
|
|
* @param vehicle_id The vehicle to move the orders.
|
|
|
|
* @param order_position_move The order to move.
|
|
|
|
* @param order_position_target The target order
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position_move).
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, order_position_target).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the order was moved.
|
|
|
|
* @note If the order is moved to a lower place (e.g. from 7 to 2)
|
|
|
|
* the target order is moved upwards (e.g. 3). If the order is moved
|
|
|
|
* to a higher place (e.g. from 7 to 9) the target will be moved
|
|
|
|
* downwards (e.g. 8).
|
|
|
|
*/
|
|
|
|
static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
|
|
|
|
|
2009-03-12 11:43:40 +00:00
|
|
|
/**
|
|
|
|
* Make a vehicle execute next_order instead of its current order.
|
|
|
|
* @param vehicle_id The vehicle that should skip some orders.
|
|
|
|
* @param next_order The order the vehicle should skip to.
|
|
|
|
* @pre IsValidVehicleOrder(vehicle_id, next_order).
|
2011-11-29 23:15:35 +00:00
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
2009-03-12 11:43:40 +00:00
|
|
|
* @return True if and only the current order was changed.
|
|
|
|
*/
|
|
|
|
static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Copies the orders from another vehicle. The orders of the main vehicle
|
|
|
|
* are going to be the orders of the changed vehicle.
|
|
|
|
* @param vehicle_id The vehicle to copy the orders to.
|
|
|
|
* @param main_vehicle_id The vehicle to copy the orders from.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
|
|
|
* @pre ScriptVehicle::IsValidVehicle(main_vehicle_id).
|
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
|
|
|
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the copying succeeded.
|
|
|
|
*/
|
|
|
|
static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shares the orders between two vehicles. The orders of the main
|
|
|
|
* vehicle are going to be the orders of the changed vehicle.
|
|
|
|
* @param vehicle_id The vehicle to add to the shared order list.
|
|
|
|
* @param main_vehicle_id The vehicle to share the orders with.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
|
|
|
* @pre ScriptVehicle::IsValidVehicle(main_vehicle_id).
|
|
|
|
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the sharing succeeded.
|
|
|
|
*/
|
|
|
|
static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the given vehicle from a shared orders list.
|
|
|
|
* @param vehicle_id The vehicle to remove from the shared order list.
|
2011-11-29 23:15:35 +00:00
|
|
|
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
2009-01-12 17:11:45 +00:00
|
|
|
* @return True if and only if the unsharing succeeded.
|
|
|
|
*/
|
|
|
|
static bool UnshareOrders(VehicleID vehicle_id);
|
|
|
|
};
|
2011-11-29 23:15:35 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(ScriptOrder::ScriptOrderFlags)
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-29 23:07:38 +00:00
|
|
|
#endif /* SCRIPT_ORDER_HPP */
|