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;
50 vehicle(vehicle), seen_hops(seen_hops), cargo(INVALID_CARGO), allow_merge(allow_merge),
51 is_full_loading(is_full_loading)
54 for (
Vehicle *v = this->vehicle; v !=
nullptr; v = v->
Next()) {
56 if (v->refit_cap > 0) {
58 this->
capacities[v->cargo_type] += v->refit_cap;
70 this->
cargo = refit_cargo;
72 bool any_refit =
false;
75 if (!
HasBit(e->info.refit_mask, this->cargo)) {
82 CargoType temp_cargo_type = v->cargo_type;
83 uint8_t temp_subtype = v->cargo_subtype;
84 v->cargo_type = this->
cargo;
87 uint16_t mail_capacity = 0;
91 v->cargo_type = temp_cargo_type;
92 v->cargo_subtype = temp_subtype;
95 if (this->
cargo != refit_it->cargo && refit_it->remaining > 0) {
96 this->
capacities[refit_it->cargo] -= refit_it->remaining;
97 refit_it->remaining = 0;
98 }
else if (amount < refit_it->remaining) {
99 this->
capacities[refit_it->cargo] -= refit_it->remaining - amount;
100 refit_it->remaining = amount;
102 refit_it->capacity = amount;
103 refit_it->cargo = this->
cargo;
109 if (mail_capacity < refit_it->remaining) {
110 this->
capacities[refit_it->cargo] -= refit_it->remaining - mail_capacity;
111 refit_it->remaining = mail_capacity;
113 refit_it->capacity = mail_capacity;
126 if (it.remaining == it.capacity)
continue;
127 this->
capacities[it.cargo] += it.capacity - it.remaining;
128 it.remaining = it.capacity;
145 auto orders = orderlist.GetOrders();
157 if (orders[next].IsType(OT_CONDITIONAL)) {
185 auto orders = orderlist.GetOrders();
187 StationID next_station = orders[next].GetDestination().ToStationID();
189 if (st !=
nullptr && next_station != StationID::Invalid() && next_station != st->
index) {
195 if (cargo_quantity == 0)
continue;
220 this->vehicle->orders->GetTotalDuration() > this->vehicle->current_order_time) {
225 {EdgeUpdateMode::Increase, restricted_mode});
256 if ((next_order->
IsType(OT_GOTO_DEPOT) || next_order->
IsType(OT_GOTO_STATION)) && next_order->
IsRefit()) {
284 if (this->
seen_hops->find(hop) != this->seen_hops->end()) {
296 if (!next_order->
IsType(OT_GOTO_STATION) && !next_order->
IsType(OT_IMPLICIT))
continue;
305 if (cur_order->
IsType(OT_GOTO_STATION) || cur_order->
IsType(OT_IMPLICIT)) {
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
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.
Utility to refresh links a consist will visit.
bool allow_merge
If the refresher is allowed to merge or extend link graphs.
void ResetRefit()
Restore capacities and refit_capacities as vehicle might have been able to load now.
VehicleOrderID PredictNextOrder(VehicleOrderID cur, VehicleOrderID next, RefreshFlags flags, uint num_hops=0)
Predict the next order the vehicle will execute and resolve conditionals by recursion and return next...
void RefreshLinks(VehicleOrderID cur, VehicleOrderID next, RefreshFlags flags, uint num_hops=0)
Iterate over orders starting at cur and next and refresh links associated with them.
void RefreshStats(VehicleOrderID cur, VehicleOrderID next)
Refresh link stats for the given pair of orders.
bool HandleRefit(CargoType refit_cargo)
Handle refit orders by updating capacities and refit_capacities.
Vehicle * vehicle
Vehicle for which the links should be refreshed.
@ UseNext
There was a conditional jump. Try to use the given next order when looking for a new one.
@ ResetRefit
Consist had a chance to load since the last refit and the refit capacities can be reset.
@ WasRefit
Consist was refit since the last stop where it could interact with cargo.
@ HasCargo
Consist could leave the last stop where it could interact with cargo carrying cargo (i....
@ InAutorefit
Currently doing an autorefit loop. Ignore the first autorefit order.
RefitList refit_capacities
Current state of capacity remaining from previous refits versus overall capacity per vehicle in the c...
LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
Constructor for link refreshing algorithm.
CargoType cargo
Cargo given in last refit order.
CargoArray capacities
Current added capacities per cargo type in the consist.
HopSet * seen_hops
Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Re...
bool is_full_loading
If the vehicle is full loading.
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
Declaration of link graph classes used for cargo distribution.
EdgeUpdateMode
Special modes for updating links.
@ Refresh
Refresh capacity.
@ Unrestricted
Use unrestricted link.
@ Increase
Increase capacity.
@ Restricted
Use restricted link.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
uint8_t VehicleOrderID
The index of an order within its current vehicle (not pool related)
@ OLFB_NO_LOAD
Do not load anything.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
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.
Definition of link refreshing utility.
void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint capacity, uint usage, uint32_t time, EdgeUpdateModes modes)
Increase capacity for a link stat given by station cargo and next hop.
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
TileIndex xy
Base tile of the station.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
A hop the refresh algorithm might evaluate.
Simulated cargo type and capacity for prediction of future links.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
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.
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...
TimerGameTick::Ticks GetTotalDuration() const
Gets the known duration of the vehicles orders, timetabled or not.
const Order * GetOrderAt(VehicleOrderID index) const
Get a certain order of the order chain.
bool IsType(OrderType type) const
Check whether this order is of the given type.
CargoType GetRefitCargo() const
Get the cargo to to refit to.
bool CanLeaveWithCargo(bool has_cargo) const
A vehicle can leave the current station with cargo if:
bool IsAutoRefit() const
Is this order a auto-refit order.
bool IsRefit() const
Is this order a refit order.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
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.
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing.
Vehicle * Next() const
Get the next vehicle of this vehicle.
OrderList * orders
Pointer to the order list for this vehicle.
uint16_t load_unload_ticks
Ticks to wait before starting next cycle.
StationID last_station_visited
The last station we stopped at.
uint8_t GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoType dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
@ VEH_AIRCRAFT
Aircraft vehicle type.