OpenTTD
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 
116  void AnchorUnchangeableSettings();
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  virtual void AddRandomDeviation();
141 
146  bool HasScript() const;
147 
151  bool IsRandom() const;
152 
156  const char *GetName() const;
157 
161  int GetVersion() const;
162 
167  void StringToSettings(const char *value);
168 
173  void SettingsToString(char *string, const char *last) const;
174 
181  const char *GetTextfile(TextfileType type, CompanyID slot) const;
182 
183 protected:
184  const char *name;
185  int version;
186  class ScriptInfo *info;
187  SettingValueList settings;
189  bool is_random;
190 
195  virtual void PushExtraConfigList() {};
196 
200  virtual void ClearConfigList();
201 
206  virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
207 };
208 
209 #endif /* SCRIPT_CONFIG_HPP */
Owner
Enum for all companies/owners.
Definition: company_type.h:18
int GetVersion() const
Get the version of the script.
Definition: script_info.hpp:72
This setting will only be visible when the Script development tools are active.
int random_deviation
The maximum random deviation from the default value.
const ScriptConfigItemList * GetConfigList() const
Get the config list for this Script.
int min_value
The minimal value this configuration setting can have.
const char * GetName() const
Get the Name of the script.
Definition: script_info.hpp:57
std::list< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
Implementation of simple mapping class.
ScriptConfigItem _start_date_config
Configuration for AI start date, every AI has this setting.
Definition: ai_config.cpp:20
LabelMapping * labels
Text labels for the integer values.
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
int max_value
The maximal value this configuration setting can have.
Script settings.
bool is_random
True if the AI in this slot was randomly chosen.
int medium_value
The default value on medium difficulty setting.
ScriptConfigItemList * config_list
List with all settings defined by this Script.
No flags set.
Get the Script config from the current game mode.
ScriptConfigFlags
Bitmask of flags for Script settings.
std::map< const char *, int, StringCompare > SettingValueList
List with name=>value pairs of all script-specific settings.
bool complete_labels
True if all values have a label.
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
ScriptSettingSource
Where to get the config from, either default (depends on current game mode) or force either newgame o...
int easy_value
The default value on easy difficulty setting.
When randomizing the Script, pick any value between min_value and max_value when on custom difficulty...
int custom_value
The default value on custom difficulty setting.
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
SmallMap< int, char * > LabelMapping
Map-type used to map the setting numbers to labels.
This value is a boolean (either 0 (false) or 1 (true) ).
const char * description
The description of the configuration setting.
ScriptConfigFlags flags
Flags for the configuration setting.
Info about a single Script setting.
int version
Version of the Script.
Get the newgame Script config.
This setting can be changed while the Script is running.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
int hard_value
The default value on hard difficulty setting.
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.
int step_size
The step size in the gui.
Get the Script config from the current game.
virtual void PushExtraConfigList()
In case you have mandatory non-Script-definable config entries in your list, add them to this functio...
const char * name
The name of the configuration setting.