OpenTTD Source: ScriptConfig Class Reference

OpenTTD Source 12.0-beta1

Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
ScriptConfig Class Referenceabstract

Script settings. More...

`#include <script_config.hpp>`

Inheritance diagram for ScriptConfig:

## 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 (const char *name, int version=-1, bool force_exact_match=false, bool is_random=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...
virtual int | GetSetting (const char *name) const
| Get the value of a setting for this config. More...
virtual void | SetSetting (const char *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.
virtual void | AddRandomDeviation ()
| Randomize all settings the Script requested to be randomized.
bool | HasScript () const
| Is this config attached to an Script? In other words, is there a Script that is assigned to this slot.
bool | IsRandom () const
| Is the current Script a randomly chosen Script?
const char * | 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.
const char * | GetTextfile (TextfileType type, CompanyID slot) const
| Search a textfile file next to this script. More...

## Protected Types
typedef std::map< const char *, int, StringCompare > | SettingValueList
| List with name=>value pairs of all script-specific settings.

## Protected Member Functions
virtual void | PushExtraConfigList ()
| In case you have mandatory non-Script-definable config entries in your list, add them to this function.
virtual void | ClearConfigList ()
| Routine that clears the config list.
virtual ScriptInfo * | FindInfo (const char *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
const char * | 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.
ScriptConfigItemList * | config_list
| List with all settings defined by this Script.
bool | is_random
| True if the AI in this slot was randomly chosen.

## Detailed Description

Script settings.

Definition at line 55 of file script_config.hpp.

## Member Enumeration Documentation

## ◆ ScriptSettingSource

enum ScriptConfig::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 102 of file script_config.hpp.

## Constructor & Destructor Documentation

## ◆ ScriptConfig()

ScriptConfig::ScriptConfig | ( | const ScriptConfig * | config | ) |

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

Parameters

  config | The object to copy.

Definition at line 45 of file script_config.cpp.

References AddRandomDeviation(), config_list, info, is_random, name, settings, stredup(), and version.

## 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 91 of file script_config.cpp.

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

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

## ◆ Change()

void ScriptConfig::Change | ( | const char * | name,
|  | int | version = `-1`,
|  | bool | force_exact_match = `false`,
|  | bool | is_random = `false`
| ) |  |

Set another Script to be loaded in this slot.

Parameters

  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.
  is_random | Is the Script chosen randomly?

Definition at line 19 of file script_config.cpp.

References ClearConfigList(), config_list, FindInfo(), free(), ScriptInfo::GetVersion(), info, is_random, name, PushExtraConfigList(), stredup(), and version.

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

## ◆ GetSetting()

int ScriptConfig::GetSetting | ( | const char * | name | ) | const
| virtual

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.

Reimplemented in AIConfig.

Definition at line 100 of file script_config.cpp.

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

Referenced by GameInstance::GetSetting().

## ◆ GetTextfile()

const char * ScriptConfig::GetTextfile | ( | TextfileType | type,
|  | CompanyID | slot
| ) |  | const

Search a textfile file next to this script.

Parameters

  type | The type of the textfile to search for.
  slot | #CompanyID to check status of.

Returns
  The filename for the textfile, `nullptr` otherwise.

Definition at line 235 of file script_config.cpp.

References AI_DIR, GAME_DIR, GetInfo(), GetTextfile(), INVALID_COMPANY, and OWNER_DEITY.

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

- src/script/script_config.hpp
- src/script/script_config.cpp