Index: map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.104 diff -u -r1.104 map.h --- map.h 2001/11/23 17:27:08 1.104 +++ map.h 2001/11/30 13:34:18 @@ -416,28 +422,35 @@ } \ } -/* Iterate through all tiles in a square with given center and radius. - Positions returned will have adjusted x, and positions with illegal y will be - automatically discarded. - */ -#define square_iterate(SI_center_x, SI_center_y, radius, SI_x_itr, SI_y_itr) \ -{ \ - int SI_x_itr, SI_y_itr; \ - int SI_x_itr1, SI_y_itr1; \ - CHECK_MAP_POS(SI_center_x, SI_center_y); \ - for (SI_y_itr1 = (SI_center_y) - (radius); \ - SI_y_itr1 <= (SI_center_y) + (radius); SI_y_itr1++) { \ - for (SI_x_itr1 = (SI_center_x) - (radius); \ - SI_x_itr1 <= (SI_center_x) + (radius); SI_x_itr1++) { \ - SI_x_itr = SI_x_itr1; \ - SI_y_itr = SI_y_itr1; \ - if (!normalize_map_pos(&SI_x_itr, &SI_y_itr)) continue; +#define square_dxy_iterate(_center_x, _center_y, _r, _x, _y, _dx, _dy) \ +do { \ + int _radius = (_r); \ + int _x0 = (_center_x); \ + int _y0 = (_center_y); \ + int (_dx), (_dy); \ + /* FIXME: Broken band-aid below. */ \ + /* CHECK_MAP_POS(_x0, _y0); */ \ + \ + for (_dy = -_radius; _dy <= _radius; _dy++) \ + for (_dx = -_radius; _dx <= _radius; _dx++) { \ + int (_x) = _x0 + _dx; \ + int (_y) = _y0 + _dy; \ + if (normalize_map_pos(&(_x), &(_y))) { -#define square_iterate_end \ +#define square_dxy_iterate_end \ + } \ } \ - } \ -} +} while (0) + +#define square_iterate(_center_x, _center_y, _radius, _x_itr, _y_itr) \ + square_dxy_iterate((_center_x), (_center_y), (_radius), \ + (_x_itr), (_y_itr), _dx, _dy) + +#define square_iterate_end \ + square_dxy_iterate_end + + /* Iterate through all tiles adjacent to a tile */ #define adjc_iterate(RI_center_x, RI_center_y, RI_x_itr, RI_y_itr) \ { \ @@ -453,7 +466,7 @@ if (!normalize_map_pos(&RI_x_itr, &RI_y_itr)) \ continue; \ if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y) \ - continue; + continue; #define adjc_iterate_end \ } \ @@ -465,21 +478,18 @@ center_y are normalized. --JDS */ #define adjc_dir_iterate(center_x, center_y, x_itr, y_itr, dir_itr) \ { \ - int x_itr, y_itr, dir_itr, MACRO_border; \ + int dir_itr, MACRO_safe; \ int MACRO_center_x = (center_x); \ int MACRO_center_y = (center_y); \ CHECK_MAP_POS(MACRO_center_x, MACRO_center_y); \ - MACRO_border = IS_BORDER_MAP_POS(MACRO_center_x, MACRO_center_y); \ + MACRO_safe = IS_SAFE_POS(MACRO_center_x, MACRO_center_y, 1); \ for (dir_itr = 0; dir_itr < 8; dir_itr++) { \ - DIRSTEP(x_itr, y_itr, dir_itr); \ - x_itr += MACRO_center_x; \ - y_itr += MACRO_center_y; \ - if (MACRO_border) { \ - if (!normalize_map_pos(&x_itr, &y_itr)) \ - continue; \ - } + int x_itr = MACRO_center_x + DIR_DX[dir_itr]; \ + int y_itr = MACRO_center_y + DIR_DY[dir_itr]; \ + if (MACRO_safe || normalize_map_pos(&x_itr, &y_itr)) { \ #define adjc_dir_iterate_end \ + } \ } \ } @@ -511,36 +521,37 @@