OpenTTD Source: CargoSpec Struct Reference

OpenTTD Source 15.3

Data Structures | Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Static Private Attributes | Friends
CargoSpec Struct Reference

Specification of a cargo type. More...

`#include <cargotype.h>`

## Data Structures
struct | IterateWrapper
struct | Iterator
| Iterator to iterate all valid CargoSpec. More...

## Public Member Functions
CargoType | Index () const
| Determines index of this cargospec.
bool | IsValid () const
| Tests for validity of this cargospec.
SpriteID | GetCargoIcon () const
| Get sprite for showing cargo of this type.
uint64_t | WeightOfNUnits (uint32_t n) const
uint64_t | WeightOfNUnitsInTrain (uint32_t n) const

## Static Public Member Functions
static size_t | GetArraySize ()
| Total number of cargospecs, both valid and invalid.
static CargoSpec * | Get (size_t index)
| Retrieve cargo details for the given cargo type.
static IterateWrapper | Iterate (size_t from=0)
| Returns an iterable ensemble of all valid CargoSpec.

## Data Fields
CargoLabel | label
| Unique label of the cargo type.
uint8_t | bitnum = INVALID_CARGO_BITNUM
| Cargo bit number, is INVALID_CARGO_BITNUM for a non-used spec.
PixelColour | legend_colour
PixelColour | rating_colour
uint8_t | weight
| Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
uint16_t | multiplier = 0x100
| Capacity multiplier for vehicles. (8 fractional bits)
CargoClasses | classes
| Classes of this cargo type.
int32_t | initial_payment
| Initial payment rate before inflation is applied.
uint8_t | transit_periods [2]
bool | is_freight
| Cargo type is considered to be freight (affects train freight multiplier).
TownAcceptanceEffect | town_acceptance_effect
| The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
TownProductionEffect | town_production_effect = INVALID_TPE
| The effect on town cargo production.
uint16_t | town_production_multiplier = TOWN_PRODUCTION_DIVISOR
| Town production multiplier, if commanded by TownProductionEffect.
CargoCallbackMasks | callback_mask
| Bitmask of cargo callbacks that have to be called.
StringID | name
| Name of this type of cargo.
StringID | name_single
| Name of a single entity of this type of cargo.
StringID | units_volume
| Name of a single unit of cargo of this type.
StringID | quantifier
| Text for multiple units of cargo of this type.
StringID | abbrev
| Two letter abbreviation for this cargo type.
SpriteID | sprite
| Icon to display this cargo type, may be `0xFFF` (which means to resolve an action123 chain).
const struct GRFFile * | grffile
| NewGRF where group belongs to.
const struct SpriteGroup * | group
Money | current_payment

## Static Public Attributes
static std::array< std::vector< const CargoSpec * >, NUM_TPE > | town_production_cargoes {}
| List of cargo specs for each Town Product Effect.

## Static Private Attributes
static CargoSpec | array [NUM_CARGO]
| Array holding all CargoSpecs.
static std::map< CargoLabel, CargoType > | label_map {}
| Translation map from CargoLabel to Cargo type.

## Friends
void | SetupCargoForClimate (LandscapeType l)
| Set up the default cargo types for the given landscape type.
void | BuildCargoLabelMap ()
| Build cargo label map.
CargoType | GetCargoTypeByLabel (CargoLabel ct)
void | FinaliseCargoArray ()
| Check for invalid cargoes.

## Detailed Description

Specification of a cargo type.

Definition at line 74 of file cargotype.h.

## Member Function Documentation

## ◆ Get()

static CargoSpec * CargoSpec::Get | ( | size_t | index | ) |
| inlinestatic

Retrieve cargo details for the given cargo type.

Parameters

  index | ID of cargo

Precondition
  index is a valid cargo type

Definition at line 137 of file cargotype.h.

References array, and lengthof.

Referenced by LinkGraphOverlay::AddLinks(), AfterLoadGame(), Subsidy::AwardTo(), BuildReplacementVehicle(), CargoReserveInfo(), CmdCreateSubsidy(), CMSAMine(), CargoesRow::ConnectIndustryProduced(), CreateSubsidy(), DeliverGoods(), Engine::DetermineCapacity(), CargoesField::Draw(), DrawCargoIconOverlay(), StationViewWindow::DrawCargoIcons(), DrawOrderString(), DrawVehicleRefitWindow(), SubsidyListWindow::DrawWidget(), FindSubsidyTownCargoRoute(), FormatString(), FreightWagonMult(), GetEngineLiveryScheme(), GetLoadAmount(), RoadVehicle::GetMaxWeight(), Train::GetMaxWeight(), GetRefitCostFactor(), VehicleScopeResolver::GetVariable(), GenericScopeResolver::GetVariable(), RoadVehicle::GetWeight(), Train::GetWeight(), IndustryCargoesWindow::GetWidgetString(), CompanyStationsWindow::GetWidgetString(), IndustryCargoesWindow::HousesCanSupply(), IsCargoInClass(), IsDefaultCargo(), BuildIndustryWindow::MakeCargoListString(), IndustryCargoesWindow::OnTooltip(), LinkGraphOverlay::RebuildCache(), LinkRefresher::RefreshLinks(), ReportNewsProductionChangeIndustry(), StationsWndShowStationRating(), and BaseCargoGraphWindow::UpdateWidgetSize().

