script_config.hpp

Go to the documentation of this file.
00001 /* $Id: script_config.hpp 25592 2013-07-12 18:54:27Z rubidium $ */
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 
00118   void AnchorUnchangeableSettings();
00119 
00127   virtual int GetSetting(const char *name) const;
00128 
00132   virtual void SetSetting(const char *name, int value);
00133 
00137   void ResetSettings();
00138 
00142   void AddRandomDeviation();
00143 
00148   bool HasScript() const;
00149 
00153   bool IsRandom() const;
00154 
00158   const char *GetName() const;
00159 
00163   int GetVersion() const;
00164 
00169   void StringToSettings(const char *value);
00170 
00175   void SettingsToString(char *string, size_t size) const;
00176 
00183   const char *GetTextfile(TextfileType type, CompanyID slot) const;
00184 
00185 protected:
00186   const char *name;                  
00187   int version;                       
00188   class ScriptInfo *info;            
00189   SettingValueList settings;         
00190   ScriptConfigItemList *config_list; 
00191   bool is_random;                    
00192 
00197   virtual void PushExtraConfigList() {};
00198 
00202   virtual void ClearConfigList();
00203 
00208   virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
00209 };
00210 
00211 #endif /* SCRIPT_CONFIG_HPP */