Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] (PR#4793) shuffled_players_iterate() macro
Home

[Freeciv-Dev] (PR#4793) shuffled_players_iterate() macro

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4793) shuffled_players_iterate() macro
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 8 Aug 2003 10:32:31 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch provides a macro that iterates over all players in the game, 
in their shuffled order.

jason

? core.11821
? rc
Index: server/autoattack.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/autoattack.c,v
retrieving revision 1.46
diff -u -r1.46 autoattack.c
--- server/autoattack.c 2003/08/01 15:58:08     1.46
+++ server/autoattack.c 2003/08/08 17:31:38
@@ -280,14 +280,13 @@
 void auto_attack(void)
 {
   static struct timer *t = NULL;      /* alloc once, never free */
-  int i;
 
   t = renew_timer_start(t, TIMER_CPU, TIMER_DEBUG);
 
   /* re-use shuffle order from civserver.c */
-  for (i = 0; i < game.nplayers; i++) {
-    auto_attack_player(shuffled_player(i));
-  }
+  shuffled_players_iterate(pplayer) {
+    auto_attack_player(pplayer);
+  } shuffled_players_iterate_end;
   if (timer_in_use(t)) {
     freelog(LOG_VERBOSE, "autoattack consumed %g milliseconds.",
            1000.0*read_timer_seconds(t));
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.55
diff -u -r1.55 plrhand.h
--- server/plrhand.h    2003/08/04 15:42:47     1.55
+++ server/plrhand.h    2003/08/08 17:31:38
@@ -88,6 +88,19 @@
 void shuffle_players(void);
 struct player *shuffled_player(int i);
 
+#define shuffled_players_iterate(pplayer)                                   \
+{                                                                           \
+  struct player *pplayer;                                                   \
+  int i;                                                                    \
+  for (i = 0; i < game.nplayers; i++) {                                     \
+    pplayer = shuffled_player(i);                                           \
+    {
+
+#define shuffled_players_iterate_end                                        \
+    }                                                                       \
+  }                                                                         \
+}
+
 bool civil_war_triggered(struct player *pplayer);
 void civil_war(struct player *pplayer);
 
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.170
diff -u -r1.170 settlers.c
--- server/settlers.c   2003/08/01 15:58:08     1.170
+++ server/settlers.c   2003/08/08 17:31:38
@@ -1444,14 +1444,13 @@
 **************************************************************************/
 static void assign_settlers(void)
 {
-  int i;
   whole_map_iterate(x, y) {
     map_get_tile(x, y)->assigned = 0;
   } whole_map_iterate_end;
 
-  for (i = 0; i < game.nplayers; i++) {
-    assign_settlers_player(shuffled_player(i));
-  }
+  shuffled_players_iterate(pplayer) {
+    assign_settlers_player(pplayer);
+  } shuffled_players_iterate_end;
 }
 
 /************************************************************************** 
@@ -1542,13 +1541,12 @@
 **************************************************************************/
 void auto_settlers(void)
 {
-  int i;
   assign_settlers();
   assign_territory();
   recount_enemy_masks();
-  for (i = 0; i < game.nplayers; i++) {
-    auto_settlers_player(shuffled_player(i));
-  }
+  shuffled_players_iterate(pplayer) {
+    auto_settlers_player(pplayer);
+  } shuffled_players_iterate_end;
 }
 
 /**************************************************************************
Index: server/spacerace.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/spacerace.c,v
retrieving revision 1.34
diff -u -r1.34 spacerace.c
--- server/spacerace.c  2003/04/04 15:47:50     1.34
+++ server/spacerace.c  2003/08/08 17:31:38
@@ -351,15 +351,11 @@
 **************************************************************************/
 void check_spaceship_arrivals(void)
 {
-  int i;
   double arrival, best_arrival = 0.0;
   struct player *best_pplayer = NULL;
-  struct player *pplayer;
-  struct player_spaceship *ship;
 
-  for(i=0; i<game.nplayers; i++) {
-    pplayer = shuffled_player(i);
-    ship = &pplayer->spaceship;
+  shuffled_players_iterate(pplayer) {
+    struct player_spaceship *ship = &pplayer->spaceship;
     
     if (ship->state == SSHIP_LAUNCHED) {
       arrival = ship->launch_year + ship->travel_time;
@@ -369,7 +365,7 @@
        best_pplayer = pplayer;
       }
     }
-  }
+  } shuffled_players_iterate_end;
   if (best_pplayer) {
     best_pplayer->spaceship.state = SSHIP_ARRIVED;
     server_state = GAME_OVER_STATE;
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.133
diff -u -r1.133 srv_main.c
--- server/srv_main.c   2003/08/04 15:42:47     1.133
+++ server/srv_main.c   2003/08/08 17:31:38
@@ -428,15 +428,12 @@
 **************************************************************************/
 static void ai_start_turn(void)
 {
-  int i;
-
-  for (i = 0; i < game.nplayers; i++) {
-    struct player *pplayer = shuffled_player(i);
+  shuffled_players_iterate(pplayer) {
     if (pplayer->ai.control) {
       ai_do_first_activities(pplayer);
       flush_packets();                 /* AIs can be such spammers... */
     }
-  }
+  } shuffled_players_iterate_end;
 }
 
 /**************************************************************************
@@ -481,8 +478,6 @@
 **************************************************************************/
 static void end_turn(void)
 {
-  int i;
-
   nocity_send = TRUE;
 
   /* AI end of turn activities */
@@ -493,24 +488,22 @@
   } players_iterate_end;
 
   /* Refresh cities */
-  for(i=0; i<game.nplayers; i++) {
-    struct player *pplayer = shuffled_player(i);
+  shuffled_players_iterate(pplayer) {
     great_library(pplayer);
     update_revolution(pplayer);
     player_restore_units(pplayer);
     update_city_activities(pplayer);
     pplayer->research.changed_from=-1;
     flush_packets();
-  }
+  } shuffled_players_iterate_end;
 
   /* Unit end of turn activities */
-  for(i=0; i<game.nplayers; i++) {
-    struct player *pplayer = shuffled_player(i);
+  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;
 
   nocity_send = FALSE;
   players_iterate(pplayer) {

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