Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2003:
[Freeciv-Dev] (PR#6873) Replace int with enum tile_terrain_type
Home

[Freeciv-Dev] (PR#6873) Replace int with enum tile_terrain_type

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6873) Replace int with enum tile_terrain_type
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Sat, 15 Nov 2003 09:31:10 -0800
Reply-to: rt@xxxxxxxxxxx

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


See $SUBJECT. It also introduces terrain_type_iterate.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "On the eigth day, God started debugging"

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.171
diff -u -u -r1.171 game.c
--- common/game.c       2003/11/10 20:33:58     1.171
+++ common/game.c       2003/11/15 17:25:52
@@ -533,7 +533,7 @@
     name_strlcpy(tthis->name, Q_(tthis->name_orig));
   } impr_type_iterate_end;
 
-  for (i=T_FIRST; i<T_COUNT; i++) {
+  terrain_type_iterate(i) {
     struct tile_type *tthis = &tile_types[i];
     sz_strlcpy(tthis->terrain_name_orig, tthis->terrain_name);
     name_strlcpy(tthis->terrain_name,
@@ -547,7 +547,8 @@
     name_strlcpy(tthis->special_2_name,
                 (strcmp(tthis->special_2_name_orig, "") != 0) ?
                        Q_(tthis->special_2_name_orig) : "");
-  }
+  } terrain_type_iterate_end;
+
   government_iterate(tthis) {
     int j;
 
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.6
diff -u -u -r1.6 terrain.h
--- common/terrain.h    2003/10/02 17:54:57     1.6
+++ common/terrain.h    2003/11/15 17:25:54
@@ -93,4 +93,14 @@
 
 #define terrain_has_flag(terr, flag) BV_ISSET(tile_types[(terr)].flags, flag)
 
+/* This iterator iterates over all terrain types. */
+#define terrain_type_iterate(id)                                            \
+{                                                                           \
+  enum tile_terrain_type id;                                                \
+  for (id = T_FIRST; id < T_COUNT; id++) {
+
+#define terrain_type_iterate_end                                            \
+  }                                                                         \
+}
+
 #endif  /* FC__TERRAIN_H */
Index: common/aicore/pf_tools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/pf_tools.c,v
retrieving revision 1.8
diff -u -u -r1.8 pf_tools.c
--- common/aicore/pf_tools.c    2003/09/21 09:06:43     1.8
+++ common/aicore/pf_tools.c    2003/11/15 17:25:55
@@ -106,7 +106,7 @@
                            int x1, int y1, struct pf_parameter *param)
 {
   struct tile *ptile = map_get_tile(x, y);
-  int terrain1 = map_get_terrain(x1, y1);
+  enum tile_terrain_type terrain1 = map_get_terrain(x1, y1);
   int move_cost;
 
   if (terrain1 == T_OCEAN) {
@@ -204,7 +204,7 @@
                             int x1, int y1, struct pf_parameter *param)
 {
   struct tile *ptile = map_get_tile(x, y);
-  int terrain1 = map_get_terrain(x1, y1);
+  enum tile_terrain_type terrain1 = map_get_terrain(x1, y1);
   int move_cost;
 
   if (terrain1 == T_OCEAN) {
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.155
diff -u -u -r1.155 ruleset.c
--- server/ruleset.c    2003/10/02 17:54:58     1.155
+++ server/ruleset.c    2003/11/15 17:26:01
@@ -1328,7 +1328,7 @@
 **************************************************************************/
 static void load_terrain_names(struct section_file *file)
 {
-  int nval, i;
+  int nval;
   char **sec;
   const char *filename = secfile_filename(file);
 
@@ -1337,20 +1337,20 @@
   /* terrain names */
 
   sec = secfile_get_secnames_prefix(file, "terrain_", &nval);
-  if (nval != (T_COUNT - T_FIRST))
-    {
-      /* sometime this restriction should be removed */
-      freelog(LOG_FATAL, "Bad number of terrains %d (%s)", nval, filename);
-      exit(EXIT_FAILURE);
-    }
+  if (nval != (T_COUNT - T_FIRST)) {
+    /* sometime this restriction should be removed */
+    freelog(LOG_FATAL, "Bad number of terrains %d (%s)", nval, filename);
+    exit(EXIT_FAILURE);
+  }
 
-  for (i = T_FIRST; i < T_COUNT; i++) {
+  terrain_type_iterate(i) {
     char *name = secfile_lookup_str(file, "%s.terrain_name", sec[i]);
     name_strlcpy(tile_types[i].terrain_name, name);
     if (0 == strcmp(tile_types[i].terrain_name, "unused")) {
       tile_types[i].terrain_name[0] = 0;
     }
-  }
+  } terrain_type_iterate_end;
+
   free(sec);
 }
 
@@ -1362,8 +1362,7 @@
   char *datafile_options;
   int nval;
   char **sec;
-  int i, j;
-  struct tile_type *t;
+  int j;
   const char *filename = secfile_filename(file);
 
   datafile_options =
@@ -1429,10 +1428,9 @@
 
   /* terrain details */
 
-  for (i = T_FIRST; i < T_COUNT; i++)
-    {
+  terrain_type_iterate(i) {
+      struct tile_type *t = &(tile_types[i]);
       char *s1_name, *s2_name, **slist;
-      t = &(tile_types[i]);
 
       sz_strlcpy(t->graphic_str,
                 secfile_lookup_str(file,"%s.graphic", sec[i]));
@@ -1505,7 +1503,7 @@
       }
       
       t->helptext = lookup_helptext(file, sec[i]);
-    }
+  } terrain_type_iterate_end;
 
   free(sec);
   section_file_check_unused(file, filename);
@@ -2620,14 +2618,13 @@
 static void send_ruleset_terrain(struct conn_list *dest)
 {
   struct packet_ruleset_terrain packet;
-  struct tile_type *t;
-  int i, j;
+
+  int j;
 
   lsend_packet_ruleset_terrain_control(dest, &terrain_control);
 
-  for (i = T_FIRST; i < T_COUNT; i++)
-    {
-      t = &(tile_types[i]);
+  terrain_type_iterate(i) {
+      struct tile_type *t = &(tile_types[i]);
 
       packet.id = i;
 
@@ -2676,7 +2673,7 @@
       packet.helptext = t->helptext;   /* pointer assignment */
       
       lsend_packet_ruleset_terrain(dest, &packet);
-    }
+  } terrain_type_iterate_end;
 }
 
 /**************************************************************************
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.38
diff -u -u -r1.38 sanitycheck.c
--- server/sanitycheck.c        2003/10/13 06:55:21     1.38
+++ server/sanitycheck.c        2003/11/15 17:26:01
@@ -38,7 +38,7 @@
 static void check_specials(void)
 {
   whole_map_iterate(x, y) {
-    int terrain = map_get_terrain(x, y);
+    enum tile_terrain_type terrain = map_get_terrain(x, y);
     int special = map_get_special(x, y);
 
     if (contains_special(special, S_RAILROAD))

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#6873) Replace int with enum tile_terrain_type, Raimar Falke <=