(svn r17214) -Add [NoAI]: GetAPIVersion() as optional function in info.nut. Return "0.7" to get an api compatible (as much as possible) with the 0.7 api or "0.8" to get the latest api.
-Change [NoAI]: move all deprecated functions to a separate squirrel script that is only loaded if an AI requests an old API version.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "ai_scanner.hpp"
|
||||
#include "../settings_type.h"
|
||||
#include "../openttd.h"
|
||||
#include "../debug.h"
|
||||
|
||||
AIConfigItem _start_date_config = {
|
||||
"start_date",
|
||||
@@ -42,6 +43,11 @@ AILibrary::~AILibrary()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool CheckAPIVersion(const char *api_version)
|
||||
{
|
||||
return strcmp(api_version, "0.7") == 0 || strcmp(api_version, "0.8") == 0;
|
||||
}
|
||||
|
||||
/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
/* Get the AIInfo */
|
||||
@@ -72,6 +78,16 @@ AILibrary::~AILibrary()
|
||||
} else {
|
||||
info->use_as_random = true;
|
||||
}
|
||||
/* Try to get the API version the AI is written for. */
|
||||
if (info->engine->MethodExists(*info->SQ_instance, "GetAPIVersion")) {
|
||||
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAPIVersion", &info->api_version)) return SQ_ERROR;
|
||||
if (!CheckAPIVersion(info->api_version)) {
|
||||
DEBUG(ai, 1, "Loading info.nut from (%s.%d): GetAPIVersion returned invalid version", info->GetName(), info->GetVersion());
|
||||
return SQ_ERROR;
|
||||
}
|
||||
} else {
|
||||
info->api_version = strdup("0.7");
|
||||
}
|
||||
|
||||
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
||||
sq_setinstanceup(vm, 2, NULL);
|
||||
@@ -86,6 +102,7 @@ AILibrary::~AILibrary()
|
||||
SQUserPointer instance;
|
||||
sq_getinstanceup(vm, 2, &instance, 0);
|
||||
AIInfo *info = (AIInfo *)instance;
|
||||
info->api_version = NULL;
|
||||
|
||||
SQInteger res = AIFileInfo::Constructor(vm, info);
|
||||
if (res != 0) return res;
|
||||
@@ -116,6 +133,7 @@ AIInfo::~AIInfo()
|
||||
}
|
||||
}
|
||||
this->config_list.clear();
|
||||
free((void*)this->api_version);
|
||||
}
|
||||
|
||||
bool AIInfo::CanLoadFromVersion(int version) const
|
||||
|
Reference in New Issue
Block a user