From bcbbf2c366b829994983513d2858762874e99964 Mon Sep 17 00:00:00 2001 From: truebrain Date: Tue, 13 Jan 2009 01:46:46 +0000 Subject: (svn r15045) -Add [NoAI API CHANGE]: in info.nut you can now have (optional) a CanLoadFromVersion(version), which should return true/false, to indicate if you can load a savegame made with your AI of version 'version' -Add [NoAI API CHANGE]: in main.nut the Load() function now should be Load(version, data), where 'version' is the version of your AI which made the savegame -Codechange [NoAI]: various of function renames to make things more sane -Add [NoAI]: push the 'version' of the AI through various of layers -Codechange [NoAI]: various of code cleanups -Add [NoAI]: store the version of the AI in the savegame too --- src/ai/ai_info.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/ai/ai_info.cpp') diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index 80f6f9e8d..e55affaa5 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -70,9 +70,26 @@ const char *AIFileInfo::GetInstanceName() return this->instance_name; } -bool AIFileInfo::AllowStartup() +bool AIFileInfo::CanLoadFromVersion(int version) { - return true; + if (version == -1) return true; + if (!this->engine->MethodExists(*this->SQ_instance, "CanLoadFromVersion")) return true; + + HSQUIRRELVM vm = this->engine->GetVM(); + int top = sq_gettop(vm); + + sq_pushobject(vm, *this->SQ_instance); + sq_pushstring(vm, OTTD2FS("CanLoadFromVersion"), -1); + sq_get(vm, -2); + sq_pushobject(vm, *this->SQ_instance); + sq_pushinteger(vm, version); + sq_call(vm, 2, SQTrue, SQFalse); + + HSQOBJECT ret; + sq_getstackobj(vm, -1, &ret); + + sq_settop(vm, top); + return sq_objtobool(&ret); } const char *AIFileInfo::GetDirName() -- cgit v1.2.3-54-g00ecf