# script_config.hpp

Go to the documentation of this file.

    00001 /* $Id: script_config.hpp 24317 2012-06-01 15:19:59Z frosch $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef SCRIPT_CONFIG_HPP
    00013 #define SCRIPT_CONFIG_HPP
    00014
    00015 #include <map>
    00016 #include <list>
    00017 #include "../core/smallmap_type.hpp"
    00018 #include "../core/string_compare_type.hpp"
    00019 #include "../company_type.h"
    00020 #include "../textfile_gui.h"
    00021
    00023 enum ScriptConfigFlags {
    00024   SCRIPTCONFIG_NONE      = 0x0,
    00025   SCRIPTCONFIG_RANDOM    = 0x1,
    00026   SCRIPTCONFIG_BOOLEAN   = 0x2,
    00027   SCRIPTCONFIG_INGAME    = 0x4,
    00028   SCRIPTCONFIG_DEVELOPER = 0x8,
    00029 };
    00030
    00031 typedef SmallMap<int, char *> LabelMapping;
    00032
    00034 struct ScriptConfigItem {
    00035   const char *name;
    00036   const char *description;
    00037   int min_value;
    00038   int max_value;
    00039   int custom_value;
    00040   int easy_value;
    00041   int medium_value;
    00042   int hard_value;
    00043   int random_deviation;
    00044   int step_size;
    00045   ScriptConfigFlags flags;
    00046   LabelMapping *labels;
    00047   bool complete_labels;
    00048 };
    00049
    00050 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
    00051
    00052 extern ScriptConfigItem _start_date_config;
    00053
    00057 class ScriptConfig {
    00058 protected:
    00060   typedef std::map<const char *, int, StringCompare> SettingValueList;
    00061
    00062 public:
    00063   ScriptConfig() :
    00064     name(NULL),
    00065     version(-1),
    00066     info(NULL),
    00067     config_list(NULL),
    00068     is_random(false)
    00069   {}
    00070
    00075   ScriptConfig(const ScriptConfig *config);
    00076
    00078   virtual ~ScriptConfig();
    00079
    00088   void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
    00089
    00093   class ScriptInfo *GetInfo() const;
    00094
    00098   const ScriptConfigItemList *GetConfigList();
    00099
    00104   enum ScriptSettingSource {
    00105     SSS_DEFAULT,
    00106     SSS_FORCE_NEWGAME,
    00107     SSS_FORCE_GAME,
    00108   };
    00109
    00117   virtual int GetSetting(const char *name) const;
    00118
    00122   virtual void SetSetting(const char *name, int value);
    00123
    00127   void ResetSettings();
    00128
    00132   void AddRandomDeviation();
    00133
    00138   bool HasScript() const;
    00139
    00143   bool IsRandom() const;
    00144
    00148   const char *GetName() const;
    00149
    00153   int GetVersion() const;
    00154
    00159   void StringToSettings(const char *value);
    00160
    00165   void SettingsToString(char *string, size_t size) const;
    00166
    00173   const char *GetTextfile(TextfileType type, CompanyID slot) const;
    00174
    00175 protected:
    00176   const char *name;
    00177   int version;
    00178   class ScriptInfo *info;
    00179   SettingValueList settings;
    00180   ScriptConfigItemList *config_list;
    00181   bool is_random;
    00182
    00187   virtual void PushExtraConfigList() {};
    00188
    00192   virtual void ClearConfigList();
    00193
    00198   virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
    00199 };
    00200
    00201 #endif /* SCRIPT_CONFIG_HPP */