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 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