mirror of https://github.com/OpenTTD/OpenTTD
(svn r3283) -Fix: decode_parameters was still used, while _cmd_text is the way
-Fix: _cmd_text is cleared after a command, so we need to store it temporaray in order to first test the command, before executingrelease/0.4.5
parent
809b03c81a
commit
ba7cc8e190
35
ai/ai.c
35
ai/ai.c
|
@ -45,11 +45,14 @@ void AI_DequeueCommands(byte player)
|
||||||
_current_player = player;
|
_current_player = player;
|
||||||
|
|
||||||
/* Copy the DP back in place */
|
/* Copy the DP back in place */
|
||||||
memcpy(_decode_parameters, com->dp, sizeof(com->dp));
|
_cmd_text = com->text;
|
||||||
DoCommandP(com->tile, com->p1, com->p2, NULL, com->procc);
|
DoCommandP(com->tile, com->p1, com->p2, NULL, com->procc);
|
||||||
|
_cmd_text = NULL;
|
||||||
|
|
||||||
/* Free item */
|
/* Free item */
|
||||||
entry_com = com->next;
|
entry_com = com->next;
|
||||||
|
if (com->text != NULL)
|
||||||
|
free(com->text);
|
||||||
free(com);
|
free(com);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,9 +84,13 @@ void AI_PutCommandInQueue(byte player, uint tile, uint32 p1, uint32 p2, uint pro
|
||||||
com->p2 = p2;
|
com->p2 = p2;
|
||||||
com->procc = procc;
|
com->procc = procc;
|
||||||
com->next = NULL;
|
com->next = NULL;
|
||||||
|
com->text = NULL;
|
||||||
|
|
||||||
/* Copy the decode_parameters */
|
/* Copy the cmd_text, if needed */
|
||||||
memcpy(com->dp, _decode_parameters, sizeof(com->dp));
|
if (_cmd_text != NULL) {
|
||||||
|
com->text = strdup(_cmd_text);
|
||||||
|
_cmd_text = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,16 +100,28 @@ int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
|
||||||
{
|
{
|
||||||
PlayerID old_lp;
|
PlayerID old_lp;
|
||||||
int32 res = 0;
|
int32 res = 0;
|
||||||
|
char *cmdtext = NULL;
|
||||||
|
|
||||||
/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
|
/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
|
||||||
* person.. should we check for those funny jokes?
|
* person.. should we check for those funny jokes?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* The test already free _cmd_text in most cases, so let's backup the string, else we have a problem ;) */
|
||||||
|
if (_cmd_text != NULL)
|
||||||
|
cmdtext = strdup(_cmd_text);
|
||||||
|
|
||||||
/* First, do a test-run to see if we can do this */
|
/* First, do a test-run to see if we can do this */
|
||||||
res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
|
res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
|
||||||
/* The command failed, or you didn't want to execute, or you are quering, return */
|
/* The command failed, or you didn't want to execute, or you are quering, return */
|
||||||
if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST))
|
if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) {
|
||||||
|
if (cmdtext != NULL)
|
||||||
|
free(cmdtext);
|
||||||
return res;
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Recover _cmd_text */
|
||||||
|
if (cmdtext != NULL)
|
||||||
|
_cmd_text = cmdtext;
|
||||||
|
|
||||||
/* If we did a DC_EXEC, and the command did not return an error, execute it
|
/* If we did a DC_EXEC, and the command did not return an error, execute it
|
||||||
over the network */
|
over the network */
|
||||||
|
@ -128,6 +147,10 @@ int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
|
||||||
/* Set _local_player back */
|
/* Set _local_player back */
|
||||||
_local_player = old_lp;
|
_local_player = old_lp;
|
||||||
|
|
||||||
|
/* Free the temp _cmd_text var */
|
||||||
|
if (cmdtext != NULL)
|
||||||
|
free(cmdtext);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +175,7 @@ int32 AI_DoCommandChecked(uint tile, uint32 p1, uint32 p2, uint32 flags, uint pr
|
||||||
new->p2 = p2;
|
new->p2 = p2;
|
||||||
new->procc = procc;
|
new->procc = procc;
|
||||||
new->next = NULL;
|
new->next = NULL;
|
||||||
new->dp[0] = unique_id;
|
new->uid = unique_id;
|
||||||
|
|
||||||
/* Add it to the back of the list */
|
/* Add it to the back of the list */
|
||||||
if (command_uid_tail[_current_player] == NULL)
|
if (command_uid_tail[_current_player] == NULL)
|
||||||
|
@ -199,7 +222,7 @@ void AI_CommandResult(uint32 cmd, uint32 p1, uint32 p2, TileIndex tile, bool suc
|
||||||
if (command_uid[_current_player] == NULL)
|
if (command_uid[_current_player] == NULL)
|
||||||
command_uid_tail[_current_player] = NULL;
|
command_uid_tail[_current_player] = NULL;
|
||||||
|
|
||||||
ai_event(_current_player, succeeded ? ottd_Event_CommandSucceeded : ottd_Event_CommandFailed, tile, command->dp[0]);
|
ai_event(_current_player, succeeded ? ottd_Event_CommandSucceeded : ottd_Event_CommandFailed, tile, command->uid);
|
||||||
free(command);
|
free(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue