? rc ? msgfmt1.diff ? air_goto-5.diff ? air_goto-6.diff ? circle_iterate-2.diff ? circle_iterate-3.diff ? unit_move_turns1.diff ? diff ? map_distance_vector2.diff ? short_worklists1.diff ? sound4.patch ? natural_citynames-code2.diff Index: common/map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.105 diff -u -r1.105 map.h --- common/map.h 2001/12/02 13:30:37 1.105 +++ common/map.h 2001/12/05 11:46:14 @@ -13,7 +13,9 @@ #ifndef FC__MAP_H #define FC__MAP_H -#include "assert.h" +#include +#include + #include "player.h" #include "terrain.h" #include "unit.h" @@ -415,27 +417,59 @@ } \ } -/* 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. +/* + * Iterate through all tiles in a square with given center and radius. + * The position (x_itr, y_itr) that is returned will be normalized; + * unreal positions will be automatically discarded. (dx_itr, dy_itr) + * is the standard distance vector between the position and the center + * position. Note that when the square is larger than the map the + * distance vector may not be the minimum distance vector. */ -#define square_iterate(SI_center_x, SI_center_y, radius, SI_x_itr, SI_y_itr) \ +#define square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr, \ + dx_itr, dy_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; + int dx_itr, dy_itr; \ + CHECK_MAP_POS((center_x), (center_y)); \ + for (dy_itr = -(radius); dy_itr <= (radius); dy_itr++) { \ + for (dx_itr = -(radius); dx_itr <= (radius); dx_itr++) { \ + int x_itr = dx_itr + (center_x), y_itr = dy_itr + (center_y); \ + if (normalize_map_pos(&x_itr, &y_itr)) { -#define square_iterate_end \ +#define square_dxy_iterate_end \ + } \ } \ } \ } + +/* + * 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(center_x, center_y, radius, x_itr, y_itr) \ +{ \ + square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr, \ + _dummy_x, _dummy_y); + +#define square_iterate_end square_dxy_iterate_end \ +} + +/* + * Iterate through all tiles in a circle with given center and squared + * radius. Positions returned will have adjusted (x, y); unreal + * positions will be automatically discarded. + */ +#define circle_iterate(center_x, center_y, sq_radius, x_itr, y_itr) \ +{ \ + int _cr_radius = (int)sqrt(sq_radius); \ + square_dxy_iterate(center_x, center_y, _cr_radius, \ + x_itr, y_itr, _dx, _dy) { \ + if (_dy * _dy + _dx * _dx <= (sq_radius)) { + +#define circle_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) \ Index: server/gamehand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v retrieving revision 1.98 diff -u -r1.98 gamehand.c --- server/gamehand.c 2001/10/18 16:45:34 1.98 +++ server/gamehand.c 2001/12/05 11:46:15 @@ -35,7 +35,7 @@ void init_new_game(void) { int i, j, x, y; - int vx, vy, dx, dy; + int dx, dy; Unit_Type_id utype; int start_pos[MAX_NUM_PLAYERS]; /* indices into map.start_positions[] */ @@ -130,16 +130,9 @@ game.players[i].name); } /* Expose visible area. */ - for (vx = 1; (vx * vx) <= game.rgame.init_vis_radius_sq; vx++) { - for (vy = 1; (vy * vy) <= game.rgame.init_vis_radius_sq; vy++) { - if (((vx *vx) + (vy *vy)) <= game.rgame.init_vis_radius_sq) { - show_area(&game.players[i], dx-vx+1, dy-vy+1, 1); - show_area(&game.players[i], dx+vx-1, dy-vy+1, 1); - show_area(&game.players[i], dx-vx+1, dy+vy-1, 1); - show_area(&game.players[i], dx+vx-1, dy+vy-1, 1); - } - } - } + circle_iterate(dx, dy, game.rgame.init_vis_radius_sq, cx, cy) { + show_area(&game.players[i], cx, cy, 0); + } circle_iterate_end; /* Create the unit of an appropriate type. */ utype = get_role_unit((j < game.settlers) ? F_CITIES : L_EXPLORER, 0); create_unit(&game.players[i], dx, dy, utype, 0, 0, -1);