OpenTTD Source: src/cargotype.h File Reference

OpenTTD Source 14.0-beta1

Data Structures | Typedefs | Enumerations | Functions | Variables
cargotype.h File Reference
`#include "economy_type.h"`
`#include "cargo_type.h"`
`#include "gfx_type.h"`
`#include "strings_type.h"`
`#include "landscape_type.h"`
`#include "core/bitmath_func.hpp"`

Go to the source code of this file.

## Data Structures
struct | CargoSpec
| Specification of a cargo type. More...
struct | CargoSpec::Iterator
| Iterator to iterate all valid CargoSpec. More...
struct | CargoSpec::IterateWrapper
struct | CargoIDComparator
| Comparator to sort CargoID by according to desired order. More...

## Typedefs
typedef uint32_t | CargoLabel
| Globally unique label of a cargo type.
using | SetCargoBitIterator = SetBitIterator< CargoID, CargoTypes >

## Enumerations
enum | TownAcceptanceEffect : byte { TAE_BEGIN = 0, TAE_NONE = TAE_BEGIN, TAE_PASSENGERS, TAE_MAIL, TAE_GOODS, TAE_WATER, TAE_FOOD, TAE_END, NUM_TAE = TAE_END }
| Town growth effect when delivering cargo. More...
enum | TownProductionEffect : byte { TPE_NONE, TPE_PASSENGERS, TPE_MAIL, NUM_TPE, INVALID_TPE }
| Town effect when producing cargo. More...
enum | CargoClass { CC_NOAVAILABLE = 0, CC_PASSENGERS = 1 << 0, CC_MAIL = 1 << 1, CC_EXPRESS = 1 << 2, CC_ARMOURED = 1 << 3, CC_BULK = 1 << 4, CC_PIECE_GOODS = 1 << 5, CC_LIQUID = 1 << 6, CC_REFRIGERATED = 1 << 7, CC_HAZARDOUS = 1 << 8, CC_COVERED = 1 << 9, CC_SPECIAL = 1 << 15 }
| Cargo classes. More...

## Functions
void | SetupCargoForClimate (LandscapeID l)
| Set up the default cargo types for the given landscape type. More...
CargoID | GetCargoIDByLabel (CargoLabel cl)
| Get the cargo ID by cargo label. More...
CargoID | GetCargoIDByBitnum (uint8_t bitnum)
| Find the CargoID of a 'bitnum' value. More...
CargoID | GetDefaultCargoID (LandscapeID l, CargoType ct)
| Get the cargo ID of a default cargo, if present. More...
Dimension | GetLargestCargoIconSize ()
| Get dimensions of largest cargo icon. More...
void | InitializeSortedCargoSpecs ()
| Initialize the list of sorted cargo specifications.
bool | IsCargoInClass (CargoID c, CargoClass cc)
| Does cargo c have cargo class cc? More...

## Variables
static const byte | INVALID_CARGO_BITNUM = 0xFF
| Constant representing invalid cargo.
static const uint | TOWN_PRODUCTION_DIVISOR = 256
CargoTypes | _cargo_mask
| Bitmask of cargo types available. More...
CargoTypes | _standard_cargo_mask
| Bitmask of real cargo types available. More...
std::array< uint8_t, NUM_CARGO > | _sorted_cargo_types
| Sort order of cargoes by cargo ID.
std::vector< const CargoSpec * > | _sorted_cargo_specs
| Cargo specifications sorted alphabetically by name.
std::span< const CargoSpec * > | _sorted_standard_cargo_specs
| Standard cargo specifications sorted alphabetically by name.

## Detailed Description

Types/functions related to cargoes.

Definition in file cargotype.h.

## Enumeration Type Documentation

## ◆ CargoClass

enum CargoClass

Cargo classes.

Enumerator
CC_NOAVAILABLE | No cargo class has been specified.
CC_PASSENGERS | Passengers.
CC_MAIL | Mail.
CC_EXPRESS | Express cargo (Goods, Food, Candy, but also possible for passengers)
CC_ARMOURED | Armoured cargo (Valuables, Gold, Diamonds)
CC_BULK | Bulk cargo (Coal, Grain etc., Ores, Fruit)
CC_PIECE_GOODS | Piece goods (Livestock, Wood, Steel, Paper)
CC_LIQUID | Liquids (Oil, Water, Rubber)
CC_REFRIGERATED | Refrigerated cargo (Food, Fruit)
CC_HAZARDOUS | Hazardous cargo (Nuclear Fuel, Explosives, etc.)
CC_COVERED | Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
CC_SPECIAL | Special bit used for livery refit tricks instead of normal cargoes.

