OpenTTD Source 20261129-master-g72a8bdc861
GoodsEntry Struct Reference

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

#include <station_base.h>

Data Structures

struct  GoodsEntryData
struct  CargoHistory
 Individual data point for station cargo history. More...
struct  CargoHistoryData
 Storage for station cargo history. More...

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>
 Bitset of State elements.

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.
bool HasHistory () const
 Test if cargo history is present.
const CargoHistoryData & GetHistory () const
 Get the cargo history data.
CargoHistoryData & GetHistory ()
 Get the cargo history data.
CargoHistoryData & GetOrCreateHistory ()
 Get or create the cargo history data.
uint8_t ConvertState () const
 Convert GoodsEntry status to the form required for NewGRF variables.
uint AvailableCount () const
 Returns sum of cargo still available for loading at the station.
uint TotalCount () const
 Returns total count of cargo at the station, including cargo which is already reserved for loading.

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.
uint16_t accumulated_rating = 0
 Accumulated rating over the last month.

Private Attributes

std::unique_ptr< GoodsEntryData > data = nullptr
 Optional cargo packet and flow data.
std::unique_ptr< CargoHistoryData > stats
 Optional cargo history data.

Detailed Description

Stores station stats for a single cargo.

Definition at line 168 of file station_base.h.

Member Typedef Documentation

◆ States

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

Bitset of State elements.

Definition at line 213 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 170 of file station_base.h.

Member Function Documentation

◆ AvailableCount()

uint GoodsEntry::AvailableCount ( ) const
inline

Returns sum of cargo still available for loading at the station.

(i.e. not counting cargo which is already reserved for loading)

Returns
Cargo on board the vehicle.

Definition at line 411 of file station_base.h.

References StationCargoList::AvailableCount(), GoodsEntry::GoodsEntryData::cargo, GetData(), and HasData().

Referenced by AfterLoadGame(), LoadUnloadVehicle(), and UpdateStationRating().

◆ ClearData()

void GoodsEntry::ClearData ( )
inline

Clear optional cargo packet/flow data.

Definition at line 334 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 61 of file newgrf_station.cpp.

References AcceptedBigtick, CurrentMonth, EverAccepted, LastMonth, SetBit(), and status.

◆ 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 352 of file station_base.h.

References data, debug_inline, and HasData().

◆ GetData() [2/2]

◆ GetHistory() [1/2]

CargoHistoryData & GoodsEntry::GetHistory ( )
inline

Get the cargo history data.

Returns
the cargo history data.

Definition at line 388 of file station_base.h.

References HasHistory(), and stats.

◆ GetHistory() [2/2]

const CargoHistoryData & GoodsEntry::GetHistory ( ) const
inline

Get the cargo history data.

Returns
the cargo history data.

Definition at line 378 of file station_base.h.

References HasHistory(), and stats.

Referenced by SlStationCargoHistoryData::Save(), and StationGraphWindow::UpdateStatistics().

◆ 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 362 of file station_base.h.

References data, and HasData().

Referenced by SlStationCargo::Load(), SlStationFlow::Load(), SlStationGoods::Load(), LoadUnloadVehicle(), SwapPackets(), and LinkGraphJob::~LinkGraphJob().

◆ GetOrCreateHistory()

CargoHistoryData & GoodsEntry::GetOrCreateHistory ( )
inline

Get or create the cargo history data.

Returns
the cargo history data.

Definition at line 398 of file station_base.h.

References HasHistory(), and stats.

Referenced by SlStationCargoHistoryData::Load(), MaybeCrashAirplane(), and UpdateStationRating().

◆ GetVia() [1/2]

StationID GoodsEntry::GetVia ( StationID source) const
inline

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

Parameters
sourceSource of the packet.
Returns
The chosen next hop or StationID::Invalid() if none was found.

Definition at line 301 of file station_base.h.

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

◆ 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
sourceSource of the packet.
excludedIf this station would be chosen choose the second best one instead.
excluded2Second station to be excluded, if != StationID::Invalid().
Returns
The chosen next hop or StationID::Invalid() if none was found.

Definition at line 317 of file station_base.h.

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

◆ HasData()

◆ HasHistory()

bool GoodsEntry::HasHistory ( ) const
inline

Test if cargo history is present.

Returns
true iff cargo history is present.

Definition at line 372 of file station_base.h.

References stats.

Referenced by GetHistory(), GetHistory(), GetOrCreateHistory(), SlStationCargoHistoryData::Save(), and StationGraphWindow::UpdateStatistics().

◆ 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 291 of file station_base.h.

References Rating, 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 285 of file station_base.h.

Referenced by UpdateStationRating().

◆ TotalCount()

uint GoodsEntry::TotalCount ( ) const
inline

Returns total count of cargo at the station, including cargo which is already reserved for loading.

Returns
Total cargo count.

Definition at line 421 of file station_base.h.

References GoodsEntry::GoodsEntryData::cargo, GetData(), HasData(), and StationCargoList::TotalCount().

Referenced by StationResolverObject::ResolveReal(), and UpdateStationRating().

Field Documentation

◆ accumulated_rating

uint16_t GoodsEntry::accumulated_rating = 0

Accumulated rating over the last month.

Definition at line 278 of file station_base.h.

◆ amount_fract

uint8_t GoodsEntry::amount_fract = 0

Fractional part of the amount in the cargo list.

Definition at line 276 of file station_base.h.

◆ data

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

Optional cargo packet and flow data.

Definition at line 427 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 274 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 268 of file station_base.h.

Referenced by AfterLoadGame(), LoadUnloadVehicle(), and UpdateStationRating().

◆ link_graph

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

◆ max_waiting_cargo

uint GoodsEntry::max_waiting_cargo = 0

Max cargo from this station waiting at any station.

Definition at line 244 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 245 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

◆ stats

std::unique_ptr<CargoHistoryData> GoodsEntry::stats
private

Optional cargo history data.

Definition at line 428 of file station_base.h.

Referenced by GetHistory(), GetHistory(), GetOrCreateHistory(), and HasHistory().

◆ status

◆ 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 255 of file station_base.h.

Referenced by LoadUnloadVehicle(), and UpdateStationRating().


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