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 #include "../company_type.h"
00020
00022 enum ScriptConfigFlags {
00023 SCRIPTCONFIG_NONE = 0x0,
00024 SCRIPTCONFIG_RANDOM = 0x1,
00025 SCRIPTCONFIG_BOOLEAN = 0x2,
00026 SCRIPTCONFIG_INGAME = 0x4,
00027 SCRIPTCONFIG_DEVELOPER = 0x8,
00028 };
00029
00030 typedef SmallMap<int, char *> LabelMapping;
00031
00033 struct ScriptConfigItem {
00034 const char *name;
00035 const char *description;
00036 int min_value;
00037 int max_value;
00038 int custom_value;
00039 int easy_value;
00040 int medium_value;
00041 int hard_value;
00042 int random_deviation;
00043 int step_size;
00044 ScriptConfigFlags flags;
00045 LabelMapping *labels;
00046 };
00047
00048 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
00049
00050 extern ScriptConfigItem _start_date_config;
00051
00055 class ScriptConfig {
00056 protected:
00058 typedef std::map<const char *, int, StringCompare> SettingValueList;
00059
00060 public:
00061 ScriptConfig() :
00062 name(NULL),
00063 version(-1),
00064 info(NULL),
00065 config_list(NULL),
00066 is_random(false)
00067 {}
00068
00073 ScriptConfig(const ScriptConfig *config);
00074
00076 virtual ~ScriptConfig();
00077
00086 void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
00087
00091 class ScriptInfo *GetInfo() const;
00092
00096 const ScriptConfigItemList *GetConfigList();
00097
00102 enum ScriptSettingSource {
00103 SSS_DEFAULT,
00104 SSS_FORCE_NEWGAME,
00105 SSS_FORCE_GAME,
00106 };
00107
00115 virtual int GetSetting(const char *name) const;
00116
00120 virtual void SetSetting(const char *name, int value);
00121
00125 void ResetSettings();
00126
00130 void AddRandomDeviation();
00131
00136 bool HasScript() const;
00137
00141 bool IsRandom() const;
00142
00146 const char *GetName() const;
00147
00151 int GetVersion() const;
00152
00157 void StringToSettings(const char *value);
00158
00163 void SettingsToString(char *string, size_t size) const;
00164
00165 protected:
00166 const char *name;
00167 int version;
00168 class ScriptInfo *info;
00169 SettingValueList settings;
00170 ScriptConfigItemList *config_list;
00171 bool is_random;
00172
00177 virtual void PushExtraConfigList() {};
00178
00182 virtual void ClearConfigList();
00183
00188 virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
00189 };
00190
00191 #endif