Changeset - r2727:858ec9f64238
[Not reviewed]
master
0 2 0
bjarni - 19 years ago 2005-12-08 21:12:15
bjarni@openttd.org
(svn r3272) -Fix: [AI] fixed issue in AI that prevented compilation without network support
2 files changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ai/ai.c
Show inline comments
 
@@ -93,53 +93,55 @@ int32 AI_DoCommand(uint tile, uint32 p1,
 
{
 
	PlayerID old_lp;
 
	int32 res = 0;
 

	
 
	/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
 
	 *   person.. should we check for those funny jokes?
 
	 */
 

	
 
	/* First, do a test-run to see if we can do this */
 
	res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
 
	/* 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;
 

	
 
	/* If we did a DC_EXEC, and the command did not return an error, execute it
 
	    over the network */
 
	if (flags & DC_AUTO)                  procc |= CMD_AUTO;
 
	if (flags & DC_NO_WATER)              procc |= CMD_NO_WATER;
 

	
 
	/* NetworkSend_Command needs _local_player to be set correctly, so
 
	    adjust it, and put it back right after the function */
 
	old_lp = _local_player;
 
	_local_player = _current_player;
 

	
 
#ifdef ENABLE_NETWORK
 
	/* Send the command */
 
	if (_networking)
 
		/* Network is easy, send it to his handler */
 
		NetworkSend_Command(tile, p1, p2, procc, NULL);
 
	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_player, tile, p1, p2, procc);
 

	
 
	/* Set _local_player back */
 
	_local_player = old_lp;
 

	
 
	return res;
 
}
 

	
 
int32 AI_DoCommandChecked(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
 
{
 
	AICommand *new;
 
	uint unique_id = uids[_current_player]++;
 
	int32 res;
 

	
 
	res = AI_DoCommand(tile, p1, p2, flags & ~DC_EXEC, procc);
 
	if (CmdFailed(res))
 
		return CMD_ERROR;
 

	
 
	/* Save the command and his things, together with the unique_id */
 
	new = malloc(sizeof(AICommand));
 
	new->tile  = tile;
 
	new->p1    = p1;
ai/ai.h
Show inline comments
 
#ifndef AI_H
 
#define AI_H
 

	
 
#include "../functions.h"
 
#include "../network.h"
 
#include "../player.h"
 
#ifdef GPMI
 
#include <gpmi.h>
 
#endif /* GPMI */
 

	
 
/* How DoCommands look like for an AI */
 
typedef struct AICommand {
 
	uint32 tile;
 
	uint32 p1;
 
	uint32 p2;
 
	uint32 procc;
 

	
 
	uint32 dp[20];
 

	
 
	struct AICommand *next;
 
} AICommand;
 

	
 
/* The struct for an AIScript Player */
 
typedef struct AIPlayer {
 
	bool active;            //! Is this AI active?
 
	AICommand *queue;       //! The commands that he has in his queue
 
	AICommand *queue_tail;  //! The tail of this queue
 
#ifdef GPMI
 
	gpmi_module *module;    //! The link to the GPMI module
 
#endif /* GPMI */
0 comments (0 inline, 0 general)