summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-15 15:56:10 +0000
committertruebrain <truebrain@openttd.org>2009-01-15 15:56:10 +0000
commit103cd2a5ed5df7f166c2024e0e4e85d4790e3529 (patch)
tree336201bee848644fdb9096a06f1ffec998951171 /src
parentd62a85f2ce2dd7f366b8d3a6610ee70046ee928a (diff)
downloadopenttd-103cd2a5ed5df7f166c2024e0e4e85d4790e3529.tar.xz
(svn r15091) -Add [NoAI] [API CHANGE]: introduce GetCategory() as a requirement for every library.nut, to indicate in which category it belongs. Currently the directory indicates the category, but this doesn't allow planned future additions
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_info.cpp17
-rw-r--r--src/ai/ai_info.hpp12
2 files changed, 24 insertions, 5 deletions
diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp
index a9bf22eae..3f275630f 100644
--- a/src/ai/ai_info.cpp
+++ b/src/ai/ai_info.cpp
@@ -118,7 +118,7 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
}
}
-/* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info)
+/* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info, bool library)
{
SQInteger res = 0;
@@ -138,6 +138,9 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
info->CheckMethods(&res, "GetVersion");
info->CheckMethods(&res, "GetDate");
info->CheckMethods(&res, "CreateInstance");
+ if (library) {
+ info->CheckMethods(&res, "GetCategory");
+ }
/* Abort if one method was missing */
if (res != 0) return res;
@@ -155,7 +158,7 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
sq_getinstanceup(vm, 2, &instance, 0);
AIInfo *info = (AIInfo *)instance;
- SQInteger res = AIFileInfo::Constructor(vm, info);
+ SQInteger res = AIFileInfo::Constructor(vm, info, false);
if (res != 0) return res;
AIConfigItem config;
@@ -191,7 +194,7 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
sq_getinstanceup(vm, 2, &instance, 0);
AIInfo *info = (AIInfo *)instance;
- SQInteger res = AIFileInfo::Constructor(vm, info);
+ SQInteger res = AIFileInfo::Constructor(vm, info, false);
if (res != 0) return res;
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
@@ -356,7 +359,7 @@ int AIInfo::GetSettingDefaultValue(const char *name)
/* Create a new AIFileInfo */
AILibrary *library = new AILibrary();
- SQInteger res = AIFileInfo::Constructor(vm, library);
+ SQInteger res = AIFileInfo::Constructor(vm, library, true);
if (res != 0) return res;
/* Register the Library to the base system */
@@ -365,6 +368,12 @@ int AIInfo::GetSettingDefaultValue(const char *name)
return 0;
}
+const char *AILibrary::GetCategory()
+{
+ if (this->category == NULL) this->category = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetCategory");
+ return this->category;
+}
+
/* static */ SQInteger AILibrary::Import(HSQUIRRELVM vm)
{
SQConvert::SQAutoFreePointers ptr;
diff --git a/src/ai/ai_info.hpp b/src/ai/ai_info.hpp
index 223fbeaf3..9708eb545 100644
--- a/src/ai/ai_info.hpp
+++ b/src/ai/ai_info.hpp
@@ -101,7 +101,7 @@ public:
/**
* Process the creation of a FileInfo object.
*/
- static SQInteger Constructor(HSQUIRRELVM vm, AIFileInfo *info);
+ static SQInteger Constructor(HSQUIRRELVM vm, AIFileInfo *info, bool library);
private:
class Squirrel *engine;
@@ -155,12 +155,22 @@ private:
class AILibrary : public AIFileInfo {
public:
+ AILibrary() : AIFileInfo(), category(NULL) {};
+
/**
* Create an AI, using this AIInfo as start-template.
*/
static SQInteger Constructor(HSQUIRRELVM vm);
static SQInteger Import(HSQUIRRELVM vm);
+
+ /**
+ * Get the category this library is in.
+ */
+ const char *GetCategory();
+
+private:
+ const char *category;
};
#endif /* AI_INFO */