From 67106dc0633c50ef6545d0ab6253384b276ab40e Mon Sep 17 00:00:00 2001 From: yexo Date: Tue, 18 Aug 2009 18:51:42 +0000 Subject: (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. --- src/ai/ai_instance.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/ai/ai_instance.cpp') diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index f5a78e269..6d3397a70 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -80,6 +80,8 @@ #undef DEFINE_SCRIPT_FILES +#include "../fileio_func.h" + AIStorage::~AIStorage() { /* Free our pointers */ @@ -121,6 +123,11 @@ AIInstance::AIInstance(AIInfo *info) : /* Register the API functions and classes */ this->RegisterAPI(); + if (!this->LoadCompatibilityScripts(info->GetAPIVersion())) { + this->Died(); + return; + } + /* Load and execute the script for this AI */ const char *main_script = info->GetMainScript(); if (strcmp(main_script, "%_dummy") == 0) { @@ -239,6 +246,28 @@ void AIInstance::RegisterAPI() this->engine->SetGlobalPointer(this->engine); } +bool AIInstance::LoadCompatibilityScripts(const char *api_version) +{ + char script_name[32]; + seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version); + char buf[MAX_PATH]; + Searchpath sp; + FOR_ALL_SEARCHPATHS(sp) { + FioAppendDirectory(buf, MAX_PATH, sp, AI_DIR); + ttd_strlcat(buf, script_name, MAX_PATH); + if (!FileExists(buf)) continue; + + if (this->engine->LoadScript(buf)) return true; + + AILog::Error("Failed to load API compatibility script"); + DEBUG(ai, 0, "Error compiling / running API compatibility script: %s", buf); + return false; + } + + AILog::Warning("API compatibility script not found"); + return true; +} + void AIInstance::Continue() { assert(this->suspend < 0); -- cgit v1.2.3-54-g00ecf