OpenTTD Source 20260218-master-g2123fca5ea
GameConfig Class Reference

Game script instantion of script configuration. More...

#include <game_config.hpp>

Inheritance diagram for GameConfig:
ScriptConfig

Public Member Functions

 GameConfig (const GameConfig &config)
 Copy constructor.
class GameInfoGetInfo () const
 Get the ScriptInfo linked to this ScriptConfig.
bool ResetInfo (bool force_exact_match)
 When ever the Game Scanner is reloaded, all infos become invalid.
Public Member Functions inherited from ScriptConfig
 ScriptConfig (const ScriptConfig &config)
 Create a new Script config that is a copy of an existing config.
virtual ~ScriptConfig ()
 Delete an Script configuration.
void Change (std::optional< std::string_view > name, int version=-1, bool force_exact_match=false)
 Set another Script to be loaded in this slot.
class ScriptInfoGetInfo () const
 Get the ScriptInfo linked to this ScriptConfig.
const ScriptConfigItemListGetConfigList ()
 Get the config list for this ScriptConfig.
void AnchorUnchangeableSettings ()
 As long as the default of a setting has not been changed, the value of the setting is not stored.
int GetSetting (const std::string &name) const
 Get the value of a setting for this config.
void SetSetting (std::string_view name, int value)
 Set the value of a setting for this config.
void ResetSettings ()
 Reset all settings to their default value.
void ResetEditableSettings (bool yet_to_start)
 Reset only editable and visible settings to their default value.
bool HasScript () const
 Is this config attached to an Script?
const std::string & GetName () const
 Get the name of the Script.
int GetVersion () const
 Get the version of the Script.
void StringToSettings (std::string_view value)
 Convert a string which is stored in the config file or savegames to custom settings of this Script.
std::string SettingsToString () const
 Convert the custom settings to a string that can be stored in the config file or savegames.
std::optional< std::string > GetTextfile (TextfileType type, CompanyID slot) const
 Search a textfile file next to this script.
void SetToLoadData (ScriptInstance::ScriptData *data)
ScriptInstance::ScriptData * GetToLoadData ()

Static Public Member Functions

static GameConfigGetConfig (ScriptSettingSource source=SSS_DEFAULT)
 Get the script configuration.

Protected Member Functions

ScriptInfoFindInfo (const std::string &name, int version, bool force_exact_match) override
 Finds the appropriate ScriptInfo for a given script name and version.
Protected Member Functions inherited from ScriptConfig
void ClearConfigList ()
 Routine that clears the config list.

Additional Inherited Members

Public Types inherited from ScriptConfig
enum  ScriptSettingSource : uint8_t { SSS_DEFAULT , SSS_FORCE_NEWGAME , SSS_FORCE_GAME }
 Where to get the config from, either default (depends on current game mode) or force either newgame or normal. More...
Protected Types inherited from ScriptConfig
typedef std::map< std::string, int > SettingValueList
 List with name=>value pairs of all script-specific settings.
Protected Attributes inherited from ScriptConfig
std::string name
 Name of the Script.
int version
 Version of the Script.
class ScriptInfoinfo
 ScriptInfo object for related to this Script version.
SettingValueList settings
 List with all setting=>value pairs that are configure for this Script.
std::unique_ptr< ScriptConfigItemListconfig_list
 List with all settings defined by this Script.
std::unique_ptr< ScriptInstance::ScriptData > to_load_data
 Data to load after the Script start.

Detailed Description

Game script instantion of script configuration.

Definition at line 16 of file game_config.hpp.

Constructor & Destructor Documentation

◆ GameConfig() [1/2]

GameConfig::GameConfig ( )
inline

Definition at line 25 of file game_config.hpp.

◆ GameConfig() [2/2]

GameConfig::GameConfig ( const GameConfig & config)
inline

Copy constructor.

Parameters
configThe configuration to copy.

Definition at line 33 of file game_config.hpp.

Member Function Documentation

◆ FindInfo()

ScriptInfo * GameConfig::FindInfo ( const std::string & name,
int version,
bool force_exact_match )
overrideprotectedvirtual

Finds the appropriate ScriptInfo for a given script name and version.

Parameters
nameThe script name to find.
versionThe version the script should have.
force_exact_matchWhether an exact match is required.
Returns
The script if found, nullptr otherwise.

Implements ScriptConfig.

Definition at line 33 of file game_config.cpp.

References Game::FindInfo(), ScriptConfig::name, and ScriptConfig::version.

◆ GetConfig()

GameConfig * GameConfig::GetConfig ( ScriptSettingSource source = SSS_DEFAULT)
static

Get the script configuration.

Parameters
sourceThe context, i.e. current / new game mode.
Returns
The configuration.

Definition at line 18 of file game_config.cpp.

References _settings_game, _settings_newgame, ScriptConfig::SSS_DEFAULT, and ScriptConfig::SSS_FORCE_NEWGAME.

Referenced by GameInstance::GetSetting(), GSConfigWindow::GetText(), GSDTChunkHandler::Load(), GSConfigWindow::OnClick(), GSConfigWindow::OnInvalidateData(), and Game::StartNew().

◆ GetInfo()

class GameInfo * GameConfig::GetInfo ( ) const

Get the ScriptInfo linked to this ScriptConfig.

Returns
The info.

Definition at line 28 of file game_config.cpp.

References ScriptConfig::GetInfo().

Referenced by GSConfigWindow::OnClick(), GSConfigWindow::OnInvalidateData(), and Game::StartNew().

◆ ResetInfo()

bool GameConfig::ResetInfo ( bool force_exact_match)

When ever the Game Scanner is reloaded, all infos become invalid.

This function tells GameConfig about this.

Parameters
force_exact_matchIf true try to find the exact same version as specified. If false any version is ok.
Returns
true if the reset was successful, false if the Game was no longer found.

Definition at line 38 of file game_config.cpp.

References Game::FindInfo(), ScriptConfig::info, ScriptConfig::name, and ScriptConfig::version.


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