# ai_info.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_info.hpp 16121 2009-04-22 09:00:19Z rubidium $ */
    00002
    00005 #ifndef AI_INFO
    00006 #define AI_INFO
    00007
    00008 #include <list>
    00009 #include "../core/smallmap_type.hpp"
    00010 #include "api/ai_object.hpp"
    00011
    00012 enum AIConfigFlags {
    00013   AICONFIG_NONE    = 0x0,
    00014   AICONFIG_RANDOM  = 0x1,
    00015   AICONFIG_BOOLEAN = 0x2,
    00016 };
    00017
    00018 typedef SmallMap<int, char *> LabelMapping;
    00019
    00020 struct AIConfigItem {
    00021   const char *name;
    00022   const char *description;
    00023   int min_value;
    00024   int max_value;
    00025   int custom_value;
    00026   int easy_value;
    00027   int medium_value;
    00028   int hard_value;
    00029   int random_deviation;
    00030   int step_size;
    00031   AIConfigFlags flags;
    00032   LabelMapping *labels;
    00033 };
    00034
    00035 extern AIConfigItem _start_date_config;
    00036
    00037 typedef std::list<AIConfigItem> AIConfigItemList;
    00038
    00039 class AIFileInfo : public AIObject {
    00040 public:
    00041   friend class AIInfo;
    00042   friend class AILibrary;
    00043
    00044   AIFileInfo() : SQ_instance(NULL), main_script(NULL), author(NULL), name(NULL), short_name(NULL), description(NULL), date(NULL), instance_name(NULL), url(NULL) {};
    00045   ~AIFileInfo();
    00046
    00050   const char *GetAuthor() const { return this->author; }
    00051
    00055   const char *GetName() const { return this->name; }
    00056
    00060   const char *GetShortName() const { return this->short_name; }
    00061
    00065   const char *GetDescription() const { return this->description; }
    00066
    00070   int GetVersion() const { return this->version; }
    00071
    00075   bool GetSettings();
    00076
    00080   const char *GetDate() const { return this->date; }
    00081
    00085   const char *GetInstanceName() const { return this->instance_name; }
    00086
    00090   const char *GetURL() const { return this->url; }
    00091
    00095   const char *GetMainScript() const { return this->main_script; }
    00096
    00100   bool CheckMethod(const char *name) const;
    00101
    00105   static SQInteger Constructor(HSQUIRRELVM vm, AIFileInfo *info, bool library);
    00106
    00107 private:
    00108   class Squirrel *engine;
    00109   HSQOBJECT *SQ_instance;
    00110   char *main_script;
    00111   class AIScanner *base;
    00112   const char *author;
    00113   const char *name;
    00114   const char *short_name;
    00115   const char *description;
    00116   const char *date;
    00117   const char *instance_name;
    00118   int version;
    00119   const char *url;
    00120 };
    00121
    00122 class AIInfo : public AIFileInfo {
    00123 public:
    00124   static const char *GetClassName() { return "AIInfo"; }
    00125
    00126   ~AIInfo();
    00127
    00131   static SQInteger Constructor(HSQUIRRELVM vm);
    00132   static SQInteger DummyConstructor(HSQUIRRELVM vm);
    00133
    00137   const AIConfigItemList *GetConfigList() const;
    00138
    00142   const AIConfigItem *GetConfigItem(const char *name) const;
    00143
    00147   bool CanLoadFromVersion(int version) const;
    00148
    00152   SQInteger AddSetting(HSQUIRRELVM vm);
    00153
    00157   SQInteger AddLabels(HSQUIRRELVM vm);
    00158
    00162   int GetSettingDefaultValue(const char *name) const;
    00163
    00167   bool UseAsRandomAI() const { return this->use_as_random; }
    00168
    00169 private:
    00170   AIConfigItemList config_list;
    00171   int min_loadable_version;
    00172   bool use_as_random;
    00173 };
    00174
    00175 class AILibrary : public AIFileInfo {
    00176 public:
    00177   AILibrary() : AIFileInfo(), category(NULL) {};
    00178   ~AILibrary();
    00179
    00183   static SQInteger Constructor(HSQUIRRELVM vm);
    00184
    00185   static SQInteger Import(HSQUIRRELVM vm);
    00186
    00190   const char *GetCategory() const { return this->category; }
    00191
    00192 private:
    00193   const char *category;
    00194 };
    00195
    00196 #endif /* AI_INFO */