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" 22 this->name = (name ==
nullptr) ?
nullptr :
stredup(name);
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((*it).name, InteractiveRandomRange((*it).max_value + 1 - (*it).min_value) + (*it).min_value);
52 for (SettingValueList::const_iterator it = config->
settings.begin(); it != config->
settings.end(); it++) {
82 for (SettingValueList::iterator it = this->
settings.begin(); it != this->
settings.end(); it++) {
92 this->
SetSetting((*it).name, this->GetSetting((*it).name));
99 SettingValueList::const_iterator it = this->
settings.find(name);
107 if (this->
info ==
nullptr)
return;
110 if (config_item ==
nullptr)
return;
114 SettingValueList::iterator it = this->
settings.find(name);
116 (*it).second = value;
124 for (SettingValueList::iterator it = this->
settings.begin(); it != this->
settings.end(); it++) {
133 if ((*it).random_deviation != 0) {
134 this->
SetSetting((*it).name, InteractiveRandomRange((*it).random_deviation * 2) - (*it).random_deviation + this->GetSetting((*it).name));
141 return this->
info !=
nullptr;
161 char *value_copy =
stredup(value);
162 char *s = value_copy;
164 while (s !=
nullptr) {
168 if (s ==
nullptr)
break;
169 if (*s ==
'\0')
break;
173 char *item_value = s;
180 this->
SetSetting(item_name, atoi(item_value));
189 for (SettingValueList::const_iterator it = this->
settings.begin(); it != this->
settings.end(); it++) {
194 size_t needed_size = strlen((*it).first) + 1 + strlen(no);
196 if (
string + needed_size > last)
break;
198 s =
strecat(s, (*it).first, last);
205 if (s !=
string) s[-1] =
'\0';
Owner
Enum for all companies/owners.
int GetVersion() const
Get the version of the script.
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
int min_value
The minimal value this configuration setting can have.
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
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.
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
Subdirectory for all game scripts.
int max_value
The maximal value this configuration setting can have.
int GetSettingDefaultValue(const char *name) const
Get the default value for a setting.
#define lastof(x)
Get the last element of an fixed size array.
virtual void AddRandomDeviation()
Randomize all settings the Script requested to be randomized.
bool is_random
True if the AI in this slot was randomly chosen.
ScriptConfigItemList * config_list
List with all settings defined by this Script.
const char * GetName() const
Get the name of the Script.
bool IsRandom() const
Is the current Script a randomly chosen Script?
virtual void ClearConfigList()
Routine that clears the config list.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
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...
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
All static information from an Script like name, version, etc.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
TextfileType
Additional text files accompanying Tar archives.
const ScriptConfigItem * GetConfigItem(const char *name) const
Get the description of a certain Script config option.
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Info about a single Script setting.
int version
Version of the Script.
Subdirectory for all AI files.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored...
This setting can be changed while the Script is running.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
void ResetSettings()
Reset all settings to their default value.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
virtual ~ScriptConfig()
Delete an Script configuration.
const char * name
Name of the Script.
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script...
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 void PushExtraConfigList()
In case you have mandatory non-Script-definable config entries in your list, add them to this functio...
The object is owned by a superuser / goal script.
ScriptInfo keeps track of all information of a script, like Author, Description, ...
int GetVersion() const
Get the version of the Script.