OpenTTD Source 20241224-master-gf74b0cf984
ScriptConfig Class Referenceabstract

Script settings. More...

#include <script_config.hpp>

Inheritance diagram for ScriptConfig:
AIConfig GameConfig

Public Types

enum  ScriptSettingSource { 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...
 

Public Member Functions

 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< const std::string > 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 (const 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? In other words, is there a Script that is assigned to this slot.
 
const std::string & GetName () const
 Get the name of the Script.
 
int GetVersion () const
 Get the version of the Script.
 
void StringToSettings (const std::string &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 ()
 

Protected Types

typedef std::map< std::string, int > SettingValueList
 List with name=>value pairs of all script-specific settings.
 

Protected Member Functions

void ClearConfigList ()
 Routine that clears the config list.
 
virtual ScriptInfoFindInfo (const std::string &name, int version, bool force_exact_match)=0
 This function should call back to the Scanner in charge of this Config, to find the ScriptInfo belonging to a name+version.
 

Protected Attributes

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

Script settings.

Definition at line 49 of file script_config.hpp.

Member Typedef Documentation

◆ SettingValueList

typedef std::map<std::string, int> ScriptConfig::SettingValueList
protected

List with name=>value pairs of all script-specific settings.

Definition at line 52 of file script_config.hpp.

Member Enumeration Documentation

◆ ScriptSettingSource

Where to get the config from, either default (depends on current game mode) or force either newgame or normal.

Enumerator
SSS_DEFAULT 

Get the Script config from the current game mode.

SSS_FORCE_NEWGAME 

Get the newgame Script config.

SSS_FORCE_GAME 

Get the Script config from the current game.

Definition at line 93 of file script_config.hpp.

Constructor & Destructor Documentation

◆ ScriptConfig() [1/2]

ScriptConfig::ScriptConfig ( )
inline

Definition at line 55 of file script_config.hpp.

◆ ScriptConfig() [2/2]

ScriptConfig::ScriptConfig ( const ScriptConfig config)

Create a new Script config that is a copy of an existing config.

Parameters
configThe object to copy.

Definition at line 36 of file script_config.cpp.

References info, name, settings, to_load_data, and version.

◆ ~ScriptConfig()

ScriptConfig::~ScriptConfig ( )
virtual

Delete an Script configuration.

Definition at line 48 of file script_config.cpp.

References ResetSettings(), and to_load_data.

Member Function Documentation

◆ AnchorUnchangeableSettings()

void ScriptConfig::AnchorUnchangeableSettings ( )

As long as the default of a setting has not been changed, the value of the setting is not stored.

This to allow changing the difficulty setting without having to reset the script's config. However, when a setting may not be changed in game, we must "anchor" this value to what the setting would be at the time of starting. Otherwise changing the difficulty setting would change the setting's value (which isn't allowed).

Definition at line 73 of file script_config.cpp.

References GetConfigList(), SCRIPTCONFIG_INGAME, and SetSetting().

Referenced by Game::StartNew(), and AI::StartNew().

◆ Change()

void ScriptConfig::Change ( std::optional< const std::string >  name,
int  version = -1,
bool  force_exact_match = false 
)

Set another Script to be loaded in this slot.

Parameters
nameThe name of the Script.
versionThe version of the Script to load, or -1 of latest.
force_exact_matchIf true try to find the exact same version as specified. If false any compatible version is ok.

Definition at line 21 of file script_config.cpp.

References ClearConfigList(), config_list, FindInfo(), ScriptInfo::GetVersion(), info, name, to_load_data, and version.

Referenced by ScriptListWindow::ChangeScript(), AIPLChunkHandler::Load(), GSDTChunkHandler::Load(), AI::ResetConfig(), and AI::StartNew().

◆ ClearConfigList()

void ScriptConfig::ClearConfigList ( )
protected

Routine that clears the config list.

Definition at line 68 of file script_config.cpp.

References settings.

Referenced by Change().

◆ FindInfo()

virtual ScriptInfo * ScriptConfig::FindInfo ( const std::string &  name,
int  version,
bool  force_exact_match 
)
protectedpure virtual

This function should call back to the Scanner in charge of this Config, to find the ScriptInfo belonging to a name+version.

Implemented in AIConfig, and GameConfig.

Referenced by Change().

◆ GetConfigList()

◆ GetInfo()

ScriptInfo * ScriptConfig::GetInfo ( ) const

Get the ScriptInfo linked to this ScriptConfig.

Definition at line 54 of file script_config.cpp.

References info.

Referenced by GetTextfile(), and ScriptListWindow::ScriptListWindow().

◆ GetName()

const std::string & ScriptConfig::GetName ( ) const

Get the name of the Script.

Definition at line 131 of file script_config.cpp.

References name.

Referenced by AI::ResetConfig().

◆ GetSetting()

int ScriptConfig::GetSetting ( const std::string &  name) const

Get the value of a setting for this config.

It might fallback to its 'info' to find the default value (if not set or if not-custom difficulty level).

Returns
The (default) value of the setting, or -1 if the setting was not found.

Definition at line 82 of file script_config.cpp.

References ScriptInfo::GetSettingDefaultValue(), info, and settings.

Referenced by GSConfigWindow::DrawWidget(), ScriptSettingsWindow::DrawWidget(), AIInstance::GetSetting(), GameInstance::GetSetting(), GSConfigWindow::OnClick(), and ScriptSettingsWindow::OnClick().

◆ GetTextfile()

std::optional< std::string > ScriptConfig::GetTextfile ( TextfileType  type,
CompanyID  slot 
) const

Search a textfile file next to this script.

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

Definition at line 177 of file script_config.cpp.

References AI_DIR, GAME_DIR, GetInfo(), ScriptInfo::GetMainScript(), INVALID_COMPANY, and OWNER_DEITY.

Referenced by GSConfigWindow::OnInvalidateData(), and ScriptTextfileWindow::OnInvalidateData().

◆ GetToLoadData()

ScriptInstance::ScriptData * ScriptConfig::GetToLoadData ( )

Definition at line 189 of file script_config.cpp.

◆ GetVersion()

int ScriptConfig::GetVersion ( ) const

Get the version of the Script.

Definition at line 136 of file script_config.cpp.

References version.

◆ HasScript()

bool ScriptConfig::HasScript ( ) const

Is this config attached to an Script? In other words, is there a Script that is assigned to this slot.

Definition at line 126 of file script_config.cpp.

References info.

Referenced by AIPLChunkHandler::Load(), GSDTChunkHandler::Load(), and AI::ResetConfig().

◆ ResetEditableSettings()

void ScriptConfig::ResetEditableSettings ( bool  yet_to_start)

◆ ResetSettings()

void ScriptConfig::ResetSettings ( )

Reset all settings to their default value.

Definition at line 102 of file script_config.cpp.

References settings.

Referenced by ResetEditableSettings(), and ~ScriptConfig().

◆ SetSetting()

void ScriptConfig::SetSetting ( const std::string_view  name,
int  value 
)

◆ SettingsToString()

std::string ScriptConfig::SettingsToString ( ) const

Convert the custom settings to a string that can be stored in the config file or savegames.

Definition at line 163 of file script_config.cpp.

References settings.

◆ SetToLoadData()

void ScriptConfig::SetToLoadData ( ScriptInstance::ScriptData *  data)

Definition at line 184 of file script_config.cpp.

◆ StringToSettings()

void ScriptConfig::StringToSettings ( const std::string &  value)

Convert a string which is stored in the config file or savegames to custom settings of this Script.

Definition at line 141 of file script_config.cpp.

References SetSetting().

Referenced by AIPLChunkHandler::Load(), and GSDTChunkHandler::Load().

Field Documentation

◆ config_list

std::unique_ptr<ScriptConfigItemList> ScriptConfig::config_list
protected

List with all settings defined by this Script.

Definition at line 177 of file script_config.hpp.

Referenced by Change(), and GetConfigList().

◆ info

class ScriptInfo* ScriptConfig::info
protected

◆ name

std::string ScriptConfig::name
protected

◆ settings

SettingValueList ScriptConfig::settings
protected

List with all setting=>value pairs that are configure for this Script.

Definition at line 176 of file script_config.hpp.

Referenced by ClearConfigList(), GetSetting(), ResetEditableSettings(), ResetSettings(), ScriptConfig(), SetSetting(), and SettingsToString().

◆ to_load_data

std::unique_ptr<ScriptInstance::ScriptData> ScriptConfig::to_load_data
protected

Data to load after the Script start.

Definition at line 178 of file script_config.hpp.

Referenced by Change(), ScriptConfig(), and ~ScriptConfig().

◆ version

int ScriptConfig::version
protected

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