30#include "table/strings.h"
49 this->type = OT_NOTHING;
60 this->
type = OT_GOTO_STATION;
62 this->
dest = destination;
75 this->
type = OT_GOTO_DEPOT;
79 this->
dest = destination;
89 this->
type = OT_GOTO_WAYPOINT;
91 this->
dest = destination;
100 this->
type = OT_LOADING;
101 if (!ordered) this->
flags = 0;
109 this->
type = OT_LEAVESTATION;
118 this->
type = OT_DUMMY;
128 this->
type = OT_CONDITIONAL;
139 this->
type = OT_IMPLICIT;
140 this->
dest = destination;
182 uint16_t order = this->
GetType();
184 case OT_GOTO_STATION:
298 if (order.IsType(OT_GOTO_STATION) || order.IsType(OT_GOTO_WAYPOINT)) {
307 if (keep_orderlist) {
332 if (order_next.
IsType(OT_CONDITIONAL)) {
342 if (order_next.
IsType(OT_GOTO_DEPOT)) {
344 if (order_next.
IsRefit())
return next;
347 if (!order_next.CanLoadOrUnload()) {
380 auto orders = v->Orders();
409 next_station.push_back(
orders[next].GetDestination().ToStationID());
419 auto it = std::ranges::next(std::begin(this->
orders), index, std::end(this->
orders));
420 auto new_order = this->
orders.emplace(it, std::move(order));
423 this->
timetable_duration += new_order->GetTimetabledWait() + new_order->GetTimetabledTravel();
424 this->
total_duration += new_order->GetWaitTime() + new_order->GetTravelTime();
428 if (new_order->IsType(OT_GOTO_STATION) || new_order->IsType(OT_GOTO_WAYPOINT)) {
441 auto to_remove = std::ranges::next(std::begin(this->
orders), index, std::end(this->
orders));
442 if (to_remove == std::end(this->
orders))
return;
446 this->
timetable_duration -= (to_remove->GetTimetabledWait() + to_remove->GetTimetabledTravel());
447 this->
total_duration -= (to_remove->GetWaitTime() + to_remove->GetTravelTime());
449 this->
orders.erase(to_remove);
459 if (from == to)
return;
463 auto it = std::begin(this->
orders);
465 std::rotate(it + from, it + from + 1, it + to + 1);
467 std::rotate(it + to, it + from, it + from + 1);
490 if (o.IsType(OT_IMPLICIT))
continue;
491 if (!o.IsCompletelyTimetabled())
return false;
500void OrderList::DebugCheckSanity()
const
504 uint check_num_vehicles = 0;
508 Debug(misc, 6,
"Checking OrderList {} for sanity...", this->
index);
512 if (!o.IsType(OT_IMPLICIT)) ++check_num_manual_orders;
513 check_timetable_duration += o.GetTimetabledWait() + o.GetTimetabledTravel();
514 check_total_duration += o.GetWaitTime() + o.GetTravelTime();
522 ++check_num_vehicles;
523 assert(v->orders ==
this);
526 Debug(misc, 6,
"... detected {} orders ({} manual), {} vehicles, {} timetabled, {} total",
541 return o.
IsType(OT_GOTO_STATION) ||
565 case OT_GOTO_WAYPOINT:
566 case OT_GOTO_STATION:
591 assert(v->
orders !=
nullptr);
593 auto orders = orderlist.GetOrders();
595 if (orders[cur].IsType(OT_CONDITIONAL)) {
600 int dist1 =
GetOrderDistance(prev, orders[cur].GetConditionSkipToOrder(), v, conditional_depth);
602 return std::max(dist1, dist2);
605 TileIndex prev_tile = orders[prev].GetLocation(v,
true);
606 TileIndex cur_tile = orders[cur].GetLocation(v,
true);
627 if (ret.
Failed())
return ret;
635 case OT_GOTO_STATION: {
641 if (ret.
Failed())
return ret;
694 case OT_GOTO_DEPOT: {
702 if (ret.
Failed())
return ret;
713 if (ret.
Failed())
return ret;
742 if (new_order.
GetDepotActionType().
Reset({OrderDepotActionFlag::Halt, OrderDepotActionFlag::NearestDepot, OrderDepotActionFlag::Unbunch}).Any())
return CMD_ERROR;
756 case OT_GOTO_WAYPOINT: {
767 if (ret.
Failed())
return ret;
775 if (ret.
Failed())
return ret;
783 if (ret.
Failed())
return ret;
795 case OT_CONDITIONAL: {
802 if (occ >= OrderConditionComparator::End)
return CMD_ERROR;
849 if (v->
orders ==
nullptr) {
864 if (sel_ord <= u->cur_real_order_index) {
867 if (cur < u->GetNumOrders()) {
878 if (sel_ord <= u->cur_implicit_order_index) {
881 if (cur < u->GetNumOrders()) {
894 for (
Order &order : v->Orders()) {
895 if (order.IsType(OT_CONDITIONAL)) {
897 if (order_id >= sel_ord) {
898 order.SetConditionSkipToOrder(order_id + 1);
900 if (order_id == cur_order_id) {
901 order.SetConditionSkipToOrder((order_id + 1) % v->
GetNumOrders());
940 if (ret.
Failed())
return ret;
984 if (sel_ord < u->cur_real_order_index) {
990 if (sel_ord < u->cur_implicit_order_index) {
1011 for (
Order &order : v->Orders()) {
1012 if (order.IsType(OT_CONDITIONAL)) {
1014 if (order_id >= sel_ord) {
1015 order_id = std::max(order_id - 1, 0);
1017 if (order_id == cur_order_id) {
1020 order.SetConditionSkipToOrder(order_id);
1042 if (ret.
Failed())
return ret;
1079 if (ret.
Failed())
return ret;
1087 if (moving_one ==
nullptr)
return CMD_ERROR;
1139 for (
Order &order : v->Orders()) {
1140 if (order.IsType(OT_CONDITIONAL)) {
1142 if (order_id == moving_order) {
1143 order_id = target_order;
1144 }
else if (order_id > moving_order && order_id <= target_order) {
1146 }
else if (order_id < moving_order && order_id >= target_order) {
1149 order.SetConditionSkipToOrder(order_id);
1179 if (ret.
Failed())
return ret;
1185 assert(order !=
nullptr);
1187 case OT_GOTO_STATION:
1195 case OT_GOTO_WAYPOINT:
1199 case OT_CONDITIONAL:
1208 default: NOT_REACHED();
1234 switch (unload_type) {
1253 switch (load_type) {
1270 if (depot_action >= OrderDepotAction::End)
return CMD_ERROR;
1285 if (cond_variable >= OrderConditionVariable::End)
return CMD_ERROR;
1291 if (cond_comparator >= OrderConditionComparator::End)
return CMD_ERROR;
1421 default: NOT_REACHED();
1466 auto orders = orderlist.GetOrders();
1471 switch (orders[cur].GetType()) {
1472 case OT_GOTO_STATION:
1474 case OT_GOTO_WAYPOINT:
1500 if (ret.
Failed())
return ret;
1510 if (ret.
Failed())
return ret;
1520 for (
const Order &order : src->Orders()) {
1534 return CommandCost(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
1538 return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
1567 if (ret.
Failed())
return ret;
1571 for (
const Order &order : src->Orders()) {
1581 return CommandCost(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
1586 return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
1595 std::vector<Order> dst_orders;
1596 for (
const Order &order : src->Orders()) {
1597 dst_orders.emplace_back(order);
1600 if (dst->
orders !=
nullptr) {
1639 if (ret.
Failed())
return ret;
1664 u->current_order.SetRefit(cargo);
1699 for (
const Order &order : v->Orders()) {
1701 if (order.IsType(OT_DUMMY)) {
1702 message = STR_NEWS_VEHICLE_HAS_VOID_ORDER;
1706 if (order.IsType(OT_GOTO_STATION)) {
1711 message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY;
1717 message = STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY;
1724 auto orders = v->Orders();
1726 if (orders.front().Equals(orders.back())) {
1727 message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
1732 if (n_st < 2 && message ==
INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
1735 if (v->
orders !=
nullptr) v->
orders->DebugCheckSanity();
1761 if ((v->type ==
VEH_AIRCRAFT && v->current_order.IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : v->current_order.GetType()) == type &&
1762 (!hangar || v->type ==
VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) {
1763 v->current_order.MakeDummy();
1767 if (v->orders ==
nullptr)
continue;
1770 for (
VehicleOrderID id = 0, next_id = 0;
id < v->GetNumOrders();
id = next_id) {
1772 Order *order = v->orders->GetOrderAt(
id);
1775 if (ot == OT_GOTO_DEPOT && hangar && v->type !=
VEH_AIRCRAFT)
continue;
1776 if (ot == OT_IMPLICIT || (v->type ==
VEH_AIRCRAFT && ot == OT_GOTO_DEPOT && !hangar)) ot = OT_GOTO_STATION;
1781 if (order->
IsType(OT_IMPLICIT)) {
1788 v->orders->UpdateTotalDuration(-order->
GetWaitTime());
1818 return std::ranges::any_of(this->Orders(), [](
const Order &order) {
return order.
IsType(OT_GOTO_DEPOT); });
1838 }
else if (v->
orders !=
nullptr) {
1841 if (!keep_orderlist) v->
orders =
nullptr;
1847 if (reset_order_indices) {
1865 if (ispercent)
return Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT);
1871 return Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
1884 return std::ranges::any_of(v->Orders(), [](
const Order &order) { return order.IsGotoOrder(); });
1901 default: NOT_REACHED();
1920 bool skip_order =
false;
1933 default: NOT_REACHED();
1955 case OT_GOTO_STATION:
1961 assert(!pbs_look_ahead);
1975 if (closest_depot.found) {
1977 if (pbs_look_ahead && closest_depot.reverse)
return false;
1979 v->SetDestTile(closest_depot.location);
1996 if (pbs_look_ahead)
return false;
2015 case OT_GOTO_WAYPOINT:
2019 case OT_CONDITIONAL: {
2020 assert(!pbs_look_ahead);
2053 if (order !=
nullptr && order->
IsType(OT_IMPLICIT)) {
2058 if (order ==
nullptr) {
2065 return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
2086 case OT_LEAVESTATION:
2121 if (order !=
nullptr && order->
IsType(OT_IMPLICIT)) {
2175 bool is_dest_station = this->
IsType(OT_GOTO_STATION) && this->
dest == station;
2183bool Order::CanLoadOrUnload()
const
2185 return (this->
IsType(OT_GOTO_STATION) || this->
IsType(OT_IMPLICIT)) &&
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
@ FLYING
Vehicle is flying in the air.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
static const CargoType CARGO_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
static const CargoType CARGO_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
Cheats _cheats
All the cheats.
Types related to cheating.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Common return value for all commands.
bool Failed() const
Did this command fail?
uint16_t reliability
Current reliability of the engine.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static DateFract date_fract
Fractional part of the day.
int32_t Ticks
The type to store ticks in.
static constexpr Year DateToYear(Date date)
Calculate the year of a given date.
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Execute
execute the given command
Definition of stuff that is very close to a company, like the company struct itself.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
A type is considered 'convertible through base()' when it has a 'base()' function that returns someth...
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Base for all depots (except hangars)
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
@ GVF_SUPPRESS_IMPLICIT_ORDERS
Disable insertion and removal of automatic orders until the vehicle completes the real order.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Functions related to news.
void AddVehicleAdviceNewsItem(AdviceType advice_type, EncodedString &&headline, VehicleID vehicle)
Adds a vehicle-advice news item.
void DeleteVehicleNews(VehicleID vid, AdviceType advice_type=AdviceType::Invalid)
Delete news with a given advice type about a vehicle.
@ Order
Something wrong with the order, e.g. invalid or duplicate entries, too few entries.
Functions related to order backups.
CommandCost CmdSkipToOrder(DoCommandFlags flags, VehicleID veh_id, VehicleOrderID sel_ord)
Goto order of order-list.
uint16_t GetServiceIntervalClamped(int interval, bool ispercent)
Clamp the service interval to the correct min/max.
static bool CheckForValidOrders(const Vehicle *v)
Check if a vehicle has any valid orders.
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
static bool OrderConditionCompare(OrderConditionComparator occ, int variable, int value)
Compare the variable and value based on the given comparator.
static void CancelLoadingDueToDeletedOrder(Vehicle *v)
Cancel the current loading order of the vehicle as the order was deleted.
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
Update the vehicle's destination tile from an order.
CommandCost CmdOrderRefit(DoCommandFlags flags, VehicleID veh, VehicleOrderID order_number, CargoType cargo)
Add/remove refit orders from an order.
void InsertOrder(Vehicle *v, Order &&new_o, VehicleOrderID sel_ord)
Insert a new order but skip the validation.
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
CommandCost CmdInsertOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID sel_ord, const Order &new_order)
Add an order to the orderlist of a vehicle.
CommandCost CmdModifyOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16_t data)
Modify an order in the orderlist of a vehicle.
CommandCost CmdCloneOrder(DoCommandFlags flags, CloneOptions action, VehicleID veh_dst, VehicleID veh_src)
Clone/share/copy an order-list of another vehicle.
static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlags flags)
Declone an order-list.
void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indices)
Delete all orders from a vehicle.
CommandCost CmdDeleteOrder(DoCommandFlags flags, VehicleID veh_id, VehicleOrderID sel_ord)
Delete an order from the orderlist of a vehicle.
uint GetOrderDistance(VehicleOrderID prev, VehicleOrderID cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
static void DeleteOrderWarnings(const Vehicle *v)
Delete all news items regarding defective orders about a vehicle This could kill still valid warnings...
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
Delete an order but skip the parameter validation.
VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
Process a conditional order and determine the next order.
CommandCost CmdMoveOrder(DoCommandFlags flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order)
Move an order inside the orderlist.
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_order)
Check if an aircraft has enough range for an order list.
static bool OrderGoesToStation(const Vehicle *v, const Order &o)
Checks whether the order goes to a station or not, i.e.
Command definitions related to orders.
OrderUnloadType
Unloading order types.
@ Transfer
Transfer all cargo onto the platform.
@ UnloadIfPossible
Unload all cargo that the station accepts.
@ NoUnload
Totally no unloading will be done.
@ Unload
Force unloading all cargo onto the platform, possibly not getting paid.
OrderConditionVariable
Variables (of a vehicle) to 'cause' skipping on.
@ Unconditionally
Always skip.
@ MaxSpeed
Skip based on the maximum speed.
@ Reliability
Skip based on the reliability.
@ MaxReliability
Skip based on the maximum reliability.
@ RequiresService
Skip when the vehicle requires service.
@ LoadPercentage
Skip based on the amount of load.
@ Age
Skip based on the age.
@ RemainingLifetime
Skip based on the remaining lifetime.
OrderStopLocation
Where to stop the trains.
@ NearEnd
Stop at the near end of the platform.
@ FarEnd
Stop at the far end of the platform.
@ Middle
Stop at the middle of the platform.
ModifyOrderFlags
Enumeration for the data to set in CmdModifyOrder.
@ MOF_COND_VARIABLE
A conditional variable changes.
@ MOF_LOAD
Passes an OrderLoadType.
@ MOF_UNLOAD
Passes an OrderUnloadType.
@ MOF_STOP_LOCATION
Passes an OrderStopLocation.
@ MOF_COND_DESTINATION
Change the destination of a conditional order.
@ MOF_COND_COMPARATOR
A comparator changes.
@ MOF_COND_VALUE
The value to set the condition to.
@ MOF_DEPOT_ACTION
Selects the OrderDepotAction.
@ MOF_NON_STOP
Passes an OrderNonStopFlags.
OrderDepotAction
Depot action to switch to when doing a MOF_DEPOT_ACTION.
@ Stop
Go to the depot and stop there.
@ AlwaysGo
Always go to the depot.
@ Service
Service only if needed.
@ Unbunch
Go to the depot and unbunch.
@ NoDestination
The vehicle will stop at any station it passes except the destination, aka via.
@ NoIntermediate
The vehicle will not stop at any stations it passes except the destination, aka non-stop.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
OrderLoadType
Loading order types.
@ FullLoad
Full load all cargoes of the consist.
@ NoLoad
Do not load anything.
@ FullLoadAny
Full load a single cargo of the consist.
@ LoadIfPossible
Load as long as there is cargo that fits in the train.
static const VehicleOrderID MAX_VEH_ORDER_ID
Last valid VehicleOrderID.
@ Halt
Service the vehicle and then halt it.
@ NearestDepot
Send the vehicle to the nearest depot.
@ Unbunch
Service the vehicle and then unbunch it.
@ PartOfOrders
This depot order is because of a regular order.
@ Service
This depot order is because of the servicing limit.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
OrderConditionComparator
Comparator for the skip reasoning.
@ IsTrue
Skip if the variable is true.
@ NotEqual
Skip if both values are not equal.
@ IsFalse
Skip if the variable is false.
@ LessThanOrEqual
Skip if the value is less or equal to the limit.
@ MoreThan
Skip if the value is more than the limit.
@ MoreThanOrEqual
Skip if the value is more or equal to the limit.
@ LessThan
Skip if the value is less than the limit.
@ Equal
Skip if both values are equal.
CloneOptions
Clone actions.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
static bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
static bool IsRoadDepotTile(Tile t)
Return whether a tile is a road depot tile.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Base classes/functions for stations.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
@ Dock
Station with a dock.
@ TruckStop
Station with truck stops.
@ Train
Station with train station.
@ BusStop
Station with bus stops.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
uint32_t cached_max_range_sqr
Cached squared maximum range.
uint16_t cached_max_range
Cached maximum range.
uint8_t subtype
Type of aircraft.
Aircraft, helicopters, rotors and their shadows belong to this class.
uint8_t state
State of the airport.
TileIndex GetOrderStationLocation(StationID station) override
Determine the location for the station where the vehicle goes to next.
StationID targetairport
Airport to go to next.
@ ShortStrip
This airport has a short landing strip, dangerous for fast aircraft.
Flags flags
Flags for this airport type.
bool HasHangar() const
Check if this airport has at least one hangar.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
Base class for all station-ish types.
TileIndex xy
Base tile of the station.
StationFacilities facilities
The facilities that this station has.
Owner owner
The owner of this station.
VehicleType type
Type of vehicle.
bool value
tells if the bool cheat is active or not
Cheat no_jetcrash
no jet will crash on small airports anymore
GUISettings gui
settings related to the GUI
Structure to return information about the closest depot location, and whether it could be found.
DestinationID destination
The DestinationID as used for orders.
uint8_t order_review_system
perform order reviews on vehicles
static void RemoveOrder(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
void DeleteOrderAt(VehicleOrderID index)
Remove an order from the order list and delete it.
std::vector< Order > orders
Orders of the order list.
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
void InsertOrderAt(Order &&order, VehicleOrderID index)
Insert a new order into the order chain.
void RemoveVehicle(Vehicle *v)
Removes the vehicle from the shared order list.
uint num_vehicles
NOSAVE: Number of vehicles that share this order list.
void Initialize(Vehicle *v)
Recomputes everything.
TimerGameTick::Ticks timetable_duration
NOSAVE: Total timetabled duration of the order list.
Vehicle * first_shared
NOSAVE: pointer to the first vehicle in the shared order chain.
VehicleOrderID GetFirstOrder() const
Get the first order of the order chain.
VehicleOrderID num_manual_orders
NOSAVE: How many manually added orders are there in the list.
void MoveOrder(VehicleOrderID from, VehicleOrderID to)
Move an order to another position within the order list.
void GetNextStoppingStation(std::vector< StationID > &next_station, const Vehicle *v, VehicleOrderID first=INVALID_VEH_ORDER_ID, uint hops=0) const
Recursively determine the next deterministic station to stop at.
VehicleOrderID GetNext(VehicleOrderID cur) const
Get the order after the given one or the first one, if the given one is the last one.
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
void RecalculateTimetableDuration()
Recomputes Timetable duration.
void FreeChain(bool keep_orderlist=false)
Free a complete order chain.
VehicleOrderID GetNextDecisionNode(VehicleOrderID next, uint hops) const
Get the next order which will make the given vehicle stop at a station or refit at a depot or evaluat...
bool IsShared() const
Is this a shared order list?
TimerGameTick::Ticks total_duration
NOSAVE: Total (timetabled or not) duration of the order list.
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
uint16_t GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
uint16_t MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
uint16_t max_speed
How fast the vehicle may go on the way to the destination.
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
DestinationID GetDestination() const
Gets the destination of this order.
bool IsType(OrderType type) const
Check whether this order is of the given type.
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
uint16_t GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
CargoType GetRefitCargo() const
Get the cargo to to refit to.
OrderType GetType() const
Get the type of order of this order.
bool IsFullLoadOrder() const
Is this order a OrderLoadType::FullLoad or OrderLoadType::FullLoadAny?
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
uint8_t type
The type of order + non-stop flags.
uint16_t wait_time
How long in ticks to wait at the destination.
void SetRefit(CargoType cargo)
Make this depot/station order also a refit order.
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
void SetWaitTime(uint16_t time)
Set the time in ticks to wait at the destination.
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
void MakeDummy()
Makes this order a Dummy order.
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
void SetConditionVariable(OrderConditionVariable condition_variable)
Set variable we have to compare.
OrderUnloadType GetUnloadType() const
How must the consist be unloaded?
uint8_t flags
Load/unload types, depot order/action types.
void MakeGoToDepot(DestinationID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=OrderNonStopFlag::NoIntermediate, OrderDepotActionFlags action={}, CargoType cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
DestinationID dest
The destination of the order.
void SetDestination(DestinationID destination)
Sets the destination of this order.
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
void SetConditionComparator(OrderConditionComparator condition_comparator)
Set the comparator to use.
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
void SetConditionSkipToOrder(VehicleOrderID order_id)
Get the order to skip to.
OrderLoadType GetLoadType() const
How must the consist be loaded?
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
void MakeLeaveStation()
Makes this order a Leave Station order.
bool CanLeaveWithCargo(bool has_cargo) const
A vehicle can leave the current station with cargo if:
void SetConditionValue(uint16_t value)
Set the value to base the skip on.
void SetUnloadType(OrderUnloadType unload_type)
Set how the consist must be unloaded.
void Free()
'Free' the order
uint16_t GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
bool ShouldStopAtStation(const Vehicle *v, StationID station) const
Check whether the given vehicle should stop at the given station based on this order and the non-stop...
CargoType refit_cargo
Refit CargoType.
uint16_t GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
void MakeImplicit(StationID destination)
Makes this order an implicit order.
void SetLoadType(OrderLoadType load_type)
Set how the consist must be loaded.
void AssignOrder(const Order &other)
Assign data to an order (from another order) This function makes sure that the index is maintained co...
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
bool IsRefit() const
Is this order a refit order.
void MakeLoading(bool ordered)
Makes this order a Loading order.
uint16_t GetConditionValue() const
Get the value to base the skip on.
uint16_t travel_time
How long in ticks the journey to this destination should take.
TileIndex tile
The base tile of the area.
Templated helper to make a PoolID a single POD value.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Base class for all pools.
static Station * Get(auto index)
Gets station with given index.
static Station * GetIfValid(auto index)
Returns station if the index is a valid index for this station type.
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
TileArea ship_station
Tile area the ship 'station' part covers.
Airport airport
Tile area the airport covers.
EngineID engine_type
The type of engine used for this vehicle.
uint16_t & GetGroundVehicleFlags()
Access the ground vehicle flags of the vehicle.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
bool HasDepotOrder() const
Checks if a vehicle has a depot in its order list.
void LeaveStation()
Perform all actions when leaving a station.
void AddToShared(Vehicle *shared_chain)
Adds this vehicle to a shared vehicle chain.
bool HasUnbunchingOrder() const
Check if the current vehicle has an unbunching order.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
uint8_t day_counter
Increased by one for each day.
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
VehStates vehstatus
Status.
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
virtual TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Order current_order
The current order (+ status, like: loading)
OrderList * orders
Pointer to the order list for this vehicle.
virtual ClosestDepot FindClosestDepot()
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
bool HasFullLoadOrder() const
Check if the current vehicle has a full load order.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
TimerGameCalendar::Date age
Age in calendar days.
TimerGameCalendar::Date max_age
Maximum age.
uint16_t reliability
Reliability.
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
void RemoveFromShared()
Removes the vehicle from the shared order list.
TileIndex tile
Current tile index.
TileIndex dest_tile
Heading for this tile.
bool NeedsServicing() const
Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for ser...
bool HasConditionalOrder() const
Check if the current vehicle has a conditional order.
StationID last_station_visited
The last station we stopped at.
Owner owner
Which company owns the vehicle?
void DeleteUnreachedImplicitOrders()
Delete all implicit orders which were not reached.
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Representation of a waypoint.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_STATION
A tile of a station.
Command definitions related to trains.
StringID GetVehicleCannotUseStationReason(const Vehicle *v, const Station *st)
Get reason string why this station can't be used by the given vehicle.
uint8_t CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
@ Crashed
Vehicle is crashed.
@ Stopped
Vehicle is stopped by the player.
Functions related to vehicles.
@ VIWD_MODIFY_ORDERS
Other order modifications.
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
bool IsShipDepotTile(Tile t)
Is it a ship depot tile?
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers: