--- a/src/ai/api/ai_object.cpp Mon Mar 31 09:51:47 2008 +0000
+++ b/src/ai/api/ai_object.cpp Mon Mar 31 10:55:13 2008 +0000
@@ -3,6 +3,7 @@
/** @file ai_object.cpp Implementation of AIObject. */
#include "ai_object.hpp"
+#include "table/strings.h"
#include "../../command_func.h"
#include "../../network/network.h"
#include "../../player_func.h"
@@ -53,6 +54,16 @@
return AIObject::GetDoCommandStruct(_current_player)->costs.GetCost();
}
+void AIObject::SetLastError(const StringID last_error)
+{
+ AIObject::GetDoCommandStruct(_current_player)->last_error = last_error;
+}
+
+const StringID AIObject::GetLastError()
+{
+ return AIObject::GetDoCommandStruct(_current_player)->last_error;
+}
+
void AIObject::SetLastCommandRes(bool res)
{
AIObject::GetDoCommandStruct(_current_player)->last_command_res = res;
@@ -120,6 +131,9 @@
CommandCost res;
const char *tmp_cmdtext;
+ /* Make sure the last error is reset, so we don't give faulty warnings */
+ SetLastError(STR_NULL);
+
if (procc != CMD_LANDSCAPE_CLEAR) flags |= DC_AUTO;
if (water_protection) flags |= DC_NO_WATER;
@@ -129,7 +143,10 @@
/* First, do a test-run to see if we can do this */
res = ::DoCommand(tile, p1, p2, flags, procc);
/* The command failed, so return */
- if (::CmdFailed(res)) return false;
+ if (::CmdFailed(res)) {
+ SetLastError(_error_message);
+ return false;
+ }
/* Restore _cmd_text */
_cmd_text = tmp_cmdtext;
@@ -172,7 +189,10 @@
AI_SuspendPlayer(_current_player, AIObject::GetDoCommandDelay());
}
- if (::CmdFailed(res)) return false;
+ if (::CmdFailed(res)) {
+ SetLastError(_error_message);
+ return false;
+ }
AIObject::IncreaseDoCommandCosts(res.GetCost());
return true;