OpenTTD Source: GoodsEntry Struct Reference

OpenTTD Source 15.0-RC2

Data Structures | Public Types | Public Member Functions | Data Fields | Private Attributes
GoodsEntry Struct Reference

Stores station stats for a single cargo. More...

`#include <station_base.h>`

## Data Structures
struct | GoodsEntryData

## Public Types
enum class | State : uint8_t { Acceptance = 0 , Rating = 1 , EverAccepted = 2 , LastMonth = 3 , CurrentMonth = 4 , AcceptedBigtick = 5 }
| Status of this cargo for the station. More...
using | States = EnumBitSet< State, uint8_t >

## Public Member Functions
bool | HasVehicleEverTriedLoading () const
| Reports whether a vehicle has ever tried to load the cargo at this station.
bool | HasRating () const
| Does this cargo have a rating at this station?
StationID | GetVia (StationID source) const
| Get the best next hop for a cargo packet from station source.
StationID | GetVia (StationID source, StationID excluded, StationID excluded2=StationID::Invalid()) const
| Get the best next hop for a cargo packet from station source, optionally excluding one or two stations.
bool | HasData () const
| Test if this goods entry has optional cargo packet/flow data.
void | ClearData ()
| Clear optional cargo packet/flow data.
const GoodsEntryData & | GetData () const
| Get optional cargo packet/flow data.
GoodsEntryData & | GetData ()
| Get non-const optional cargo packet/flow data.
GoodsEntryData & | GetOrCreateData ()
| Get optional cargo packet/flow data.
uint8_t | ConvertState () const
| Convert GoodsEntry status to the form required for NewGRF variables.

## Data Fields
uint | max_waiting_cargo = 0
| Max cargo from this station waiting at any station.
NodeID | node = INVALID_NODE
| ID of node in link graph referring to this goods entry.
LinkGraphID | link_graph = LinkGraphID::Invalid()
| Link graph this station belongs to.
States | status {}
| Status of this cargo, see State.
uint8_t | time_since_pickup = 255
| Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
uint8_t | rating = INITIAL_STATION_RATING
| Station rating for this cargo.
uint8_t | last_speed = 0
| Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
uint8_t | last_age = 255
| Age in years (up to 255) of the last vehicle that tried to load this cargo.
uint8_t | amount_fract = 0
| Fractional part of the amount in the cargo list.

## Private Attributes
std::unique_ptr< GoodsEntryData > | data = nullptr
| Optional cargo packet and flow data.

## Detailed Description

Stores station stats for a single cargo.

Definition at line 167 of file station_base.h.

## Member Typedef Documentation

## ◆ States

using GoodsEntry::States = EnumBitSet<State, uint8_t>

Definition at line 210 of file station_base.h.

## Member Enumeration Documentation

## ◆ State

enum class GoodsEntry::State : uint8_t
| strong

Status of this cargo for the station.

Enumerator
Acceptance | Set when the station accepts the cargo currently for final deliveries. It is updated every STATION_ACCEPTANCE_TICKS ticks by checking surrounding tiles for acceptance >= 8/8.
Rating | This indicates whether a cargo has a rating at the station. Set when cargo was ever waiting at the station. It is set when cargo supplied by surrounding tiles is moved to the station, or when arriving vehicles unload/transfer cargo without it being a final delivery. This flag is cleared after 255 * STATION_RATING_TICKS of not having seen a pickup.
EverAccepted | Set when a vehicle ever delivered cargo to the station for final delivery. This flag is never cleared.
LastMonth | Set when cargo was delivered for final delivery last month. This flag is set to the value of State::CurrentMonth at the start of each month.
CurrentMonth | Set when cargo was delivered for final delivery this month. This flag is reset on the beginning of every month.
AcceptedBigtick | Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval. This flag is reset every STATION_ACCEPTANCE_TICKS ticks.

Definition at line 169 of file station_base.h.

## Member Function Documentation

## ◆ ClearData()

void GoodsEntry::ClearData | ( |  | ) |
| inline

Clear optional cargo packet/flow data.

