summaryrefslogtreecommitdiff
path: root/ai/ai.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-11-22 15:55:38 +0000
committertruelight <truelight@openttd.org>2005-11-22 15:55:38 +0000
commit6a4ba84320ae137793760b628dad23de29d0b633 (patch)
tree6702beccddba7217fe3ad311ffda9285b6719e5d /ai/ai.c
parent4d2c4c5d8a9c260e4087fab654f61140e984f79c (diff)
downloadopenttd-6a4ba84320ae137793760b628dad23de29d0b633.tar.xz
(svn r3226) -Fix: GPMI implementation had minor glitches
-Fix: the AI speed control is done by the AI-core, individual AIs don't have to do it (so, AIs were delayed twice ;) -Add: Support for AI-network-clients (an AI, connecting to a remote server) -Fix: minor AI-core problems
Diffstat (limited to 'ai/ai.c')
-rw-r--r--ai/ai.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/ai/ai.c b/ai/ai.c
index b3d3af123..b7271d2ce 100644
--- a/ai/ai.c
+++ b/ai/ai.c
@@ -87,7 +87,7 @@ int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
/* 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 ((res & CMD_ERROR) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST))
+ 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
@@ -162,10 +162,10 @@ void AI_RunGameLoop(void)
return;
/* Check for AI-client (so joining a network with an AI) */
- if (_ai.network_client) {
+ if (_ai.network_client && _ai_player[_ai.network_playas].active) {
/* Run the script */
- AI_DequeueCommands(_ai.network_player);
- AI_RunTick(_ai.network_player);
+ AI_DequeueCommands(_ai.network_playas);
+ AI_RunTick(_ai.network_playas);
} else if (!_networking || _network_server) {
/* Check if we want to run AIs (server or SP only) */
Player *p;
@@ -199,6 +199,9 @@ void AI_StartNewAI(PlayerID player)
*/
void AI_PlayerDied(PlayerID player)
{
+ if (_ai.network_client && _ai.network_playas == player)
+ _ai.network_playas = OWNER_SPECTATOR;
+
/* Called if this AI died */
_ai_player[player].active = false;
}
@@ -208,9 +211,13 @@ void AI_PlayerDied(PlayerID player)
*/
void AI_Initialize(void)
{
+ bool ai_network_client = _ai.network_client;
+
memset(&_ai, 0, sizeof(_ai));
memset(&_ai_player, 0, sizeof(_ai_player));
+ _ai.network_client = ai_network_client;
+ _ai.network_playas = OWNER_SPECTATOR;
_ai.enabled = true;
}