OpenTTD Source
20241121-master-g67a0fccfad
|
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. More... | |
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. More... | |
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. More... | |
int | GetSetting (const std::string &name) const |
Get the value of a setting for this config. More... | |
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. More... | |
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.
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.
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.
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 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 AI::ResetConfig(), and AI::StartNew().
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 AIInstance::GetSetting(), and GameInstance::GetSetting().
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(), GetTextfile(), INVALID_COMPANY, and OWNER_DEITY.