summaryrefslogtreecommitdiff
path: root/src/ai/api
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-14 18:25:48 +0000
committertruebrain <truebrain@openttd.org>2009-01-14 18:25:48 +0000
commit3cd6bf0ead727d93e1b7850b8a11511603d9c092 (patch)
tree07d0968f275b6eab29bc1d30ad86c38c981f8f41 /src/ai/api
parenta483ddf7aee75771bdd630354991b724b57d4f7e (diff)
downloadopenttd-3cd6bf0ead727d93e1b7850b8a11511603d9c092.tar.xz
(svn r15084) -Fix [NoAI] (r15027): by removing the threads for NoAIs, it is no longer possible to use DoCommand (even indirect) in AIAbstractList::Valuator().
Diffstat (limited to 'src/ai/api')
-rw-r--r--src/ai/api/ai_abstractlist.cpp12
-rw-r--r--src/ai/api/ai_object.cpp2
2 files changed, 12 insertions, 2 deletions
diff --git a/src/ai/api/ai_abstractlist.cpp b/src/ai/api/ai_abstractlist.cpp
index d447311ac..9357f39c5 100644
--- a/src/ai/api/ai_abstractlist.cpp
+++ b/src/ai/api/ai_abstractlist.cpp
@@ -756,6 +756,10 @@ SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) {
return sq_throwerror(vm, _SC("parameter 2 has an invalid type (expected function)"));
}
+ /* Don't allow docommand from a Valuator, as we can't resume in
+ * mid-code */
+ AIObject::SetAllowDoCommand(false);
+
sq_addref(vm, &obj_func);
/* Read the params */
@@ -782,7 +786,10 @@ SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) {
}
/* Call the function */
- if (SQ_FAILED(sq_call(vm, nparam + 2, SQTrue, SQTrue))) return SQ_ERROR;
+ if (SQ_FAILED(sq_call(vm, nparam + 2, SQTrue, SQTrue))) {
+ AIObject::SetAllowDoCommand(true);
+ return SQ_ERROR;
+ }
/* Retreive the return value */
SQInteger value;
@@ -802,6 +809,7 @@ SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) {
sq_release(vm, &obj_func);
for (int i = 0; i < nparam; i++) sq_release(vm, &obj_params[i]);
+ AIObject::SetAllowDoCommand(true);
return sq_throwerror(vm, _SC("return value of valuator is not valid (not integer/bool)"));
}
}
@@ -814,5 +822,7 @@ SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) {
sq_release(vm, &obj_func);
for (int i = 0; i < nparam; i++) sq_release(vm, &obj_params[i]);
+
+ AIObject::SetAllowDoCommand(true);
return 0;
}
diff --git a/src/ai/api/ai_object.cpp b/src/ai/api/ai_object.cpp
index 55ca4dfed..1ae5b4fd0 100644
--- a/src/ai/api/ai_object.cpp
+++ b/src/ai/api/ai_object.cpp
@@ -198,7 +198,7 @@ int AIObject::GetCallbackVariable(int index)
bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text, AISuspendCallbackProc *callback)
{
if (AIObject::GetAllowDoCommand() == false) {
- AILog::Error("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), and Load().\n");
+ AILog::Error("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.\n");
return false;
}