OpenTTD Source 20250205-master-gfd85ab1e2c
GRFConfig Struct Reference

Information about GRF, used in the game and (part of it) in savegames. More...

#include <newgrf_config.h>

Public Member Functions

 GRFConfig (const std::string &filename)
 
 GRFConfig (const GRFConfig &config)
 Create a new GRFConfig that is a deep copy of an existing config.
 
GRFConfigoperator= (GRFConfig &rhs)=delete
 
bool IsCompatible (uint32_t old_version) const
 Return whether this NewGRF can replace an older version of the same NewGRF.
 
void SetParams (std::span< const uint32_t > pars)
 
void CopyParams (const GRFConfig &src)
 Copy the parameter information from the src config.
 
uint32_t GetValue (const GRFParameterInfo &info) const
 Get the value of the given user-changeable parameter.
 
void SetValue (const GRFParameterInfo &info, uint32_t value)
 Set the value of the given user-changeable parameter.
 
std::optional< std::string > GetTextfile (TextfileType type) const
 Search a textfile file next to this NewGRF.
 
const char * GetName () const
 Get the name of this grf.
 
const char * GetDescription () const
 Get the grf info.
 
const char * GetURL () const
 Get the grf url.
 
void SetParameterDefaults ()
 Set the default value for all parameters as specified by action14.
 
void SetSuitablePalette ()
 Set the palette of this GRFConfig to something suitable.
 
void FinalizeParameterInfo ()
 Finalize Action 14 info after file scan is finished.
 

Data Fields

GRFIdentifier ident {}
 grfid and md5sum to uniquely identify newgrfs
 
MD5Hash original_md5sum {}
 MD5 checksum of original file if only a 'compatible' file was loaded.
 
std::string filename {}
 Filename - either with or without full path.
 
GRFTextWrapper name {}
 NOSAVE: GRF name (Action 0x08)
 
GRFTextWrapper info {}
 NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
 
GRFTextWrapper url {}
 NOSAVE: URL belonging to this GRF.
 
std::optional< GRFErrorerror = std::nullopt
 NOSAVE: Error/Warning during GRF loading (Action 0x0B)
 
uint32_t version = 0
 NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
 
uint32_t min_loadable_version = 0
 NOSAVE: Minimum compatible version a NewGRF can define.
 
GRFConfigFlags flags = {}
 NOSAVE: GCF_Flags, bitset.
 
GRFStatus status = GCS_UNKNOWN
 NOSAVE: GRFStatus, enum.
 
GRFBugs grf_bugs = {}
 NOSAVE: bugs in this GRF in this run,.
 
uint8_t num_valid_params = MAX_NUM_PARAMS
 NOSAVE: Number of valid parameters (action 0x14)
 
uint8_t palette = 0
 GRFPalette, bitset.
 
bool has_param_defaults = false
 NOSAVE: did this newgrf specify any defaults for it's parameters.
 
std::vector< std::optional< GRFParameterInfo > > param_info
 NOSAVE: extra information about the parameters.
 
std::vector< uint32_t > param
 GRF parameters.
 

Static Public Attributes

static constexpr uint8_t MAX_NUM_PARAMS = 0x80
 

Detailed Description

Information about GRF, used in the game and (part of it) in savegames.

Definition at line 156 of file newgrf_config.h.

Constructor & Destructor Documentation

◆ GRFConfig() [1/2]

GRFConfig::GRFConfig ( const std::string &  filename)
inline

Definition at line 160 of file newgrf_config.h.

◆ GRFConfig() [2/2]

GRFConfig::GRFConfig ( const GRFConfig config)

Create a new GRFConfig that is a deep copy of an existing config.

Parameters
configThe GRFConfig object to make a copy of.

Definition at line 36 of file newgrf_config.cpp.

References Copy, flags, and EnumBitSet< Tenum, Tstorage >::Reset().

Member Function Documentation

◆ CopyParams()

void GRFConfig::CopyParams ( const GRFConfig src)

Copy the parameter information from the src config.

