OpenTTD Source 20241224-master-gf74b0cf984
GRFConfig Struct Reference

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

#include <newgrf_config.h>

Inheritance diagram for GRFConfig:
ZeroedMemoryAllocator

Public Member Functions

 GRFConfig (const std::string &filename=std::string{})
 Create a new GRFConfig.
 
 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.
 
- Public Member Functions inherited from ZeroedMemoryAllocator
void * operator new (size_t size)
 Memory allocator for a single class instance.
 
void * operator new[] (size_t size)
 Memory allocator for an array of class instances.
 
void operator delete (void *ptr)
 Memory release for a single class instance.
 
void operator delete[] (void *ptr)
 Memory release for an array of class instances.
 

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
 NOSAVE: Error/Warning during GRF loading (Action 0x0B)
 
uint32_t version
 NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
 
uint32_t min_loadable_version
 NOSAVE: Minimum compatible version a NewGRF can define.
 
uint8_t flags
 NOSAVE: GCF_Flags, bitset.
 
GRFStatus status
 NOSAVE: GRFStatus, enum.
 
uint32_t grf_bugs
 NOSAVE: bugs in this GRF in this run,.
 
uint8_t num_valid_params
 NOSAVE: Number of valid parameters (action 0x14)
 
uint8_t palette
 GRFPalette, bitset.
 
bool has_param_defaults
 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.
 
struct GRFConfignext
 NOSAVE: Next item in the linked list.
 

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 154 of file newgrf_config.h.

Constructor & Destructor Documentation

◆ GRFConfig() [1/2]

GRFConfig::GRFConfig ( const std::string &  filename = std::string{})

Create a new GRFConfig.

Parameters
filenameSet the filename of this GRFConfig to filename.

Definition at line 37 of file newgrf_config.cpp.

◆ 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 43 of file newgrf_config.cpp.

Member Function Documentation

◆ CopyParams()

void GRFConfig::CopyParams ( const GRFConfig src)

Copy the parameter information from the src config.

Parameters
srcSource config.

Definition at line 82 of file newgrf_config.cpp.

References param.

◆ FinalizeParameterInfo()

void GRFConfig::FinalizeParameterInfo ( )

Finalize Action 14 info after file scan is finished.

Definition at line 148 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 102 of file newgrf_config.cpp.

References GetGRFStringFromGRFText(), and info.

◆ GetName()

const char * GRFConfig::GetName ( ) const

◆ 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 724 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 111 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 176 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 73 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 117 of file newgrf_config.cpp.

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

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

◆ SetParams()

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

Definition at line 65 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 134 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 192 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

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

Definition at line 169 of file newgrf_config.h.

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

◆ filename

◆ flags

◆ grf_bugs

uint32_t GRFConfig::grf_bugs

NOSAVE: bugs in this GRF in this run,.

See also
enum GRFBugs

Definition at line 175 of file newgrf_config.h.

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

◆ has_param_defaults

bool GRFConfig::has_param_defaults

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

Definition at line 178 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 167 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 155 of file newgrf_config.h.

◆ min_loadable_version

uint32_t GRFConfig::min_loadable_version

NOSAVE: Minimum compatible version a NewGRF can define.

Definition at line 172 of file newgrf_config.h.

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

◆ name

GRFTextWrapper GRFConfig::name

NOSAVE: GRF name (Action 0x08)

Definition at line 166 of file newgrf_config.h.

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

◆ next

◆ num_valid_params

uint8_t GRFConfig::num_valid_params

◆ original_md5sum

MD5Hash GRFConfig::original_md5sum

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

Definition at line 164 of file newgrf_config.h.

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

◆ palette

uint8_t GRFConfig::palette

◆ param

◆ param_info

◆ status

◆ url

GRFTextWrapper GRFConfig::url

NOSAVE: URL belonging to this GRF.

Definition at line 168 of file newgrf_config.h.

Referenced by ChangeGRFURL(), and GetURL().

◆ version

uint32_t GRFConfig::version

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

Definition at line 171 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: