OpenTTD Source  14.0-beta1
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...
 
Dimension GetLargestCargoIconSize ()
 Get dimensions of largest cargo icon. More...
 
CargoID GetDefaultCargoID (LandscapeID l, CargoType ct)
 Get the cargo ID of a default cargo, if present. 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...
 
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...
 
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

◆ 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
clCargo 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
lLandscape
ctDefault 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().

◆ SetupCargoForClimate()

void SetupCargoForClimate ( LandscapeID  l)

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

Parameters
lLandscape

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