# CargoSpec Struct Reference

Specification of a cargo type. More...

`#include <cargotype.h>`

## Public Member Functions
FORCEINLINE CargoID | Index () const
| Determines index of this cargospec.
FORCEINLINE bool | IsValid () const
| Tests for validity of this cargospec.
SpriteID | GetCargoIcon () const
| Get sprite for showing cargo of this type.
## Static Public Member Functions
static FORCEINLINE size_t | GetArraySize ()
| Total number of cargospecs, both valid and invalid.
static FORCEINLINE CargoSpec * | Get (size_t index)
| Retrieve cargo details for the given cargo ID.
## 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 | initial_payment
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.
struct GRFFile * | grffile
| NewGRF where group belongs to.
struct SpriteGroup * | group
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.

## Detailed Description

Specification of a cargo type.

Definition at line 53 of file cargotype.h.

## Member Function Documentation

FORCEINLINE CargoID CargoSpec::Index | ( |  | ) | const`[inline]`

Determines index of this cargospec.

Returns:
  index (in the CargoSpec::array array)

Definition at line 85 of file cargotype.h.

References array.

Referenced by CalculateRefitMasks(), StationViewWindow::DrawCargoRatings(), CompanyStationsWindow::DrawWidget(), GetCargoIDByBitnum(), GetCargoIDByLabel(), MakeCargoButtons(), and CompanyStationsWindow::OnClick().

FORCEINLINE 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 95 of file cargotype.h.

References bitnum, and INVALID_CARGO.

Referenced by CargoWidgets(), CompanyStationsWindow::DrawWidget(), CompanyStationsWindow::OnClick(), StationsWndShowStationRating(), TownHouseChangeInfo(), and CompanyStationsWindow::UpdateWidgetSize().

static FORCEINLINE size_t CargoSpec::GetArraySize | ( |  | ) | `[inline, static]`

Total number of cargospecs, both valid and invalid.

Returns:
  length of CargoSpec::array

Definition at line 104 of file cargotype.h.

References array, and lengthof.

static FORCEINLINE CargoSpec* CargoSpec::Get | ( | size_t | index | ) | `[inline, static]`

Retrieve cargo details for the given cargo ID.

Parameters:

  | index | ID of cargo

Precondition:
  index is a valid cargo ID

Definition at line 114 of file cargotype.h.

References array, and lengthof.

Referenced by CargoWidgets(), CMSAForest(), CMSAMine(), DeliverGoods(), DrawCargoIcons(), DrawCargoListText(), DrawOrderString(), DrawVehicleRefitWindow(), CompanyStationsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), FreightWagonMult(), AICargo::GetCargoLabel(), GetEngineLivery(), AICargo::GetTownEffect(), IsCargoInClass(), AICargo::IsFreight(), AICargo::IsValidCargo(), CompanyStationsWindow::OnClick(), ReportNewsProductionChangeIndustry(), SetupCargoForClimate(), ShowRefitOptionsList(), ShowRejectOrAcceptNews(), StationsWndShowStationRating(), TileLoop_Town(), TownHouseChangeInfo(), TrainCargoChanged(), CompanyStationsWindow::UpdateWidgetSize(), and BuildIndustryWindow::UpdateWidgetSize().

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

Get sprite for showing cargo of this type.

Returns:
  Sprite number to use.

Definition at line 103 of file cargotype.cpp.

References sprite.

Referenced by DrawCargoIcons().

## Friends And Related Function Documentation

void SetupCargoForClimate | ( | LandscapeID | l | ) | `[friend]`

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

Parameters:

  | l | Landscape

Definition at line 31 of file cargotype.cpp.

## Field Documentation

uint16 CargoSpec::classes

Classes of this cargo type.

See also:
  CargoClass

Definition at line 75 of file cargotype.h.

Referenced by CalculateRefitMasks(), and CMSAMine().

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

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