(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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user