(svn r13290) [NoAI] -Fix: do not activate a new player when no suitable AI can be found to start it. Also, when loading a savegame, do not consider a player as AI if no suitable AI can be found for it.
--- a/src/ai/ai.cpp Tue May 27 14:11:56 2008 +0000
+++ b/src/ai/ai.cpp Tue May 27 15:24:23 2008 +0000
@@ -85,12 +85,13 @@
/**
* A new AI sees the day of light. You can do here what ever you think is needed.
+ * @return True if the AI is started.
*/
-void AI_StartNewAI(PlayerID player)
+bool AI_StartNewAI(PlayerID player)
{
assert(IsValidPlayer(player));
- if (!_ai_enabled) return;
- if (_networking && !_network_server) return;
+ if (!_ai_enabled) return false;
+ if (_networking && !_network_server) return false;
AIInfo *info;
if (_forced_ai_name == NULL) {
@@ -104,8 +105,7 @@
} else {
DEBUG(ai, 0, "The AI named \"%s\" is unknown or not suitable", _forced_ai_name);
}
- /* XXX -- We have no clean way to handle this yet! */
- return;
+ return false;
}
_current_player = player;
@@ -114,6 +114,7 @@
_ai_player[player] = info->CreateInstance();
AI_StartPlayer(player, _ai_player[player]);
InvalidateWindowData(WC_AI_DEBUG, 0, -1);
+ return true;
}
/**
--- a/src/ai/ai.h Tue May 27 14:11:56 2008 +0000
+++ b/src/ai/ai.h Tue May 27 15:24:23 2008 +0000
@@ -7,7 +7,7 @@
#include "api/ai_event_types.hpp"
-void AI_StartNewAI(PlayerID player);
+bool AI_StartNewAI(PlayerID player);
void AI_PlayerDied(PlayerID player);
void AI_RunGameLoop();
void AI_Initialize();
--- a/src/oldloader.cpp Tue May 27 14:11:56 2008 +0000
+++ b/src/oldloader.cpp Tue May 27 15:24:23 2008 +0000
@@ -894,7 +894,7 @@
if (p->location_of_house == 0xFFFF)
p->location_of_house = 0;
- if (p->is_ai) AI_StartNewAI(p->index);
+ p->is_ai = p->is_ai && AI_StartNewAI(p->index);
return true;
}
--- a/src/players.cpp Tue May 27 14:11:56 2008 +0000
+++ b/src/players.cpp Tue May 27 15:24:23 2008 +0000
@@ -526,7 +526,6 @@
ResetPlayerLivery(p);
_player_colors[p->index] = p->player_color;
p->name_1 = STR_SV_UNNAMED;
- p->is_active = true;
p->player_money = p->current_loan = 100000;
@@ -551,7 +550,7 @@
InvalidateWindow(WC_TOOLBAR_MENU, 0);
InvalidateWindow(WC_CLIENT_LIST, 0);
- if (is_ai) AI_StartNewAI(p->index);
+ p->is_active = !is_ai || AI_StartNewAI(p->index);
free(p->num_engines);
p->num_engines = CallocT<uint16>(GetEnginePoolSize());
@@ -1325,7 +1324,7 @@
p->is_noai = true;
/* This is needed so an AI is attached to a loaded AI */
- if (p->is_ai) AI_StartNewAI(p->index);
+ p->is_ai = p->is_ai && AI_StartNewAI(p->index);
}
}