OpenTTD Source: GRFConfig Struct Reference

OpenTTD Source 15.0-RC2

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>`

## 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.
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.
std::string | GetName () const
| Get the name of this grf.
std::optional< std::string > | GetDescription () const
| Get the grf info.
std::optional< std::string > | 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::vector< GRFError > | errors
| 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 158 of file newgrf_config.h.

## Constructor & Destructor Documentation

## ◆ GRFConfig() [1/2]

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

Definition at line 162 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

  config | The GRFConfig object to make a copy of.

Definition at line 36 of file newgrf_config.cpp.

References Copy, flags, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset().

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

References param.

## ◆ FinalizeParameterInfo()

void GRFConfig::FinalizeParameterInfo | ( |  | ) |

Finalize Action 14 info after file scan is finished.

Definition at line 145 of file newgrf_config.cpp.

References info, and param_info.

Referenced by FillGRFDetails().

## ◆ GetDescription()

std::optional< std::string > 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()

std::string 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(), and name.

Referenced by GRFFileScanner::AddFile(), DisableStaticNewGRFInfluencingNonStaticNewGRFs(), DrawVehiclePurchaseInfo(), NewGRFWindow::DrawWidget(), ErrorUnknownCallbackResult(), NewGRFTextfileWindow::GetWidgetString(), NewGRFWindow::NameSorter(), 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 647 of file newgrf_config.cpp.

References filename, and NEWGRF_DIR.

Referenced by NewGRFWindow::OnInvalidateData().

## ◆ GetURL()

std::optional< std::string > GRFConfig::GetURL | ( |  | ) | const

Get the grf url.

Returns
  A string with an url of this grf.

Definition at line 106 of file newgrf_config.cpp.

References GetGRFStringFromGRFText(), and url.

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

## ◆ 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 164 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 114 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 131 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 180 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

## ◆ errors

std::vector<GRFError> GRFConfig::errors

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

Definition at line 174 of file newgrf_config.h.

Referenced by DisableGrf(), and NewGRFWindow::DrawWidget().

## ◆ filename

std::string GRFConfig::filename {}

Filename - either with or without full path.

Definition at line 170 of file newgrf_config.h.

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

## ◆ flags

GRFConfigFlags GRFConfig::flags = {}

NOSAVE: GCF_Flags, bitset.

Definition at line 178 of file newgrf_config.h.

Referenced by NewGRFWindow::AddGRFToActive(), FillGRFDetails(), NewGRFWindow::GetPalette(), GRFConfig(), GRFUnsafe(), IsGoodGRFConfigList(), IsLoggableGrfConfig(), LoadNewGRFFile(), NewGRFWindow::OnClick(), NewGRFWindow::OnInvalidateData(), ParamSet(), and ShowMissingContentWindow().

## ◆ grf_bugs

GRFBugs GRFConfig::grf_bugs = {}

NOSAVE: bugs in this GRF in this run,.

See also
  enum GRFBugs

Definition at line 180 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 183 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 168 of file newgrf_config.h.

Referenced by NewGRFWindow::AddGRFToActive(), CalcGRFMD5Sum(), ChangeGRFDescription(), ChangeGRFName(), ChangeGRFParamDescription(), ChangeGRFParamName(), ChangeGRFParamValueNames(), ChangeGRFURL(), DisableGrf(), FillGRFDetails(), FillGrfidMap(), Gamelog::GetOverriddenIdentifier(), Gamelog::GRFAdd(), Gamelog::GRFUpdate(), IsGoodGRFConfigList(), NewGRFWindow::NameSorter(), NewGRFWindow::OnInvalidateData(), and ShowMissingContentWindow().

## ◆ info

GRFTextWrapper GRFConfig::info {}

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

Definition at line 172 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 159 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 177 of file newgrf_config.h.

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

## ◆ name

GRFTextWrapper GRFConfig::name {}

NOSAVE: GRF name (Action 0x08)

Definition at line 171 of file newgrf_config.h.

Referenced by ChangeGRFName(), GetName(), IsGoodGRFConfigList(), and NetworkAfterNewGRFScan().

## ◆ num_valid_params

uint8_t GRFConfig::num_valid_params = MAX_NUM_PARAMS

NOSAVE: Number of valid parameters (action 0x14)

Definition at line 181 of file newgrf_config.h.

Referenced by ChangeGRFNumUsedParams(), HandleParameterInfo(), IsGoodGRFConfigList(), 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 169 of file newgrf_config.h.

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

## ◆ palette

uint8_t GRFConfig::palette = 0

GRFPalette, bitset.

Definition at line 182 of file newgrf_config.h.

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

## ◆ param

std::vector<uint32_t> GRFConfig::param

GRF parameters.

Definition at line 185 of file newgrf_config.h.

Referenced by CopyParams(), GetValue(), GraphicsSetSaveConfig(), GRFBuildParamList(), 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 184 of file newgrf_config.h.

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

## ◆ status

GRFStatus GRFConfig::status = GCS_UNKNOWN

NOSAVE: GRFStatus, enum.

Definition at line 179 of file newgrf_config.h.

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

## ◆ url

GRFTextWrapper GRFConfig::url {}

NOSAVE: URL belonging to this GRF.

Definition at line 173 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 176 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