OpenTTD Source: src/cargotype.h File Reference

OpenTTD Source 15.0-beta1

Data Structures | Typedefs | Enumerations | Functions | Variables
cargotype.h File Reference

Types/functions related to cargoes. More...

`#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
using | CargoClasses = uint16_t
| Bitmask of cargo classes.
using | SetCargoBitIterator = SetBitIterator< CargoID, CargoTypes >

## Enumerations
enum | TownAcceptanceEffect : uint8_t { 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 : uint8_t { TPE_NONE , TPE_PASSENGERS , TPE_MAIL , NUM_TPE , INVALID_TPE }
| Town effect when producing cargo. More...
enum | CargoClass : uint16_t { 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_OVERSIZED = 1 << 10 , CC_POWDERIZED = 1 << 11 , CC_NOT_POURABLE = 1 << 12 , CC_POTABLE = 1 << 13 , CC_NON_POTABLE = 1 << 14 , CC_SPECIAL = 1 << 15 }
| Cargo classes. More...

## Functions
void | SetupCargoForClimate (LandscapeID l)
| Set up the default cargo types for the given landscape type.
bool | IsDefaultCargo (CargoID cid)
| Test if a cargo is a default cargo type.
void | BuildCargoLabelMap ()
| Build cargo label map.
std::optional< std::string > | BuildCargoAcceptanceString (const CargoArray &acceptance, StringID label)
| Build comma-separated cargo acceptance string.
CargoID | GetCargoIDByLabel (CargoLabel label)
Dimension | GetLargestCargoIconSize ()
| Get dimensions of largest cargo icon.
void | InitializeSortedCargoSpecs ()
| Initialize the list of sorted cargo specifications.
bool | IsCargoInClass (CargoID c, CargoClass cc)
| Does cargo c have cargo class cc?

## Variables
static const uint8_t | INVALID_CARGO_BITNUM = 0xFF
| Constant representing invalid cargo.
static const uint | TOWN_PRODUCTION_DIVISOR = 256
CargoTypes | _cargo_mask
| Bitmask of cargo types available.
CargoTypes | _standard_cargo_mask
| Bitmask of real cargo types available.
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.

## Typedef Documentation

## ◆ CargoClasses

using CargoClasses = uint16_t

Bitmask of cargo classes.

Definition at line 69 of file cargotype.h.

## ◆ SetCargoBitIterator

using SetCargoBitIterator = SetBitIterator<CargoID, CargoTypes>

Definition at line 244 of file cargotype.h.

## Enumeration Type Documentation

## ◆ CargoClass

enum CargoClass : uint16_t

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_OVERSIZED | Oversized (stake/flatbed wagon)
CC_POWDERIZED | Powderized, moist protected (powder/silo wagon)
CC_NOT_POURABLE | Not Pourable (open wagon, but not hopper wagon)
CC_POTABLE | Potable / food / clean.
CC_NON_POTABLE | Non-potable / non-food / dirty.
CC_SPECIAL | Special bit used for livery refit tricks instead of normal cargoes.

Definition at line 48 of file cargotype.h.

## ◆ TownAcceptanceEffect

enum TownAcceptanceEffect : uint8_t

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

## ◆ TownProductionEffect

enum TownProductionEffect : uint8_t

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

## Function Documentation

## ◆ BuildCargoAcceptanceString()

std::optional< std::string > BuildCargoAcceptanceString | ( | const CargoArray & | acceptance,
|  | StringID | label
| ) |  |

Build comma-separated cargo acceptance string.

Parameters

  acceptance | CargoArray filled with accepted cargo.
  label | Label to prefix cargo acceptance list.

Returns
  String of accepted cargo, or nullopt if no cargo is accepted.

Definition at line 269 of file cargotype.cpp.

References _sorted_cargo_specs, GetListSeparator(), GetString(), and SetDParam().

Referenced by BuildHouseWindow::GetHouseInformation(), and LandInfoWindow::OnInit().

## ◆ BuildCargoLabelMap()

void BuildCargoLabelMap | ( |  | ) |

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 205 of file cargotype.cpp.

Referenced by CargoChangeInfo().

## ◆ GetCargoIDByLabel()

CargoID GetCargoIDByLabel | ( | CargoLabel | label | ) |
| inline

Definition at line 219 of file cargotype.h.

## ◆ GetLargestCargoIconSize()

Dimension GetLargestCargoIconSize | ( |  | ) |

Get dimensions of largest cargo icon.

Returns
  Dimensions of largest cargo icon.

Definition at line 165 of file cargotype.cpp.

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

Referenced by BaseVehicleListWindow::BuildCargoDropDownList(), DrawAircraftImage(), IndustryCargoesWindow::OnClick(), IndustryViewWindow::OnInit(), and SubsidyListWindow::OnInit().

## ◆ InitializeSortedCargoSpecs()

void InitializeSortedCargoSpecs | ( |  | ) |

Initialize the list of sorted cargo specifications.

Definition at line 225 of file cargotype.cpp.

References _sorted_cargo_specs, _sorted_cargo_types, _sorted_standard_cargo_specs, _standard_cargo_mask, CargoSpecClassSorter(), CC_SPECIAL, INVALID_TPE, CargoSpec::Iterate(), SetBit(), and CargoSpec::town_production_cargoes.

Referenced by AfterLoadGRFs(), and ReadLanguagePack().

## ◆ 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 239 of file cargotype.h.

References CargoSpec::Get().

Referenced by CargoFilterSingle(), Vehicle::Crash(), Engine::DetermineCapacity(), MultiCommodityFlow::Dijkstra(), DrawStationCoverageAreaText(), GetEngineLiveryScheme(), RoadVehicle::IsBus(), LoadUnloadVehicle(), and UpdateStationAcceptance().

## ◆ IsDefaultCargo()

bool IsDefaultCargo | ( | CargoID | cid | ) |

Test if a cargo is a default cargo type.

Parameters

  cid | Cargo ID.

Returns
  true iff the cargo type is a default cargo type.

Definition at line 152 of file cargotype.cpp.

References _default_cargo_labels, and CargoSpec::Get().

Referenced by CalculateRefitMasks().

## ◆ SetupCargoForClimate()

void SetupCargoForClimate | ( | LandscapeID | l | ) |

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

Parameters

  l | Landscape

Definition at line 204 of file cargotype.cpp.

Referenced by ResetNewGRFData().

## Variable Documentation

## ◆ _cargo_mask

CargoTypes _cargo_mask
| extern

Bitmask of cargo types available.

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

Definition at line 33 of file cargotype.cpp.

Referenced by CalculateRefitMasks(), CargoChangeInfo(), CompanyStationsWindow::OnDropdownSelect(), CompanyStationsWindow::SetStringParameters(), and ShowRefitOptionsList().

## ◆ _sorted_cargo_specs

std::vector<const CargoSpec *> _sorted_cargo_specs
| extern

Cargo specifications sorted alphabetically by name.

Definition at line 192 of file cargotype.cpp.

Referenced by BuildCargoAcceptanceString(), BaseVehicleListWindow::BuildCargoDropDownList(), BuildLinkStatsLegend(), RefitWindow::BuildRefitList(), DrawRoadVehDetails(), DrawTrainDetails(), LinkGraphLegendWindow::DrawWidget(), FormatString(), GetLargestCargoIconSize(), InitializeSortedCargoSpecs(), LinkGraphLegendWindow::OnInvalidateData(), DepotWindow::OnRightClick(), LinkGraphLegendWindow::OnTooltip(), LinkGraphLegendWindow::SetOverlay(), LinkGraphLegendWindow::UpdateOverlayCargoes(), and LinkGraphLegendWindow::UpdateWidgetSize().

## ◆ _sorted_cargo_types

std::array<uint8_t, NUM_CARGO> _sorted_cargo_types
| extern

Sort order of cargoes by cargo ID.

Definition at line 191 of file cargotype.cpp.

Referenced by InitializeSortedCargoSpecs().

## ◆ _sorted_standard_cargo_specs

std::span<const CargoSpec *> _sorted_standard_cargo_specs
| extern

Standard cargo specifications sorted alphabetically by name.

Definition at line 193 of file cargotype.cpp.

Referenced by StationViewWindow::DrawCargoRatings(), PaymentRatesGraphWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), InitializeSortedCargoSpecs(), PaymentRatesGraphWindow::OnClick(), IndustryCargoesWindow::OnClick(), PaymentRatesGraphWindow::UpdatePaymentRates(), PaymentRatesGraphWindow::UpdateWidgetSize(), and CompanyStationsWindow::UpdateWidgetSize().

## ◆ _standard_cargo_mask

CargoTypes _standard_cargo_mask
| extern

Bitmask of real cargo types available.

Phony cargoes like regearing cargoes are excluded.

Definition at line 38 of file cargotype.cpp.

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

## ◆ INVALID_CARGO_BITNUM

const uint8_t INVALID_CARGO_BITNUM = 0xFF
| static

Constant representing invalid cargo.

Definition at line 71 of file cargotype.h.

Referenced by CargoSpec::IsValid().

## ◆ TOWN_PRODUCTION_DIVISOR

const uint TOWN_PRODUCTION_DIVISOR = 256
| static

Definition at line 73 of file cargotype.h.