summaryrefslogtreecommitdiff
path: root/src/ai
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
commit87e5a8b52bf2f200467d65c1e17fd79548d31129 (patch)
tree36bbbb5d389d41119ee184607bc012666dda7812 /src/ai
parent53679122af1e0a68bbe4e9c1f73526dd7e118df6 (diff)
downloadopenttd-87e5a8b52bf2f200467d65c1e17fd79548d31129.tar.xz
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai.cpp34
-rw-r--r--src/ai/ai.h6
-rw-r--r--src/ai/default/default.cpp2
3 files changed, 14 insertions, 28 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);
}
diff --git a/src/ai/ai.h b/src/ai/ai.h
index 89cddea11..beac1cbdf 100644
--- a/src/ai/ai.h
+++ b/src/ai/ai.h
@@ -15,7 +15,7 @@ struct AICommand {
uint32 tile;
uint32 p1;
uint32 p2;
- uint32 procc;
+ uint32 cmd;
CommandCallback *callback;
char *text;
@@ -47,8 +47,8 @@ void AI_CompanyDied(CompanyID company);
void AI_RunGameLoop();
void AI_Initialize();
void AI_Uninitialize();
-CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
-CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
+CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, const char *text = NULL);
+CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback, const char *text = NULL);
/** Is it allowed to start a new AI.
* This function checks some boundries to see if we should launch a new AI.
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index 5f7f5a59b..2dc322d4d 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -320,7 +320,7 @@ static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
if (bak->order == NULL) return;
for (uint i = 0; !bak->order[i].IsType(OT_NOTHING); i++) {
- if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
+ if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
break;
}
}