83 */ |
83 */ |
84 int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback) |
84 int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback) |
85 { |
85 { |
86 PlayerID old_lp; |
86 PlayerID old_lp; |
87 int32 res = 0; |
87 int32 res = 0; |
88 char *tmp_cmdtext = NULL; |
88 const char* tmp_cmdtext; |
89 |
89 |
90 /* If you enable DC_EXEC with DC_QUERY_COST you are a really strange |
90 /* If you enable DC_EXEC with DC_QUERY_COST you are a really strange |
91 * person.. should we check for those funny jokes? |
91 * person.. should we check for those funny jokes? |
92 */ |
92 */ |
93 |
93 |
94 /* The test already free _cmd_text in most cases, so let's backup the string, else we have a problem ;) */ |
94 /* The test already resets _cmd_text, so backup the pointer */ |
95 if (_cmd_text != NULL) |
95 tmp_cmdtext = _cmd_text; |
96 tmp_cmdtext = strdup(_cmd_text); |
|
97 |
96 |
98 /* First, do a test-run to see if we can do this */ |
97 /* First, do a test-run to see if we can do this */ |
99 res = DoCommand(tile, p1, p2, flags & ~DC_EXEC, procc); |
98 res = DoCommand(tile, p1, p2, flags & ~DC_EXEC, procc); |
100 /* The command failed, or you didn't want to execute, or you are quering, return */ |
99 /* The command failed, or you didn't want to execute, or you are quering, return */ |
101 if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) { |
100 if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) { |
102 free(tmp_cmdtext); |
|
103 return res; |
101 return res; |
104 } |
102 } |
105 |
103 |
106 /* Recover _cmd_text */ |
104 /* Restore _cmd_text */ |
107 if (tmp_cmdtext != NULL) |
105 _cmd_text = tmp_cmdtext; |
108 _cmd_text = tmp_cmdtext; |
|
109 |
106 |
110 /* If we did a DC_EXEC, and the command did not return an error, execute it |
107 /* If we did a DC_EXEC, and the command did not return an error, execute it |
111 over the network */ |
108 over the network */ |
112 if (flags & DC_AUTO) procc |= CMD_AUTO; |
109 if (flags & DC_AUTO) procc |= CMD_AUTO; |
113 if (flags & DC_NO_WATER) procc |= CMD_NO_WATER; |
110 if (flags & DC_NO_WATER) procc |= CMD_NO_WATER; |
129 AI_PutCommandInQueue(_current_player, tile, p1, p2, procc, callback); |
126 AI_PutCommandInQueue(_current_player, tile, p1, p2, procc, callback); |
130 |
127 |
131 /* Set _local_player back */ |
128 /* Set _local_player back */ |
132 _local_player = old_lp; |
129 _local_player = old_lp; |
133 |
130 |
134 free(tmp_cmdtext); |
|
135 |
|
136 return res; |
131 return res; |
137 } |
132 } |
138 |
133 |
139 |
134 |
140 int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc) |
135 int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc) |