1 /* $Id: order_type.h 25735 2013-08-20 20:05:31Z fonsinchen $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file order_type.h Types related to orders. */
15 #include "core/enum_type.hpp"
17 typedef byte VehicleOrderID
; ///< The index of an order within its current vehicle (not pool related)
18 typedef uint16 OrderID
;
19 typedef uint16 OrderListID
;
20 typedef uint16 DestinationID
;
22 /** Invalid vehicle order index (sentinel) */
23 static const VehicleOrderID INVALID_VEH_ORDER_ID
= 0xFF;
24 /** Last valid VehicleOrderID. */
25 static const VehicleOrderID MAX_VEH_ORDER_ID
= INVALID_VEH_ORDER_ID
- 1;
27 /** Invalid order (sentinel) */
28 static const OrderID INVALID_ORDER
= 0xFFFF;
31 * Maximum number of orders in implicit-only lists before we start searching
32 * harder for duplicates.
34 static const uint IMPLICIT_ORDER_ONLY_CAP
= 32;
52 /** It needs to be 8bits, because we save and load it as such */
53 typedef SimpleTinyEnumT
<OrderType
, byte
> OrderTypeByte
;
57 * Flags related to the unloading order.
59 enum OrderUnloadFlags
{
60 OUF_UNLOAD_IF_POSSIBLE
= 0, ///< Unload all cargo that the station accepts.
61 OUFB_UNLOAD
= 1 << 0, ///< Force unloading all cargo onto the platform, possibly not getting paid.
62 OUFB_TRANSFER
= 1 << 1, ///< Transfer all cargo onto the platform.
63 OUFB_NO_UNLOAD
= 1 << 2, ///< Totally no unloading will be done.
64 OUFB_CARGO_TYPE_UNLOAD
= 1 << 3, ///< Unload actions are defined per cargo type.
65 OUFB_CARGO_TYPE_UNLOAD_ENCODING
= (1 << 0) | (1 << 2), ///< Raw encoding of OUFB_CARGO_TYPE_UNLOAD
69 * Flags related to the loading order.
72 OLF_LOAD_IF_POSSIBLE
= 0, ///< Load as long as there is cargo that fits in the train.
73 OLFB_FULL_LOAD
= 1 << 1, ///< Full load all cargoes of the consist.
74 OLF_FULL_LOAD_ANY
= 3, ///< Full load a single cargo of the consist.
75 OLFB_NO_LOAD
= 4, ///< Do not load anything.
76 OLFB_CARGO_TYPE_LOAD
= 1 << 3, ///< Load actions are defined per cargo type.
77 OLFB_CARGO_TYPE_LOAD_ENCODING
= (1 << 1) | 4, ///< Raw encoding of OLFB_CARGO_TYPE_LOAD
81 * Non-stop order flags.
83 enum OrderNonStopFlags
{
84 ONSF_STOP_EVERYWHERE
= 0, ///< The vehicle will stop at any station it passes and the destination.
85 ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
= 1, ///< The vehicle will not stop at any stations it passes except the destination.
86 ONSF_NO_STOP_AT_DESTINATION_STATION
= 2, ///< The vehicle will stop at any station it passes except the destination.
87 ONSF_NO_STOP_AT_ANY_STATION
= 3, ///< The vehicle will not stop at any stations it passes including the destination.
92 * Where to stop the trains.
94 enum OrderStopLocation
{
95 OSL_PLATFORM_NEAR_END
= 0, ///< Stop at the near end of the platform
96 OSL_PLATFORM_MIDDLE
= 1, ///< Stop at the middle of the platform
97 OSL_PLATFORM_FAR_END
= 2, ///< Stop at the far end of the platform
102 * Reasons that could cause us to go to the depot.
104 enum OrderDepotTypeFlags
{
105 ODTF_MANUAL
= 0, ///< Manually initiated order.
106 ODTFB_SERVICE
= 1 << 0, ///< This depot order is because of the servicing limit.
107 ODTFB_PART_OF_ORDERS
= 1 << 1, ///< This depot order is because of a regular order.
111 * Actions that can be performed when the vehicle enters the depot.
113 enum OrderDepotActionFlags
{
114 ODATF_SERVICE_ONLY
= 0, ///< Only service the vehicle.
115 ODATFB_HALT
= 1 << 0, ///< Service the vehicle and then halt it.
116 ODATFB_NEAREST_DEPOT
= 1 << 1, ///< Send the vehicle to the nearest depot.
118 DECLARE_ENUM_AS_BIT_SET(OrderDepotActionFlags
)
121 * Flags for go to waypoint orders
123 enum OrderWaypointFlags
{
124 OWF_DEFAULT
= 0, ///< Default waypoint behavior
125 OWF_REVERSE
= 1 << 0, ///< Reverse train at the waypoint
127 DECLARE_ENUM_AS_BIT_SET(OrderWaypointFlags
)
131 * Variables (of a vehicle) to 'cause' skipping on.
133 enum OrderConditionVariable
{
134 OCV_LOAD_PERCENTAGE
, ///< Skip based on the amount of load
135 OCV_RELIABILITY
, ///< Skip based on the reliability
136 OCV_MAX_SPEED
, ///< Skip based on the maximum speed
137 OCV_AGE
, ///< Skip based on the age
138 OCV_REQUIRES_SERVICE
, ///< Skip when the vehicle requires service
139 OCV_UNCONDITIONALLY
, ///< Always skip
140 OCV_REMAINING_LIFETIME
, ///< Skip based on the remaining lifetime
141 OCV_CARGO_WAITING
, ///< Skip if specified cargo is waiting at next station
142 OCV_CARGO_ACCEPTANCE
, ///< Skip if specified cargo is accepted at next station
143 OCV_FREE_PLATFORMS
, ///< Skip based on free platforms at next station
144 OCV_SLOT_OCCUPANCY
, ///< Test if train slot is fully occupied
145 OCV_PERCENT
, ///< Skip xx percent of times
150 * Comparator for the skip reasoning.
152 enum OrderConditionComparator
{
153 OCC_EQUALS
, ///< Skip if both values are equal
154 OCC_NOT_EQUALS
, ///< Skip if both values are not equal
155 OCC_LESS_THAN
, ///< Skip if the value is less than the limit
156 OCC_LESS_EQUALS
, ///< Skip if the value is less or equal to the limit
157 OCC_MORE_THAN
, ///< Skip if the value is more than the limit
158 OCC_MORE_EQUALS
, ///< Skip if the value is more or equal to the limit
159 OCC_IS_TRUE
, ///< Skip if the variable is true
160 OCC_IS_FALSE
, ///< Skip if the variable is false
166 * Enumeration for the data to set in #CmdModifyOrder.
168 enum ModifyOrderFlags
{
169 MOF_NON_STOP
, ///< Passes an OrderNonStopFlags.
170 MOF_STOP_LOCATION
, ///< Passes an OrderStopLocation.
171 MOF_UNLOAD
, ///< Passes an OrderUnloadType.
172 MOF_LOAD
, ///< Passes an OrderLoadType
173 MOF_DEPOT_ACTION
, ///< Selects the OrderDepotAction
174 MOF_COND_VARIABLE
, ///< A conditional variable changes.
175 MOF_COND_COMPARATOR
, ///< A comparator changes.
176 MOF_COND_VALUE
, ///< The value to set the condition to.
177 MOF_COND_DESTINATION
, ///< Change the destination of a conditional order.
178 MOF_WAYPOINT_FLAGS
, ///< Change the waypoint flags
179 MOF_CARGO_TYPE_UNLOAD
, ///< Passes an OrderUnloadType and a CargoID.
180 MOF_CARGO_TYPE_LOAD
, ///< Passes an OrderLoadType and a CargoID.
183 template <> struct EnumPropsT
<ModifyOrderFlags
> : MakeEnumPropsT
<ModifyOrderFlags
, byte
, MOF_NON_STOP
, MOF_END
, MOF_END
, 4> {};
186 * Depot action to switch to when doing a #MOF_DEPOT_ACTION.
188 enum OrderDepotAction
{
189 DA_ALWAYS_GO
, ///< Always go to the depot
190 DA_SERVICE
, ///< Service only if needed
191 DA_STOP
, ///< Go to the depot and stop there
196 * Enumeration for the data to set in #CmdChangeTimetable.
198 enum ModifyTimetableFlags
{
199 MTF_WAIT_TIME
, ///< Set wait time.
200 MTF_TRAVEL_TIME
, ///< Set travel time.
201 MTF_TRAVEL_SPEED
, ///< Set max travel speed.
204 template <> struct EnumPropsT
<ModifyTimetableFlags
> : MakeEnumPropsT
<ModifyTimetableFlags
, byte
, MTF_WAIT_TIME
, MTF_END
, MTF_END
, 2> {};
207 /** Clone actions. */
217 #endif /* ORDER_TYPE_H */