00001 /* $Id$ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 00006 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00007 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 00008 */ 00009 00012 #ifndef AI_INFO_HPP 00013 #define AI_INFO_HPP 00014 00015 #ifdef ENABLE_AI 00016 00017 #include <list> 00018 #include "../core/smallmap_type.hpp" 00019 #include "../script/script_info.hpp" 00020 00022 enum AIConfigFlags { 00023 AICONFIG_NONE = 0x0, 00024 AICONFIG_RANDOM = 0x1, 00025 AICONFIG_BOOLEAN = 0x2, 00026 AICONFIG_INGAME = 0x4, 00027 }; 00028 00029 typedef SmallMap<int, char *> LabelMapping; 00030 00032 struct AIConfigItem { 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 AIConfigFlags flags; 00044 LabelMapping *labels; 00045 }; 00046 00047 extern AIConfigItem _start_date_config; 00048 00049 typedef std::list<AIConfigItem> AIConfigItemList; 00050 00052 class AIFileInfo : public ScriptFileInfo { 00053 public: 00057 static SQInteger Constructor(HSQUIRRELVM vm, AIFileInfo *info); 00058 00059 protected: 00060 class AIScanner *base; 00061 }; 00062 00064 class AIInfo : public AIFileInfo { 00065 public: 00070 static const char *GetClassName() { return "AIInfo"; } 00071 00072 AIInfo(); 00073 ~AIInfo(); 00074 00078 static SQInteger Constructor(HSQUIRRELVM vm); 00079 00083 static SQInteger DummyConstructor(HSQUIRRELVM vm); 00084 00088 bool GetSettings(); 00089 00093 const AIConfigItemList *GetConfigList() const; 00094 00098 const AIConfigItem *GetConfigItem(const char *name) const; 00099 00103 bool CanLoadFromVersion(int version) const; 00104 00108 SQInteger AddSetting(HSQUIRRELVM vm); 00109 00113 SQInteger AddLabels(HSQUIRRELVM vm); 00114 00118 int GetSettingDefaultValue(const char *name) const; 00119 00123 bool UseAsRandomAI() const { return this->use_as_random; } 00124 00128 const char *GetAPIVersion() const { return this->api_version; } 00129 00130 private: 00131 AIConfigItemList config_list; 00132 int min_loadable_version; 00133 bool use_as_random; 00134 const char *api_version; 00135 }; 00136 00138 class AILibrary : public AIFileInfo { 00139 public: 00140 AILibrary() : AIFileInfo(), category(NULL) {}; 00141 ~AILibrary(); 00142 00146 static SQInteger Constructor(HSQUIRRELVM vm); 00147 00153 static SQInteger Import(HSQUIRRELVM vm); 00154 00158 const char *GetCategory() const { return this->category; } 00159 00160 private: 00161 const char *category; 00162 }; 00163 00164 #endif /* ENABLE_AI */ 00165 #endif /* AI_INFO_HPP */