--- a/src/ai/ai_info.cpp Tue Jun 10 14:08:39 2008 +0000
+++ b/src/ai/ai_info.cpp Tue Jun 10 14:11:35 2008 +0000
@@ -1,6 +1,6 @@
/* $Id$ */
-/** @file ai_info.cpp Implementation of AIInfo */
+/** @file ai_info.cpp Implementation of AIFileInfo */
#include "../stdafx.h"
#include "../core/alloc_func.hpp"
@@ -10,88 +10,92 @@
#include "../squirrel_helper.hpp"
#include "../squirrel_class.hpp"
#include "../squirrel_std.hpp"
+#include "ai.h"
#include "ai_info.hpp"
#include "ai_squirrel.hpp"
#include "api/ai_controller.hpp"
-AIInfo::~AIInfo()
+AIFileInfo::~AIFileInfo()
{
this->engine->ReleaseObject(this->SQ_instance);
free((void *)this->author);
free((void *)this->name);
free((void *)this->description);
free((void *)this->date);
+ free((void *)this->instance_name);
free(this->script_name);
free(this->dir_name);
free(this->SQ_instance);
}
-const char *AIInfo::GetAuthor()
+const char *AIFileInfo::GetAuthor()
{
if (this->author == NULL) this->author = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetAuthor");
return this->author;
}
-const char *AIInfo::GetName()
+const char *AIFileInfo::GetName()
{
if (this->name == NULL) this->name = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetName");
return this->name;
}
-const char *AIInfo::GetDescription()
+const char *AIFileInfo::GetDescription()
{
if (this->description == NULL) this->description = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetDescription");
return this->description;
}
-int AIInfo::GetVersion()
+int AIFileInfo::GetVersion()
{
return this->engine->CallIntegerMethod(*this->SQ_instance, "GetVersion");
}
-const char *AIInfo::GetDate()
+const char *AIFileInfo::GetDate()
{
if (this->date == NULL) this->date = this->engine->CallStringMethodStrdup(*this->SQ_instance, "GetDate");
return this->date;
}
-bool AIInfo::AllowStartup()
+const char *AIFileInfo::GetInstanceName()
+{
+ if (this->instance_name == NULL) this->instance_name = this->engine->CallStringMethodStrdup(*this->SQ_instance, "CreateInstance");
+ return this->instance_name;
+}
+
+bool AIFileInfo::AllowStartup()
{
return true;
}
-AIController *AIInfo::CreateInstance()
+AIController *AIFileInfo::CreateInstance()
{
- const char *class_name = this->engine->CallStringMethodStrdup(*this->SQ_instance, "CreateInstance");
- AIController *ai_controller = new AIController(this->script_name, class_name);
- free((void *)class_name);
+ AIController *ai_controller = new AIController(this->script_name, this->GetInstanceName());
return ai_controller;
}
-const char *AIInfo::GetDirName()
+const char *AIFileInfo::GetDirName()
{
return this->dir_name;
}
-const char *AIInfo::GetScriptName()
+const char *AIFileInfo::GetScriptName()
{
return this->script_name;
}
-void AIInfo::CheckMethods(SQInteger *res, const char *name)
+void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
{
if (!this->engine->MethodExists(*this->SQ_instance, name)) {
char error[1024];
- snprintf(error, sizeof(error), "your AIInfo doesn't have the method '%s'", name);
+ snprintf(error, sizeof(error), "your AIFileInfo doesn't have the method '%s'", name);
this->engine->ThrowError(error);
*res = SQ_ERROR;
}
}
-/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm)
+/* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info)
{
- /* Create a new AIInfo */
- AIInfo *info = new AIInfo();
SQInteger res = 0;
/* Set some basic info from the parent */
@@ -116,8 +120,44 @@
info->script_name = strdup(info->base->GetCurrentScript());
info->dir_name = strdup(info->base->GetCurrentDirName());
+ return 0;
+}
+
+/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm)
+{
+ /* Create a new AIFileInfo */
+ AIInfo *info = new AIInfo();
+
+ SQInteger res = AIFileInfo::Constructor(vm, info);
+ if (res != 0) return res;
+
/* Register the AI to the base system */
info->base->RegisterAI(info);
return 0;
}
+
+/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)
+{
+ /* Create a new AIFileInfo */
+ AILibrary *library = new AILibrary();
+
+ SQInteger res = AIFileInfo::Constructor(vm, library);
+ if (res != 0) return res;
+
+ /* Register the Library to the base system */
+ library->base->RegisterLibrary(library);
+
+ return 0;
+}
+
+/* static */ SQInteger AILibrary::Import(HSQUIRRELVM vm)
+{
+ SQConvert::SQAutoFreePointers ptr;
+ const char *library = GetParam(SQConvert::ForceType<const char *>(), vm, 2, &ptr);
+ const char *class_name = GetParam(SQConvert::ForceType<const char *>(), vm, 3, &ptr);
+ int version = GetParam(SQConvert::ForceType<int>(), vm, 4, &ptr);
+
+ if (!AI_ImportLibrary(library, class_name, version, vm)) return -1;
+ return 0;
+}