Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9337) new iterator specialist_type_iterate
Home

[Freeciv-Dev] (PR#9337) new iterator specialist_type_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9337) new iterator specialist_type_iterate
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 11 Jul 2004 09:08:00 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9337 >

This patch adds a new iterator, specialist_type_iterate(), to game.h. 
The new iterator is used in a number of places.

jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.40
diff -u -r1.40 citydlg_common.c
--- client/citydlg_common.c     10 Jul 2004 18:48:17 -0000      1.40
+++ client/citydlg_common.c     11 Jul 2004 16:07:03 -0000
@@ -389,7 +389,7 @@
 void get_city_citizen_types(struct city *pcity, int index,
                            struct citizen_type *citizens)
 {
-  int i = 0, n, sp;
+  int i = 0, n;
   assert(index >= 0 && index < 5);
 
   for (n = 0; n < pcity->ppl_happy[index]; n++, i++) {
@@ -405,12 +405,12 @@
     citizens[i].type = CITIZEN_ANGRY;
   }
 
-  for (sp = 0; sp < SP_COUNT; sp++) {
+  specialist_type_iterate(sp) {
     for (n = 0; n < pcity->specialists[sp]; n++, i++) {
       citizens[i].type = CITIZEN_SPECIALIST;
       citizens[i].spec_type = sp;
     }
-  }
+  } specialist_type_iterate_end;
 
   assert(i == pcity->size);
 }
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.386
diff -u -r1.386 packhand.c
--- client/packhand.c   11 Jul 2004 15:05:55 -0000      1.386
+++ client/packhand.c   11 Jul 2004 16:07:03 -0000
@@ -434,9 +434,9 @@
     pcity->ppl_unhappy[i] = packet->ppl_unhappy[i];
     pcity->ppl_angry[i] = packet->ppl_angry[i];
   }
-  for (i = 0; i < SP_COUNT; i++) {
-    pcity->specialists[i] = packet->specialists[i];
-  }
+  specialist_type_iterate(sp) {
+    pcity->specialists[sp] = packet->specialists[sp];
+  } specialist_type_iterate_end;
 
   pcity->city_options = packet->city_options;
 
@@ -712,9 +712,9 @@
     int i;
     int x, y;
 
