OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../settings_type.h"
12 #include "../core/random_func.hpp"
14 #include "api/script_object.hpp"
15 #include "../textfile_gui.h"
16 #include "../string_func.h"
19 #include "../safeguards.h"
23 if (
name.has_value()) {
24 this->name = std::move(
name.value());
43 for (
const auto &item : config->
settings) {
44 this->
settings[item.first] = item.second;
63 this->
config_list = std::make_unique<ScriptConfigItemList>();
77 this->
SetSetting(item.name, this->GetSetting(item.name));
84 const auto it = this->
settings.find(name);
92 if (this->
info ==
nullptr)
return;
95 if (config_item ==
nullptr)
return;
111 for (SettingValueList::iterator it = this->
settings.begin(); it != this->settings.end();) {
113 assert(config_item !=
nullptr);
118 if (editable && visible) {
128 return this->
info !=
nullptr;
143 std::string_view to_process = value;
146 size_t pos = to_process.find_first_of(
'=');
147 if (pos == std::string_view::npos)
return;
149 std::string_view item_name = to_process.substr(0, pos);
151 to_process.remove_prefix(pos + 1);
152 pos = to_process.find_first_of(
',');
154 std::from_chars(to_process.data(), to_process.data() + std::min(pos, to_process.size()), item_value);
158 if (pos == std::string_view::npos)
return;
159 to_process.remove_prefix(pos + 1);
165 if (this->
settings.empty())
return {};
168 for (
const auto &item : this->
settings) {
169 fmt::format_to(std::back_inserter(result),
"{}={},", item.first, item.second);
173 result.resize(result.size() - 1);
184 void ScriptConfig::SetToLoadData(ScriptInstance::ScriptData *data)
189 ScriptInstance::ScriptData *ScriptConfig::GetToLoadData()
@ OWNER_DEITY
The object is owned by a superuser / goal script.
std::unique_ptr< ScriptConfigItemList > config_list
List with all settings defined by this Script.
@ INVALID_COMPANY
An invalid company.
std::vector< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Owner
Enum for all companies/owners.
virtual ~ScriptConfig()
Delete an Script configuration.
ClientSettings _settings_client
The current settings for this game.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
int min_value
The minimal value this configuration setting can have.
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.
int GetSettingDefaultValue(const std::string &name) const
Get the default value for a setting.
bool ai_developer_tools
activate AI/GS developer tools
int max_value
The maximal value this configuration setting can have.
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
@ AI_DIR
Subdirectory for all AI files.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
std::optional< std::string > GetTextfile(TextfileType type, Subdirectory dir, const std::string &filename)
Search a textfile file next to the given content.
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
@ GAME_DIR
Subdirectory for all game scripts.
int version
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.
int GetVersion() const
Get the version of the Script.
void ResetSettings()
Reset all settings to their default value.
std::unique_ptr< ScriptInstance::ScriptData > to_load_data
Data to load after the Script start.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored.
int GetVersion() const
Get the version of the script.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
std::string name
Name of the Script.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
ScriptConfigFlags flags
Flags for the configuration setting.
void ClearConfigList()
Routine that clears the config list.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
TextfileType
Additional text files accompanying Tar archives.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
All static information from an Script like name, version, etc.
Info about a single Script setting.
void SetSetting(const std::string_view name, int value)
Set the value of a setting for this config.
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...
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
GUISettings gui
settings related to the GUI
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
const ScriptConfigItem * GetConfigItem(const std::string_view name) const
Get the description of a certain Script config option.
const std::string & GetName() const
Get the name of the Script.