OpenTTD: src/cargotype.cpp File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Functions | Variables
cargotype.cpp File Reference

Implementation of cargoes. More...

`#include "stdafx.h"`
`#include "cargotype.h"`
`#include "newgrf_cargo.h"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "core/sort_func.hpp"`
`#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.
CargoID | GetCargoIDByLabel (CargoLabel cl)
| Get the cargo ID by cargo label.
CargoID | GetCargoIDByBitnum (uint8 bitnum)
| Find the CargoID of a 'bitnum' value.
static int CDECL | CargoSpecNameSorter (const CargoSpec *const *a, const CargoSpec *const *b)
| Sort cargo specifications by their name.
static int CDECL | 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
uint32 | _cargo_mask
| Bitmask of cargo types available.
uint32 | _standard_cargo_mask
| Bitmask of real cargo types available.
const CargoSpec * | _sorted_cargo_specs [NUM_CARGO]
| Cargo specifications sorted alphabetically by name.
uint8 | _sorted_cargo_specs_size
| Number of cargo specifications stored at the _sorted_cargo_specs array (including special cargoes).
uint8 | _sorted_standard_cargo_specs_size
| Number of standard cargo specifications stored at the _sorted_cargo_specs array.

## Detailed Description

Implementation of cargoes.

Definition in file cargotype.cpp.

## Function Documentation

static int CDECL CargoSpecClassSorter | ( | const CargoSpec *const * | a,
|  | const CargoSpec *const * | b
| ) |  |
| static

Sort cargo specifications by their cargo class.

Definition at line 156 of file cargotype.cpp.

References CargoSpecNameSorter(), CC_MAIL, CC_PASSENGERS, and CC_SPECIAL.

Referenced by InitializeSortedCargoSpecs().

static int CDECL CargoSpecNameSorter | ( | const CargoSpec *const * | a,
|  | const CargoSpec *const * | b
| ) |  |
| static

Sort cargo specifications by their name.

Definition at line 141 of file cargotype.cpp.

References lastof, and strnatcmp().

Referenced by CargoSpecClassSorter().

CargoID GetCargoIDByBitnum | ( | uint8 | bitnum | ) |

Find the CargoID of a 'bitnum' value.

Parameters

  bitnum | 'bitnum' to find.

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

Definition at line 105 of file cargotype.cpp.

References CargoSpec::bitnum, CT_INVALID, CargoSpec::Index(), and INVALID_CARGO.

Referenced by GetCargoTranslation().

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 CT_INVALID

Definition at line 88 of file cargotype.cpp.

References CT_INVALID, CargoSpec::Index(), and CargoSpec::label.

Referenced by CalculateRefitMasks(), and GetCargoTranslation().

void InitializeSortedCargoSpecs | ( |  | ) |

Initialize the list of sorted cargo specifications.

Definition at line 173 of file cargotype.cpp.

References _sorted_cargo_specs_size, _sorted_standard_cargo_specs_size, _standard_cargo_mask, CargoSpecClassSorter(), CC_SPECIAL, CargoSpec::classes, FOR_ALL_SORTED_CARGOSPECS, CargoSpec::Index(), QSortT(), and SetBit().

Referenced by AfterLoadGRFs(), and ReadLanguagePack().

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::bitnum, CargoSpec::Get(), INVALID_CARGO, lengthof, CargoSpec::multiplier, and SetBit().

Referenced by ResetNewGRFData().

## Variable Documentation

uint32 _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 CalculateRefitMasks(), CargoChangeInfo(), CompanyStationsWindow::OnClick(), SetupCargoForClimate(), and ShowRefitOptionsList().

uint32 _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 CargoFilter(), and InitializeSortedCargoSpecs().