(svn r17223) -Change [NoAI] [FS#2980]: Crash an AI when it uses a DoCommand / Sleep instead of just printing an error message in the AI Debug Window

This commit is contained in:
yexo
2009-08-19 16:14:15 +00:00
parent 0780dc8138
commit a4afa140f3
8 changed files with 46 additions and 5 deletions

View File

@@ -352,6 +352,10 @@ void AIInstance::GameLoop()
} catch (AI_VMSuspend e) {
this->suspend = e.GetSuspendTime();
this->callback = e.GetSuspendCallback();
} catch (AI_FatalError e) {
this->engine->ThrowError(e.GetErrorMessage());
this->engine->ResumeError();
this->Died();
}
this->is_started = true;
@@ -368,6 +372,10 @@ void AIInstance::GameLoop()
} catch (AI_VMSuspend e) {
this->suspend = e.GetSuspendTime();
this->callback = e.GetSuspendCallback();
} catch (AI_FatalError e) {
this->engine->ThrowError(e.GetErrorMessage());
this->engine->ResumeError();
this->Died();
}
}

View File

@@ -18,7 +18,7 @@ public:
AI_VMSuspend(int time, AISuspendCallbackProc *callback) :
time(time),
callback(callback)
{}
{}
int GetSuspendTime() { return time; }
AISuspendCallbackProc *GetSuspendCallback() { return callback; }
@@ -28,6 +28,21 @@ private:
AISuspendCallbackProc *callback;
};
/**
* A throw-class that is given when the AI made a fatal error.
*/
class AI_FatalError {
public:
AI_FatalError(const char *msg) :
msg(msg)
{}
const char *GetErrorMessage() { return msg; }
private:
const char *msg;
};
class AIInstance {
public:
friend class AIObject;

View File

@@ -24,8 +24,7 @@
/* static */ void AIController::Sleep(int ticks)
{
if (!AIObject::GetAllowDoCommand()) {
AILog::Error("You are not allowed to call Sleep in your constructor, Save(), Load(), and any valuator.\n");
return;
throw AI_FatalError("You are not allowed to call Sleep in your constructor, Save(), Load(), and any valuator.");
}
if (ticks <= 0) {

View File

@@ -191,8 +191,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(), Load(), and any valuator.\n");
return false;
throw AI_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.");
}
CommandCost res;