1
0
Fork 0

(svn r17500) -Fix (r16502): The wrong value was restored to SetAllowDoCommand possible resulting in an AI that wasn't allowed to do any actions

release/1.0
yexo 2009-09-11 17:18:06 +00:00
parent c9a25c88fa
commit 8ef7b80719
3 changed files with 16 additions and 4 deletions

View File

@ -30,7 +30,7 @@
/* static */ void AIController::Sleep(int ticks) /* static */ void AIController::Sleep(int ticks)
{ {
if (!AIObject::GetAllowDoCommand()) { if (!AIObject::CanSuspend()) {
throw AI_FatalError("You are not allowed to call Sleep in your constructor, Save(), Load(), and any valuator."); throw AI_FatalError("You are not allowed to call Sleep in your constructor, Save(), Load(), and any valuator.");
} }

View File

@ -169,6 +169,11 @@ void AIObject::SetAllowDoCommand(bool allow)
} }
bool AIObject::GetAllowDoCommand() bool AIObject::GetAllowDoCommand()
{
return GetStorage()->allow_do_command;
}
bool AIObject::CanSuspend()
{ {
Squirrel *squirrel = Company::Get(_current_company)->ai_instance->engine; Squirrel *squirrel = Company::Get(_current_company)->ai_instance->engine;
return GetStorage()->allow_do_command && squirrel->CanSuspend(); return GetStorage()->allow_do_command && squirrel->CanSuspend();
@ -197,7 +202,7 @@ int AIObject::GetCallbackVariable(int index)
bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text, AISuspendCallbackProc *callback) bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text, AISuspendCallbackProc *callback)
{ {
if (AIObject::GetAllowDoCommand() == false) { if (!AIObject::CanSuspend()) {
throw AI_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator."); throw AI_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.");
} }

View File

@ -140,8 +140,15 @@ protected:
static GroupID GetNewGroupID(); static GroupID GetNewGroupID();
/** /**
* Get the latest stored allow_do_command. * Can we suspend the AI at this moment?
* If this is false, you are not allowed to do any DoCommands. */
static bool CanSuspend();
/**
* Get the internal value of allow_do_command. This can differ
* from CanSuspend() if the reason we are not allowed
* to execute a DoCommand is in squirrel and not the API.
* In that case use this function to restore the previous value.
*/ */
static bool GetAllowDoCommand(); static bool GetAllowDoCommand();