Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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
00021 enum ScriptConfigFlags {
00022 SCRIPTCONFIG_NONE = 0x0,
00023 SCRIPTCONFIG_RANDOM = 0x1,
00024 SCRIPTCONFIG_BOOLEAN = 0x2,
00025 SCRIPTCONFIG_INGAME = 0x4,
00026 SCRIPTCONFIG_DEVELOPER = 0x8,
00027 };
00028
00029 typedef SmallMap<int, char *> LabelMapping;
00030
00032 struct ScriptConfigItem {
00033 const char *name;
00034 const char *description;
00035 int min_value;
00036 int max_value;
00037 int custom_value;
00038 int easy_value;
00039 int medium_value;
00040 int hard_value;
00041 int random_deviation;
00042 int step_size;
00043 ScriptConfigFlags flags;
00044 LabelMapping *labels;
00045 };
00046
00047 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
00048
00049 extern ScriptConfigItem _start_date_config;
00050
00054 class ScriptConfig {
00055 protected:
00057 typedef std::map<const char *, int, StringCompare> SettingValueList;
00058
00059 public:
00060 ScriptConfig() :
00061 name(NULL),
00062 version(-1),
00063 info(NULL),
00064 config_list(NULL),
00065 is_random(false)
00066 {}
00067
00072 ScriptConfig(const ScriptConfig *config);
00073
00075 virtual ~ScriptConfig();
00076
00085 void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
00086
00090 class ScriptInfo *GetInfo() const;
00091
00095 const ScriptConfigItemList *GetConfigList();
00096
00101 enum ScriptSettingSource {
00102 SSS_DEFAULT,
00103 SSS_FORCE_NEWGAME,
00104 SSS_FORCE_GAME,
00105 };
00106
00114 virtual int GetSetting(const char *name) const;
00115
00119 virtual void SetSetting(const char *name, int value);
00120
00124 void ResetSettings();
00125
00129 void AddRandomDeviation();
00130
00135 bool HasScript() const;
00136
00140 bool IsRandom() const;
00141
00145 const char *GetName() const;
00146
00150 int GetVersion() const;
00151
00156 void StringToSettings(const char *value);
00157
00162 void SettingsToString(char *string, size_t size) const;
00163
00164 protected:
00165 const char *name;
00166 int version;
00167 class ScriptInfo *info;
00168 SettingValueList settings;
00169 ScriptConfigItemList *config_list;
00170 bool is_random;
00171
00176 virtual void PushExtraConfigList() {};
00177
00181 virtual void ClearConfigList();
00182
00187 virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
00188 };
00189
00190 #endif