Definition at line 310 of file station_base.h.

References data.

Referenced by LinkGraphJob::~LinkGraphJob().

## ◆ ConvertState()

uint8_t GoodsEntry::ConvertState | ( |  | ) | const

Convert GoodsEntry status to the form required for NewGRF variables.

Returns
  NewGRF representation of GoodsEntry state.

Definition at line 60 of file newgrf_station.cpp.

References AcceptedBigtick, CurrentMonth, EverAccepted, LastMonth, SetBit(), status, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ GetData() [1/2]

GoodsEntryData & GoodsEntry::GetData | ( |  | ) |
| inline

Get non-const optional cargo packet/flow data.

Precondition
  HasData()

Returns
  non-const cargo packet/flow data.

Definition at line 328 of file station_base.h.

References data, and HasData().

## ◆ GetData() [2/2]

const GoodsEntryData & GoodsEntry::GetData | ( |  | ) | const
| inline

Get optional cargo packet/flow data.

Precondition
  HasData()

Returns
  cargo packet/flow data.

Definition at line 317 of file station_base.h.

References data, and HasData().

Referenced by LinkGraphOverlay::AddLinks(), StationViewWindow::BuildCargoList(), DeleteStaleLinks(), StationViewWindow::DrawEntries(), StationViewWindow::EstimateDestinations(), GetVia(), GetVia(), LoadUnloadVehicle(), RerouteCargo(), StationResolverObject::ResolveReal(), VehicleCargoList::Stage(), TruncateCargo(), UpdateStationRating(), and LinkGraphJob::~LinkGraphJob().

## ◆ GetOrCreateData()

GoodsEntryData & GoodsEntry::GetOrCreateData | ( |  | ) |
| inline

Get optional cargo packet/flow data.

The data is create if it is not already present.

Returns
  cargo packet/flow data.

Definition at line 338 of file station_base.h.

References data, and HasData().

Referenced by LoadUnloadVehicle(), SwapPackets(), and LinkGraphJob::~LinkGraphJob().

## ◆ GetVia() [1/2]

StationID GoodsEntry::GetVia | ( | StationID | source | ) | const
| inline

Get the best next hop for a cargo packet from station source.

Parameters

  source | Source of the packet.

Returns
  The chosen next hop or StationID::Invalid() if none was found.

Definition at line 277 of file station_base.h.

References GoodsEntry::GoodsEntryData::flows, GetData(), and HasData().

Referenced by StationCargoReroute::operator()(), and VehicleCargoReroute::operator()().

## ◆ GetVia() [2/2]

StationID GoodsEntry::GetVia | ( | StationID | source,
|  | StationID | excluded,
|  | StationID | excluded2 = `StationID::Invalid()`
| ) |  | const
| inline

Get the best next hop for a cargo packet from station source, optionally excluding one or two stations.

Parameters

  source | Source of the packet.
  excluded | If this station would be chosen choose the second best one instead.
  excluded2 | Second station to be excluded, if != StationID::Invalid().

Returns
  The chosen next hop or StationID::Invalid() if none was found.

Definition at line 293 of file station_base.h.

References GoodsEntry::GoodsEntryData::flows, GetData(), and HasData().

## ◆ HasData()

bool GoodsEntry::HasData | ( |  | ) | const
| inline

Test if this goods entry has optional cargo packet/flow data.

Returns
  true iff optional data is present.

Definition at line 305 of file station_base.h.

References data.

Referenced by LinkGraphOverlay::AddLinks(), StationViewWindow::BuildCargoList(), DeleteStaleLinks(), StationViewWindow::DrawEntries(), StationViewWindow::EstimateDestinations(), GetData(), GetData(), GetOrCreateData(), GetVia(), GetVia(), LoadUnloadVehicle(), RerouteCargo(), StationResolverObject::ResolveReal(), VehicleCargoList::Stage(), TruncateCargo(), and UpdateStationRating().

## ◆ HasRating()

bool GoodsEntry::HasRating | ( |  | ) | const
| inline