Parameters
srcSource config.

Definition at line 75 of file newgrf_config.cpp.

References param.

◆ FinalizeParameterInfo()

void GRFConfig::FinalizeParameterInfo ( )

Finalize Action 14 info after file scan is finished.

Definition at line 141 of file newgrf_config.cpp.

References info, and param_info.

Referenced by FillGRFDetails().

◆ GetDescription()

const char * GRFConfig::GetDescription ( ) const

Get the grf info.

Returns
A string with a description of this grf.

Definition at line 95 of file newgrf_config.cpp.

References GetGRFStringFromGRFText(), and info.

◆ GetName()

const char * GRFConfig::GetName ( ) const

Get the name of this grf.

In case the name isn't known the filename is returned.

Returns
The name of filename of this grf.

Definition at line 85 of file newgrf_config.cpp.

References filename, GetGRFStringFromGRFText(), name, and StrEmpty().

Referenced by DisableStaticNewGRFInfluencingNonStaticNewGRFs(), DrawVehiclePurchaseInfo(), NewGRFWindow::DrawWidget(), ErrorUnknownCallbackResult(), NewGRFWindow::NameSorter(), NewGRFTextfileWindow::SetStringParameters(), ShowMissingContentWindow(), and ShowNewGrfVehicleError().

◆ GetTextfile()

std::optional< std::string > GRFConfig::GetTextfile ( TextfileType  type) const

Search a textfile file next to this NewGRF.

Parameters
typeThe type of the textfile to search for.
Returns
The filename for the textfile.

Definition at line 654 of file newgrf_config.cpp.

References filename, and NEWGRF_DIR.

Referenced by NewGRFWindow::OnInvalidateData().

◆ GetURL()

const char * GRFConfig::GetURL ( ) const

Get the grf url.

Returns
A string with an url of this grf.

Definition at line 104 of file newgrf_config.cpp.

References GetGRFStringFromGRFText(), and url.

Referenced by NewGRFWindow::OnClick().

◆ GetValue()

uint32_t GRFConfig::GetValue ( const GRFParameterInfo info) const

Get the value of the given user-changeable parameter.

Parameters
infoThe grf parameter info to get the value for.
Returns
The value of this parameter.

Definition at line 169 of file newgrf_config.cpp.

References GB(), info, param, and GRFParameterInfo::param_nr.

Referenced by NewGRFParametersWindow::DrawWidget(), and NewGRFParametersWindow::OnClick().

◆ IsCompatible()

bool GRFConfig::IsCompatible ( uint32_t  old_version) const

Return whether this NewGRF can replace an older version of the same NewGRF.

Definition at line 66 of file newgrf_config.cpp.

References min_loadable_version, and version.

Referenced by openttd_main().

◆ SetParameterDefaults()

void GRFConfig::SetParameterDefaults ( )

Set the default value for all parameters as specified by action14.

Definition at line 110 of file newgrf_config.cpp.

References has_param_defaults, info, param, param_info, and SetValue().

Referenced by NewGRFParametersWindow::OnClick(), and GameOptionsWindow::OnClick().

◆ SetParams()

void GRFConfig::SetParams ( std::span< const uint32_t >  pars)

Definition at line 58 of file newgrf_config.cpp.

◆ SetSuitablePalette()

void GRFConfig::SetSuitablePalette ( )

Set the palette of this GRFConfig to something suitable.

That is either the setting coming from the NewGRF or the globally used palette.

Definition at line 127 of file newgrf_config.cpp.

References _settings_client, GRFP_GRF_DOS, GRFP_GRF_MASK, GRFP_GRF_WINDOWS, GRFP_USE_BIT, GRFP_USE_DOS, GRFP_USE_WINDOWS, ClientSettings::gui, GUISettings::newgrf_default_palette, PAL_DOS, PAL_WINDOWS, palette, and SB().

Referenced by FillGRFDetails().

◆ SetValue()

void GRFConfig::SetValue ( const GRFParameterInfo info,
uint32_t  value 
)