Definition at line 51 of file cargotype.h.

## ◆ TownAcceptanceEffect

enum TownAcceptanceEffect : byte

Town growth effect when delivering cargo.

Enumerator
TAE_NONE | Cargo has no effect.
TAE_PASSENGERS | Cargo behaves passenger-like.
TAE_MAIL | Cargo behaves mail-like.
TAE_GOODS | Cargo behaves goods/candy-like.
TAE_WATER | Cargo behaves water-like.
TAE_FOOD | Cargo behaves food/fizzy-drinks-like.
TAE_END | End of town effects.
NUM_TAE | Amount of town effects.

Definition at line 24 of file cargotype.h.

## ◆ TownProductionEffect

enum TownProductionEffect : byte

Town effect when producing cargo.

Enumerator
TPE_NONE | Town will not produce this cargo type.
TPE_PASSENGERS | Cargo behaves passenger-like for production.
TPE_MAIL | Cargo behaves mail-like for production.
INVALID_TPE | Invalid town production effect. Used as a sentinel to indicate if a NewGRF has explicitly set an effect. This does not 'exist' after cargo types are finalised.

Definition at line 37 of file cargotype.h.

## Function Documentation

## ◆ GetCargoIDByBitnum()

CargoID GetCargoIDByBitnum | ( | uint8_t | bitnum | ) |

Find the CargoID of a 'bitnum' value.

Parameters

  bitnum | 'bitnum' to find.

Returns
  First CargoID with the given bitnum, or #INVALID_CARGO if not found or if the provided bitnum is invalid.

Definition at line 131 of file cargotype.cpp.

References INVALID_CARGO_BITNUM.

## ◆ GetCargoIDByLabel()

CargoID GetCargoIDByLabel | ( | CargoLabel | cl | ) |

Get the cargo ID by cargo label.

Parameters

  cl | Cargo type to get.

Returns
  ID number if the cargo exists, else #INVALID_CARGO

Definition at line 115 of file cargotype.cpp.

References CargoSpec::Iterate().

## ◆ GetDefaultCargoID()

CargoID GetDefaultCargoID | ( | LandscapeID | l,
|  | CargoType | ct
| ) |  |

Get the cargo ID of a default cargo, if present.

Parameters

  l | Landscape
  ct | Default cargo type.

Returns
  ID number if the cargo exists, else #INVALID_CARGO

Definition at line 94 of file cargotype.cpp.

References _default_climate_cargo, IsValidCargoType(), and lengthof.

Referenced by CalculateRefitMasks().

## ◆ GetLargestCargoIconSize()

Dimension GetLargestCargoIconSize | ( |  | ) |

Get dimensions of largest cargo icon.

Returns
  Dimensions of largest cargo icon.

Definition at line 79 of file cargotype.cpp.

References _sorted_cargo_specs, GetSpriteSize(), and maxdim().

Referenced by BaseVehicleListWindow::BuildCargoDropDownList().

## ◆ IsCargoInClass()

bool IsCargoInClass | ( | CargoID | c,
|  | CargoClass | cc
| ) |  |
| inline

Does cargo c have cargo class cc?

Parameters

  c | Cargo type.
  cc | Cargo class.

Returns
  The type fits in the class.

Definition at line 222 of file cargotype.h.

References CargoSpec::Get().

Referenced by CargoFilterSingle(), Vehicle::Crash(), RoadVehicle::IsBus(), and UpdateStationAcceptance().

## ◆ SetupCargoForClimate()

void SetupCargoForClimate | ( | LandscapeID | l | ) |

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

Parameters

  l | Landscape

Definition at line 42 of file cargotype.cpp.

References _cargo_mask, _default_cargo, _default_climate_cargo, CargoSpec::array, CargoSpec::label, and lengthof.

## Variable Documentation

## ◆ _cargo_mask

CargoTypes _cargo_mask

Bitmask of cargo types available.

This includes phony cargoes like regearing cargoes. Initialized during a call to SetupCargoForClimate.

Definition at line 31 of file cargotype.cpp.

Referenced by SetupCargoForClimate().

## ◆ _standard_cargo_mask

CargoTypes _standard_cargo_mask

Bitmask of real cargo types available.

Phony cargoes like regearing cargoes are excluded.

Definition at line 36 of file cargotype.cpp.

Referenced by CargoAndEngineFilter(), InitializeSortedCargoSpecs(), and BuildVehicleWindow::SetCargoFilterArray().