diff --git a/ai/tex/texaiplayer.c b/ai/tex/texaiplayer.c index cc1c14d973..d40d5bce1e 100644 --- a/ai/tex/texaiplayer.c +++ b/ai/tex/texaiplayer.c @@ -23,6 +23,7 @@ #include "city.h" #include "game.h" #include "map.h" +#include "player.h" #include "unit.h" /* server/advisors */ @@ -57,6 +58,7 @@ struct texai_thr int num_players; struct texai_msgs msgs_to; struct texai_reqs reqs_from; + struct player_list* controlled_players; bool thread_running; fc_thread ait; } exthrai; @@ -75,6 +77,7 @@ void texai_init_threading(void) exthrai.thread_running = FALSE; exthrai.num_players = 0; + exthrai.controlled_players = player_list_new(); } /**********************************************************************//** @@ -332,6 +335,8 @@ void texai_control_gained(struct ai_type *ait, struct player *pplayer) } unit_list_iterate_end; } players_iterate_end; } + + player_list_append(exthrai.controlled_players, pplayer); } /**********************************************************************//** @@ -339,9 +344,17 @@ void texai_control_gained(struct ai_type *ait, struct player *pplayer) **************************************************************************/ void texai_control_lost(struct ai_type *ait, struct player *pplayer) { + /* do we actually control the player? The game doesn't tell us */ + if (player_list_search(exthrai.controlled_players, pplayer) == NULL) { + /* we never actually did have control */ + log_debug("%s not actually under tex AI control, nothing to release", + pplayer->name); + return; + } exthrai.num_players--; + player_list_remove(exthrai.controlled_players, pplayer); - log_debug("%s no longer under threaded AI (%d)", pplayer->name, + log_debug("%s no longer under tex AI (%d)", pplayer->name, exthrai.num_players); if (exthrai.num_players <= 0) {