OpenTTD: src/cargotype.h File Reference

OpenTTD

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

- File List
- Globals

Data Structures | Macros | 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"`

Go to the source code of this file.

## Data Structures
struct | CargoSpec
| Specification of a cargo type. More...

## Macros
#define | FOR_ALL_CARGOSPECS_FROM(var, start)
#define | FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
#define | FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, uint, cargo_bits)
#define | FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs_size && (var = _sorted_cargo_specs[index], true) ; index++)
| Loop header for iterating over cargoes, sorted by name.
#define | FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_standard_cargo_specs_size && (var = _sorted_cargo_specs[index], true); index++)
| Loop header for iterating over 'real' cargoes, sorted by name.

## Typedefs
typedef uint32 | CargoLabel
| Globally unique label of a cargo type.

## Enumerations
enum | TownEffect { TE_BEGIN = 0, TE_NONE = TE_BEGIN, TE_PASSENGERS, TE_MAIL, TE_GOODS, TE_WATER, TE_FOOD, TE_END, NUM_TE = TE_END }
| Town growth effect when delivering 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.
CargoID | GetCargoIDByLabel (CargoLabel cl)
| Get the cargo ID by cargo label.
CargoID | GetCargoIDByBitnum (uint8 bitnum)
| Find the CargoID of a 'bitnum' value.
void | InitializeSortedCargoSpecs ()
| Initialize the list of sorted cargo specifications.
static bool | IsCargoInClass (CargoID c, CargoClass cc)
| Does cargo c have cargo class cc?

## Variables
static const byte | INVALID_CARGO = 0xFF
| Constant representing invalid cargo.
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

Types/functions related to cargoes.

Definition in file cargotype.h.

## Macro Definition Documentation

#define FOR_ALL_CARGOSPECS_FROM | ( |  | var,
|  |  | start
| ) |  |

Value:
for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
if ((var = CargoSpec::Get(cargospec_index))->IsValid())

Definition at line 155 of file cargotype.h.

#define FOR_ALL_SORTED_CARGOSPECS | ( |  | var | ) | for (uint8 index = 0; index < _sorted_cargo_specs_size && (var = _sorted_cargo_specs[index], true) ; index++)

Loop header for iterating over cargoes, sorted by name.

This includes phony cargoes like regearing cargoes.

Parameters

  var | Reference getting the cargospec.

See Also
  CargoSpec

Definition at line 166 of file cargotype.h.

Referenced by RefitWindow::BuildRefitList(), FormatString(), and InitializeSortedCargoSpecs().

#define FOR_ALL_SORTED_STANDARD_CARGOSPECS | ( |  | var | ) | for (uint8 index = 0; index < _sorted_standard_cargo_specs_size && (var = _sorted_cargo_specs[index], true); index++)

Loop header for iterating over 'real' cargoes, sorted by name.

Phony cargoes like regearing cargoes are skipped.

Parameters

  var | Reference getting the cargospec.

See Also
  CargoSpec

Definition at line 173 of file cargotype.h.

Referenced by StationViewWindow::DrawCargoRatings(), PaymentRatesGraphWindow::OnClick(), IndustryCargoesWindow::OnClick(), PaymentRatesGraphWindow::OnHundredthTick(), and BuildVehicleWindow::SetCargoFilterArray().

## Typedef Documentation

typedef uint32 CargoLabel

Globally unique label of a cargo type.

Definition at line 22 of file cargotype.h.

## Enumeration Type Documentation

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

enum TownEffect

Town growth effect when delivering cargo.

Enumerator:

  TE_NONE | Cargo has no effect.
  TE_PASSENGERS | Cargo behaves passenger-like.
  TE_MAIL | Cargo behaves mail-like.
  TE_GOODS | Cargo behaves goods/candy-like.
  TE_WATER | Cargo behaves water-like.
  TE_FOOD | Cargo behaves food/fizzy-drinks-like.
  TE_END | End of town effects.
  NUM_TE | Amount of town effects.

Definition at line 25 of file cargotype.h.

## Function Documentation

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().

static bool IsCargoInClass | ( | CargoID | c,
|  | CargoClass | cc
| ) |  |
| inlinestatic

Does cargo c have cargo class cc?

Parameters

  c | Cargo type.
  cc | Cargo class.

Returns
  The type fits in the class.

Definition at line 150 of file cargotype.h.

References CargoSpec::Get().

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

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().