12 #include "../stdafx.h" 13 #include "../settings_type.h" 14 #include "../core/random_func.hpp" 16 #include "../textfile_gui.h" 17 #include "../string_func.h" 19 #include "../safeguards.h" 24 this->name = (name == NULL) ? NULL :
stredup(name);
25 this->
info = (name == NULL) ? NULL : this->
FindInfo(this->name, version, force_exact_match);
34 if (_game_mode == GM_NORMAL && this->
info != NULL) {
39 this->
SetSetting((*it).name, InteractiveRandomRange((*it).max_value - (*it).min_value) + (*it).min_value);
54 for (SettingValueList::const_iterator it = config->
settings.begin(); it != config->
settings.end(); it++) {
84 for (SettingValueList::iterator it = this->
settings.begin(); it != this->
settings.end(); it++) {
94 this->
SetSetting((*it).name, this->GetSetting((*it).name));
101 SettingValueList::const_iterator it = this->
settings.find(name);
109 if (this->
info == NULL)
return;
112 if (config_item == NULL)
return;
116 SettingValueList::iterator it = this->
settings.find(name);
118 (*it).second = value;
126 for (SettingValueList::iterator it = this->
settings.begin(); it != this->
settings.end(); it++) {
135 if ((*it).random_deviation != 0) {
136 this->
SetSetting((*it).name, InteractiveRandomRange((*it).random_deviation * 2) - (*it).random_deviation + this->GetSetting((*it).name));
143 return this->
info != NULL;
163 char *value_copy =
stredup(value);
164 char *s = value_copy;
170 if (s == NULL)
break;
171 if (*s ==
'\0')
break;
175 char *item_value = s;
182 this->
SetSetting(item_name, atoi(item_value));
191 for (SettingValueList::const_iterator it = this->
settings.begin(); it != this->
settings.end(); it++) {
196 size_t needed_size = strlen((*it).first) + 1 + strlen(no);
198 if (
string + needed_size > last)
break;
200 s =
strecat(s, (*it).first, last);
207 if (s !=
string) s[-1] =
'\0';
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.
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.
The object is owned by a superuser / goal 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.
Owner
Enum for all companies/owners.
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...
ScriptInfo keeps track of all information of a script, like Author, Description, ...
int GetVersion() const
Get the version of the Script.