OpenTTD

script_config.hpp
Go to the documentation of this file.
1 /* $Id: script_config.hpp 26493 2014-04-24 04:41:54Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef SCRIPT_CONFIG_HPP
13 #define SCRIPT_CONFIG_HPP
14
15 #include <map>
16 #include <list>
17 #include "../core/smallmap_type.hpp"
18 #include "../core/string_compare_type.hpp"
19 #include "../company_type.h"
20 #include "../textfile_gui.h"
21
23 enum ScriptConfigFlags {
24 SCRIPTCONFIG_NONE = 0x0,
25 SCRIPTCONFIG_RANDOM = 0x1,
26 SCRIPTCONFIG_BOOLEAN = 0x2,
27 SCRIPTCONFIG_INGAME = 0x4,
28 SCRIPTCONFIG_DEVELOPER = 0x8,
29 };
30
31 typedef SmallMap<int, char *> LabelMapping;
32
34 struct ScriptConfigItem {
35 const char *name;
36 const char *description;
37 int min_value;
38 int max_value;
39 int custom_value;
40 int easy_value;
41 int medium_value;
42 int hard_value;
43 int random_deviation;
44 int step_size;
45 ScriptConfigFlags flags;
46 LabelMapping *labels;
47 bool complete_labels;
48 };
49
50 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
51
52 extern ScriptConfigItem _start_date_config;
53
57 class ScriptConfig {
58 protected:
60 typedef std::map<const char *, int, StringCompare> SettingValueList;
61
62 public:
63 ScriptConfig() :
64 name(NULL),
65 version(-1),
66 info(NULL),
67 config_list(NULL),
68 is_random(false)
69 {}
70
75 ScriptConfig(const ScriptConfig *config);
76
78 virtual ~ScriptConfig();
79
88 void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
89
93 class ScriptInfo *GetInfo() const;
94
98 const ScriptConfigItemList *GetConfigList();
99
104 enum ScriptSettingSource {
105 SSS_DEFAULT,
106 SSS_FORCE_NEWGAME,
107 SSS_FORCE_GAME,
108 };
109
118 void AnchorUnchangeableSettings();
119
127 virtual int GetSetting(const char *name) const;
128
132 virtual void SetSetting(const char *name, int value);
133
137 void ResetSettings();
138
142 void AddRandomDeviation();
143
148 bool HasScript() const;
149
153 bool IsRandom() const;
154
158 const char *GetName() const;
159
163 int GetVersion() const;
164
169 void StringToSettings(const char *value);
170
175 void SettingsToString(char *string, const char *last) const;
176
183 const char *GetTextfile(TextfileType type, CompanyID slot) const;
184
185 protected:
186 const char *name;
187 int version;
188 class ScriptInfo *info;
189 SettingValueList settings;
190 ScriptConfigItemList *config_list;
191 bool is_random;
192
197 virtual void PushExtraConfigList() {};
198
202 virtual void ClearConfigList();
203
208 virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
209 };
210
211 #endif /* SCRIPT_CONFIG_HPP */
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:74
SCRIPTCONFIG_DEVELOPER
This setting will only be visible when the Script development tools are active.
Definition: script_config.hpp:28
ScriptConfigItem::random_deviation
int random_deviation
The maximum random deviation from the default value.
Definition: script_config.hpp:43
ScriptInfo::GetConfigList
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
Definition: script_info.cpp:282
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition: script_config.hpp:37
ScriptInfo::GetName
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:59
ScriptConfigItemList
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Definition: script_config.hpp:50
SmallMap
Implementation of simple mapping class.
Definition: smallmap_type.hpp:42
_start_date_config
ScriptConfigItem _start_date_config
Configuration for AI start date, every AI has this setting.
Definition: ai_config.cpp:22
ScriptConfigItem::labels
LabelMapping * labels
Text labels for the integer values.
Definition: script_config.hpp:46
ScriptConfig::settings
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
Definition: script_config.hpp:189
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition: script_config.hpp:38
ScriptConfig
Script settings.
Definition: script_config.hpp:57
ScriptConfig::is_random
bool is_random
True if the AI in this slot was randomly chosen.
Definition: script_config.hpp:191
ScriptConfigItem::medium_value
int medium_value
The default value on medium difficulty setting.
Definition: script_config.hpp:41
ScriptConfig::config_list
ScriptConfigItemList * config_list
List with all settings defined by this Script.
Definition: script_config.hpp:190
SCRIPTCONFIG_NONE
No flags set.
Definition: script_config.hpp:24
ScriptConfig::SSS_DEFAULT
Get the Script config from the current game mode.
Definition: script_config.hpp:105
ScriptConfigFlags
ScriptConfigFlags
Bitmask of flags for Script settings.
Definition: script_config.hpp:23
ScriptConfig::SettingValueList
std::map< const char *, int, StringCompare > SettingValueList
List with name=>value pairs of all script-specific settings.
Definition: script_config.hpp:60
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition: script_config.hpp:47
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:32
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:104
ScriptConfigItem::easy_value
int easy_value
The default value on easy difficulty setting.
Definition: script_config.hpp:40
SCRIPTCONFIG_RANDOM
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
Definition: script_config.hpp:25
ScriptConfigItem::custom_value
int custom_value
The default value on custom difficulty setting.
Definition: script_config.hpp:39
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:16
LabelMapping
SmallMap< int, char * > LabelMapping
Map-type used to map the setting numbers to labels.
Definition: script_config.hpp:31
SCRIPTCONFIG_BOOLEAN
This value is a boolean (either 0 (false) or 1 (true) ).
Definition: script_config.hpp:26
ScriptConfigItem::description
const char * description
The description of the configuration setting.
Definition: script_config.hpp:36
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition: script_config.hpp:45
ScriptConfigItem
Info about a single Script setting.
Definition: script_config.hpp:34
ScriptConfig::version
int version
Version of the Script.
Definition: script_config.hpp:187
ScriptConfig::SSS_FORCE_NEWGAME
Get the newgame Script config.
Definition: script_config.hpp:106
SCRIPTCONFIG_INGAME
This setting can be changed while the Script is running.
Definition: script_config.hpp:27
ScriptConfig::info
class ScriptInfo * info
ScriptInfo object for related to this Script version.
Definition: script_config.hpp:188
ScriptConfigItem::hard_value
int hard_value
The default value on hard difficulty setting.
Definition: script_config.hpp:42
ScriptConfig::name
const char * name
Name of the Script.
Definition: script_config.hpp:186
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:386
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition: script_config.hpp:44
ScriptConfig::SSS_FORCE_GAME
Get the Script config from the current game.
Definition: script_config.hpp:107
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:197
ScriptConfigItem::name
const char * name
The name of the configuration setting.
Definition: script_config.hpp:35