OpenTTD Source: GRFConfig Struct Reference

OpenTTD Source 15.0-beta1

Public Member Functions | Data Fields | Static Public Attributes
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:

## 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.
GRFConfig & | operator= (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< GRFError > | error
| 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 GRFConfig * | next
| 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

  filename | Set 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

  config | The 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

  src | Source 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

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

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

Referenced by GRFFileScanner::AddFile(), DisableStaticNewGRFInfluencingNonStaticNewGRFs(), DrawVehiclePurchaseInfo(), NewGRFWindow::DrawWidget(), ErrorUnknownCallbackResult(), GRFSorter(), 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

  type | The 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

  info | The 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

  info | The grf parameter info to set the value for.
  value | The 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

std::string GRFConfig::filename

Filename - either with or without full path.

Definition at line 165 of file newgrf_config.h.

Referenced by GRFFileScanner::AddFile(), AddGrfInfo(), CalcGRFMD5Sum(), FillGRFDetails(), GetName(), ContentInfo::GetTextfile(), GetTextfile(), GRFFile::GRFFile(), GRFLoadConfig(), GrfMsgI(), InitNewGRFFile(), IsGoodGRFConfigList(), LoadNewGRF(), LoadNewGRFFile(), LoadNewGRFFileFromFile(), and NetworkAfterNewGRFScan().

## ◆ flags

uint8_t GRFConfig::flags

NOSAVE: GCF_Flags, bitset.

Definition at line 173 of file newgrf_config.h.

Referenced by NewGRFWindow::AddGRFToActive(), CopyGRFConfigList(), FillGRFDetails(), NewGRFWindow::GetPalette(), GRFLoadConfig(), GRFUnsafe(), IsGoodGRFConfigList(), IsLoggableGrfConfig(), LoadNewGRF(), LoadNewGRFFile(), NewGRFWindow::OnClick(), NewGRFWindow::OnInvalidateData(), ParamSet(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), and ShowMissingContentWindow().

## ◆ 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

GRFIdentifier GRFConfig::ident

grfid and md5sum to uniquely identify newgrfs

Definition at line 163 of file newgrf_config.h.

Referenced by GRFFileScanner::AddFile(), CalcGRFMD5Sum(), ChangeGRFDescription(), ChangeGRFName(), ChangeGRFParamDescription(), ChangeGRFParamName(), ChangeGRFParamValueNames(), ChangeGRFURL(), FillGRFDetails(), FillGrfidMap(), GetGRFConfig(), Gamelog::GetOverriddenIdentifier(), Gamelog::GRFAdd(), GRFFile::GRFFile(), GRFLoadConfig(), Gamelog::GRFUpdate(), IsGoodGRFConfigList(), LoadNewGRF(), NewGRFWindow::NameSorter(), NewGRFWindow::OnInvalidateData(), RemoveDuplicatesFromGRFConfigList(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), and ShowMissingContentWindow().

## ◆ 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

struct GRFConfig* GRFConfig::next

NOSAVE: Next item in the linked list.

Definition at line 182 of file newgrf_config.h.

Referenced by GRFFileScanner::AddFile(), NewGRFWindow::AddGRFToActive(), AfterLoadGame(), AppendStaticGRFConfigs(), AppendToGRFConfigList(), NewGRFWindow::CanUpgradeCurrent(), ClearGRFConfigList(), CopyGRFConfigList(), DoScanNewGRFFiles(), NewGRFWindow::DrawWidget(), FillGrfidMap(), FindGRFConfig(), GenerateGRFList(), GetGRFConfig(), Gamelog::GRFAddList(), GRFLoadConfig(), HandleSavegameLoadCrash(), IsGoodGRFConfigList(), LoadNewGRF(), MakePNGImage(), NewGRFConfirmationCallback(), NewGRFWindow::OnClick(), NewGRFWindow::OnDragDrop(), NewGRFWindow::OnInvalidateData(), RemoveDuplicatesFromGRFConfigList(), ResetNewGRFErrors(), NGRFChunkHandler::Save(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), ShowMissingContentWindow(), ShowNewGRFError(), SurveyGrfs(), SwitchNewGRFBlitter(), UpdateNewGRFConfigPalette(), NewGRFWindow::UpdateScrollBars(), and NewGRFWindow::UpgradeCurrent().

## ◆ num_valid_params

uint8_t GRFConfig::num_valid_params

NOSAVE: Number of valid parameters (action 0x14)

Definition at line 176 of file newgrf_config.h.

Referenced by ChangeGRFNumUsedParams(), HandleParameterInfo(), IsGoodGRFConfigList(), NewGRFParametersWindow::OnClick(), NewGRFWindow::OnClick(), NewGRFParametersWindow::OnInvalidateData(), and NewGRFWindow::OnInvalidateData().

## ◆ 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

GRFPalette, bitset.

Definition at line 177 of file newgrf_config.h.

Referenced by ChangeGRFBlitter(), ChangeGRFPalette(), GetGlobalVariable(), LoadNewGRFFile(), NewGRFWindow::OnClick(), and SetSuitablePalette().

## ◆ param

std::vector<uint32_t> GRFConfig::param

GRF parameters.

Definition at line 180 of file newgrf_config.h.

Referenced by CopyParams(), GetValue(), GraphicsSetSaveConfig(), GRFBuildParamList(), GRFFile::GRFFile(), Gamelog::GRFUpdate(), NewGRFParametersWindow::OnClick(), GameOptionsWindow::OnClick(), NewGRFParametersWindow::OnInvalidateData(), SetParameterDefaults(), SetValue(), and SurveyConfiguration().

## ◆ param_info

std::vector<std::optional<GRFParameterInfo> > GRFConfig::param_info

NOSAVE: extra information about the parameters.

Definition at line 179 of file newgrf_config.h.

Referenced by FinalizeParameterInfo(), NewGRFParametersWindow::GetParameterInfo(), HandleParameterInfo(), NewGRFParametersWindow::HasParameterInfo(), IsGoodGRFConfigList(), SetParameterDefaults(), and NewGRFParametersWindow::UpdateWidgetSize().

## ◆ status

GRFStatus GRFConfig::status

NOSAVE: GRFStatus, enum.

Definition at line 174 of file newgrf_config.h.

Referenced by FillGRFDetails(), NewGRFWindow::GetPalette(), GRFLoadConfig(), IsLoggableGrfConfig(), LoadNewGRF(), LoadNewGRFFile(), NewGRFWindow::OnInvalidateData(), ParamSet(), ShowMissingContentWindow(), and TranslateGRFStrings().

## ◆ 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:

- src/newgrf_config.h
- src/newgrf_config.cpp