-    for (i = 0; i < SP_COUNT; i++) {
-      pcity->specialists[i] = 0;
-    }
+    specialist_type_iterate(sp) {
+      pcity->specialists[sp] = 0;
+    } specialist_type_iterate_end;
     for (i = 0; i < NUM_TRADEROUTES; i++) {
       pcity->trade[i] = 0;
       pcity->trade_value[i] = 0;
@@ -2710,11 +2710,11 @@
 {
   int i;
 
-  for (i = 0; i < SP_COUNT; i++) {
-    sz_strlcpy(game.rgame.specialists[i].name, packet->specialist_name[i]);
-    game.rgame.specialists[i].min_size = packet->specialist_min_size[i];
-    game.rgame.specialists[i].bonus = packet->specialist_bonus[i];
-  }
+  specialist_type_iterate(sp) {
+    sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
+    game.rgame.specialists[sp].min_size = packet->specialist_min_size[sp];
+    game.rgame.specialists[sp].bonus = packet->specialist_bonus[sp];
+  } specialist_type_iterate_end;
   tilespec_setup_specialist_types();
 
   game.rgame.changable_tax = packet->changable_tax;
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.182
diff -u -r1.182 tilespec.c
--- client/tilespec.c   10 Jul 2004 18:48:17 -0000      1.182
+++ client/tilespec.c   11 Jul 2004 16:07:04 -0000
@@ -1055,13 +1055,12 @@
 ****************************************************************************/
 void tilespec_setup_specialist_types(void)
 {
-  int i, j;
-  char buffer[512];
-
   /* Load the specialist sprite graphics. */
-  for (i = 0; i < SP_COUNT; i++) {
+  specialist_type_iterate(i) {
     struct citizen_type c = {.type = CITIZEN_SPECIALIST, .spec_type = i};
     const char *name = get_citizen_name(c);
+    char buffer[512];
+    int j;
 
     for (j = 0; j < NUM_TILES_CITIZEN; j++) {
       my_snprintf(buffer, sizeof(buffer), "specialist.%s_%d", name, j);
@@ -1075,7 +1074,7 @@
       freelog(LOG_NORMAL, _("No graphics for specialist %s."), name);
       exit(EXIT_FAILURE);
     }
-  }
+  } specialist_type_iterate_end;
 }
 
 /****************************************************************************
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.53
diff -u -r1.53 cma_core.c
--- client/agents/cma_core.c    29 May 2004 20:34:31 -0000      1.53
+++ client/agents/cma_core.c    11 Jul 2004 16:07:04 -0000
@@ -269,7 +269,7 @@
 static void get_current_as_result(struct city *pcity,
                                  struct cm_result *result)
 {
-  int worker = 0, i;
+  int worker = 0;
 
   memset(result->worker_positions_used, 0,
         sizeof(result->worker_positions_used));
@@ -282,9 +282,9 @@
     }
   } my_city_map_iterate_end;
 
-  for (i = 0; i < SP_COUNT; i++) {
-    result->specialists[i] = pcity->specialists[i];
-  }
+  specialist_type_iterate(sp) {
+    result->specialists[sp] = pcity->specialists[sp];
+  } specialist_type_iterate_end;
 
   assert(worker + result->specialists[SP_ELVIS]
         + result->specialists[SP_SCIENTIST]
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.225
diff -u -r1.225 city.c
--- common/city.c       9 Jul 2004 19:40:23 -0000       1.225
+++ common/city.c       11 Jul 2004 16:07:05 -0000
@@ -2524,11 +2524,11 @@
 **************************************************************************/
 int city_specialists(const struct city *pcity)
 {
-  int count = 0, i;
+  int count = 0;
 
-  for (i = 0; i < SP_COUNT; i++) {
-    count += pcity->specialists[i];
-  }
+  specialist_type_iterate(sp) {
+    count += pcity->specialists[sp];
+  } specialist_type_iterate_end;
 
   return count;
 }
@@ -2680,9 +2680,9 @@
   pcity->y = y;
   sz_strlcpy(pcity->name, name);
   pcity->size = 1;
-  for (i = 0; i < SP_COUNT; i++) {
-    pcity->specialists[i] = 0;
-  }
+  specialist_type_iterate(sp) {
+    pcity->specialists[sp] = 0;
+  } specialist_type_iterate_end;
   pcity->specialists[SP_ELVIS] = 1;
   pcity->ppl_happy[4] = 0;
   pcity->ppl_content[4] = 1;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.143
diff -u -r1.143 game.h
--- common/game.h       3 Jul 2004 17:11:34 -0000       1.143
+++ common/game.h       11 Jul 2004 16:07:05 -0000
@@ -500,4 +500,14 @@
 
 #define GAME_START_YEAR -4000
 
+#define specialist_type_iterate(sp)                                        \
+  {                                                                        \
+  int sp;                                                                   \
+                                                                            \
+  for (sp = 0; sp < SP_COUNT; sp++) {
+
+#define specialist_type_iterate_end                                         \
+  }                                                                         \
+}
+
 #endif  /* FC__GAME_H */
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.29
diff -u -r1.29 cm.c
--- common/aicore/cm.c  11 Jul 2004 05:27:20 -0000      1.29
+++ common/aicore/cm.c  11 Jul 2004 16:07:06 -0000
@@ -307,11 +307,11 @@
 ****************************************************************************/
 static int get_num_specialists(const struct cm_result *const result)
 {
-  int sp, count = 0;
+  int count = 0;
 
-  for (sp = 0; sp < SP_COUNT; sp++) {
+  specialist_type_iterate(sp) {
     count += result->specialists[sp];
-  }
+  } specialist_type_iterate_end;
 
   return count;
 }
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.250
diff -u -r1.250 cityturn.c
--- server/cityturn.c   7 Jul 2004 07:32:03 -0000       1.250
+++ server/cityturn.c   11 Jul 2004 16:07:07 -0000
@@ -147,8 +147,6 @@
 **************************************************************************/
 void apply_cmresult_to_city(struct city *pcity, struct cm_result *cmr)
 {
-  int i;
-
   /* Now apply results */
   city_map_checked_iterate(pcity->x, pcity->y, x, y, mapx, mapy) {
     if (pcity->city_map[x][y] == C_TILE_WORKER
@@ -162,9 +160,9 @@
       server_set_worker_city(pcity, x, y);
     }
   } city_map_checked_iterate_end;
-  for (i = 0; i < SP_COUNT; i++) {
-    pcity->specialists[i] = cmr->specialists[i];
-  }
+  specialist_type_iterate(sp) {
+    pcity->specialists[sp] = cmr->specialists[sp];
+  } specialist_type_iterate_end;
 }
 
 /**************************************************************************
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.177
diff -u -r1.177 ruleset.c
--- server/ruleset.c    10 Jul 2004 18:43:45 -0000      1.177
+++ server/ruleset.c    11 Jul 2004 16:07:08 -0000
@@ -3115,11 +3115,11 @@
   int i;
   struct packet_ruleset_game misc_p;
 
-  for (i = 0; i < SP_COUNT; i++) {
-    sz_strlcpy(misc_p.specialist_name[i], game.rgame.specialists[i].name);
-    misc_p.specialist_min_size[i] = game.rgame.specialists[i].min_size;
-    misc_p.specialist_bonus[i] = game.rgame.specialists[i].bonus;
-  }
+  specialist_type_iterate(sp) {
+    sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
+    misc_p.specialist_min_size[sp] = game.rgame.specialists[sp].min_size;
+    misc_p.specialist_bonus[sp] = game.rgame.specialists[sp].bonus;
+  } specialist_type_iterate_end;
   misc_p.changable_tax = game.rgame.changable_tax;
   misc_p.forced_science = game.rgame.forced_science;
   misc_p.forced_luxury = game.rgame.forced_luxury;
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.163
diff -u -r1.163 savegame.c
--- server/savegame.c   6 Jul 2004 21:48:48 -0000       1.163
+++ server/savegame.c   11 Jul 2004 16:07:09 -0000
@@ -1247,11 +1247,11 @@
 
     pcity->steal=secfile_lookup_int(file, "player%d.c%d.steal", plrno, i);
 
-    for (j = 0; j < SP_COUNT; j++) {
-      pcity->specialists[j]
+    specialist_type_iterate(sp) {
+      pcity->specialists[sp]
        = secfile_lookup_int(file, "player%d.c%d.n%s", plrno, i,
-                            game.rgame.specialists[j].name);
-    }
+                            game.rgame.specialists[sp].name);
+    } specialist_type_iterate_end;
 
     for (j = 0; j < NUM_TRADEROUTES; j++)
       pcity->trade[j]=secfile_lookup_int(file, "player%d.c%d.traderoute%d",
@@ -1866,11 +1866,11 @@
                       plrno, i);
     secfile_insert_int(file, pcity->size, "player%d.c%d.size", plrno, i);
     secfile_insert_int(file, pcity->steal, "player%d.c%d.steal", plrno, i);
-    for (j = 0; j < SP_COUNT; j++) {
-      secfile_insert_int(file, pcity->specialists[j],
+    specialist_type_iterate(sp) {
+      secfile_insert_int(file, pcity->specialists[sp],
                         "player%d.c%d.n%s", plrno, i,
-                        game.rgame.specialists[j].name);
-    }
+                        game.rgame.specialists[sp].name);
+    } specialist_type_iterate_end;
 
     for (j = 0; j < NUM_TRADEROUTES; j++)
       secfile_insert_int(file, pcity->trade[j], "player%d.c%d.traderoute%d", 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9337) new iterator specialist_type_iterate, Jason Short <=