OpenTTD Source: src/cargotype.cpp File Reference

OpenTTD Source 14.0-RC3

Functions | Variables
cargotype.cpp File Reference
`#include "stdafx.h"`
`#include "cargotype.h"`
`#include "core/geometry_func.hpp"`
`#include "newgrf_cargo.h"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "settings_type.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`
`#include "table/cargo_const.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
void | SetupCargoForClimate (LandscapeID l)
| Set up the default cargo types for the given landscape type. More...
void | BuildCargoLabelMap ()
| Build cargo label map. More...
bool | IsDefaultCargo (CargoID cid)
| Test if a cargo is a default cargo type. More...
Dimension | GetLargestCargoIconSize ()
| Get dimensions of largest cargo icon. More...
CargoID | GetCargoIDByBitnum (uint8_t bitnum)
| Find the CargoID of a 'bitnum' value. More...
static bool | CargoSpecNameSorter (const CargoSpec *const &a, const CargoSpec *const &b)
| Sort cargo specifications by their name.
static bool | CargoSpecClassSorter (const CargoSpec *const &a, const CargoSpec *const &b)
| Sort cargo specifications by their cargo class.
void | InitializeSortedCargoSpecs ()
| Initialize the list of sorted cargo specifications.

## Variables
CargoTypes | _cargo_mask
| Bitmask of cargo types available. More...
CargoTypes | _standard_cargo_mask
| Bitmask of real cargo types available. More...
static std::vector< CargoLabel > | _default_cargo_labels
| List of default cargo labels, used when setting up cargo types for default vehicles. 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

Implementation of cargoes.

Definition in file cargotype.cpp.

## Function Documentation

## ◆ 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 93 of file cargotype.cpp.

References CargoSpec::array, and CargoSpec::label_map.

## ◆ 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 138 of file cargotype.cpp.

References INVALID_CARGO_BITNUM.

## ◆ GetLargestCargoIconSize()

Dimension GetLargestCargoIconSize | ( |  | ) |

Get dimensions of largest cargo icon.

Returns
  Dimensions of largest cargo icon.

Definition at line 124 of file cargotype.cpp.

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

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

## ◆ 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 111 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 48 of file cargotype.cpp.

References _cargo_mask, _default_cargo, _default_cargo_labels, _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().

## ◆ _default_cargo_labels

std::vector<CargoLabel> _default_cargo_labels
| static

List of default cargo labels, used when setting up cargo types for default vehicles.

This is done by label so that a cargo label can be redefined in a different slot.

Definition at line 42 of file cargotype.cpp.

Referenced by IsDefaultCargo(), and 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().