## ◆ GetArraySize()

static size_t CargoSpec::GetArraySize | ( |  | ) |
| inlinestatic

Total number of cargospecs, both valid and invalid.

Returns
  length of CargoSpec::array

Definition at line 127 of file cargotype.h.

References array, and lengthof.

Referenced by FormatString().

## ◆ GetCargoIcon()

SpriteID CargoSpec::GetCargoIcon | ( |  | ) | const

Get sprite for showing cargo of this type.

Returns
  Sprite number to use.

Definition at line 176 of file cargotype.cpp.

References GetCustomCargoSprite(), and sprite.

Referenced by DrawCargoIconOverlay(), and StationViewWindow::DrawCargoIcons().

## ◆ Index()

CargoType CargoSpec::Index | ( |  | ) | const
| inline

Determines index of this cargospec.

Returns
  index (in the CargoSpec::array array)

Definition at line 108 of file cargotype.h.

References array.

Referenced by BuildLinkStatsLegend(), TownViewWindow::DrawWidget(), and TruncateCargo().

## ◆ IsValid()

bool CargoSpec::IsValid | ( |  | ) | const
| inline

Tests for validity of this cargospec.

Returns
  is this cargospec valid?

Note
  assert(cs->IsValid()) can be triggered when GRF config is modified

Definition at line 118 of file cargotype.h.

References INVALID_CARGO_BITNUM.

Referenced by LinkGraphOverlay::AddLinks(), CargoReserveInfo(), LinkGraphOverlay::RebuildCache(), and StationsWndShowStationRating().

## ◆ Iterate()

static IterateWrapper CargoSpec::Iterate | ( | size_t | from = `0` | ) |
| inlinestatic

Returns an iterable ensemble of all valid CargoSpec.

Parameters

  from | index of the first CargoSpec to consider

Returns
  an iterable ensemble of all valid CargoSpec

Definition at line 192 of file cargotype.h.

Referenced by BuildCargoTranslationMap(), CalculateRefitMasks(), FindFirstCargoWithTownAcceptanceEffect(), InitializeSortedCargoSpecs(), IndustryCargoesWindow::OnInit(), RecomputePrices(), and UpdateStationRating().

## ◆ WeightOfNUnits()

uint64_t CargoSpec::WeightOfNUnits | ( | uint32_t | n | ) | const
| inline

Definition at line 145 of file cargotype.h.

## ◆ WeightOfNUnitsInTrain()

uint64_t CargoSpec::WeightOfNUnitsInTrain | ( | uint32_t | n | ) | const

Definition at line 255 of file cargotype.cpp.

## Friends And Related Symbol Documentation

## ◆ BuildCargoLabelMap

void BuildCargoLabelMap | ( |  | ) |
| friend

Build cargo label map.

This is called multiple times during NewGRF initialization as cargos are defined, so that TranslateRefitMask() and GetCargoTranslation(), also used during initialization, get the correct information.

Definition at line 132 of file cargotype.cpp.

## ◆ FinaliseCargoArray

void FinaliseCargoArray | ( |  | ) |
| friend

Check for invalid cargoes.

Definition at line 937 of file newgrf.cpp.

## ◆ GetCargoTypeByLabel

CargoType GetCargoTypeByLabel | ( | CargoLabel | ct | ) |
| friend

Definition at line 216 of file cargotype.h.

## ◆ SetupCargoForClimate

void SetupCargoForClimate | ( | LandscapeType | l | ) |
| friend

Set up the default cargo types for the given landscape type.

Parameters

  l | Landscape

Definition at line 62 of file cargotype.cpp.

## Field Documentation

## ◆ abbrev

StringID CargoSpec::abbrev

Two letter abbreviation for this cargo type.

Definition at line 95 of file cargotype.h.

Referenced by CargoReserveInfo(), LinkGraphLegendWindow::DrawWidget(), StationsWndShowStationRating(), and LinkGraphLegendWindow::UpdateWidgetSize().

## ◆ array

CargoSpec CargoSpec::array
| staticprivate

Array holding all CargoSpecs.

Definition at line 198 of file cargotype.h.

Referenced by Get(), GetArraySize(), and Index().

## ◆ bitnum

uint8_t CargoSpec::bitnum = INVALID_CARGO_BITNUM

Cargo bit number, is INVALID_CARGO_BITNUM for a non-used spec.

Definition at line 76 of file cargotype.h.

Referenced by CargoReserveInfo(), and GenericScopeResolver::GetVariable().

## ◆ callback_mask

CargoCallbackMasks CargoSpec::callback_mask

Bitmask of cargo callbacks that have to be called.

Definition at line 89 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ classes

CargoClasses CargoSpec::classes

Classes of this cargo type.

See also
  CargoClass

Definition at line 81 of file cargotype.h.

