Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] [PATCH] city_map_iterate cleanup
Home

[Freeciv-Dev] [PATCH] city_map_iterate cleanup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] city_map_iterate cleanup
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Wed, 22 Aug 2001 03:21:30 -0400

This small patch changes about 20 lines, adding in another
city_map_iterate and some is_valid_city_coords calls and removing about
a dozen lines of code.  Unfortunately, it doesn't look like any of the
other city coordinate iterations can be replaced by city_map_iterate.

jason
Jason Short
jshort@xxxxxxxxxxxx

Some very small cleanups related to city_map_iterate.

Advantages: shorter, cleaner
Disadvantages:
Chance of bugs: very small

Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.89
diff -u -r1.89 citydlg.c
--- client/gui-gtk/citydlg.c    2001/08/04 21:06:12     1.89
+++ client/gui-gtk/citydlg.c    2001/08/22 07:14:07
@@ -1429,9 +1429,7 @@
   struct city *pcity=pdialog->pcity;
   for(y=0; y<CITY_MAP_SIZE; y++)
     for(x=0; x<CITY_MAP_SIZE; x++) {
-      if(!(x==0 && y==0) && !(x==0 && y==CITY_MAP_SIZE-1) &&
-        !(x==CITY_MAP_SIZE-1 && y==0) && 
-        !(x==CITY_MAP_SIZE-1 && y==CITY_MAP_SIZE-1) &&
+      if(is_valid_city_coords(x, y) &&
         tile_is_known(pcity->x+x-CITY_MAP_SIZE/2, 
                       pcity->y+y-CITY_MAP_SIZE/2)) {
        pixmap_put_tile(pdialog->map_canvas_store,
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.58
diff -u -r1.58 mapclass.c
--- client/gui-mui/mapclass.c   2001/08/20 07:55:59     1.58
+++ client/gui-mui/mapclass.c   2001/08/22 07:14:11
@@ -2433,11 +2433,8 @@
          LONG x2 = x1 + get_normal_tile_width() - 1;
          LONG y2 = y1 + get_normal_tile_height() - 1;
 
-         if (!(x == 0 && y == 0) && !(x == 0 && y == CITY_MAP_SIZE - 1) &&
-             !(x == CITY_MAP_SIZE - 1 && y == 0) &&
-             !(x == CITY_MAP_SIZE - 1 && y == CITY_MAP_SIZE - 1) &&
-              (tiley >= 0 && tiley < map.ysize))
-         {
+         if (is_valid_city_coords(x, y) &&
+             is_real_tile(tilex, tiley)) {
            if (tile_is_known(tilex,tiley))
            {
              put_tile(_rp(o), tilex, tiley, x1, y1, 1);
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.53
diff -u -r1.53 citydlg.c
--- client/gui-xaw/citydlg.c    2001/06/29 18:28:59     1.53
+++ client/gui-xaw/citydlg.c    2001/08/22 07:14:12
@@ -1563,10 +1563,8 @@
   
   for(y=0; y<CITY_MAP_SIZE; y++)
     for(x=0; x<CITY_MAP_SIZE; x++) {
-      if(!(x==0 && y==0) && !(x==0 && y==CITY_MAP_SIZE-1) &&
-        !(x==CITY_MAP_SIZE-1 && y==0) && 
-        !(x==CITY_MAP_SIZE-1 && y==CITY_MAP_SIZE-1) &&
-        tile_is_known(pcity->x+x-CITY_MAP_SIZE/2, 
+      if(is_valid_city_coords(x, y) &&
+        tile_is_known(pcity->x+x-CITY_MAP_SIZE/2,
                       pcity->y+y-CITY_MAP_SIZE/2)) {
        pixmap_put_tile(XtWindow(pdialog->map_canvas),
                        pcity->x+x-CITY_MAP_SIZE/2,
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.81
diff -u -r1.81 city.h
--- common/city.h       2001/05/23 19:09:55     1.81
+++ common/city.h       2001/08/22 07:14:13
@@ -106,23 +106,16 @@
 
 /* Iterate a city radius in map coordinates; skip non-existant squares */
 
-#define map_city_radius_iterate(city_x, city_y, x_itr, y_itr) \
-{ \
-  int x_itr, y_itr; \
-  int MCMI_x, MCMI_y; \
-  for (MCMI_x=0; MCMI_x<CITY_MAP_SIZE; MCMI_x++) { \
-    for (MCMI_y=0; MCMI_y<CITY_MAP_SIZE; MCMI_y++) { \
-      if (! ((MCMI_x == 0 || MCMI_x == (CITY_MAP_SIZE-1)) \
-            && (MCMI_y == 0 || MCMI_y == (CITY_MAP_SIZE-1))) ) { \
-        y_itr = city_y + MCMI_y - CITY_MAP_SIZE/2; \
-        if (y_itr < 0 || y_itr >= map.ysize) \
-         continue; \
-       x_itr = map_adjust_x(city_x + MCMI_x - CITY_MAP_SIZE/2);
+#define map_city_radius_iterate(city_x, city_y, x_itr, y_itr)                 \
+{                                                                             \
+  int _city_x = (city_x), _city_y = (city_y);                                 \
+  city_map_iterate(_city_x_itr, _city_y_itr) {                                \
+    int x_itr = _city_x + _city_x_itr - CITY_MAP_SIZE/2;                      \
+    int y_itr = _city_y + _city_y_itr - CITY_MAP_SIZE/2;                      \
+    if (!normalize_map_pos(&x_itr, &y_itr)) continue;
 
-#define map_city_radius_iterate_end \
-      } \
-    } \
-  } \
+#define map_city_radius_iterate_end                                           \
+  } city_map_iterate_end;                                                     \
 }
 
 

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