summaryrefslogtreecommitdiff
path: root/src/ai/ai.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-28 14:37:19 +0000
committerrubidium <rubidium@openttd.org>2008-12-28 14:37:19 +0000
commite83cca7d130872b9d64523ce1a0d61306bc31599 (patch)
tree36bbbb5d389d41119ee184607bc012666dda7812 /src/ai/ai.cpp
parent9c2c1dea067d305601650c60a67f389e090ad835 (diff)
downloadopenttd-e83cca7d130872b9d64523ce1a0d61306bc31599.tar.xz
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
Diffstat (limited to 'src/ai/ai.cpp')
-rw-r--r--src/ai/ai.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp
index 78189917a..a19d43625 100644
--- a/src/ai/ai.cpp
+++ b/src/ai/ai.cpp
@@ -40,8 +40,7 @@ static void AI_DequeueCommands(CompanyID company)
while ((com = entry_com) != NULL) {
_current_company = company;
- _cmd_text = com->text;
- DoCommandP(com->tile, com->p1, com->p2, com->callback, com->procc);
+ DoCommandP(com->tile, com->p1, com->p2, com->cmd, com->callback, com->text);
/* Free item */
entry_com = com->next;
@@ -54,7 +53,7 @@ static void AI_DequeueCommands(CompanyID company)
* Needed for SP; we need to delay DoCommand with 1 tick, because else events
* will make infinite loops (AIScript).
*/
-static void AI_PutCommandInQueue(CompanyID company, TileIndex tile, uint32 p1, uint32 p2, uint32 procc, CommandCallback* callback)
+static void AI_PutCommandInQueue(CompanyID company, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback* callback, const char *text = NULL)
{
AICommand *com;
@@ -75,44 +74,31 @@ static void AI_PutCommandInQueue(CompanyID company, TileIndex tile, uint32 p1, u
com->tile = tile;
com->p1 = p1;
com->p2 = p2;
- com->procc = procc;
+ com->cmd = cmd;
com->callback = callback;
com->next = NULL;
- com->text = NULL;
-
- /* Copy the cmd_text, if needed */
- if (_cmd_text != NULL) {
- com->text = strdup(_cmd_text);
- _cmd_text = NULL;
- }
+ com->text = text == NULL ? NULL : strdup(text);
}
/**
* Executes a raw DoCommand for the AI.
*/
-CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc, CommandCallback* callback)
+CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, CommandCallback* callback, const char *text)
{
CompanyID old_local_company;
CommandCost res;
- const char* tmp_cmdtext;
/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
* person.. should we check for those funny jokes?
*/
- /* The test already resets _cmd_text, so backup the pointer */
- tmp_cmdtext = _cmd_text;
-
/* First, do a test-run to see if we can do this */
- res = DoCommand(tile, p1, p2, flags & ~DC_EXEC, procc);
+ res = DoCommand(tile, p1, p2, flags & ~DC_EXEC, cmd, text);
/* 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)) {
return res;
}
- /* Restore _cmd_text */
- _cmd_text = tmp_cmdtext;
-
/* NetworkSend_Command needs _local_company to be set correctly, so
* adjust it, and put it back right after the function */
old_local_company = _local_company;
@@ -122,14 +108,14 @@ CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, u
/* Send the command */
if (_networking) {
/* Network is easy, send it to his handler */
- NetworkSend_Command(tile, p1, p2, procc, callback);
+ NetworkSend_Command(tile, p1, p2, cmd, callback, text);
} else {
#else
{
#endif
/* If we execute BuildCommands directly in SP, we have a big problem with events
* so we need to delay is for 1 tick */
- AI_PutCommandInQueue(_current_company, tile, p1, p2, procc, callback);
+ AI_PutCommandInQueue(_current_company, tile, p1, p2, cmd, callback, text);
}
/* Set _local_company back */
@@ -139,9 +125,9 @@ CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, u
}
-CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc)
+CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text)
{
- return AI_DoCommandCc(tile, p1, p2, flags, procc, NULL);
+ return AI_DoCommandCc(tile, p1, p2, flags, cmd, NULL, text);
}