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 #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 };
00048
00049 typedef std::list<ScriptConfigItem> ScriptConfigItemList;
00050
00051 extern ScriptConfigItem _start_date_config;
00052
00056 class ScriptConfig {
00057 protected:
00059 typedef std::map<const char *, int, StringCompare> SettingValueList;
00060
00061 public:
00062 ScriptConfig() :
00063 name(NULL),
00064 version(-1),
00065 info(NULL),
00066 config_list(NULL),
00067 is_random(false)
00068 {}
00069
00074 ScriptConfig(const ScriptConfig *config);
00075
00077 virtual ~ScriptConfig();
00078
00087 void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
00088
00092 class ScriptInfo *GetInfo() const;
00093
00097 const ScriptConfigItemList *GetConfigList();
00098
00103 enum ScriptSettingSource {
00104 SSS_DEFAULT,
00105 SSS_FORCE_NEWGAME,
00106 SSS_FORCE_GAME,
00107 };
00108
00116 virtual int GetSetting(const char *name) const;
00117
00121 virtual void SetSetting(const char *name, int value);
00122
00126 void ResetSettings();
00127
00131 void AddRandomDeviation();
00132
00137 bool HasScript() const;
00138
00142 bool IsRandom() const;
00143
00147 const char *GetName() const;
00148
00152 int GetVersion() const;
00153
00158 void StringToSettings(const char *value);
00159
00164 void SettingsToString(char *string, size_t size) const;
00165
00172 const char *GetTextfile(TextfileType type, CompanyID slot) const;
00173
00174 protected:
00175 const char *name;
00176 int version;
00177 class ScriptInfo *info;
00178 SettingValueList settings;
00179 ScriptConfigItemList *config_list;
00180 bool is_random;
00181
00186 virtual void PushExtraConfigList() {};
00187
00191 virtual void ClearConfigList();
00192
00197 virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
00198 };
00199
00200 #endif