OpenTTD Source: src/order_type.h Source File

OpenTTD Source 15.0-RC2

order_type.h
Go to the documentation of this file.
1/*
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef ORDER_TYPE_H
11#define ORDER_TYPE_H
12
13#include "core/enum_type.hpp"
14#include "depot_type.h"
15#include "core/pool_type.hpp"
16#include "station_type.h"
17
18 typedef uint8_t VehicleOrderID;
19using OrderListID = PoolID<uint16_t, struct OrderListIDTag, 64000, 0xFFFF>;
20
21 struct DestinationID {
22 using BaseType = uint16_t;
23 BaseType value = 0;
24
25 explicit DestinationID() = default;
26 constexpr DestinationID(size_t index) : value(static_cast<BaseType>(index)) {}
27 constexpr DestinationID(DepotID depot) : value(depot.base()) {}
28 constexpr DestinationID(StationID station) : value(station.base()) {}
29
30 constexpr DepotID ToDepotID() const noexcept { return static_cast<DepotID>(this->value); }
31 constexpr StationID ToStationID() const noexcept { return static_cast<StationID>(this->value); }
32 constexpr BaseType base() const noexcept { return this->value; }
33
34 constexpr bool operator ==(const DestinationID &destination) const { return this->value == destination.value; }
35 constexpr bool operator ==(const StationID &station) const { return this->value == station; }
36};
37
39 static const VehicleOrderID INVALID_VEH_ORDER_ID = 0xFF;
41 static const VehicleOrderID MAX_VEH_ORDER_ID = INVALID_VEH_ORDER_ID - 1;
42
47 static const uint IMPLICIT_ORDER_ONLY_CAP = 32;
48
50 enum OrderType : uint8_t {
51 OT_BEGIN = 0,
52 OT_NOTHING = 0,
53 OT_GOTO_STATION = 1,
54 OT_GOTO_DEPOT = 2,
55 OT_LOADING = 3,
56 OT_LEAVESTATION = 4,
57 OT_DUMMY = 5,
58 OT_GOTO_WAYPOINT = 6,
59 OT_CONDITIONAL = 7,
60 OT_IMPLICIT = 8,
61 OT_END
62};
63
67 enum class OrderUnloadType : uint8_t {
68 UnloadIfPossible = 0,
69 Unload = 1,
70 Transfer = 2,
71 NoUnload = 4,
72};
73
77 enum class OrderLoadType : uint8_t {
78 LoadIfPossible = 0,
79 FullLoad = 2,
80 FullLoadAny = 3,
81 NoLoad = 4,
82};
83
87 enum class OrderNonStopFlag : uint8_t {
88 NoIntermediate = 0,
89 NoDestination = 1,
90};
91
92using OrderNonStopFlags = EnumBitSet<OrderNonStopFlag, uint8_t>;
93
97 enum class OrderStopLocation : uint8_t {
98 NearEnd = 0,
99 Middle = 1,
100 FarEnd = 2,
101 End,
102};
103
107 enum class OrderDepotTypeFlag : uint8_t {
108 Service = 0,
109 PartOfOrders = 1,
110};
111
112using OrderDepotTypeFlags = EnumBitSet<OrderDepotTypeFlag, uint8_t>;
113
117 enum class OrderDepotActionFlag : uint8_t {
118 Halt = 0,
119 NearestDepot = 1,
120 Unbunch = 2,
121};
122
123using OrderDepotActionFlags = EnumBitSet<OrderDepotActionFlag, uint8_t>;
124
128 enum class OrderConditionVariable : uint8_t {
129 LoadPercentage = 0,
130 Reliability = 1,
131 MaxSpeed = 2,
132 Age = 3,
133 RequiresService = 4,
134 Unconditionally = 5,
135 RemainingLifetime = 6,
136 MaxReliability = 7,
137 End,
138};
139
143 enum class OrderConditionComparator : uint8_t {
144 Equal = 0,
145 NotEqual = 1,
146 LessThan = 2,
147 LessThanOrEqual = 3,
148 MoreThan = 4,
149 MoreThanOrEqual = 5,
150 IsTrue = 6,
151 IsFalse = 7,
152 End,
153};
154
155
159 enum ModifyOrderFlags : uint8_t {
160 MOF_NON_STOP,
161 MOF_STOP_LOCATION,
162 MOF_UNLOAD,
163 MOF_LOAD,
164 MOF_DEPOT_ACTION,
165 MOF_COND_VARIABLE,
166 MOF_COND_COMPARATOR,
167 MOF_COND_VALUE,
168 MOF_COND_DESTINATION,
169 MOF_END
170};
171
175 enum class OrderDepotAction : uint8_t {
176 AlwaysGo = 0,
177 Service = 1,
178 Stop = 2,
179 Unbunch = 3,
180 End
181};
182
186 enum ModifyTimetableFlags : uint8_t {
187 MTF_WAIT_TIME,
188 MTF_TRAVEL_TIME,
189 MTF_TRAVEL_SPEED,
190 MTF_END
191};
192
194 enum CloneOptions : uint8_t {
195 CO_SHARE = 0,
196 CO_COPY = 1,
197 CO_UNSHARE = 2
198};
199
200struct Order;
201struct OrderList;
202
203#endif /* ORDER_TYPE_H */
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
CommandType::End
@ End
End marker.
depot_type.h
Header files for depots (not hangars)
enum_type.hpp
Type (helpers) for enums.
OrderUnloadType
OrderUnloadType
Unloading order types.
Definition order_type.h:67
OrderUnloadType::Transfer
@ Transfer
Transfer all cargo onto the platform.
OrderUnloadType::UnloadIfPossible
@ UnloadIfPossible
Unload all cargo that the station accepts.
OrderUnloadType::NoUnload
@ NoUnload
Totally no unloading will be done.
OrderUnloadType::Unload
@ Unload
Force unloading all cargo onto the platform, possibly not getting paid.
OrderConditionVariable
OrderConditionVariable
Variables (of a vehicle) to 'cause' skipping on.
Definition order_type.h:128
OrderConditionVariable::Unconditionally
@ Unconditionally
Always skip.
OrderConditionVariable::MaxSpeed
@ MaxSpeed
Skip based on the maximum speed.
OrderConditionVariable::Reliability
@ Reliability
Skip based on the reliability.
OrderConditionVariable::MaxReliability
@ MaxReliability
Skip based on the maximum reliability.
OrderConditionVariable::RequiresService
@ RequiresService
Skip when the vehicle requires service.
OrderConditionVariable::LoadPercentage
@ LoadPercentage
Skip based on the amount of load.
OrderConditionVariable::Age
@ Age
Skip based on the age.
OrderConditionVariable::RemainingLifetime
@ RemainingLifetime
Skip based on the remaining lifetime.
OrderStopLocation
OrderStopLocation
Where to stop the trains.
Definition order_type.h:97
OrderStopLocation::NearEnd
@ NearEnd
Stop at the near end of the platform.
OrderStopLocation::FarEnd
@ FarEnd
Stop at the far end of the platform.
OrderStopLocation::Middle
@ Middle
Stop at the middle of the platform.
ModifyOrderFlags
ModifyOrderFlags
Enumeration for the data to set in CmdModifyOrder.
Definition order_type.h:159
MOF_COND_VARIABLE
@ MOF_COND_VARIABLE
A conditional variable changes.
Definition order_type.h:165
MOF_LOAD
@ MOF_LOAD
Passes an OrderLoadType.
Definition order_type.h:163
MOF_UNLOAD
@ MOF_UNLOAD
Passes an OrderUnloadType.
Definition order_type.h:162
MOF_STOP_LOCATION
@ MOF_STOP_LOCATION
Passes an OrderStopLocation.
Definition order_type.h:161
MOF_COND_DESTINATION
@ MOF_COND_DESTINATION
Change the destination of a conditional order.
Definition order_type.h:168
MOF_COND_COMPARATOR
@ MOF_COND_COMPARATOR
A comparator changes.
Definition order_type.h:166
MOF_COND_VALUE
@ MOF_COND_VALUE
The value to set the condition to.
Definition order_type.h:167
MOF_DEPOT_ACTION
@ MOF_DEPOT_ACTION
Selects the OrderDepotAction.
Definition order_type.h:164
MOF_NON_STOP
@ MOF_NON_STOP
Passes an OrderNonStopFlags.
Definition order_type.h:160
OrderDepotAction
OrderDepotAction
Depot action to switch to when doing a MOF_DEPOT_ACTION.
Definition order_type.h:175
OrderDepotAction::Stop
@ Stop
Go to the depot and stop there.
OrderDepotAction::AlwaysGo
@ AlwaysGo
Always go to the depot.
OrderNonStopFlag
OrderNonStopFlag
Non-stop order flags.
Definition order_type.h:87
OrderNonStopFlag::NoDestination
@ NoDestination
The vehicle will stop at any station it passes except the destination, aka via.
OrderNonStopFlag::NoIntermediate
@ NoIntermediate
The vehicle will not stop at any stations it passes except the destination, aka non-stop.
VehicleOrderID
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition order_type.h:18
OrderLoadType
OrderLoadType
Loading order types.
Definition order_type.h:77
OrderLoadType::FullLoad
@ FullLoad
Full load all cargoes of the consist.
OrderLoadType::NoLoad
@ NoLoad
Do not load anything.
OrderLoadType::FullLoadAny
@ FullLoadAny
Full load a single cargo of the consist.
OrderLoadType::LoadIfPossible
@ LoadIfPossible
Load as long as there is cargo that fits in the train.
MAX_VEH_ORDER_ID
static const VehicleOrderID MAX_VEH_ORDER_ID
Last valid VehicleOrderID.
Definition order_type.h:41
OrderDepotActionFlag
OrderDepotActionFlag
Actions that can be performed when the vehicle enters the depot.
Definition order_type.h:117
OrderDepotActionFlag::Halt
@ Halt
Service the vehicle and then halt it.
OrderDepotActionFlag::NearestDepot
@ NearestDepot
Send the vehicle to the nearest depot.
OrderDepotActionFlag::Unbunch
@ Unbunch
Service the vehicle and then unbunch it.
OrderDepotTypeFlag
OrderDepotTypeFlag
Reasons that could cause us to go to the depot.
Definition order_type.h:107
OrderDepotTypeFlag::PartOfOrders
@ PartOfOrders
This depot order is because of a regular order.
OrderDepotTypeFlag::Service
@ Service
This depot order is because of the servicing limit.
INVALID_VEH_ORDER_ID
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition order_type.h:39
IMPLICIT_ORDER_ONLY_CAP
static const uint IMPLICIT_ORDER_ONLY_CAP
Maximum number of orders in implicit-only lists before we start searching harder for duplicates.
Definition order_type.h:47
OrderConditionComparator
OrderConditionComparator
Comparator for the skip reasoning.
Definition order_type.h:143
OrderConditionComparator::IsTrue
@ IsTrue
Skip if the variable is true.
OrderConditionComparator::NotEqual
@ NotEqual
Skip if both values are not equal.
OrderConditionComparator::IsFalse
@ IsFalse
Skip if the variable is false.
OrderConditionComparator::LessThanOrEqual
@ LessThanOrEqual
Skip if the value is less or equal to the limit.
OrderConditionComparator::MoreThan
@ MoreThan
Skip if the value is more than the limit.
OrderConditionComparator::MoreThanOrEqual
@ MoreThanOrEqual
Skip if the value is more or equal to the limit.
OrderConditionComparator::LessThan
@ LessThan
Skip if the value is less than the limit.
OrderConditionComparator::Equal
@ Equal
Skip if both values are equal.
ModifyTimetableFlags
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition order_type.h:186
MTF_TRAVEL_TIME
@ MTF_TRAVEL_TIME
Set travel time.
Definition order_type.h:188
MTF_WAIT_TIME
@ MTF_WAIT_TIME
Set wait time.
Definition order_type.h:187
MTF_TRAVEL_SPEED
@ MTF_TRAVEL_SPEED
Set max travel speed.
Definition order_type.h:189
CloneOptions
CloneOptions
Clone actions.
Definition order_type.h:194
OrderType
OrderType
Order types.
Definition order_type.h:50
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
station_type.h
Types related to stations.
DestinationID
Definition order_type.h:21
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition order_base.h:274
Order
Definition order_base.h:33
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43