ai/ai.c
changeset 2740 4f48b7ad85ba
parent 2739 6a2caa243d5c
child 2752 55e04dee346d
equal deleted inserted replaced
2739:6a2caa243d5c 2740:4f48b7ad85ba
    97  */
    97  */
    98 int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
    98 int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
    99 {
    99 {
   100 	PlayerID old_lp;
   100 	PlayerID old_lp;
   101 	int32 res = 0;
   101 	int32 res = 0;
   102 	char *cmdtext = NULL;
   102 	char *tmp_cmdtext = NULL;
   103 
   103 
   104 	/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
   104 	/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
   105 	 *   person.. should we check for those funny jokes?
   105 	 *   person.. should we check for those funny jokes?
   106 	 */
   106 	 */
   107 
   107 
   108 	/* The test already free _cmd_text in most cases, so let's backup the string, else we have a problem ;) */
   108 	/* The test already free _cmd_text in most cases, so let's backup the string, else we have a problem ;) */
   109 	if (_cmd_text != NULL)
   109 	if (_cmd_text != NULL)
   110 		cmdtext = strdup(_cmd_text);
   110 		tmp_cmdtext = strdup(_cmd_text);
   111 
   111 
   112 	/* First, do a test-run to see if we can do this */
   112 	/* First, do a test-run to see if we can do this */
   113 	res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
   113 	res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
   114 	/* The command failed, or you didn't want to execute, or you are quering, return */
   114 	/* The command failed, or you didn't want to execute, or you are quering, return */
   115 	if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) {
   115 	if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) {
   116 		if (cmdtext != NULL)
   116 		if (tmp_cmdtext != NULL)
   117 			free(cmdtext);
   117 			free(tmp_cmdtext);
   118 		return res;
   118 		return res;
   119 	}
   119 	}
   120 
   120 
   121 	/* Recover _cmd_text */
   121 	/* Recover _cmd_text */
   122 	if (cmdtext != NULL)
   122 	if (tmp_cmdtext != NULL)
   123 		_cmd_text = cmdtext;
   123 		_cmd_text = tmp_cmdtext;
   124 
   124 
   125 	/* If we did a DC_EXEC, and the command did not return an error, execute it
   125 	/* If we did a DC_EXEC, and the command did not return an error, execute it
   126 	    over the network */
   126 	    over the network */
   127 	if (flags & DC_AUTO)                  procc |= CMD_AUTO;
   127 	if (flags & DC_AUTO)                  procc |= CMD_AUTO;
   128 	if (flags & DC_NO_WATER)              procc |= CMD_NO_WATER;
   128 	if (flags & DC_NO_WATER)              procc |= CMD_NO_WATER;
   145 
   145 
   146 	/* Set _local_player back */
   146 	/* Set _local_player back */
   147 	_local_player = old_lp;
   147 	_local_player = old_lp;
   148 
   148 
   149 	/* Free the temp _cmd_text var */
   149 	/* Free the temp _cmd_text var */
   150 	if (cmdtext != NULL)
   150 	if (tmp_cmdtext != NULL)
   151 		free(cmdtext);
   151 		free(tmp_cmdtext);
   152 
   152 
   153 	return res;
   153 	return res;
   154 }
   154 }
   155 
   155 
   156 int32 AI_DoCommandChecked(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
   156 int32 AI_DoCommandChecked(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)