OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../settings_type.h"
12 #include "../core/random_func.hpp"
14 #include "../textfile_gui.h"
15 #include "../string_func.h"
17 #include "../safeguards.h"
23 this->
info = (name ==
nullptr) ?
nullptr : this->
FindInfo(this->name,
version, force_exact_match);
32 if (_game_mode == GM_NORMAL && this->
info !=
nullptr) {
37 this->
SetSetting(item.name, InteractiveRandomRange(item.max_value + 1 - item.min_value) + item.min_value);
52 for (
const auto &item : config->
settings) {
82 for (
const auto &item : this->
settings) {
85 this->settings.clear();
92 this->
SetSetting(item.name, this->GetSetting(item.name));
99 const auto it = this->
settings.find(name);
107 if (this->
info ==
nullptr)
return;
110 if (config_item ==
nullptr)
return;
114 const auto it = this->
settings.find(name);
116 (*it).second = value;
124 for (
const auto &item : this->
settings) {
127 this->settings.clear();
134 for (SettingValueList::iterator it = this->
settings.begin(); it != this->settings.end();) {
136 assert(config_item !=
nullptr);
141 if (editable && visible) {
153 if (item.random_deviation != 0) {
154 this->
SetSetting(item.name, InteractiveRandomRange(item.random_deviation * 2 + 1) - item.random_deviation + this->GetSetting(item.name));
161 return this->
info !=
nullptr;
181 char *value_copy =
stredup(value);
182 char *s = value_copy;
184 while (s !=
nullptr) {
188 if (s ==
nullptr)
break;
189 if (*s ==
'\0')
break;
193 char *item_value = s;
200 this->
SetSetting(item_name, atoi(item_value));
209 for (
const auto &item : this->
settings) {
214 size_t needed_size = strlen(item.first) + 1 + strlen(no);
216 if (
string + needed_size > last)
break;
218 s =
strecat(s, item.first, last);
225 if (s !=
string) s[-1] =
'\0';
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
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 belong...
void SettingsToString(char *string, const char *last) const
Convert the custom settings to a string that can be stored in the config file or savegames.
virtual ~ScriptConfig()
Delete an Script configuration.
ClientSettings _settings_client
The current settings for this game.
Owner
Enum for all companies/owners.
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.
bool ai_developer_tools
activate AI developer tools
int max_value
The maximal value this configuration setting can have.
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
virtual void AddRandomDeviation()
Randomize all settings the Script requested to be randomized.
@ AI_DIR
Subdirectory for all AI files.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
const char * GetName() const
Get the name of the Script.
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
bool IsRandom() const
Is the current Script a randomly chosen Script?
@ 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.
int GetVersion() const
Get the version of the Script.
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
ScriptConfigItemList * config_list
List with all settings defined by this Script.
void ResetSettings()
Reset all settings to their default value.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored.
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
int GetVersion() const
Get the version of the script.
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
@ OWNER_DEITY
The object is owned by a superuser / goal script.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
@ SCRIPTCONFIG_RANDOM
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
ScriptConfigFlags flags
Flags for the configuration setting.
const char * name
Name of the Script.
virtual void ClearConfigList()
Routine that clears the config list.
const ScriptConfigItem * GetConfigItem(const char *name) const
Get the description of a certain Script config option.
@ INVALID_COMPANY
An invalid company.
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.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
TextfileType
Additional text files accompanying Tar archives.
int GetSettingDefaultValue(const char *name) const
Get the default value for a setting.
virtual void PushExtraConfigList()
In case you have mandatory non-Script-definable config entries in your list, add them to this functio...
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
All static information from an Script like name, version, etc.
Info about a single Script setting.
#define lastof(x)
Get the last element of an fixed size array.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
bool is_random
True if the AI in this slot was randomly chosen.
GUISettings gui
settings related to the GUI
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.