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 
29 };
30 
32 
35  const char *name;
36  const char *description;
37  int min_value;
38  int max_value;
40  int easy_value;
42  int hard_value;
44  int step_size;
48 };
49 
50 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
51 
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 
99 
108  };
109 
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;
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 */