OpenTTD Source: LinkRefresher Class Reference

OpenTTD Source 15.3

Data Structures | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
LinkRefresher Class Reference

Utility to refresh links a consist will visit. More...

`#include <refresh.h>`

## Data Structures
struct | Hop
| A hop the refresh algorithm might evaluate. More...
struct | RefitDesc
| Simulated cargo type and capacity for prediction of future links. More...

## Static Public Member Functions
static void | Run (Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
| Refresh all links the given vehicle will visit.

## Protected Types
enum class | RefreshFlag : uint8_t { UseNext , HasCargo , WasRefit , ResetRefit , InAutorefit }
| Various flags about properties of the last examined link that might have an influence on the next one. More...
using | RefreshFlags = EnumBitSet< RefreshFlag, uint8_t >
typedef std::vector< RefitDesc > | RefitList
typedef std::set< Hop > | HopSet

## Protected Member Functions
| LinkRefresher (Vehicle *v, HopSet *seen_hops, bool allow_merge, bool is_full_loading)
| Constructor for link refreshing algorithm.
bool | HandleRefit (CargoType refit_cargo)
| Handle refit orders by updating capacities and refit_capacities.
void | ResetRefit ()
| Restore capacities and refit_capacities as vehicle might have been able to load now.
void | RefreshStats (VehicleOrderID cur, VehicleOrderID next)
| Refresh link stats for the given pair of orders.
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 non-conditional order in list.
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.

## Protected Attributes
Vehicle * | vehicle
| Vehicle for which the links should be refreshed.
CargoArray | capacities {}
| Current added capacities per cargo type in the consist.
RefitList | refit_capacities
| Current state of capacity remaining from previous refits versus overall capacity per vehicle 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 Refreshers of the same run.
CargoType | cargo
| Cargo given in last refit order.
bool | allow_merge
| If the refresher is allowed to merge or extend link graphs.
bool | is_full_loading
| If the vehicle is full loading.

## Detailed Description

Utility to refresh links a consist will visit.

Definition at line 19 of file refresh.h.

## Member Typedef Documentation

## ◆ HopSet

typedef std::set<Hop> LinkRefresher::HopSet
| protected

Definition at line 81 of file refresh.h.

## ◆ RefitList

typedef std::vector<RefitDesc> LinkRefresher::RefitList
| protected

Definition at line 80 of file refresh.h.

## ◆ RefreshFlags

using LinkRefresher::RefreshFlags = EnumBitSet<RefreshFlag, uint8_t>
| protected

Definition at line 36 of file refresh.h.

## Member Enumeration Documentation

## ◆ RefreshFlag

enum class LinkRefresher::RefreshFlag : uint8_t
| strongprotected

Various flags about properties of the last examined link that might have an influence on the next one.

Enumerator
UseNext | There was a conditional jump. Try to use the given next order when looking for a new one.
HasCargo | Consist could leave the last stop where it could interact with cargo carrying cargo (i.e. not an "unload all" + "no loading" order).
WasRefit | Consist was refit since the last stop where it could interact with cargo.
ResetRefit | Consist had a chance to load since the last refit and the refit capacities can be reset.
InAutorefit | Currently doing an autorefit loop. Ignore the first autorefit order.

Definition at line 28 of file refresh.h.

## Constructor & Destructor Documentation

## ◆ LinkRefresher()

LinkRefresher::LinkRefresher | ( | Vehicle * | vehicle,
|  | HopSet * | seen_hops,
|  | bool | allow_merge,
|  | bool | is_full_loading
| ) |  |
| protected

Constructor for link refreshing algorithm.

Parameters

  vehicle | Vehicle to refresh links for.
  seen_hops | Set of hops already seen. This is shared between this refresher and all its children.
  allow_merge | If the refresher is allowed to merge or extend link graphs.
  is_full_loading | If the vehicle is full loading.

Definition at line 49 of file refresh.cpp.

References capacities, Vehicle::Next(), NUM_CARGO, and refit_capacities.

## Member Function Documentation

## ◆ HandleRefit()

bool LinkRefresher::HandleRefit | ( | CargoType | refit_cargo | ) |
| protected

Handle refit orders by updating capacities and refit_capacities.

Parameters

  refit_cargo | Cargo to refit to.

Returns
  True if any vehicle was refit; false if none was.

Definition at line 68 of file refresh.cpp.

References capacities, cargo, Engine::DetermineCapacity(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), GetBestFittingSubType(), HasBit(), Vehicle::Next(), refit_capacities, VEH_AIRCRAFT, and vehicle.

Referenced by RefreshLinks().

## ◆ PredictNextOrder()

VehicleOrderID LinkRefresher::PredictNextOrder | ( | VehicleOrderID | cur,
|  | VehicleOrderID | next,
|  | RefreshFlags | flags,
|  | uint | num_hops = `0`
| ) |  |
| protected

Predict the next order the vehicle will execute and resolve conditionals by recursion and return next non-conditional order in list.

Parameters

  cur | Current order being evaluated.
  next | Next order to be evaluated.
  flags | RefreshFlags to give hints about the previous link and state carried over from that.
  num_hops | Number of hops already taken by recursive calls to this method.

Returns
  new next Order.

Definition at line 141 of file refresh.cpp.

References OrderList::GetNext(), OrderList::GetNextDecisionNode(), OrderList::GetNumOrders(), INVALID_VEH_ORDER_ID, Vehicle::orders, RefreshLinks(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UseNext, and vehicle.

Referenced by RefreshLinks().

## ◆ RefreshLinks()

void LinkRefresher::RefreshLinks | ( | VehicleOrderID | cur,
|  | VehicleOrderID | next,
|  | RefreshFlags | flags,
|  | uint | num_hops = `0`
| ) |  |
| protected

Iterate over orders starting at cur and next and refresh links associated with them.

cur and next can be equal. If they're not they must be "neighbours" in their order list, which means next must be directly reachable from cur without passing any further OT_GOTO_STATION or OT_IMPLICIT orders in between.

Parameters

  cur | Current order being evaluated.
  next | Next order to be checked.
  flags | RefreshFlags to give hints about the previous link and state carried over from that.
  num_hops | Number of hops already taken by recursive calls to this method.

Definition at line 249 of file refresh.cpp.

References Order::CanLeaveWithCargo(), cargo, CargoSpec::Get(), OrderList::GetNumOrders(), OrderList::GetOrderAt(), Order::GetRefitCargo(), HandleRefit(), HasCargo, InAutorefit, INVALID_VEH_ORDER_ID, Order::IsAutoRefit(), Order::IsRefit(), Order::IsType(), NUM_CARGO, Vehicle::orders, PredictNextOrder(), RefreshLinks(), RefreshStats(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), ResetRefit, ResetRefit(), seen_hops, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UseNext, vehicle, and WasRefit.

Referenced by PredictNextOrder(), RefreshLinks(), and Run().

## ◆ RefreshStats()

void LinkRefresher::RefreshStats | ( | VehicleOrderID | cur,
|  | VehicleOrderID | next
| ) |  |
| protected

Refresh link stats for the given pair of orders.

Parameters

  cur | Last stop where the consist could interact with cargo.
  next | Next order to be processed.

Definition at line 181 of file refresh.cpp.

References allow_merge, capacities, cargo, DistanceManhattan(), SpecializedStation< Station, false >::Get(), Vehicle::GetDisplayMaxSpeed(), SpecializedStation< Station, false >::GetIfValid(), OrderList::GetTotalDuration(), Station::goods, Increase, IncreaseStats(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, is_full_loading, Vehicle::last_station_visited, Vehicle::load_unload_ticks, NoLoad, NUM_CARGO, Vehicle::orders, RandomRange(), Refresh, Restricted, Unrestricted, vehicle, and BaseStation::xy.

Referenced by RefreshLinks().

## ◆ ResetRefit()

void LinkRefresher::ResetRefit | ( |  | ) |
| protected

Restore capacities and refit_capacities as vehicle might have been able to load now.

Definition at line 123 of file refresh.cpp.

References capacities, and refit_capacities.

Referenced by RefreshLinks().

## ◆ Run()

void LinkRefresher::Run | ( | Vehicle * | v,
|  | bool | allow_merge = `true`,
|  | bool | is_full_loading = `false`
| ) |  |
| static

Refresh all links the given vehicle will visit.

Parameters

  v | Vehicle to refresh links for.
  allow_merge | If the refresher is allowed to merge or extend link graphs.
  is_full_loading | If the vehicle is full loading.

Definition at line 26 of file refresh.cpp.

References allow_merge, BaseConsist::cur_implicit_order_index, OrderList::GetNextDecisionNode(), INVALID_VEH_ORDER_ID, is_full_loading, Vehicle::last_loading_station, Vehicle::orders, RefreshLinks(), and seen_hops.

Referenced by DeleteStaleLinks(), Vehicle::LeaveStation(), and LoadUnloadVehicle().

## Field Documentation

## ◆ allow_merge

bool LinkRefresher::allow_merge
| protected

If the refresher is allowed to merge or extend link graphs.

Definition at line 88 of file refresh.h.

Referenced by RefreshStats(), and Run().

## ◆ capacities

CargoArray LinkRefresher::capacities {}
| protected

Current added capacities per cargo type in the consist.

Definition at line 84 of file refresh.h.

Referenced by HandleRefit(), LinkRefresher(), RefreshStats(), and ResetRefit().

## ◆ cargo

CargoType LinkRefresher::cargo
| protected

Cargo given in last refit order.

Definition at line 87 of file refresh.h.

Referenced by HandleRefit(), RefreshLinks(), and RefreshStats().

## ◆ is_full_loading

bool LinkRefresher::is_full_loading
| protected

If the vehicle is full loading.

Definition at line 89 of file refresh.h.

Referenced by RefreshStats(), and Run().

## ◆ refit_capacities

RefitList LinkRefresher::refit_capacities
| protected

Current state of capacity remaining from previous refits versus overall capacity per vehicle in the consist.

Definition at line 85 of file refresh.h.

Referenced by HandleRefit(), LinkRefresher(), and ResetRefit().

## ◆ seen_hops

HopSet* LinkRefresher::seen_hops
| protected

Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Refreshers of the same run.

Definition at line 86 of file refresh.h.

Referenced by RefreshLinks(), and Run().

## ◆ vehicle

Vehicle* LinkRefresher::vehicle
| protected

Vehicle for which the links should be refreshed.

Definition at line 83 of file refresh.h.

Referenced by HandleRefit(), PredictNextOrder(), RefreshLinks(), and RefreshStats().

The documentation for this class was generated from the following files:

- src/linkgraph/refresh.h
- src/linkgraph/refresh.cpp