summaryrefslogtreecommitdiff
path: root/src/ai/ai_instance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai/ai_instance.cpp')
-rw-r--r--src/ai/ai_instance.cpp29
1 files changed, 29 insertions, 0 deletions
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);