summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-12-05 12:27:58 +0000
committertruelight <truelight@openttd.org>2005-12-05 12:27:58 +0000
commit0f2a0df16591a8f23b03b800b780090cf9b88c9a (patch)
tree9ac101fe0118919eae98a05abc9e97de6f1f5e33 /command.c
parent2946f3c1f9d25327cc29a521cf13ce6bd73bec15 (diff)
downloadopenttd-0f2a0df16591a8f23b03b800b780090cf9b88c9a.tar.xz
(svn r3260) -Add: add events for AIs to check if a command execution failed or succeeded
Diffstat (limited to 'command.c')
-rw-r--r--command.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/command.c b/command.c
index b99ea82eb..5b32156a8 100644
--- a/command.c
+++ b/command.c
@@ -10,6 +10,7 @@
#include "player.h"
#include "network.h"
#include "variables.h"
+#include "ai/ai.h"
const char* _cmd_text = NULL;
@@ -476,10 +477,16 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
res = proc(x,y, flags, p1, p2);
if (CmdFailed(res)) {
if (res & 0xFFFF) _error_message = res & 0xFFFF;
+ /* Trigger an event special for the AI, so it knows the build has failed
+ * Because the commands are always delayed, this is the only way. */
+ AI_CommandResult(cmd, p1, p2, tile, false);
goto show_error;
}
// no money? Only check if notest is off
- if (!notest && res != 0 && !CheckPlayerHasMoney(res)) goto show_error;
+ if (!notest && res != 0 && !CheckPlayerHasMoney(res)) {
+ AI_CommandResult(cmd, p1, p2, tile, false);
+ goto show_error;
+ }
}
#ifdef ENABLE_NETWORK
@@ -514,10 +521,13 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
} else {
if (CmdFailed(res2)) {
if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF;
+ AI_CommandResult(cmd, p1, p2, tile, false);
goto show_error;
}
}
+ AI_CommandResult(cmd, p1, p2, tile, true);
+
SubtractMoneyFromPlayer(res2);
if (IsLocalPlayer() && _game_mode != GM_EDITOR) {