Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6220) !pplayer->is_dying assertion fails
Home

[Freeciv-Dev] Re: (PR#6220) !pplayer->is_dying assertion fails

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jshort@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#6220) !pplayer->is_dying assertion fails
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 24 Sep 2003 14:32:11 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Jason Short wrote:
> This patch is loosely based on one that Per sent me, and aims to kill 
> off dying players pretty often.
> 
> Players are killed off:
>    - Right after all AI players move.
>    - After each client packet is handled.
>    - At the end of the turn.
> 
> A player is dead if:
>    - pplayer->is_dying is set, or
>    - the player has no units or cities remaining
> 
> These checks may sometimes be overzealous, but that shouldn't be a 
> problem.  They may still miss some cases, though.

Same patch, fewer bugs.  However I believe there are still some bugs.

jason

? core.8973
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.294
diff -u -r1.294 plrhand.c
--- server/plrhand.c    2003/09/22 20:25:56     1.294
+++ server/plrhand.c    2003/09/24 21:29:19
@@ -174,18 +174,26 @@
   begin_cities_turn(pplayer);
 }
 
-/**************************************************************************
-...
-**************************************************************************/
-void update_player_aliveness(struct player *pplayer)
+/****************************************************************************
+  Check all players to see if they are dying.  Kill them if so.
+
+  WARNING: do not call this while doing any handling of players, units,
+  etc.  If a player dies, all his units will be wiped and other data will
+  be overwritten.
+****************************************************************************/
+void kill_dying_players(void)
 {
-  assert(pplayer != NULL);
-  if (pplayer->is_alive) {
-     if (unit_list_size(&pplayer->units) == 0
-         && city_list_size(&pplayer->cities) == 0) {
-       kill_player(pplayer);
-     }
-  }
+  players_iterate(pplayer) {
+    if (pplayer->is_alive) {
+      if (unit_list_size(&pplayer->units) == 0
+         && city_list_size(&pplayer->cities) == 0) {
+       pplayer->is_dying = TRUE;
+      }
+      if (pplayer->is_dying) {
+       kill_player(pplayer);
+      }
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************
@@ -194,6 +202,7 @@
 void kill_player(struct player *pplayer) {
   bool palace;
 
+  pplayer->is_dying = FALSE; /* Can't get more dead than this. */
   pplayer->is_alive = FALSE;
 
   /* Remove shared vision. Do it for both for completeness. */
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.57
diff -u -r1.57 plrhand.h
--- server/plrhand.h    2003/09/22 20:25:56     1.57
+++ server/plrhand.h    2003/09/24 21:29:19
@@ -28,7 +28,7 @@
 void server_remove_player(struct player *pplayer);
 void kill_player(struct player *pplayer);
 void begin_player_turn(struct player *pplayer);
-void update_player_aliveness(struct player *pplayer);
+void kill_dying_players(void);
 void update_revolution(struct player *pplayer);
 void great_library(struct player *pplayer);
 void handle_player_revolution(struct player *pplayer);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.139
diff -u -r1.139 srv_main.c
--- server/srv_main.c   2003/09/23 15:59:05     1.139
+++ server/srv_main.c   2003/09/24 21:29:19
@@ -437,6 +437,7 @@
       flush_packets();                 /* AIs can be such spammers... */
     }
   } shuffled_players_iterate_end;
+  kill_dying_players();
 }
 
 /**************************************************************************
@@ -509,11 +510,12 @@
   /* Unit end of turn activities */
   shuffled_players_iterate(pplayer) {
     update_unit_activities(pplayer); /* major network traffic */
-    update_player_aliveness(pplayer);
     flush_packets();
     pplayer->turn_done = FALSE;
   } shuffled_players_iterate_end;
 
+  kill_dying_players();
+
   nocity_send = FALSE;
   players_iterate(pplayer) {
     send_player_cities(pplayer);
@@ -966,9 +968,8 @@
            type, conn_description(pconn));
   }
 
-  if (pplayer->is_alive && pplayer->is_dying) {
-    kill_player(pplayer);
-  }
+  kill_dying_players();
+
   free(packet);
   pplayer->current_conn = NULL;
   return TRUE;

[Prev in Thread] Current Thread [Next in Thread]