OpenTTD Source 20241224-master-gf74b0cf984
|
Script settings. More...
#include <script_config.hpp>
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 ScriptInfo * | GetInfo () const |
Get the ScriptInfo linked to this ScriptConfig. | |
const ScriptConfigItemList * | GetConfigList () |
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 ScriptInfo * | FindInfo (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 ScriptInfo * | info |
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< ScriptConfigItemList > | config_list |
List with all settings defined by this Script. | |
std::unique_ptr< ScriptInstance::ScriptData > | to_load_data |
Data to load after the Script start. | |
Script settings.
Definition at line 49 of file script_config.hpp.
|
protected |
List with name=>value pairs of all script-specific settings.
Definition at line 52 of file script_config.hpp.
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.
|
inline |
Definition at line 55 of file script_config.hpp.
ScriptConfig::ScriptConfig | ( | const ScriptConfig * | config | ) |
Create a new Script config that is a copy of an existing config.
config | The object to copy. |
Definition at line 36 of file script_config.cpp.
References info, name, settings, to_load_data, and version.
|
virtual |
Delete an Script configuration.
Definition at line 48 of file script_config.cpp.
References ResetSettings(), and to_load_data.
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().
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.
name | The name of the Script. |
version | The version of the Script to load, or -1 of latest. |
force_exact_match | If 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().
|
protected |
Routine that clears the config list.
Definition at line 68 of file script_config.cpp.
References settings.
Referenced by Change().
|
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().
const ScriptConfigItemList * ScriptConfig::GetConfigList | ( | ) |
Get the config list for this ScriptConfig.
Definition at line 59 of file script_config.cpp.
References config_list, ScriptInfo::GetConfigList(), and info.
Referenced by AnchorUnchangeableSettings(), ScriptSettingsWindow::OnInvalidateData(), ScriptDebugWindow::OnInvalidateData(), GSConfigWindow::RebuildVisibleSettings(), and ScriptSettingsWindow::RebuildVisibleSettings().
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().
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().
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).
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().
std::optional< std::string > ScriptConfig::GetTextfile | ( | TextfileType | type, |
CompanyID | slot | ||
) | const |
Search a textfile file next to this script.
type | The type of the textfile to search for. |
slot | CompanyID to check status of. |
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().
ScriptInstance::ScriptData * ScriptConfig::GetToLoadData | ( | ) |
Definition at line 189 of file script_config.cpp.
int ScriptConfig::GetVersion | ( | ) | const |
Get the version of the Script.
Definition at line 136 of file script_config.cpp.
References version.
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().
void ScriptConfig::ResetEditableSettings | ( | bool | yet_to_start | ) |
Reset only editable and visible settings to their default value.
Definition at line 107 of file script_config.cpp.
References _settings_client, GUISettings::ai_developer_tools, ScriptConfigItem::flags, ScriptInfo::GetConfigItem(), ClientSettings::gui, info, ResetSettings(), SCRIPTCONFIG_DEVELOPER, SCRIPTCONFIG_INGAME, and settings.
Referenced by GSConfigWindow::OnClick(), and ScriptSettingsWindow::OnClick().
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().
void ScriptConfig::SetSetting | ( | const std::string_view | name, |
int | value | ||
) |
Set the value of a setting for this config.
Definition at line 89 of file script_config.cpp.
References Clamp(), ScriptInfo::GetConfigItem(), info, ScriptConfigItem::max_value, ScriptConfigItem::min_value, name, and settings.
Referenced by AnchorUnchangeableSettings(), GSConfigWindow::OnClick(), ScriptSettingsWindow::OnClick(), and StringToSettings().
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.
void ScriptConfig::SetToLoadData | ( | ScriptInstance::ScriptData * | data | ) |
Definition at line 184 of file script_config.cpp.
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().
|
protected |
List with all settings defined by this Script.
Definition at line 177 of file script_config.hpp.
Referenced by Change(), and GetConfigList().
|
protected |
ScriptInfo object for related to this Script version.
Definition at line 175 of file script_config.hpp.
Referenced by Change(), GetConfigList(), GetInfo(), GetSetting(), HasScript(), ResetEditableSettings(), AIConfig::ResetInfo(), GameConfig::ResetInfo(), ScriptConfig(), and SetSetting().
|
protected |
Name of the Script.
Definition at line 173 of file script_config.hpp.
Referenced by Change(), AIConfig::FindInfo(), GameConfig::FindInfo(), GetName(), AIConfig::ResetInfo(), GameConfig::ResetInfo(), ScriptConfig(), and SetSetting().
|
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().
|
protected |
Data to load after the Script start.
Definition at line 178 of file script_config.hpp.
Referenced by Change(), ScriptConfig(), and ~ScriptConfig().
|
protected |
Version of the Script.
Definition at line 174 of file script_config.hpp.
Referenced by Change(), AIConfig::FindInfo(), GameConfig::FindInfo(), GetVersion(), AIConfig::ResetInfo(), GameConfig::ResetInfo(), and ScriptConfig().