OpenTTD Source 20241224-master-gee860a5c8e
|
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 <sstream>
#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. | |
std::span< const CargoLabel > | GetClimateDependentCargoTranslationTable () |
Get default climate-dependent cargo translation table for a NewGRF, used if the NewGRF does not provide its own. | |
std::span< const CargoLabel > | GetClimateIndependentCargoTranslationTable () |
Get default climate-independent cargo translation table for a NewGRF, used if the NewGRF does not provide its own. | |
void | BuildCargoLabelMap () |
Build cargo label map. | |
bool | IsDefaultCargo (CargoID cid) |
Test if a cargo is a default cargo type. | |
Dimension | GetLargestCargoIconSize () |
Get dimensions of largest cargo icon. | |
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. | |
std::optional< std::string > | BuildCargoAcceptanceString (const CargoArray &acceptance, StringID label) |
Build comma-separated cargo acceptance string. | |
Variables | |
CargoTypes | _cargo_mask |
Bitmask of cargo types available. | |
CargoTypes | _standard_cargo_mask |
Bitmask of real cargo types available. | |
static std::vector< CargoLabel > | _default_cargo_labels |
List of default cargo labels, used when setting up cargo types for default vehicles. | |
static std::array< CargoLabel, 12 > | _climate_dependent_cargo_labels |
Default cargo translation for upto version 7 NewGRFs. | |
static std::array< CargoLabel, 32 > | _climate_independent_cargo_labels |
Default cargo translation for version 8+ NewGRFs. | |
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.
std::optional< std::string > BuildCargoAcceptanceString | ( | const CargoArray & | acceptance, |
StringID | label | ||
) |
Build comma-separated cargo acceptance string.
acceptance | CargoArray filled with accepted cargo. |
label | Label to prefix cargo acceptance list. |
Definition at line 269 of file cargotype.cpp.
References _sorted_cargo_specs, GetListSeparator(), GetString(), and SetDParam().
Referenced by BuildHouseWindow::GetHouseInformation(), and LandInfoWindow::OnInit().
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 134 of file cargotype.cpp.
Referenced by CargoChangeInfo().
Sort cargo specifications by their cargo class.
Definition at line 208 of file cargotype.cpp.
References CargoSpecNameSorter(), CC_MAIL, CC_PASSENGERS, CC_SPECIAL, and CargoSpec::classes.
Referenced by InitializeSortedCargoSpecs().
Sort cargo specifications by their name.
Definition at line 196 of file cargotype.cpp.
References GetString(), CargoSpec::name, and StrNaturalCompare().
Referenced by CargoSpecClassSorter().
std::span< const CargoLabel > GetClimateDependentCargoTranslationTable | ( | ) |
Get default climate-dependent cargo translation table for a NewGRF, used if the NewGRF does not provide its own.
Definition at line 115 of file cargotype.cpp.
References _climate_dependent_cargo_labels.
Referenced by GetCargoTranslation(), and GetCargoTranslationTable().
std::span< const CargoLabel > GetClimateIndependentCargoTranslationTable | ( | ) |
Get default climate-independent cargo translation table for a NewGRF, used if the NewGRF does not provide its own.
Definition at line 124 of file cargotype.cpp.
References _climate_independent_cargo_labels.
Referenced by GetCargoTranslation(), and GetCargoTranslationTable().
Dimension GetLargestCargoIconSize | ( | ) |
Get dimensions of largest cargo icon.
Definition at line 165 of file cargotype.cpp.
References _sorted_cargo_specs, GetSpriteSize(), and maxdim().
Referenced by BaseVehicleListWindow::BuildCargoDropDownList(), DrawAircraftImage(), IndustryCargoesWindow::OnClick(), IndustryViewWindow::OnInit(), and SubsidyListWindow::OnInit().
void InitializeSortedCargoSpecs | ( | ) |
Initialize the list of sorted cargo specifications.
Definition at line 225 of file cargotype.cpp.
References _sorted_cargo_specs, _sorted_cargo_types, _sorted_standard_cargo_specs, _standard_cargo_mask, CargoSpecClassSorter(), CC_SPECIAL, INVALID_TPE, CargoSpec::Iterate(), SetBit(), and CargoSpec::town_production_cargoes.
Referenced by AfterLoadGRFs(), and ReadLanguagePack().
bool IsDefaultCargo | ( | CargoID | cid | ) |
Test if a cargo is a default cargo type.
cid | Cargo ID. |
Definition at line 152 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 64 of file cargotype.cpp.
Referenced by ResetNewGRFData().
CargoTypes _cargo_mask |
Bitmask of cargo types available.
This includes phony cargoes like regearing cargoes. Initialized during a call to SetupCargoForClimate.
Definition at line 33 of file cargotype.cpp.
Referenced by CalculateRefitMasks(), CargoChangeInfo(), CompanyStationsWindow::OnDropdownSelect(), CompanyStationsWindow::SetStringParameters(), and ShowRefitOptionsList().
|
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 51 of file cargotype.cpp.
Referenced by GetClimateDependentCargoTranslationTable().
|
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 58 of file cargotype.cpp.
Referenced by GetClimateIndependentCargoTranslationTable().
|
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 44 of file cargotype.cpp.
Referenced by IsDefaultCargo().
std::vector<const CargoSpec *> _sorted_cargo_specs |
Cargo specifications sorted alphabetically by name.
Definition at line 192 of file cargotype.cpp.
Referenced by BuildCargoAcceptanceString(), BaseVehicleListWindow::BuildCargoDropDownList(), BuildLinkStatsLegend(), RefitWindow::BuildRefitList(), DrawRoadVehDetails(), DrawTrainDetails(), LinkGraphLegendWindow::DrawWidget(), FormatString(), GetLargestCargoIconSize(), InitializeSortedCargoSpecs(), LinkGraphLegendWindow::OnInvalidateData(), DepotWindow::OnRightClick(), LinkGraphLegendWindow::OnTooltip(), LinkGraphLegendWindow::SetOverlay(), LinkGraphLegendWindow::UpdateOverlayCargoes(), and LinkGraphLegendWindow::UpdateWidgetSize().
std::array<uint8_t, NUM_CARGO> _sorted_cargo_types |
Sort order of cargoes by cargo ID.
Definition at line 191 of file cargotype.cpp.
Referenced by InitializeSortedCargoSpecs().
std::span<const CargoSpec *> _sorted_standard_cargo_specs |
Standard cargo specifications sorted alphabetically by name.
Definition at line 193 of file cargotype.cpp.
Referenced by StationViewWindow::DrawCargoRatings(), PaymentRatesGraphWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), InitializeSortedCargoSpecs(), PaymentRatesGraphWindow::OnClick(), IndustryCargoesWindow::OnClick(), PaymentRatesGraphWindow::UpdatePaymentRates(), PaymentRatesGraphWindow::UpdateWidgetSize(), and CompanyStationsWindow::UpdateWidgetSize().
CargoTypes _standard_cargo_mask |
Bitmask of real cargo types available.
Phony cargoes like regearing cargoes are excluded.
Definition at line 38 of file cargotype.cpp.
Referenced by CalculateRefitMasks(), CargoAndEngineFilter(), InitializeSortedCargoSpecs(), and BuildVehicleWindow::SetCargoFilterArray().