OpenTTD Source  12.0-beta2
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

CargoID Index () const
 Determines index of this cargospec. More...
 
bool IsValid () const
 Tests for validity of this cargospec. More...
 
SpriteID GetCargoIcon () const
 Get sprite for showing cargo of this type. More...
 

Static Public Member Functions

static size_t GetArraySize ()
 Total number of cargospecs, both valid and invalid. More...
 
static CargoSpecGet (size_t index)
 Retrieve cargo details for the given cargo ID. More...
 
static IterateWrapper Iterate (size_t from=0)
 Returns an iterable ensemble of all valid CargoSpec. More...
 

Data Fields

uint8 bitnum
 Cargo bit number, is INVALID_CARGO for a non-used spec.
 
CargoLabel label
 Unique label of the cargo type.
 
uint8 legend_colour
 
uint8 rating_colour
 
uint8 weight
 Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
 
uint16 multiplier
 Capacity multiplier for vehicles. (8 fractional bits)
 
int32 initial_payment
 Initial payment rate before inflation is applied.
 
uint8 transit_days [2]
 
bool is_freight
 Cargo type is considered to be freight (affects train freight multiplier).
 
TownEffect town_effect
 The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
 
uint16 multipliertowngrowth
 Size of the effect.
 
uint8 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).
 
uint16 classes
 Classes of this cargo type. More...
 
const struct GRFFilegrffile
 NewGRF where #group belongs to.
 
const struct SpriteGroupgroup
 
Money current_payment
 

Static Private Attributes

static CargoSpec array [NUM_CARGO]
 Array holding all CargoSpecs.
 

Friends

void SetupCargoForClimate (LandscapeID l)
 Set up the default cargo types for the given landscape type. More...
 

Detailed Description

Specification of a cargo type.

Definition at line 57 of file cargotype.h.

Member Function Documentation

◆ Get()

◆ GetArraySize()

static size_t CargoSpec::GetArraySize ( )
inlinestatic

Total number of cargospecs, both valid and invalid.

Returns
length of CargoSpec::array

Definition at line 109 of file cargotype.h.

References array, and lengthof.

Referenced by GetCargoTranslation().

◆ GetCargoIcon()

SpriteID CargoSpec::GetCargoIcon ( ) const

Get sprite for showing cargo of this type.

Returns
Sprite number to use.

Definition at line 139 of file cargotype.cpp.

References GetCustomCargoSprite(), and sprite.

◆ Index()

CargoID CargoSpec::Index ( ) const
inline

Determines index of this cargospec.

Returns
index (in the CargoSpec::array array)

Definition at line 90 of file cargotype.h.

References array.

Referenced by BuildLinkStatsLegend(), CompanyStationsWindow::OnClick(), 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 100 of file cargotype.h.

References INVALID_CARGO.

Referenced by CargoChangeInfo(), FinaliseCargoArray(), and IndustryCargoesWindow::OnInit().

◆ Iterate()

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

Returns an iterable ensemble of all valid CargoSpec.

Parameters
fromindex of the first CargoSpec to consider
Returns
an iterable ensemble of all valid CargoSpec

Definition at line 168 of file cargotype.h.

Referenced by FindFirstCargoWithTownEffect(), GetCargoIDByBitnum(), GetCargoIDByLabel(), and InitializeSortedCargoSpecs().

Friends And Related Function Documentation

◆ SetupCargoForClimate

void SetupCargoForClimate ( LandscapeID  l)
friend

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

Parameters
lLandscape

Definition at line 39 of file cargotype.cpp.

Field Documentation

◆ classes

uint16 CargoSpec::classes

Classes of this cargo type.

See also
CargoClass

Definition at line 80 of file cargotype.h.

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


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