summaryrefslogtreecommitdiff
path: root/src/ai/ai_instance.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-13 01:46:46 +0000
committertruebrain <truebrain@openttd.org>2009-01-13 01:46:46 +0000
commit5573d9a459746442e5374fe7298230a4c2981bce (patch)
treea2e699a90fbe7d2ebd18ddd9ea713546f3f641bc /src/ai/ai_instance.cpp
parent27c0a4c8014af73a01f24568a642f3797473bb8e (diff)
downloadopenttd-5573d9a459746442e5374fe7298230a4c2981bce.tar.xz
(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
Diffstat (limited to 'src/ai/ai_instance.cpp')
-rw-r--r--src/ai/ai_instance.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index a0612498d..1e57c6496 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -592,37 +592,38 @@ void AIInstance::Save()
LoadObjects(NULL);
}
-bool AIInstance::Load()
+void AIInstance::Load(int version)
{
- HSQUIRRELVM vm = (this->engine == NULL) ? NULL : this->engine->GetVM();
+ if (this->engine == NULL || version == -1) {
+ LoadEmpty();
+ return;
+ }
+ HSQUIRRELVM vm = this->engine->GetVM();
SlObject(NULL, _ai_byte);
/* Check if there was anything saved at all. */
- if (_ai_sl_byte == 0) return true;
+ if (_ai_sl_byte == 0) return;
AIObject::SetAllowDoCommand(false);
- if (vm != NULL) {
- /* Go to the instance-root */
- sq_pushobject(vm, *this->instance);
- /* Find the function-name inside the script */
- sq_pushstring(vm, OTTD2FS("Load"), -1);
- if (SQ_FAILED(sq_get(vm, -2))) sq_pushnull(vm);
- sq_pushobject(vm, *this->instance);
- }
+ /* Go to the instance-root */
+ sq_pushobject(vm, *this->instance);
+ /* Find the function-name inside the script */
+ sq_pushstring(vm, OTTD2FS("Load"), -1);
+ if (SQ_FAILED(sq_get(vm, -2))) sq_pushnull(vm);
+ sq_pushobject(vm, *this->instance);
+ sq_pushinteger(vm, version);
LoadObjects(vm);
- if (this->engine != NULL) {
- if (this->engine->MethodExists(*this->instance, "Load")) {
- sq_call(vm, 2, SQFalse, SQFalse);
- } else {
- AILog::Warning("Loading failed: there was data for the AI to load, but the AI does not have a Load() function.");
- }
+ if (this->engine->MethodExists(*this->instance, "Load")) {
+ sq_call(vm, 3, SQFalse, SQFalse);
+ } else {
+ AILog::Warning("Loading failed: there was data for the AI to load, but the AI does not have a Load() function.");
}
- /* Pop 1) the object instance, 2) the function name, 3) the instance again, 4) the table. */
- if (vm != NULL) sq_pop(vm, 4);
+ /* Pop 1) the object instance, 2) the function name, 3) the instance again, 4) the (null) result. */
+ sq_pop(vm, 4);
AIObject::SetAllowDoCommand(true);
- return true;
+ return;
}