diff options
author | yexo <yexo@openttd.org> | 2009-08-18 18:51:42 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-08-18 18:51:42 +0000 |
commit | 67106dc0633c50ef6545d0ab6253384b276ab40e (patch) | |
tree | 09964556afb30a650b4549b0a919ba38230e363a /src/ai/ai_info.cpp | |
parent | 58a0ff945c4025e20e30868c8774c8528909600c (diff) | |
download | openttd-67106dc0633c50ef6545d0ab6253384b276ab40e.tar.xz |
(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.
Diffstat (limited to 'src/ai/ai_info.cpp')
-rw-r--r-- | src/ai/ai_info.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index 0ae9582ed..22e2dcded 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -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 |