summaryrefslogtreecommitdiff
path: root/src/ai/ai_instance.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-02-10 19:22:09 +0000
committeryexo <yexo@openttd.org>2009-02-10 19:22:09 +0000
commit8ef2024b9673586b8eba9b4f3599bc966348db03 (patch)
tree035036289bb46372fcd255af1b34730f2a1f827e /src/ai/ai_instance.cpp
parent2c317b7321534d185776f9da0f360b5f3da6c94d (diff)
downloadopenttd-8ef2024b9673586b8eba9b4f3599bc966348db03.tar.xz
(svn r15440) -Fix: Backup AIObject::GetAllowDoCommand and restore the old value so AIs can't work around it.
Diffstat (limited to 'src/ai/ai_instance.cpp')
-rw-r--r--src/ai/ai_instance.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 834ad40f3..496ad6c34 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -272,13 +272,13 @@ void AIInstance::GameLoop()
if (!this->is_started) {
try {
+ AIObject::SetAllowDoCommand(false);
/* Run the constructor if it exists. Don't allow any DoCommands in it. */
if (this->engine->MethodExists(*this->instance, "constructor")) {
- AIObject::SetAllowDoCommand(false);
this->engine->CallMethod(*this->instance, "constructor");
- AIObject::SetAllowDoCommand(true);
}
this->CallLoad();
+ AIObject::SetAllowDoCommand(true);
/* Start the AI by calling Start() */
if (!this->engine->CallMethod(*this->instance, "Start", _settings_game.ai.ai_max_opcode_till_suspend)) this->Died();
} catch (AI_VMSuspend e) {
@@ -524,9 +524,10 @@ void AIInstance::Save()
} else if (this->engine->MethodExists(*this->instance, "Save")) {
HSQOBJECT savedata;
/* We don't want to be interrupted during the save function. */
+ bool backup_allow = AIObject::GetAllowDoCommand();
AIObject::SetAllowDoCommand(false);
this->engine->CallMethod(*this->instance, "Save", &savedata);
- AIObject::SetAllowDoCommand(true);
+ AIObject::SetAllowDoCommand(backup_allow);
if (!sq_istable(savedata)) {
AILog::Error("Save function should return a table.");
@@ -653,8 +654,6 @@ void AIInstance::CallLoad()
return;
}
- AIObject::SetAllowDoCommand(false);
-
/* Go to the instance-root */
sq_pushobject(vm, *this->instance);
/* Find the function-name inside the script */
@@ -673,6 +672,4 @@ void AIInstance::CallLoad()
/* Pop 1) The version, 2) the savegame data, 3) the object instance, 4) the function pointer. */
sq_pop(vm, 4);
-
- AIObject::SetAllowDoCommand(true);
}