Set the value of the given user-changeable parameter.

Parameters
infoThe grf parameter info to set the value for.
valueThe new value.

Definition at line 185 of file newgrf_config.cpp.

References Clamp(), info, param, GRFParameterInfo::param_nr, SB(), SetWindowDirty(), WC_GAME_OPTIONS, and WN_GAME_OPTIONS_NEWGRF_STATE.

Referenced by NewGRFParametersWindow::OnClick(), NewGRFParametersWindow::OnDropdownSelect(), NewGRFParametersWindow::OnQueryTextFinished(), and SetParameterDefaults().

Field Documentation

◆ error

std::optional<GRFError> GRFConfig::error = std::nullopt

NOSAVE: Error/Warning during GRF loading (Action 0x0B)

Definition at line 172 of file newgrf_config.h.

Referenced by NewGRFWindow::DrawWidget(), LoadNewGRF(), and ResetNewGRFErrors().

◆ filename

◆ flags

◆ grf_bugs

GRFBugs GRFConfig::grf_bugs = {}

NOSAVE: bugs in this GRF in this run,.

See also
enum GRFBugs

Definition at line 178 of file newgrf_config.h.

Referenced by ErrorUnknownCallbackResult(), ShowNewGrfVehicleError(), and VehicleLengthChanged().

◆ has_param_defaults

bool GRFConfig::has_param_defaults = false

NOSAVE: did this newgrf specify any defaults for it's parameters.

Definition at line 181 of file newgrf_config.h.

Referenced by ChangeGRFParamDefault(), IsGoodGRFConfigList(), and SetParameterDefaults().

◆ ident

◆ info

GRFTextWrapper GRFConfig::info {}

NOSAVE: GRF info (author, copyright, ...) (Action 0x08)

Definition at line 170 of file newgrf_config.h.

Referenced by ChangeGRFDescription(), FinalizeParameterInfo(), GetDescription(), GetValue(), NetworkAfterNewGRFScan(), SetParameterDefaults(), and SetValue().

◆ MAX_NUM_PARAMS

constexpr uint8_t GRFConfig::MAX_NUM_PARAMS = 0x80
staticconstexpr

Definition at line 157 of file newgrf_config.h.

◆ min_loadable_version

uint32_t GRFConfig::min_loadable_version = 0

NOSAVE: Minimum compatible version a NewGRF can define.

Definition at line 175 of file newgrf_config.h.

Referenced by ChangeGRFMinVersion(), ChangeGRFVersion(), IsCompatible(), and IsGoodGRFConfigList().

◆ name

GRFTextWrapper GRFConfig::name {}

NOSAVE: GRF name (Action 0x08)

Definition at line 169 of file newgrf_config.h.

Referenced by GRFFileScanner::AddFile(), ChangeGRFName(), GetName(), IsGoodGRFConfigList(), and NetworkAfterNewGRFScan().

◆ num_valid_params

uint8_t GRFConfig::num_valid_params = MAX_NUM_PARAMS

◆ original_md5sum

MD5Hash GRFConfig::original_md5sum {}

MD5 checksum of original file if only a 'compatible' file was loaded.

Definition at line 167 of file newgrf_config.h.

Referenced by NewGRFWindow::OnInvalidateData(), and ShowMissingContentWindow().

◆ palette

uint8_t GRFConfig::palette = 0

◆ param

◆ param_info

◆ status

◆ url

GRFTextWrapper GRFConfig::url {}

NOSAVE: URL belonging to this GRF.

Definition at line 171 of file newgrf_config.h.

Referenced by ChangeGRFURL(), and GetURL().

◆ version

uint32_t GRFConfig::version = 0

NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.

Definition at line 174 of file newgrf_config.h.

Referenced by ChangeGRFMinVersion(), ChangeGRFVersion(), FindGRFConfig(), GraphicsSetSaveConfig(), IsCompatible(), IsGoodGRFConfigList(), NewGRFWindow::NameSorter(), and ParamSet().


The documentation for this struct was generated from the following files: