OpenTTD Source  1.11.2
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 <map>
14 #include <list>
15 #include "../core/smallmap_type.hpp"
16 #include "../core/string_compare_type.hpp"
17 #include "../company_type.h"
18 #include "../textfile_gui.h"
19 
27 };
28 
30 
33  const char *name;
34  const char *description;
35  int min_value;
36  int max_value;
38  int easy_value;
40  int hard_value;
42  int step_size;
46 };
47 
48 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
49 
51 
55 class ScriptConfig {
56 protected:
58  typedef std::map<const char *, int, StringCompare> SettingValueList;
59 
60 public:
61  ScriptConfig() :
62  name(nullptr),
63  version(-1),
64  info(nullptr),
65  config_list(nullptr),
66  is_random(false)
67  {}
68 
73  ScriptConfig(const ScriptConfig *config);
74 
76  virtual ~ScriptConfig();
77 
86  void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
87 
91  class ScriptInfo *GetInfo() const;
92 
97 
106  };
107 
117 
125  virtual int GetSetting(const char *name) const;
126 
130  virtual void SetSetting(const char *name, int value);
131 
135  void ResetSettings();
136 
140  void ResetEditableSettings(bool yet_to_start);
141 
145  virtual void AddRandomDeviation();
146 
151  bool HasScript() const;
152 
156  bool IsRandom() const;
157 
161  const char *GetName() const;
162 
166  int GetVersion() const;
167 
172  void StringToSettings(const char *value);
173 
178  void SettingsToString(char *string, const char *last) const;
179 
186  const char *GetTextfile(TextfileType type, CompanyID slot) const;
187 
188 protected:
189  const char *name;
190  int version;
191  class ScriptInfo *info;
194  bool is_random;
195 
200  virtual void PushExtraConfigList() {};
201 
205  virtual void ClearConfigList();
206 
211  virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
212 };
213 
214 #endif /* SCRIPT_CONFIG_HPP */
ScriptConfig::StringToSettings
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
Definition: script_config.cpp:179
ScriptConfig::FindInfo
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...
ScriptConfig::SettingsToString
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.
Definition: script_config.cpp:205
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:42
ScriptConfigFlags
ScriptConfigFlags
Bitmask of flags for Script settings.
Definition: script_config.hpp:21
ScriptConfigItem::labels
LabelMapping * labels
Text labels for the integer values.
Definition: script_config.hpp:44
ScriptConfig::~ScriptConfig
virtual ~ScriptConfig()
Delete an Script configuration.
Definition: script_config.cpp:58
ScriptConfigItem::medium_value
int medium_value
The default value on medium difficulty setting.
Definition: script_config.hpp:39
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition: script_config.cpp:130
SCRIPTCONFIG_BOOLEAN
@ SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
Definition: script_config.hpp:24
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition: script_config.hpp:35
SmallMap
Implementation of simple mapping class.
Definition: smallmap_type.hpp:26
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:45
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition: script_config.hpp:36
ScriptConfigItemList
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Definition: script_config.hpp:48
ScriptConfig::AddRandomDeviation
virtual void AddRandomDeviation()
Randomize all settings the Script requested to be randomized.
Definition: script_config.cpp:150
ScriptConfig::SSS_DEFAULT
@ SSS_DEFAULT
Get the Script config from the current game mode.
Definition: script_config.hpp:103
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:65
ScriptConfig::GetName
const char * GetName() const
Get the name of the Script.
Definition: script_config.cpp:169
SCRIPTCONFIG_NONE
@ SCRIPTCONFIG_NONE
No flags set.
Definition: script_config.hpp:22
ScriptConfig::SetSetting
virtual void SetSetting(const char *name, int value)
Set the value of a setting for this config.
Definition: script_config.cpp:104
ScriptConfig::IsRandom
bool IsRandom() const
Is the current Script a randomly chosen Script?
Definition: script_config.cpp:164
SCRIPTCONFIG_INGAME
@ SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:25
SCRIPTCONFIG_DEVELOPER
@ SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:26
ScriptConfig::version
int version
Version of the Script.
Definition: script_config.hpp:190
LabelMapping
SmallMap< int, char * > LabelMapping
Map-type used to map the setting numbers to labels.
Definition: script_config.hpp:29
ScriptConfigItem::easy_value
int easy_value
The default value on easy difficulty setting.
Definition: script_config.hpp:38
ScriptConfig::GetVersion
int GetVersion() const
Get the version of the Script.
Definition: script_config.cpp:174
ScriptConfig::GetTextfile
const char * GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition: script_config.cpp:228
ScriptConfig::config_list
ScriptConfigItemList * config_list
List with all settings defined by this Script.
Definition: script_config.hpp:193
ScriptConfig::ResetSettings
void ResetSettings()
Reset all settings to their default value.
Definition: script_config.cpp:122
ScriptConfigItem::custom_value
int custom_value
The default value on custom difficulty setting.
Definition: script_config.hpp:37
ScriptConfig::info
class ScriptInfo * info
ScriptInfo object for related to this Script version.
Definition: script_config.hpp:191
ScriptConfig::AnchorUnchangeableSettings
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored.
Definition: script_config.cpp:88
ScriptConfigItem::description
const char * description
The description of the configuration setting.
Definition: script_config.hpp:34
ScriptConfig::GetSetting
virtual int GetSetting(const char *name) const
Get the value of a setting for this config.
Definition: script_config.cpp:97
ScriptConfig
Script settings.
Definition: script_config.hpp:55
ScriptConfig::SSS_FORCE_NEWGAME
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
Definition: script_config.hpp:104
SCRIPTCONFIG_RANDOM
@ SCRIPTCONFIG_RANDOM
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
Definition: script_config.hpp:23
ScriptConfig::name
const char * name
Name of the Script.
Definition: script_config.hpp:189
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:43
ScriptConfig::ClearConfigList
virtual void ClearConfigList()
Routine that clears the config list.
Definition: script_config.cpp:80
ScriptConfig::Change
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.
Definition: script_config.cpp:19
ScriptConfig::SettingValueList
std::map< const char *, int, StringCompare > SettingValueList
List with name=>value pairs of all script-specific settings.
Definition: script_config.hpp:58
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition: script_config.cpp:70
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
ScriptConfig::PushExtraConfigList
virtual void PushExtraConfigList()
In case you have mandatory non-Script-definable config entries in your list, add them to this functio...
Definition: script_config.hpp:200
ScriptConfigItem::hard_value
int hard_value
The default value on hard difficulty setting.
Definition: script_config.hpp:40
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:32
ScriptConfig::SSS_FORCE_GAME
@ SSS_FORCE_GAME
Get the Script config from the current game.
Definition: script_config.hpp:105
ScriptConfigItem::random_deviation
int random_deviation
The maximum random deviation from the default value.
Definition: script_config.hpp:41
ScriptConfigItem::name
const char * name
The name of the configuration setting.
Definition: script_config.hpp:33
ScriptConfig::HasScript
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
Definition: script_config.cpp:159
_start_date_config
ScriptConfigItem _start_date_config
Configuration for AI start date, every AI has this setting.
Definition: ai_config.cpp:20
ScriptConfig::is_random
bool is_random
True if the AI in this slot was randomly chosen.
Definition: script_config.hpp:194
ScriptConfig::settings
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
Definition: script_config.hpp:192
ScriptConfig::ScriptSettingSource
ScriptSettingSource
Where to get the config from, either default (depends on current game mode) or force either newgame o...
Definition: script_config.hpp:102