OpenTTD Source 20241224-master-gf74b0cf984
script_config.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef SCRIPT_CONFIG_HPP
11#define SCRIPT_CONFIG_HPP
12
13#include "../company_type.h"
14#include "../textfile_gui.h"
15#include "script_instance.hpp"
16
18static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION = 10 + 1 + 1;
19
28
29typedef std::map<int, std::string> LabelMapping;
30
43
44typedef std::vector<ScriptConfigItem> ScriptConfigItemList;
45
50protected:
52 typedef std::map<std::string, int> SettingValueList;
53
54public:
55 ScriptConfig() :
56 version(-1),
57 info(nullptr),
58 to_load_data(nullptr)
59 {}
60
65 ScriptConfig(const ScriptConfig *config);
66
68 virtual ~ScriptConfig();
69
77 void Change(std::optional<const std::string> name, int version = -1, bool force_exact_match = false);
78
82 class ScriptInfo *GetInfo() const;
83
88
98
108
116 int GetSetting(const std::string &name) const;
117
121 void SetSetting(const std::string_view name, int value);
122
126 void ResetSettings();
127
131 void ResetEditableSettings(bool yet_to_start);
132
137 bool HasScript() const;
138
142 const std::string &GetName() const;
143
147 int GetVersion() const;
148
153 void StringToSettings(const std::string &value);
154
159 std::string SettingsToString() const;
160
167 std::optional<std::string> GetTextfile(TextfileType type, CompanyID slot) const;
168
169 void SetToLoadData(ScriptInstance::ScriptData *data);
170 ScriptInstance::ScriptData *GetToLoadData();
171
172protected:
173 std::string name;
177 std::unique_ptr<ScriptConfigItemList> config_list;
178 std::unique_ptr<ScriptInstance::ScriptData> to_load_data;
179
183 void ClearConfigList();
184
189 virtual ScriptInfo *FindInfo(const std::string &name, int version, bool force_exact_match) = 0;
190};
191
192#endif /* SCRIPT_CONFIG_HPP */
Script settings.
ScriptSettingSource
Where to get the config from, either default (depends on current game mode) or force either newgame o...
@ SSS_FORCE_GAME
Get the Script config from the current game.
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
@ SSS_DEFAULT
Get the Script config from the current game mode.
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
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.
virtual ~ScriptConfig()
Delete an Script configuration.
int version
Version of the Script.
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 belong...
const std::string & GetName() const
Get the name of the Script.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
std::map< std::string, int > SettingValueList
List with name=>value pairs of all script-specific settings.
std::unique_ptr< ScriptConfigItemList > config_list
List with all settings defined by this Script.
int GetVersion() const
Get the version of the Script.
void ClearConfigList()
Routine that clears the config list.
std::unique_ptr< ScriptInstance::ScriptData > to_load_data
Data to load after the Script start.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
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.
std::string name
Name of the Script.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
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.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
All static information from an Script like name, version, etc.
Owner
Enum for all companies/owners.
ScriptConfigFlags
Bitmask of flags for Script settings.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
@ SCRIPTCONFIG_NONE
No flags set.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
std::vector< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
std::map< int, std::string > LabelMapping
Map-type used to map the setting numbers to labels.
The ScriptInstance tracks a script.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
LabelMapping labels
Text labels for the integer values.
std::string name
The name of the configuration setting.
int default_value
The default value of this configuration setting.
int min_value
The minimal value this configuration setting can have.
int max_value
The maximal value this configuration setting can have.
int step_size
The step size in the gui.
std::string description
The description of the configuration setting.
bool complete_labels
True if all values have a label.
TextfileType
Additional text files accompanying Tar archives.