OpenTTD Source
20241108-master-g80f628063a
|
Implementation of cargoes. More...
#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... | |
std::span< const CargoLabel > | GetDefaultCargoTranslationTable (uint8_t grf_version) |
Get default cargo translation table for a NewGRF, used if the NewGRF does not provide its own. 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... | |
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... | |
static std::array< CargoLabel, 12 > | _v7_cargo_labels |
Default cargo translation for upto version 7 NewGRFs. More... | |
static std::array< CargoLabel, 32 > | _v8_cargo_labels |
Default cargo translation for version 8+ NewGRFs. 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. | |
Implementation of cargoes.
Definition in file cargotype.cpp.
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 122 of file cargotype.cpp.
References CargoSpecNameSorter(), CC_SPECIAL, and CargoSpec::classes.
std::span<const CargoLabel> GetDefaultCargoTranslationTable | ( | uint8_t | grf_version | ) |
Get default cargo translation table for a NewGRF, used if the NewGRF does not provide its own.
grf_version | GRF version of translation table. |
Definition at line 111 of file cargotype.cpp.
References _v7_cargo_labels, and _v8_cargo_labels.
Referenced by GetCargoTranslation().
Dimension GetLargestCargoIconSize | ( | ) |
Get dimensions of largest cargo icon.
Definition at line 153 of file cargotype.cpp.
References _sorted_cargo_specs, GetSpriteSize(), and maxdim().
Referenced by IndustryViewWindow::OnInit(), and SubsidyListWindow::OnInit().
bool IsDefaultCargo | ( | CargoID | cid | ) |
Test if a cargo is a default cargo type.
cid | Cargo ID. |
Definition at line 140 of file cargotype.cpp.
References _default_cargo_labels, and CargoSpec::Get().
Referenced by CalculateRefitMasks().
void SetupCargoForClimate | ( | LandscapeID | l | ) |
Set up the default cargo types for the given landscape type.
l | Landscape |
Definition at line 62 of file cargotype.cpp.
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.
|
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().
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().
|
static |
Default cargo translation for upto version 7 NewGRFs.
This maps the original 12 cargo slots to their original label. If a climate dependent cargo is not present it will map to CT_INVALID. For default cargoes this ends up as a 1:1 mapping via climate slot -> label -> cargo ID.
Definition at line 49 of file cargotype.cpp.
Referenced by GetDefaultCargoTranslationTable().
|
static |
Default cargo translation for version 8+ NewGRFs.
This maps the 32 "bitnum" cargo slots to their original label. If a bitnum is not present it will map to CT_INVALID.
Definition at line 56 of file cargotype.cpp.
Referenced by GetDefaultCargoTranslationTable().