diff -u -r freeciv/common/map.c fc4/common/map.c --- freeciv/common/map.c 2003-09-14 13:08:43.000000000 +0200 +++ fc4/common/map.c 2003-09-15 22:54:36.000000000 +0200 @@ -66,7 +66,7 @@ N_("Fallout") }; -#define MAP_TILE(x,y) (map.tiles + map_pos_to_index(x, y)) +#define MAP_TILE(x,y) tile_from_index(map_pos_to_index(x, y)) /*************************************************************** ... @@ -1225,18 +1220,11 @@ return contains_special(MAP_TILE(x, y)->special, special); } -/*************************************************************** - Returns TRUE iff the given tile has the given special. -***************************************************************/ -bool tile_has_special(struct tile *ptile, enum tile_special_type special) -{ - return contains_special(ptile->special, special); -} - +#ifdef DEBUG /*************************************************************** Returns TRUE iff the given special is found in the given set. ***************************************************************/ -bool contains_special(enum tile_special_type set, +bool debug_contains_special(enum tile_special_type set, enum tile_special_type to_test_for) { enum tile_special_type masked = set & to_test_for; @@ -1251,6 +1239,7 @@ return masked == to_test_for; } +#endif /*************************************************************** ... diff -u -r freeciv/common/map.h fc4/common/map.h --- freeciv/common/map.h 2003-09-14 13:08:43.000000000 +0200 +++ fc4/common/map.h 2003-09-15 23:41:45.000000000 +0200 @@ -245,6 +245,9 @@ (CHECK_MAP_POS((map_x), (map_y)), \ (map_x) + (map_y) * map.xsize) +#define index_from_tile(ptile) ((ptile) - (map.tiles)) +#define tile_from_index(index) ((map.tiles) + (index)) + /* index_to_map_pos(int *, int *, int) inverts map_pos_to_index */ #define index_to_map_pos(pmap_x, pmap_y, index) \ (CHECK_INDEX(index), \ @@ -286,10 +289,38 @@ /* special testing */ bool map_has_special(int x, int y, enum tile_special_type to_test_for); -bool tile_has_special(struct tile *ptile, - enum tile_special_type to_test_for); -bool contains_special(enum tile_special_type all, - enum tile_special_type to_test_for); +#ifdef DEBUG +bool debug_contains_special(enum tile_special_type all, + enum tile_special_type to_test_for); + +#define contains_special(all, to_test_for) \ + debug_contains_special(all, to_test_for) +#else +#define contains_special(all, to_test_for) ((all & to_test_for) == to_test_for) +#endif + +#define tile_has_special(ptile, to_test_for) \ + contains_special(ptile->special, to_test_for) + +#define tile_get_special(ptile) ptile->special +#define tile_set_special(ptile, all_specials) ptile->special = all_specials + +#define tile_add_special(ptile, special_to_add) \ + ptile->special |= special_to_add +#define tile_clear_special(ptile, special_to_clear) \ + ptile->special &= ~special_to_clear + +#define tile_get_terrain(ptile) ptile->terrain +#define tile_set_terrain(ptile, ter) ptile->terrain = ter + +#define tile_get_city(ptile) ptile->city +#define tile_set_city(ptile, pcity) ptile->city = pcity + +#define tile_get_continent(ptile) ptile->continent +#define tile_set_continent(ptile, cont) ptile->continent = cont + +#define tile_get_owner(ptile) ptile->owner +#define tile_set_owner(ptile, pl) ptile->owner = pl /* * Determines whether the position is normal given that it's in the @@ -435,6 +466,76 @@ } \ } +/* + * The same as above only additionaly make tile iteration which is faster. + * that calculation tile inside loop manualy. + */ +#define iterate_tile_outward(ARG_start_tile, ARG_start_x, ARG_start_y, \ + ARG_max_dist, ARG_x_itr, ARG_y_itr, ARG_tile_itr) \ +{ \ + int ARG_x_itr, ARG_y_itr; \ + struct tile *ARG_tile_itr, *ARG_cache_start_tile = (ARG_start_tile); \ + int MACRO_max_dx = map.xsize/2; \ + int MACRO_min_dx = -MACRO_max_dx - 1 + (map.xsize % 2); \ + bool MACRO_xcycle = TRUE; \ + bool MACRO_positive = FALSE; \ + bool MACRO_is_border = IS_BORDER_MAP_POS(ARG_start_x, ARG_start_y, \ + ARG_max_dist); \ + int MACRO_dxy = 0, MACRO_do_xy, MACRO_pitch = 0, nMACRO_pitch = 0; \ + CHECK_MAP_POS(ARG_start_x, ARG_start_y); \ + while(MACRO_dxy <= (ARG_max_dist)) { \ + for (MACRO_do_xy = -MACRO_dxy; MACRO_do_xy <= MACRO_dxy; MACRO_do_xy++) { \ + if (MACRO_xcycle) { \ + ARG_x_itr = (ARG_start_x) + MACRO_do_xy; \ + ARG_tile_itr = (ARG_cache_start_tile) + MACRO_do_xy; \ + if (MACRO_positive) { \ + ARG_y_itr = (ARG_start_y) + MACRO_dxy; \ + ARG_tile_itr -= MACRO_pitch; \ + } else { \ + ARG_y_itr = (ARG_start_y) - MACRO_dxy; \ + ARG_tile_itr += MACRO_pitch; \ + } \ + } else { /* ! MACRO_xcycle */ \ + if (MACRO_dxy == MACRO_do_xy || MACRO_dxy == -MACRO_do_xy) \ + continue; \ + ARG_y_itr = (ARG_start_y) + MACRO_do_xy; \ + nMACRO_pitch += map.xsize; \ + ARG_tile_itr = (ARG_cache_start_tile) + nMACRO_pitch; \ + if (MACRO_positive) { \ + ARG_x_itr = (ARG_start_x) + MACRO_dxy; \ + ARG_tile_itr += MACRO_dxy; \ + } else { \ + ARG_x_itr = (ARG_start_x) - MACRO_dxy; \ + ARG_tile_itr -= MACRO_dxy; \ + } \ + } \ + { \ + int MACRO_dx = (ARG_start_x) - ARG_x_itr; \ + if (MACRO_dx > MACRO_max_dx || MACRO_dx < MACRO_min_dx) \ + continue; \ + } \ + if (MACRO_is_border) { \ + if (normalize_map_pos(&ARG_x_itr, &ARG_y_itr)) { \ + ARG_tile_itr = tile_from_index(map_pos_to_index(ARG_x_itr, ARG_y_itr)); \ + } else { \ + continue; \ + } \ + } + +#define iterate_tile_outward_end \ + } \ + if (!MACRO_positive) { \ + if (!MACRO_xcycle) { \ + MACRO_dxy++; \ + MACRO_pitch = MACRO_dxy * -map.xsize; \ + } \ + MACRO_xcycle = !MACRO_xcycle; \ + } \ + MACRO_positive = !MACRO_positive; \ + nMACRO_pitch = MACRO_pitch; \ + } \ +} + #define rectangle_iterate(map_x0, map_y0, map_width, map_height, \ x_itr, y_itr) \ { \ @@ -476,6 +577,36 @@ } \ } +/* + * The same as above only additionaly make tile iteration which is faster. + * that calculation tile inside loop manualy. + */ +#define square_dxy_tile_iterate(center_tile, center_x, center_y, radius, \ + x_itr, y_itr, tile_itr, dx_itr, dy_itr) \ +{ \ + int dx_itr, dy_itr; \ + bool _is_border = IS_BORDER_MAP_POS((center_x), (center_y), (radius)); \ + struct tile *tile_itr, *_pstart = (center_tile) - (radius) * (1 + map.xsize); \ + CHECK_MAP_POS((center_x), (center_y)); \ + for (dy_itr = -(radius); dy_itr <= (radius); dy_itr++) { \ + tile_itr = _pstart - 1; \ + _pstart += map.xsize; \ + for (dx_itr = -(radius); dx_itr <= (radius); dx_itr++) { \ + int x_itr = dx_itr + (center_x), y_itr = dy_itr + (center_y); \ + tile_itr++; \ + if (_is_border) { \ + if(normalize_map_pos(&x_itr, &y_itr)) { \ + tile_itr = tile_from_index(map_pos_to_index(x_itr, y_itr)); \ + } else { \ + continue; \ + } \ + } + +#define square_dxy_tile_iterate_end \ + } \ + } \ +} + /* * Iterate through all tiles in a square with given center and radius. * Positions returned will have adjusted x, and positions with illegal @@ -490,6 +621,19 @@ } /* + * The same as above only additionaly make tile iteration which is faster. + * that calculation tile inside loop manualy. + */ +#define square_tile_iterate(center_tile, center_x, center_y, \ + radius, x_itr, y_itr, tile_itr) \ +{ \ + square_dxy_tile_iterate(center_tile, center_x, center_y, \ + radius, x_itr, y_itr, tile_itr, _dummy_x, _dummy_y); + +#define square_tile_iterate_end square_dxy_tile_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. @@ -518,6 +662,23 @@ } square_iterate_end; \ } +/* + * The same as above only additionaly make tile iteration which is faster. + * that calculation tile inside loop manualy. + */ +#define adjc_tile_iterate(RI_center_tile, RI_center_x, RI_center_y, \ + RI_x_itr, RI_y_itr, RI_tile_itr) \ +{ \ + square_tile_iterate(RI_center_tile, RI_center_x, RI_center_y, 1, \ + RI_x_itr, RI_y_itr, RI_tile_itr) { \ + if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y) { \ + continue; \ + } + +#define adjc_tile_iterate_end \ + } square_tile_iterate_end; \ +} + /* Iterate through all tiles adjacent to a tile. dir_itr is the directional value (see DIR_D[XY]). This assumes that center_x and center_y are normalized. --JDS */ @@ -540,18 +701,63 @@ } \ } +/* Iterate through all tiles adjacent to a tile. + * The same as above only additionaly make tile iteration which is faster. + * that calculation tile inside loop manualy. */ +#define adjc_dir_tile_iterate(pcenter_tile, center_x, center_y, \ + x_itr, y_itr, ptile_itr, dir_itr) \ +{ \ + int x_itr, y_itr, dir_itr; \ + struct tile *ptile_itr, *_pstart = (pcenter_tile); \ + bool MACRO_border = IS_BORDER_MAP_POS((center_x), (center_y), 1); \ + int MACRO_center_x = (center_x); \ + int MACRO_center_y = (center_y); \ + CHECK_MAP_POS(MACRO_center_x, MACRO_center_y); \ + for (dir_itr = 0; dir_itr < 8; dir_itr++) { \ + DIRSTEP(x_itr, y_itr, dir_itr); \ + ptile_itr = _pstart + x_itr; \ + if (y_itr) { \ + if (y_itr > 0) { \ + ptile_itr += map.xsize; \ + } else { \ + ptile_itr -= map.xsize; \ + } \ + } \ + x_itr += MACRO_center_x; \ + y_itr += MACRO_center_y; \ + if (MACRO_border) { \ + if(normalize_map_pos(&x_itr, &y_itr)) { \ + ptile_itr = tile_from_index(map_pos_to_index(x_itr, y_itr)); \ + } else { \ + continue; \ + } \ + } + +#define adjc_dir_tile_iterate_end \ + } \ +} + +/* Index iterate over all positions on the globe. */ +#define indexed_whole_map_iterate(WMI_index) \ +{ \ + int WMI_index; /* We use index positions for cache efficiency. */ \ + for (WMI_index = 0; WMI_index < MAX_MAP_INDEX; WMI_index++) { \ + +#define indexed_whole_map_iterate_end \ + } \ +} + /* Iterate over all positions on the globe. */ #define whole_map_iterate(map_x, map_y) \ { \ - int WMI_index; /* We use index positions for cache efficiency. */ \ - for (WMI_index = 0; WMI_index < MAX_MAP_INDEX; WMI_index++) { \ - int map_x, map_y; \ + int map_x, map_y; \ + indexed_whole_map_iterate(WMI_index) { \ index_to_map_pos(&map_x, &map_y, WMI_index); \ { #define whole_map_iterate_end \ } \ - } \ + } indexed_whole_map_iterate_end; \ } /* diff -u -r freeciv/server/maphand.h fc4/server/maphand.h --- freeciv/server/maphand.h 2003-08-05 09:49:36.000000000 +0200 +++ fc4/server/maphand.h 2003-09-14 17:06:54.000000000 +0200 @@ -68,8 +68,20 @@ void map_fog_pseudo_city_area(struct player *pplayer, int x,int y); bool map_is_known_and_seen(int x, int y, struct player *pplayer); + +#define tile_get_player_tile(pmap_tile, pplayer) \ + ((pplayer->private_map) + index_from_tile(pmap_tile)) + +#define tile_is_known_and_seen(pmap_tile, pplayer) \ + (TEST_BIT(pmap_tile->known, pplayer->player_no) \ + && (tile_get_player_tile(pmap_tile, pplayer)->seen != 0)) + void map_change_seen(int x, int y, struct player *pplayer, int change); bool map_is_known(int x, int y, struct player *pplayer); + +#define tile_is_known(pmap_tile, pplayer) \ + TEST_BIT(pmap_tile->known, pplayer->player_no) + void map_set_known(int x, int y, struct player *pplayer); void map_clear_known(int x, int y, struct player *pplayer); void map_know_all(struct player *pplayer);