OpenTTD Source
20240917-master-g9ab0a47812
|
10 #include "../stdafx.h"
11 #include "../core/bitmath_func.hpp"
12 #include "../station_func.h"
13 #include "../engine_base.h"
14 #include "../vehicle_func.h"
18 #include "../safeguards.h"
29 if (v->
orders ==
nullptr)
return;
33 if (first ==
nullptr)
return;
50 }
else if (this->
from > other.
from) {
53 if (this->
to < other.
to) {
55 }
else if (this->
to > other.
to) {
76 for (
Vehicle *v = this->vehicle; v !=
nullptr; v = v->
Next()) {
78 if (v->refit_cap > 0) {
80 this->
capacities[v->cargo_type] += v->refit_cap;
92 this->
cargo = refit_cargo;
94 bool any_refit =
false;
97 if (!
HasBit(e->info.refit_mask, this->cargo)) {
104 CargoID temp_cid = v->cargo_type;
105 uint8_t temp_subtype = v->cargo_subtype;
106 v->cargo_type = this->
cargo;
109 uint16_t mail_capacity = 0;
113 v->cargo_type = temp_cid;
114 v->cargo_subtype = temp_subtype;
117 if (this->
cargo != refit_it->cargo && refit_it->remaining > 0) {
118 this->
capacities[refit_it->cargo] -= refit_it->remaining;
119 refit_it->remaining = 0;
120 }
else if (amount < refit_it->remaining) {
121 this->
capacities[refit_it->cargo] -= refit_it->remaining - amount;
122 refit_it->remaining = amount;
124 refit_it->capacity = amount;
125 refit_it->cargo = this->
cargo;
131 if (mail_capacity < refit_it->remaining) {
132 this->
capacities[refit_it->cargo] -= refit_it->remaining - mail_capacity;
133 refit_it->remaining = mail_capacity;
135 refit_it->capacity = mail_capacity;
148 if (it.remaining == it.capacity)
continue;
149 this->
capacities[it.cargo] += it.capacity - it.remaining;
150 it.remaining = it.capacity;
175 if (next->
IsType(OT_CONDITIONAL)) {
205 if (st !=
nullptr && next_station != INVALID_STATION && next_station != st->
index) {
211 if (cargo_quantity == 0)
continue;
236 this->vehicle->orders->GetTotalDuration() > this->vehicle->current_order_time) {
267 while (next !=
nullptr) {
295 if (next ==
nullptr)
break;
297 if (this->
seen_hops->find(hop) != this->seen_hops->end()) {
307 if (!next->
IsType(OT_GOTO_STATION) && !next->
IsType(OT_IMPLICIT))
continue;
315 if (cur->
IsType(OT_GOTO_STATION) || cur->
IsType(OT_IMPLICIT)) {
OrderID from
Last order where vehicle could interact with cargo or absolute first order.
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
bool IsRefit() const
Is this order a refit order.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
CargoID cargo
Cargo the consist is probably carrying or INVALID_CARGO if unknown.
bool IsType(OrderType type) const
Check whether this order is of the given type.
static Titem * Get(size_t index)
Returns Titem with given index.
OrderID to
Next order to be processed.
@ IN_AUTOREFIT
Currently doing an autorefit loop. Ignore the first autorefit order.
Vehicle * Next() const
Get the next vehicle of this vehicle.
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
DestinationID GetDestination() const
Gets the destination of this order.
@ USE_NEXT
There was a conditional jump. Try to use the given next order when looking for a new one.
@ EUM_UNRESTRICTED
Use unrestricted link.
CargoID cargo
Cargo given in last refit order.
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
Constructor for link refreshing algorithm.
uint capacities[NUM_CARGO]
Current added capacities per cargo ID in the consist.
@ EUM_INCREASE
Increase capacity.
static Station * Get(size_t index)
Gets station with given index.
void RefreshLinks(const Order *cur, const Order *next, uint8_t flags, uint num_hops=0)
Iterate over orders starting at cur and next and refresh links associated with them.
Vehicle * vehicle
Vehicle for which the links should be refreshed.
EdgeUpdateMode
Special modes for updating links.
const Order * PredictNextOrder(const Order *cur, const Order *next, uint8_t flags, uint num_hops=0)
Predict the next order the vehicle will execute and resolve conditionals by recursion and return next...
const Order * GetNextDecisionNode(const Order *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...
Utility to refresh links a consist will visit.
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
bool HandleRefit(CargoID refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
CargoID GetRefitCargo() const
Get the cargo to to refit to.
HopSet * seen_hops
Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Re...
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
StationID last_station_visited
The last station we stopped at.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
bool is_full_loading
If the vehicle is full loading.
@ RESET_REFIT
Consist had a chance to load since the last refit and the refit capacities can be reset.
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
LinkGraphID link_graph
Link graph this station belongs to.
@ EUM_REFRESH
Refresh capacity.
uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
Order * GetOrderAt(int index) const
Get a certain order of the order chain.
void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode)
Increase capacity for a link stat given by station cargo and next hop.
void RefreshStats(const Order *cur, const Order *next)
Refresh link stats for the given pair of orders.
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
uint16_t load_unload_ticks
Ticks to wait before starting next cycle.
TimerGameTick::Ticks GetTotalDuration() const
Gets the known duration of the vehicles orders, timetabled or not.
A hop the refresh algorithm might evaluate.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
bool IsAutoRefit() const
Is this order a auto-refit order.
TileIndex xy
Base tile of the station.
@ EUM_RESTRICTED
Use restricted link.
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
const Order * GetNext(const Order *curr) const
Get the order after the given one or the first one, if the given one is the last one.
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
@ HAS_CARGO
Consist could leave the last stop where it could interact with cargo carrying cargo (i....
@ WAS_REFIT
Consist was refit since the last stop where it could interact with cargo.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
bool CanLeaveWithCargo(bool has_cargo) const
A vehicle can leave the current station with cargo if:
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
OrderList * orders
Pointer to the order list for this vehicle.
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
Simulated cargo type and capacity for prediction of future links.
@ OLFB_NO_LOAD
Do not load anything.
bool operator<(const Hop &other) const
Comparison operator to allow hops to be used in a std::set.
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.