8 #include "gui.h" |
8 #include "gui.h" |
9 #include "command.h" |
9 #include "command.h" |
10 #include "player.h" |
10 #include "player.h" |
11 #include "network.h" |
11 #include "network.h" |
12 #include "variables.h" |
12 #include "variables.h" |
|
13 #include "ai/ai.h" |
13 |
14 |
14 const char* _cmd_text = NULL; |
15 const char* _cmd_text = NULL; |
15 |
16 |
16 #define DEF_COMMAND(yyyy) int32 yyyy(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
17 #define DEF_COMMAND(yyyy) int32 yyyy(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
17 |
18 |
474 if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) { |
475 if (!((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) { |
475 // first test if the command can be executed. |
476 // first test if the command can be executed. |
476 res = proc(x,y, flags, p1, p2); |
477 res = proc(x,y, flags, p1, p2); |
477 if (CmdFailed(res)) { |
478 if (CmdFailed(res)) { |
478 if (res & 0xFFFF) _error_message = res & 0xFFFF; |
479 if (res & 0xFFFF) _error_message = res & 0xFFFF; |
|
480 /* Trigger an event special for the AI, so it knows the build has failed |
|
481 * Because the commands are always delayed, this is the only way. */ |
|
482 AI_CommandResult(cmd, p1, p2, tile, false); |
479 goto show_error; |
483 goto show_error; |
480 } |
484 } |
481 // no money? Only check if notest is off |
485 // no money? Only check if notest is off |
482 if (!notest && res != 0 && !CheckPlayerHasMoney(res)) goto show_error; |
486 if (!notest && res != 0 && !CheckPlayerHasMoney(res)) { |
|
487 AI_CommandResult(cmd, p1, p2, tile, false); |
|
488 goto show_error; |
|
489 } |
483 } |
490 } |
484 |
491 |
485 #ifdef ENABLE_NETWORK |
492 #ifdef ENABLE_NETWORK |
486 /** If we are in network, and the command is not from the network |
493 /** If we are in network, and the command is not from the network |
487 * send it to the command-queue and abort execution |
494 * send it to the command-queue and abort execution |
512 if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) { |
519 if (!notest && !((cmd & CMD_NO_TEST_IF_IN_NETWORK) && _networking)) { |
513 assert(res == res2); // sanity check |
520 assert(res == res2); // sanity check |
514 } else { |
521 } else { |
515 if (CmdFailed(res2)) { |
522 if (CmdFailed(res2)) { |
516 if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF; |
523 if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF; |
|
524 AI_CommandResult(cmd, p1, p2, tile, false); |
517 goto show_error; |
525 goto show_error; |
518 } |
526 } |
519 } |
527 } |
|
528 |
|
529 AI_CommandResult(cmd, p1, p2, tile, true); |
520 |
530 |
521 SubtractMoneyFromPlayer(res2); |
531 SubtractMoneyFromPlayer(res2); |
522 |
532 |
523 if (IsLocalPlayer() && _game_mode != GM_EDITOR) { |
533 if (IsLocalPlayer() && _game_mode != GM_EDITOR) { |
524 if (res2 != 0) |
534 if (res2 != 0) |