Does this cargo have a rating at this station?

Returns
  true if the cargo has a rating, i.e. cargo has been moved to the station.

Definition at line 267 of file station_base.h.

References Rating, status, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by StationViewWindow::DrawCargoRatings(), LoadUnloadVehicle(), and UpdateStationRating().

## ◆ HasVehicleEverTriedLoading()

bool GoodsEntry::HasVehicleEverTriedLoading | ( |  | ) | const
| inline

Reports whether a vehicle has ever tried to load the cargo at this station.

This does not imply that there was cargo available for loading. Refer to GoodsEntry::State::Rating for that.

Returns
  true if vehicle tried to load.

Definition at line 261 of file station_base.h.

Referenced by UpdateStationRating().

## Field Documentation

## ◆ amount_fract

uint8_t GoodsEntry::amount_fract = 0

Fractional part of the amount in the cargo list.

Definition at line 254 of file station_base.h.

## ◆ data

std::unique_ptr<GoodsEntryData> GoodsEntry::data = nullptr
| private

Optional cargo packet and flow data.

Definition at line 347 of file station_base.h.

Referenced by ClearData(), GetData(), GetData(), GetOrCreateData(), and HasData().

## ◆ last_age

uint8_t GoodsEntry::last_age = 255

Age in years (up to 255) of the last vehicle that tried to load this cargo.

This does not imply there was any cargo to load.

Definition at line 252 of file station_base.h.

Referenced by LoadUnloadVehicle(), and UpdateStationRating().

## ◆ last_speed

uint8_t GoodsEntry::last_speed = 0

Maximum speed (up to 255) of the last vehicle that tried to load this cargo.

This does not imply there was any cargo to load. The unit used is a special vehicle-specific speed unit for station ratings.

- Trains: km-ish/h
- RV: km-ish/h
- Ships: 0.5 * km-ish/h
- Aircraft: 8 * mph

Definition at line 246 of file station_base.h.

Referenced by LoadUnloadVehicle(), and UpdateStationRating().

## ◆ link_graph

LinkGraphID GoodsEntry::link_graph = LinkGraphID::Invalid()

Link graph this station belongs to.

Definition at line 224 of file station_base.h.

Referenced by LinkGraphOverlay::AddLinks(), DeleteStaleLinks(), StationViewWindow::DrawCargoRatings(), IncreaseStats(), UpdateStationAcceptance(), and LinkGraphJob::~LinkGraphJob().

## ◆ max_waiting_cargo

uint GoodsEntry::max_waiting_cargo = 0

Max cargo from this station waiting at any station.

Definition at line 222 of file station_base.h.

Referenced by TruncateCargo(), and UpdateStationRating().

## ◆ node

NodeID GoodsEntry::node = INVALID_NODE

ID of node in link graph referring to this goods entry.

Definition at line 223 of file station_base.h.

Referenced by LinkGraphOverlay::AddLinks(), DeleteStaleLinks(), StationViewWindow::DrawCargoRatings(), IncreaseStats(), UpdateStationAcceptance(), and LinkGraphJob::~LinkGraphJob().

## ◆ rating

uint8_t GoodsEntry::rating = INITIAL_STATION_RATING

Station rating for this cargo.

Definition at line 235 of file station_base.h.

Referenced by StationViewWindow::DrawCargoRatings(), and UpdateStationRating().

## ◆ status

States GoodsEntry::status {}

Status of this cargo, see State.

Definition at line 226 of file station_base.h.

Referenced by LinkGraph::AddNode(), ConvertState(), HasRating(), LoadUnloadVehicle(), PrepareUnload(), UpdateStationAcceptance(), and UpdateStationRating().

## ◆ time_since_pickup

uint8_t GoodsEntry::time_since_pickup = 255

Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.

The unit used is STATION_RATING_TICKS. This does not imply there was any cargo to load.

Definition at line 233 of file station_base.h.

Referenced by LoadUnloadVehicle(), and UpdateStationRating().

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

- src/station_base.h
- src/newgrf_station.cpp