Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] PATCH: substituting whole_map_iterate (PR#943)
Home

[Freeciv-Dev] PATCH: substituting whole_map_iterate (PR#943)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: substituting whole_map_iterate (PR#943)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Fri, 7 Sep 2001 00:49:31 -0700 (PDT)

The attached patches substitute whole_map_iterate for the equivalent
functionality in a lot of places.  Again they may duplicate Ross's code,
but they're certainly in a simpler form.

Most substitutions should result in almost identical code once the
preprocessor is through.  In one or two places I've substituted code in
a slightly different order, but it should all give identical
functionality.

Note that in the long run, a general topology may not be a perfect
rectangle so it will be necessary to use whole_map_iterate (or a
substitute) everywhere.  This patch makes the substitution into every
place where it can be done without changing existing code (I don't think
I've missed any).

All of the changes required re-indentation of the inner loop, so there
are two versions of the patch.  The nospace one was diffed with the -b
option so that whitespace was ignored; this one will not fix the
indentation but is much easier to read.  The regular one includes all
changes to the indentation.

As with my previous map_adjust patch, all changes should be independent
so the patch should be easy to evaluate.

jason short
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.94
diff -u -b -r1.94 mapview.c
--- client/gui-gtk/mapview.c    2001/08/29 13:19:26     1.94
+++ client/gui-gtk/mapview.c    2001/09/07 07:37:53
@@ -925,14 +925,11 @@
 **************************************************************************/
 void refresh_overview_canvas(void)
 {
-  int x, y;
-  
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++) {
+  whole_map_iterate(x, y) {
       set_overview_tile_foreground_color(x, y);
       gdk_draw_rectangle( overview_canvas_store, fill_bg_gc, TRUE, x*2, y*2,
                        2, 2 );
-    }
+  } whole_map_iterate_end;
 
   gdk_gc_set_foreground( fill_bg_gc, colors_standard[COLOR_STD_BLACK] );
 }
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.1
diff -u -b -r1.1 mapview.c
--- client/gui-win32/mapview.c  2001/09/04 19:09:37     1.1
+++ client/gui-win32/mapview.c  2001/09/07 07:37:55
@@ -1102,12 +1102,10 @@
 refresh_overview_canvas(void)
 {
   HDC hdc;
-  int x, y;
   int pos;
   RECT rc;
   hdc=GetDC(root_window);
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++) {
+  whole_map_iterate(x, y) {
       rc.left=x*2;
       rc.right=rc.left+2;
       rc.top=y*2;
@@ -1123,8 +1121,7 @@
       rc.top=overview_win_y+y*2;
       rc.bottom=rc.top+2;
       FillRect(hdc,&rc,brush_std[overview_tile_color(x,y)]);
- 
-    }  
+  } whole_map_iterate_end;
   ReleaseDC(root_window,hdc);
 }
 
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.76
diff -u -b -r1.76 mapview.c
--- client/gui-xaw/mapview.c    2001/08/25 07:09:37     1.76
+++ client/gui-xaw/mapview.c    2001/09/07 07:37:56
@@ -565,14 +565,11 @@
 **************************************************************************/
 void refresh_overview_canvas(void)
 {
-  int x, y;
-  
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++) {
+  whole_map_iterate(x, y) {
       set_overview_tile_foreground_color(x, y);
       XFillRectangle(display, overview_canvas_store, fill_bg_gc, x*2, y*2, 
                     2, 2);
-    }
+  } whole_map_iterate_end;
 
   XSetForeground(display, fill_bg_gc, 0);
 }
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.136
diff -u -b -r1.136 citytools.c
--- server/citytools.c  2001/09/02 13:37:59     1.136
+++ server/citytools.c  2001/09/07 07:37:58
@@ -1257,19 +1257,16 @@
 {
   conn_list_do_buffer(dest);
   conn_list_iterate(*dest, pconn) {
-    int x, y;
     struct player *pplayer = pconn->player;
     if (pplayer==NULL && !pconn->observer) {
       continue;
     }
-    for(y=0; y<map.ysize; y++) {
-      for(x=0; x<map.xsize; x++) {
+    whole_map_iterate(x, y) {
        if (pplayer==NULL
            || map_get_player_tile(x, y, pplayer)->city) {
          send_city_info_at_tile(pplayer, &pconn->self, NULL, x, y);
        }
-      }
-    }
+    } whole_map_iterate_end;
   }
   conn_list_iterate_end;
   conn_list_do_unbuffer(dest);
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.111
diff -u -b -r1.111 gotohand.c
--- server/gotohand.c   2001/08/30 13:00:16     1.111
+++ server/gotohand.c   2001/09/07 07:38:00
@@ -1300,15 +1300,13 @@
 **************************************************************************/
 static void make_list_of_refuel_points(struct player *pplayer)
 {
-  int x, y;
   struct refuel *prefuel;
   struct city *pcity;
   struct tile *ptile;
 
   refuellist_size = 0;
 
-  for (x = 0; x < map.xsize; x++) {
-    for (y = 0; y < map.ysize; y++) {
+  whole_map_iterate(x, y) {
       ptile = map_get_tile(x,y);
       if ((pcity = is_allied_city_tile(ptile, pplayer))
          && !is_non_allied_unit_tile(ptile, pplayer)) {
@@ -1325,8 +1323,7 @@
                    FUEL_AIRBASE, MAP_MAX_HEIGHT+MAP_MAX_WIDTH, 0);
        refuels[refuellist_size++] = prefuel;
       }
-    }
-  }
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.70
diff -u -b -r1.70 mapgen.c
--- server/mapgen.c     2001/07/28 12:03:29     1.70
+++ server/mapgen.c     2001/09/07 07:38:02
@@ -762,11 +762,10 @@
 **************************************************************************/
 static void make_plains(void)
 {
-  int x,y;
-  for (y=0;y<map.ysize;y++)
-    for (x=0;x<map.xsize;x++)
+  whole_map_iterate(x, y) {
       if (map_get_terrain(x, y)==T_GRASSLAND && myrand(100)>50)
        map_set_terrain(x, y, T_PLAINS);
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
@@ -824,7 +823,6 @@
 **************************************************************************/
 static void make_land(void)
 {
-  int x, y;
   int tres=(maxval*map.landpercent)/100;
   int count=0;
   int total=(map.xsize*map.ysize*map.landpercent)/100;
@@ -833,15 +831,14 @@
     forever++;
     if (forever>50) break; /* loop elimination */
     count=0;
-    for (y=0;y<map.ysize;y++)
-      for (x=0;x<map.xsize;x++) {
+    whole_map_iterate(x, y) {
        if (hmap(x, y)<tres)
          map_set_terrain(x, y, T_OCEAN);
        else {
          map_set_terrain(x, y, T_GRASSLAND);
          count++;
-       }
       }
+    } whole_map_iterate_end;
     if (count>total)
       tres*=11;
     else
@@ -918,12 +915,11 @@
 **************************************************************************/
 void assign_continent_numbers(void)
 {
-  int x, y;
   int isle = 1;
 
-  for (y=0; y<map.ysize; y++)
-    for (x=0; x<map.xsize; x++)
+  whole_map_iterate(x, y) {
       map_set_continent(x, y, 0);
+  } whole_map_iterate_end;
 
   if (map.generator != 0) {
     assign_continent_flood(0, 0, 1);
@@ -931,13 +927,11 @@
     isle = 3;
   }
       
-  for (y=0; y<map.ysize; y++) {
-    for (x=0; x<map.xsize; x++) { 
+  whole_map_iterate(x, y) {
       if (!map_get_continent(x, y) && map_get_terrain(x, y)!=T_OCEAN) {
        assign_continent_flood(x, y, isle++);
-      }
-    }
   }
+  } whole_map_iterate_end;
   map.num_continents = isle-1;
   freelog(LOG_VERBOSE, "Map has %d continents", map.num_continents);
 }
@@ -949,7 +943,7 @@
 **************************************************************************/
 static void setup_isledata(void)
 {
-  int x,y;
+  int x;
   int good, mingood, maxgood;
   int riches;
   int starters;
@@ -970,15 +964,13 @@
   }
 
   /* get x and y positions: (top left) */
-  for (y=0; y<map.ysize; y++) {
-    for (x=0; x<map.xsize; x++) {
+  whole_map_iterate(x, y) {
       int cont = map_get_continent(x, y);
       if (islands[cont].x == -1) {
        islands[cont].x = x;
        islands[cont].y = y;
-      }
-    }
   }
+  } whole_map_iterate_end;
 
   /* Add up the goodies: for useable ocean, add value to continent
      for _every_ adjacent land tile.  This is IMO not very good,
@@ -987,8 +979,7 @@
      results of the previous method which used flood_fill().  --dwp
      This is also the correct place to add S_HUT bonus.
   */
-  for (y=0; y<map.ysize; y++) {
-    for (x=0; x<map.xsize; x++) {
+  whole_map_iterate(x, y) {
       int cont = map_get_continent(x, y);
       if (cont) {
        islands[cont].goodies += is_good_tile(x, y);
@@ -1008,9 +999,8 @@
            }
          } square_iterate_end;
        }
-      }
     }
-  }
+  } whole_map_iterate_end;
   
   /* the arctic and the antarctic are continents 1 and 2 for generator>0*/
   if (map.generator>0) {
@@ -1296,12 +1286,9 @@
 **************************************************************************/
 static void adjust_map(int minval)
 {
-  int x,y;
-  for (y=0;y<map.ysize;y++) {
-    for (x=0;x<map.xsize;x++) {
+  whole_map_iterate(x, y) {
       hmap(x, y) -= minval;
-    }
-  }
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
@@ -1309,17 +1296,15 @@
 **************************************************************************/
 static void mapgenerator1(void)
 {
-  int x,y, i;
+  int i;
   int minval=5000000;
   height_map=fc_malloc (sizeof(int)*map.xsize*map.ysize);
 
   adjust_terrain_param();
   
-  for (y=0;y<map.ysize;y++) {
-    for (x=0;x<map.xsize;x++) {
+  whole_map_iterate(x, y) {
       hmap(x, y) = myrand(40)+((500-abs(map.ysize/2-y))/10);
-    }
-  }
+  } whole_map_iterate_end;
   for (i=0;i<1500;i++) {
     height_map[myrand(map.ysize*map.xsize)]+=myrand(5000);
     if (!(i%100)) {
@@ -1331,13 +1316,13 @@
   smooth_map(); 
   smooth_map(); 
 
-  for (y=0;y<map.ysize;y++)
-    for (x=0;x<map.xsize;x++) {
+  whole_map_iterate(x, y) {
       if (hmap(x, y)>maxval) 
        maxval=hmap(x, y);
       if (hmap(x, y)<minval)
        minval=hmap(x, y);
-    }
+  } whole_map_iterate_end;
+
   maxval-=minval;
   adjust_map(minval);
 
@@ -1351,14 +1336,12 @@
 **************************************************************************/
 static void smooth_map(void)
 {
-  int x,y;
   int mx,my,px,py;
   int a;
   
-  for (y=0;y<map.ysize;y++) {
+  whole_map_iterate(x, y) {
     my=map_adjust_y(y-1);
     py=map_adjust_y(y+1);
-    for (x=0;x<map.xsize;x++) {
       mx=map_adjust_x(x-1);
       px=map_adjust_x(x+1);
       a=hmap(x, y)*2;
@@ -1378,8 +1361,7 @@
       a-=30;
       if (a<0) a=0;
       hmap(x, y) = a/10;
-    }
-  }
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.28
diff -u -b -r1.28 savegame.c
--- server/savegame.c   2001/09/02 13:38:00     1.28
+++ server/savegame.c   2001/09/07 07:38:04
@@ -484,9 +484,9 @@
 
   /* Should be handled as part of send_all_know_tiles,
      but do it here too for safety */
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++)
+  whole_map_iterate(x, y) {
       map_get_tile(x,y)->sent = 0;
+  } whole_map_iterate_end;
 }
 
 /***************************************************************
@@ -1245,9 +1245,9 @@
   int x,y,i;
 
   if (!plr->is_alive)
-    for (x=0; x<map.xsize; x++)
-      for (y=0; y<map.ysize; y++)
+    whole_map_iterate(x, y) {
        map_change_seen(x, y, plr, +1);
+    } whole_map_iterate_end;
 
   /* load map if:
      1) it from a fog of war build
@@ -1393,23 +1393,20 @@
 
     /* This shouldn't be neccesary if the savegame was consistent, but there
        is a bug in some pre-1.11 savegames. Anyway, it can't hurt */
-    for (x=0; x<map.xsize; x++) {
-      for (y=0; y<map.ysize; y++) {
+    whole_map_iterate(x, y) {
        if (map_get_known_and_seen(x, y, get_player(plrno))) {
          update_tile_knowledge(plr, x, y);
          reality_check_city(plr, x, y);
          if (map_get_city(x, y)) {
            update_dumb_city(plr, map_get_city(x, y));
          }
-       }
       }
-    }
+    } whole_map_iterate_end;
 
   } else {
     /* We have an old savegame or fog of war was turned off; the players 
private
        knowledge is set to be what he could see without fog of war */
-    for(y=0; y<map.ysize; y++)
-      for(x=0; x<map.xsize; x++)
+    whole_map_iterate(x, y) {
        if (map_get_known(x, y, plr)) {
          struct city *pcity = map_get_city(x,y);
          update_player_tile_last_seen(plr, x, y);
@@ -1417,6 +1414,7 @@
          if (pcity)
            update_dumb_city(plr, pcity);
        }
+    } whole_map_iterate_end;
   }
 }
 
@@ -1792,8 +1790,7 @@
       struct dumb_city *pdcity;
       i = 0;
       
-      for (x = 0; x < map.xsize; x++)
-       for (y = 0; y < map.ysize; y++)
+      whole_map_iterate(x, y) {
          if ((pdcity = map_get_player_tile(x, y, plr)->city)) {
            secfile_insert_int(file, pdcity->id, "player%d.dc%d.id", plrno, i);
            secfile_insert_int(file, x, "player%d.dc%d.x", plrno, i);
@@ -1804,6 +1801,7 @@
            secfile_insert_int(file, pdcity->owner, "player%d.dc%d.owner", 
plrno, i);
            i++;
          }
+      } whole_map_iterate_end;
     }
     secfile_insert_int(file, i, "player%d.total_ncities", plrno);
   }
@@ -1851,7 +1849,7 @@
 ***************************************************************/
 static void calc_unit_ordering(void)
 {
-  int i, j, x, y;
+  int i, j;
   
   for(i=0; i<game.nplayers; i++) {
     /* to avoid junk values for unsupported units: */
@@ -1867,14 +1865,12 @@
     city_list_iterate_end;
   }
 
-  for(y=0; y<map.ysize; y++) {
-    for(x=0; x<map.xsize; x++) {
+  whole_map_iterate(x, y) {
       j = 0;
       unit_list_iterate(map_get_tile(x,y)->units, punit) 
        punit->ord_map = j++;
       unit_list_iterate_end;
-    }
-  }
+  } whole_map_iterate_end;
 }
 /***************************************************************
  For each city and tile, sort unit lists according to
@@ -1882,7 +1878,7 @@
 ***************************************************************/
 static void apply_unit_ordering(void)
 {
-  int i, x, y;
+  int i;
   
   for(i=0; i<game.nplayers; i++) {
     city_list_iterate(get_player(i)->cities, pcity) {
@@ -1891,11 +1887,9 @@
     city_list_iterate_end;
   }
 
-  for(y=0; y<map.ysize; y++) {
-    for(x=0; x<map.xsize; x++) { 
+  whole_map_iterate(x, y) {
       unit_list_sort_ord_map(&map_get_tile(x,y)->units);
-    }
-  }
+  } whole_map_iterate_end;
 }
 
 /***************************************************************
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.104
diff -u -b -r1.104 settlers.c
--- server/settlers.c   2001/08/26 13:10:13     1.104
+++ server/settlers.c   2001/09/07 07:38:06
@@ -1424,10 +1424,10 @@
 
 static void assign_settlers(void)
 {
-  int i, x, y;
-  for (x = 0; x < map.xsize; x++)
-    for (y = 0; y < map.ysize; y++)
+  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));
@@ -1477,10 +1477,11 @@
 **************************************************************************/
 static void assign_territory(void)
 {
-  int i, x, y;
-  for (x = 0; x < map.xsize; x++)
-    for (y = 0; y < map.ysize; y++)
+  int i;
+
+  whole_map_iterate(x, y) {
       territory[x][y] = 0xFFFFFFFF;
+  } whole_map_iterate_end;
 
   for (i = 0; i < game.nplayers; i++) {
     assign_territory_player(shuffled_player(i));
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.48
diff -u -b -r1.48 srv_main.c
--- server/srv_main.c   2001/09/02 10:24:29     1.48
+++ server/srv_main.c   2001/09/07 07:38:08
@@ -276,16 +276,14 @@
                                       int *current, int *accum, int *level,
                                       void (*upset_action_fn)(int))
 {
-  int x, y, count;
+  int count;
 
   count = 0;
-  for (x = 0; x < map.xsize; x++) {
-    for (y = 0; y < map.ysize; y++) {
+  whole_map_iterate(x, y) {
       if (map_get_special(x,y) & cause) {
        count++;
       }
-    }
-  }
+  } whole_map_iterate_end;
 
   *current = count;
   *accum += count;
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.94
diff -u -r1.94 mapview.c
--- client/gui-gtk/mapview.c    2001/08/29 13:19:26     1.94
+++ client/gui-gtk/mapview.c    2001/09/07 07:36:03
@@ -925,14 +925,11 @@
 **************************************************************************/
 void refresh_overview_canvas(void)
 {
-  int x, y;
-  
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++) {
-      set_overview_tile_foreground_color(x, y);
-      gdk_draw_rectangle( overview_canvas_store, fill_bg_gc, TRUE, x*2, y*2,
+  whole_map_iterate(x, y) {
+    set_overview_tile_foreground_color(x, y);
+    gdk_draw_rectangle( overview_canvas_store, fill_bg_gc, TRUE, x*2, y*2,
                        2, 2 );
-    }
+  } whole_map_iterate_end;
 
   gdk_gc_set_foreground( fill_bg_gc, colors_standard[COLOR_STD_BLACK] );
 }
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.1
diff -u -r1.1 mapview.c
--- client/gui-win32/mapview.c  2001/09/04 19:09:37     1.1
+++ client/gui-win32/mapview.c  2001/09/07 07:36:04
@@ -1102,29 +1102,26 @@
 refresh_overview_canvas(void)
 {
   HDC hdc;
-  int x, y;
   int pos;
   RECT rc;
   hdc=GetDC(root_window);
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++) {
-      rc.left=x*2;
-      rc.right=rc.left+2;
-      rc.top=y*2;
-      rc.bottom=rc.top+2;
-      FillRect(overviewstoredc,&rc,brush_std[overview_tile_color(x, y)]); 
-      pos= x + map.xsize/2 - (map_view_x + map_win_width/2);
+  whole_map_iterate(x, y) {
+    rc.left=x*2;
+    rc.right=rc.left+2;
+    rc.top=y*2;
+    rc.bottom=rc.top+2;
+    FillRect(overviewstoredc,&rc,brush_std[overview_tile_color(x, y)]);
+    pos= x + map.xsize/2 - (map_view_x + map_win_width/2);
   
-      pos %= map.xsize;
-      if (pos < 0)
-       pos += map.xsize;
-      rc.left=overview_win_x+pos*2;
-      rc.right=rc.left+2;
-      rc.top=overview_win_y+y*2;
-      rc.bottom=rc.top+2;
-      FillRect(hdc,&rc,brush_std[overview_tile_color(x,y)]);
- 
-    }  
+    pos %= map.xsize;
+    if (pos < 0)
+      pos += map.xsize;
+    rc.left=overview_win_x+pos*2;
+    rc.right=rc.left+2;
+    rc.top=overview_win_y+y*2;
+    rc.bottom=rc.top+2;
+    FillRect(hdc,&rc,brush_std[overview_tile_color(x,y)]);
+  } whole_map_iterate_end;
   ReleaseDC(root_window,hdc);
 }
 
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.76
diff -u -r1.76 mapview.c
--- client/gui-xaw/mapview.c    2001/08/25 07:09:37     1.76
+++ client/gui-xaw/mapview.c    2001/09/07 07:36:06
@@ -565,14 +565,11 @@
 **************************************************************************/
 void refresh_overview_canvas(void)
 {
-  int x, y;
-  
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++) {
-      set_overview_tile_foreground_color(x, y);
-      XFillRectangle(display, overview_canvas_store, fill_bg_gc, x*2, y*2, 
-                    2, 2);
-    }
+  whole_map_iterate(x, y) {
+    set_overview_tile_foreground_color(x, y);
+    XFillRectangle(display, overview_canvas_store, fill_bg_gc, x*2, y*2,
+                  2, 2);
+  } whole_map_iterate_end;
 
   XSetForeground(display, fill_bg_gc, 0);
 }
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.136
diff -u -r1.136 citytools.c
--- server/citytools.c  2001/09/02 13:37:59     1.136
+++ server/citytools.c  2001/09/07 07:36:08
@@ -1257,19 +1257,16 @@
 {
   conn_list_do_buffer(dest);
   conn_list_iterate(*dest, pconn) {
-    int x, y;
     struct player *pplayer = pconn->player;
     if (pplayer==NULL && !pconn->observer) {
       continue;
     }
-    for(y=0; y<map.ysize; y++) {
-      for(x=0; x<map.xsize; x++) {
-       if (pplayer==NULL
-           || map_get_player_tile(x, y, pplayer)->city) {
-         send_city_info_at_tile(pplayer, &pconn->self, NULL, x, y);
-       }
+    whole_map_iterate(x, y) {
+      if (pplayer==NULL
+         || map_get_player_tile(x, y, pplayer)->city) {
+       send_city_info_at_tile(pplayer, &pconn->self, NULL, x, y);
       }
-    }
+    } whole_map_iterate_end;
   }
   conn_list_iterate_end;
   conn_list_do_unbuffer(dest);
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.111
diff -u -r1.111 gotohand.c
--- server/gotohand.c   2001/08/30 13:00:16     1.111
+++ server/gotohand.c   2001/09/07 07:36:10
@@ -1300,33 +1300,30 @@
 **************************************************************************/
 static void make_list_of_refuel_points(struct player *pplayer)
 {
-  int x, y;
   struct refuel *prefuel;
   struct city *pcity;
   struct tile *ptile;
 
   refuellist_size = 0;
 
-  for (x = 0; x < map.xsize; x++) {
-    for (y = 0; y < map.ysize; y++) {
-      ptile = map_get_tile(x,y);
-      if ((pcity = is_allied_city_tile(ptile, pplayer))
-         && !is_non_allied_unit_tile(ptile, pplayer)) {
-       prefuel = fc_malloc(sizeof(struct refuel));
-       init_refuel(prefuel, x, y, FUEL_CITY, MAP_MAX_HEIGHT+MAP_MAX_WIDTH, 0);
-       refuels[refuellist_size++] = prefuel;
+  whole_map_iterate(x, y) {
+    ptile = map_get_tile(x,y);
+    if ((pcity = is_allied_city_tile(ptile, pplayer))
+       && !is_non_allied_unit_tile(ptile, pplayer)) {
+      prefuel = fc_malloc(sizeof(struct refuel));
+      init_refuel(prefuel, x, y, FUEL_CITY, MAP_MAX_HEIGHT+MAP_MAX_WIDTH, 0);
+      refuels[refuellist_size++] = prefuel;
+      continue;
+    }
+    if ((ptile = map_get_tile(x,y))->special&S_AIRBASE) {
+      if (is_non_allied_unit_tile(ptile, pplayer))
        continue;
-      }
-      if ((ptile = map_get_tile(x,y))->special&S_AIRBASE) {
-       if (is_non_allied_unit_tile(ptile, pplayer))
-         continue;
-       prefuel = fc_malloc(sizeof(struct refuel));
-       init_refuel(prefuel, x, y,
-                   FUEL_AIRBASE, MAP_MAX_HEIGHT+MAP_MAX_WIDTH, 0);
-       refuels[refuellist_size++] = prefuel;
-      }
+      prefuel = fc_malloc(sizeof(struct refuel));
+      init_refuel(prefuel, x, y,
+                 FUEL_AIRBASE, MAP_MAX_HEIGHT+MAP_MAX_WIDTH, 0);
+      refuels[refuellist_size++] = prefuel;
     }
-  }
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.70
diff -u -r1.70 mapgen.c
--- server/mapgen.c     2001/07/28 12:03:29     1.70
+++ server/mapgen.c     2001/09/07 07:36:12
@@ -762,11 +762,10 @@
 **************************************************************************/
 static void make_plains(void)
 {
-  int x,y;
-  for (y=0;y<map.ysize;y++)
-    for (x=0;x<map.xsize;x++)
-      if (map_get_terrain(x, y)==T_GRASSLAND && myrand(100)>50)
-       map_set_terrain(x, y, T_PLAINS);
+  whole_map_iterate(x, y) {
+    if (map_get_terrain(x, y)==T_GRASSLAND && myrand(100)>50)
+      map_set_terrain(x, y, T_PLAINS);
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
@@ -824,7 +823,6 @@
 **************************************************************************/
 static void make_land(void)
 {
-  int x, y;
   int tres=(maxval*map.landpercent)/100;
   int count=0;
   int total=(map.xsize*map.ysize*map.landpercent)/100;
@@ -833,15 +831,14 @@
     forever++;
     if (forever>50) break; /* loop elimination */
     count=0;
-    for (y=0;y<map.ysize;y++)
-      for (x=0;x<map.xsize;x++) {
-       if (hmap(x, y)<tres)
-         map_set_terrain(x, y, T_OCEAN);
-       else {
-         map_set_terrain(x, y, T_GRASSLAND);
-         count++;
-       }
+    whole_map_iterate(x, y) {
+      if (hmap(x, y)<tres)
+       map_set_terrain(x, y, T_OCEAN);
+      else {
+       map_set_terrain(x, y, T_GRASSLAND);
+       count++;
       }
+    } whole_map_iterate_end;
     if (count>total)
       tres*=11;
     else
@@ -918,26 +915,23 @@
 **************************************************************************/
 void assign_continent_numbers(void)
 {
-  int x, y;
   int isle = 1;
 
-  for (y=0; y<map.ysize; y++)
-    for (x=0; x<map.xsize; x++)
-      map_set_continent(x, y, 0);
+  whole_map_iterate(x, y) {
+    map_set_continent(x, y, 0);
+  } whole_map_iterate_end;
 
   if (map.generator != 0) {
     assign_continent_flood(0, 0, 1);
     assign_continent_flood(0, map.ysize-1, 2);
     isle = 3;
   }
-      
-  for (y=0; y<map.ysize; y++) {
-    for (x=0; x<map.xsize; x++) { 
-      if (!map_get_continent(x, y) && map_get_terrain(x, y)!=T_OCEAN) {
-       assign_continent_flood(x, y, isle++);
-      }
+
+  whole_map_iterate(x, y) {
+    if (!map_get_continent(x, y) && map_get_terrain(x, y)!=T_OCEAN) {
+      assign_continent_flood(x, y, isle++);
     }
-  }
+  } whole_map_iterate_end;
   map.num_continents = isle-1;
   freelog(LOG_VERBOSE, "Map has %d continents", map.num_continents);
 }
@@ -949,7 +943,7 @@
 **************************************************************************/
 static void setup_isledata(void)
 {
-  int x,y;
+  int x;
   int good, mingood, maxgood;
   int riches;
   int starters;
@@ -970,15 +964,13 @@
   }
 
   /* get x and y positions: (top left) */
-  for (y=0; y<map.ysize; y++) {
-    for (x=0; x<map.xsize; x++) {
-      int cont = map_get_continent(x, y);
-      if (islands[cont].x == -1) {
-       islands[cont].x = x;
-       islands[cont].y = y;
-      }
+  whole_map_iterate(x, y) {
+    int cont = map_get_continent(x, y);
+    if (islands[cont].x == -1) {
+      islands[cont].x = x;
+      islands[cont].y = y;
     }
-  }
+  } whole_map_iterate_end;
 
   /* Add up the goodies: for useable ocean, add value to continent
      for _every_ adjacent land tile.  This is IMO not very good,
@@ -987,30 +979,28 @@
      results of the previous method which used flood_fill().  --dwp
      This is also the correct place to add S_HUT bonus.
   */
-  for (y=0; y<map.ysize; y++) {
-    for (x=0; x<map.xsize; x++) {
-      int cont = map_get_continent(x, y);
-      if (cont) {
-       islands[cont].goodies += is_good_tile(x, y);
-       if (map_get_special(x,y) & S_HUT) {
-         islands[cont].goodies += 0; /* 3; */   /* regression testing */
-       }
-      } else {
-       assert(map_get_terrain(x, y)==T_OCEAN);
-       /* no need to check is_sea_usable(x,y), because will
-          only use for adjacent land (cont1>0) below */
-       {
-         int goodval = is_good_tile(x, y);
-         square_iterate(x, y, 1, x1, y1) {
-           int cont1 = map_get_continent(x1, y1);
-           if (cont1>0) {  
-             islands[cont1].goodies += goodval;
-           }
-         } square_iterate_end;
-       }
+  whole_map_iterate(x, y) {
+    int cont = map_get_continent(x, y);
+    if (cont) {
+      islands[cont].goodies += is_good_tile(x, y);
+      if (map_get_special(x,y) & S_HUT) {
+       islands[cont].goodies += 0; /* 3; */   /* regression testing */
       }
+    } else {
+      assert(map_get_terrain(x, y)==T_OCEAN);
+      /* no need to check is_sea_usable(x,y), because will
+        only use for adjacent land (cont1>0) below */
+      {
+       int goodval = is_good_tile(x, y);
+       square_iterate(x, y, 1, x1, y1) {
+         int cont1 = map_get_continent(x1, y1);
+         if (cont1>0) {
+           islands[cont1].goodies += goodval;
+         }
+       } square_iterate_end;
+      }
     }
-  }
+  } whole_map_iterate_end;
   
   /* the arctic and the antarctic are continents 1 and 2 for generator>0*/
   if (map.generator>0) {
@@ -1296,12 +1286,9 @@
 **************************************************************************/
 static void adjust_map(int minval)
 {
-  int x,y;
-  for (y=0;y<map.ysize;y++) {
-    for (x=0;x<map.xsize;x++) {
-      hmap(x, y) -= minval;
-    }
-  }
+  whole_map_iterate(x, y) {
+    hmap(x, y) -= minval;
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
@@ -1309,17 +1296,15 @@
 **************************************************************************/
 static void mapgenerator1(void)
 {
-  int x,y, i;
+  int i;
   int minval=5000000;
   height_map=fc_malloc (sizeof(int)*map.xsize*map.ysize);
 
   adjust_terrain_param();
-  
-  for (y=0;y<map.ysize;y++) {
-    for (x=0;x<map.xsize;x++) {
-      hmap(x, y) = myrand(40)+((500-abs(map.ysize/2-y))/10);
-    }
-  }
+
+  whole_map_iterate(x, y) {
+    hmap(x, y) = myrand(40)+((500-abs(map.ysize/2-y))/10);
+  } whole_map_iterate_end;
   for (i=0;i<1500;i++) {
     height_map[myrand(map.ysize*map.xsize)]+=myrand(5000);
     if (!(i%100)) {
@@ -1331,13 +1316,13 @@
   smooth_map(); 
   smooth_map(); 
 
-  for (y=0;y<map.ysize;y++)
-    for (x=0;x<map.xsize;x++) {
-      if (hmap(x, y)>maxval) 
-       maxval=hmap(x, y);
-      if (hmap(x, y)<minval)
-       minval=hmap(x, y);
-    }
+  whole_map_iterate(x, y) {
+    if (hmap(x, y)>maxval)
+      maxval=hmap(x, y);
+    if (hmap(x, y)<minval)
+      minval=hmap(x, y);
+  } whole_map_iterate_end;
+
   maxval-=minval;
   adjust_map(minval);
 
@@ -1351,35 +1336,32 @@
 **************************************************************************/
 static void smooth_map(void)
 {
-  int x,y;
   int mx,my,px,py;
   int a;
   
-  for (y=0;y<map.ysize;y++) {
+  whole_map_iterate(x, y) {
     my=map_adjust_y(y-1);
     py=map_adjust_y(y+1);
-    for (x=0;x<map.xsize;x++) {
-      mx=map_adjust_x(x-1);
-      px=map_adjust_x(x+1);
-      a=hmap(x, y)*2;
+    mx=map_adjust_x(x-1);
+    px=map_adjust_x(x+1);
+    a=hmap(x, y)*2;
       
-      a+=hmap(px, my);
-      a+=hmap(mx, my);
-      a+=hmap(mx, py);
-      a+=hmap(px, py);
+    a+=hmap(px, my);
+    a+=hmap(mx, my);
+    a+=hmap(mx, py);
+    a+=hmap(px, py);
 
-      a+=hmap(x, my);
-      a+=hmap(mx, y);
+    a+=hmap(x, my);
+    a+=hmap(mx, y);
       
-      a+=hmap(x, py);
-      a+=hmap(px, y);
+    a+=hmap(x, py);
+    a+=hmap(px, y);
 
-      a+=myrand(60);
-      a-=30;
-      if (a<0) a=0;
-      hmap(x, y) = a/10;
-    }
-  }
+    a+=myrand(60);
+    a-=30;
+    if (a<0) a=0;
+    hmap(x, y) = a/10;
+  } whole_map_iterate_end;
 }
 
 /**************************************************************************
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.28
diff -u -r1.28 savegame.c
--- server/savegame.c   2001/09/02 13:38:00     1.28
+++ server/savegame.c   2001/09/07 07:36:15
@@ -484,9 +484,9 @@
 
   /* Should be handled as part of send_all_know_tiles,
      but do it here too for safety */
-  for(y=0; y<map.ysize; y++)
-    for(x=0; x<map.xsize; x++)
-      map_get_tile(x,y)->sent = 0;
+  whole_map_iterate(x, y) {
+    map_get_tile(x,y)->sent = 0;
+  } whole_map_iterate_end;
 }
 
 /***************************************************************
@@ -1245,9 +1245,9 @@
   int x,y,i;
 
   if (!plr->is_alive)
-    for (x=0; x<map.xsize; x++)
-      for (y=0; y<map.ysize; y++)
-       map_change_seen(x, y, plr, +1);
+    whole_map_iterate(x, y) {
+      map_change_seen(x, y, plr, +1);
+    } whole_map_iterate_end;
 
   /* load map if:
      1) it from a fog of war build
@@ -1393,30 +1393,28 @@
 
     /* This shouldn't be neccesary if the savegame was consistent, but there
        is a bug in some pre-1.11 savegames. Anyway, it can't hurt */
-    for (x=0; x<map.xsize; x++) {
-      for (y=0; y<map.ysize; y++) {
-       if (map_get_known_and_seen(x, y, get_player(plrno))) {
-         update_tile_knowledge(plr, x, y);
-         reality_check_city(plr, x, y);
-         if (map_get_city(x, y)) {
-           update_dumb_city(plr, map_get_city(x, y));
-         }
+    whole_map_iterate(x, y) {
+      if (map_get_known_and_seen(x, y, get_player(plrno))) {
+       update_tile_knowledge(plr, x, y);
+       reality_check_city(plr, x, y);
+       if (map_get_city(x, y)) {
+         update_dumb_city(plr, map_get_city(x, y));
        }
       }
-    }
+    } whole_map_iterate_end;
 
   } else {
     /* We have an old savegame or fog of war was turned off; the players 
private
        knowledge is set to be what he could see without fog of war */
-    for(y=0; y<map.ysize; y++)
-      for(x=0; x<map.xsize; x++)
-       if (map_get_known(x, y, plr)) {
-         struct city *pcity = map_get_city(x,y);
-         update_player_tile_last_seen(plr, x, y);
-         update_tile_knowledge(plr, x, y);
-         if (pcity)
-           update_dumb_city(plr, pcity);
-       }
+    whole_map_iterate(x, y) {
+      if (map_get_known(x, y, plr)) {
+       struct city *pcity = map_get_city(x,y);
+       update_player_tile_last_seen(plr, x, y);
+       update_tile_knowledge(plr, x, y);
+       if (pcity)
+         update_dumb_city(plr, pcity);
+      }
+    } whole_map_iterate_end;
   }
 }
 
@@ -1792,18 +1790,18 @@
       struct dumb_city *pdcity;
       i = 0;
       
-      for (x = 0; x < map.xsize; x++)
-       for (y = 0; y < map.ysize; y++)
-         if ((pdcity = map_get_player_tile(x, y, plr)->city)) {
-           secfile_insert_int(file, pdcity->id, "player%d.dc%d.id", plrno, i);
-           secfile_insert_int(file, x, "player%d.dc%d.x", plrno, i);
-           secfile_insert_int(file, y, "player%d.dc%d.y", plrno, i);
-           secfile_insert_str(file, pdcity->name, "player%d.dc%d.name", plrno, 
i);
-           secfile_insert_int(file, pdcity->size, "player%d.dc%d.size", plrno, 
i);
-           secfile_insert_int(file, pdcity->has_walls, 
"player%d.dc%d.has_walls", plrno, i);    
-           secfile_insert_int(file, pdcity->owner, "player%d.dc%d.owner", 
plrno, i);
-           i++;
-         }
+      whole_map_iterate(x, y) {
+       if ((pdcity = map_get_player_tile(x, y, plr)->city)) {
+         secfile_insert_int(file, pdcity->id, "player%d.dc%d.id", plrno, i);
+         secfile_insert_int(file, x, "player%d.dc%d.x", plrno, i);
+         secfile_insert_int(file, y, "player%d.dc%d.y", plrno, i);
+         secfile_insert_str(file, pdcity->name, "player%d.dc%d.name", plrno, 
i);
+         secfile_insert_int(file, pdcity->size, "player%d.dc%d.size", plrno, 
i);
+         secfile_insert_int(file, pdcity->has_walls, 
"player%d.dc%d.has_walls", plrno, i);
+         secfile_insert_int(file, pdcity->owner, "player%d.dc%d.owner", plrno, 
i);
+         i++;
+       }
+      } whole_map_iterate_end;
     }
     secfile_insert_int(file, i, "player%d.total_ncities", plrno);
   }
@@ -1851,7 +1849,7 @@
 ***************************************************************/
 static void calc_unit_ordering(void)
 {
-  int i, j, x, y;
+  int i, j;
   
   for(i=0; i<game.nplayers; i++) {
     /* to avoid junk values for unsupported units: */
@@ -1867,14 +1865,12 @@
     city_list_iterate_end;
   }
 
-  for(y=0; y<map.ysize; y++) {
-    for(x=0; x<map.xsize; x++) {
-      j = 0;
-      unit_list_iterate(map_get_tile(x,y)->units, punit) 
-       punit->ord_map = j++;
-      unit_list_iterate_end;
-    }
-  }
+  whole_map_iterate(x, y) {
+    j = 0;
+    unit_list_iterate(map_get_tile(x,y)->units, punit)
+      punit->ord_map = j++;
+    unit_list_iterate_end;
+  } whole_map_iterate_end;
 }
 /***************************************************************
  For each city and tile, sort unit lists according to
@@ -1882,7 +1878,7 @@
 ***************************************************************/
 static void apply_unit_ordering(void)
 {
-  int i, x, y;
+  int i;
   
   for(i=0; i<game.nplayers; i++) {
     city_list_iterate(get_player(i)->cities, pcity) {
@@ -1891,11 +1887,9 @@
     city_list_iterate_end;
   }
 
-  for(y=0; y<map.ysize; y++) {
-    for(x=0; x<map.xsize; x++) { 
-      unit_list_sort_ord_map(&map_get_tile(x,y)->units);
-    }
-  }
+  whole_map_iterate(x, y) {
+    unit_list_sort_ord_map(&map_get_tile(x,y)->units);
+  } whole_map_iterate_end;
 }
 
 /***************************************************************
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.104
diff -u -r1.104 settlers.c
--- server/settlers.c   2001/08/26 13:10:13     1.104
+++ server/settlers.c   2001/09/07 07:36:17
@@ -1424,10 +1424,10 @@
 
 static void assign_settlers(void)
 {
-  int i, x, y;
-  for (x = 0; x < map.xsize; x++)
-    for (y = 0; y < map.ysize; y++)
-      map_get_tile(x, y)->assigned = 0;
+  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));
@@ -1477,10 +1477,11 @@
 **************************************************************************/
 static void assign_territory(void)
 {
-  int i, x, y;
-  for (x = 0; x < map.xsize; x++)
-    for (y = 0; y < map.ysize; y++)
-      territory[x][y] = 0xFFFFFFFF;
+  int i;
+
+  whole_map_iterate(x, y) {
+    territory[x][y] = 0xFFFFFFFF;
+  } whole_map_iterate_end;
 
   for (i = 0; i < game.nplayers; i++) {
     assign_territory_player(shuffled_player(i));
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.48
diff -u -r1.48 srv_main.c
--- server/srv_main.c   2001/09/02 10:24:29     1.48
+++ server/srv_main.c   2001/09/07 07:36:18
@@ -276,16 +276,14 @@
                                       int *current, int *accum, int *level,
                                       void (*upset_action_fn)(int))
 {
-  int x, y, count;
+  int count;
 
   count = 0;
-  for (x = 0; x < map.xsize; x++) {
-    for (y = 0; y < map.ysize; y++) {
-      if (map_get_special(x,y) & cause) {
-       count++;
-      }
+  whole_map_iterate(x, y) {
+    if (map_get_special(x,y) & cause) {
+      count++;
     }
-  }
+  } whole_map_iterate_end;
 
   *current = count;
   *accum += count;

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