Referenced by CargoReserveInfo(), CargoSpecClassSorter(), CMSAMine(), GetRefitCostFactor(), VehicleScopeResolver::GetVariable(), and IsCargoInClass().

## ◆ current_payment

Money CargoSpec::current_payment

Definition at line 102 of file cargotype.h.

## ◆ grffile

const struct GRFFile* CargoSpec::grffile

NewGRF where group belongs to.

Definition at line 99 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ group

const struct SpriteGroup* CargoSpec::group

Definition at line 100 of file cargotype.h.

## ◆ initial_payment

int32_t CargoSpec::initial_payment

Initial payment rate before inflation is applied.

Definition at line 82 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ is_freight

bool CargoSpec::is_freight

Cargo type is considered to be freight (affects train freight multiplier).

Definition at line 85 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ label

CargoLabel CargoSpec::label

Unique label of the cargo type.

Definition at line 75 of file cargotype.h.

Referenced by CargoReserveInfo(), and CargoResolverObject::GetDebugID().

## ◆ label_map

std::map<CargoLabel, CargoType> CargoSpec::label_map {}
| inlinestaticprivate

Translation map from CargoLabel to Cargo type.

Definition at line 199 of file cargotype.h.

## ◆ legend_colour

PixelColour CargoSpec::legend_colour

Definition at line 77 of file cargotype.h.

## ◆ multiplier

uint16_t CargoSpec::multiplier = 0x100

Capacity multiplier for vehicles. (8 fractional bits)

Definition at line 80 of file cargotype.h.

Referenced by CargoReserveInfo(), Engine::DetermineCapacity(), and GetLoadAmount().

## ◆ name

StringID CargoSpec::name

Name of this type of cargo.

Definition at line 91 of file cargotype.h.

Referenced by Subsidy::AwardTo(), BuildLinkStatsLegend(), BuildReplacementVehicle(), CargoReserveInfo(), CargoSpecNameSorter(), CreateSubsidy(), CargoesField::Draw(), DrawOrderString(), DrawVehicleRefitWindow(), SubsidyListWindow::DrawWidget(), TownViewWindow::DrawWidget(), IndustryCargoesWindow::GetWidgetString(), CompanyStationsWindow::GetWidgetString(), IndustryCargoesWindow::OnTooltip(), LinkGraphLegendWindow::OnTooltip(), ReportNewsProductionChangeIndustry(), and BaseCargoGraphWindow::UpdateWidgetSize().

## ◆ name_single

StringID CargoSpec::name_single

Name of a single entity of this type of cargo.

Definition at line 92 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ quantifier

StringID CargoSpec::quantifier

Text for multiple units of cargo of this type.

Definition at line 94 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ rating_colour

PixelColour CargoSpec::rating_colour

Definition at line 78 of file cargotype.h.

## ◆ sprite

SpriteID CargoSpec::sprite

Icon to display this cargo type, may be `0xFFF` (which means to resolve an action123 chain).

Definition at line 97 of file cargotype.h.

Referenced by CargoReserveInfo(), and GetCargoIcon().

## ◆ town_acceptance_effect

TownAcceptanceEffect CargoSpec::town_acceptance_effect

The effect that delivering this cargo type has on towns. Also affects destination of subsidies.

Definition at line 86 of file cargotype.h.

Referenced by AfterLoadGame(), CargoReserveInfo(), and DeliverGoods().

## ◆ town_production_cargoes

std::array< std::vector< const CargoSpec * >, NUM_TPE > CargoSpec::town_production_cargoes {}
| static

List of cargo specs for each Town Product Effect.

Definition at line 25 of file cargotype.h.

Referenced by TownViewWindow::DrawWidget(), FindSubsidyPassengerRoute(), FindSubsidyTownCargoRoute(), TownViewWindow::GetDesiredInfoHeight(), GetProducedCargoOfHouse(), InitializeSortedCargoSpecs(), TownGenerateCargoBinomial(), TownGenerateCargoOriginal(), and UpdateTownMaxPass().

## ◆ town_production_effect

TownProductionEffect CargoSpec::town_production_effect = INVALID_TPE

The effect on town cargo production.

Definition at line 87 of file cargotype.h.

Referenced by CargoReserveInfo(), CargoesRow::ConnectIndustryProduced(), and IndustryCargoesWindow::HousesCanSupply().

## ◆ town_production_multiplier

uint16_t CargoSpec::town_production_multiplier = TOWN_PRODUCTION_DIVISOR

Town production multiplier, if commanded by TownProductionEffect.

Definition at line 88 of file cargotype.h.

Referenced by CargoReserveInfo().

## ◆ transit_periods

uint8_t CargoSpec::transit_periods[2]

Definition at line 83 of file cargotype.h.

## ◆ units_volume

StringID CargoSpec::units_volume

Name of a single unit of cargo of this type.

Definition at line 93 of file cargotype.h.

Referenced by CargoReserveInfo(), and FormatString().

## ◆ weight

uint8_t CargoSpec::weight

Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).

Definition at line 79 of file cargotype.h.

Referenced by CargoReserveInfo(), and VehicleScopeResolver::GetVariable().

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

- src/cargotype.h
- src/cargotype.cpp