42#define MAP_IS_ISOMETRIC (CURRENT_TOPOLOGY & (TF_ISO + TF_HEX))
44#define CURRENT_TOPOLOGY (wld.map.topology_id)
45#define CURRENT_WRAP (wld.map.wrap_id)
47#define topo_has_flag(topo, flag) (((topo) & (flag)) != 0)
48#define current_topo_has_flag(flag) topo_has_flag((CURRENT_TOPOLOGY), (flag))
50#define wrap_has_flag(wrap, flag) (((wrap) & (flag)) != 0)
51#define current_wrap_has_flag(flag) wrap_has_flag((CURRENT_WRAP), (flag))
53#define ALL_DIRECTIONS_CARDINAL() topo_has_flag((CURRENT_TOPOLOGY), TF_HEX)
71 const struct tile *src_tile,
75 const struct tile *src_tile,
110#define startpos_nations_iterate(ARG_psp, NAME_pnation) \
111 generic_iterate(struct startpos_iter, const struct nation_type *, \
112 NAME_pnation, startpos_iter_sizeof, \
113 startpos_iter_init, (ARG_psp))
114#define startpos_nations_iterate_end generic_iterate_end
130#define map_startpos_iterate(NAME_psp) \
131 generic_iterate(struct map_startpos_iter, struct startpos *, \
132 NAME_psp, map_startpos_iter_sizeof, map_startpos_iter_init)
133#define map_startpos_iterate_end generic_iterate_end
137#define MAP_INDEX_SIZE (wld.map.xsize * wld.map.ysize)
140#define CHECK_MAP_POS(x,y) \
141 fc_assert(is_normal_map_pos((x),(y)))
142#define CHECK_NATIVE_POS(x, y) \
143 fc_assert((x) >= 0 && (x) < wld.map.xsize && (y) >= 0 && (y) < wld.map.ysize)
144#define CHECK_INDEX(mindex) \
145 fc_assert((mindex) >= 0 && (mindex) < MAP_INDEX_SIZE)
147#define CHECK_MAP_POS(x,y) ((void)0)
148#define CHECK_NATIVE_POS(x, y) ((void)0)
149#define CHECK_INDEX(mindex) ((void)0)
152#define native_pos_to_index_nocheck(nat_x, nat_y) \
153 ((nat_x) + (nat_y) * wld.map.xsize)
154#define native_pos_to_index(nat_x, nat_y) \
155 (CHECK_NATIVE_POS((nat_x), (nat_y)), \
156 native_pos_to_index_nocheck(nat_x, nat_y))
157#define index_to_native_pos(pnat_x, pnat_y, mindex) \
158 (*(pnat_x) = index_to_native_pos_x(mindex), \
159 *(pnat_y) = index_to_native_pos_y(mindex))
160#define index_to_native_pos_x(mindex) \
161 ((mindex) % wld.map.xsize)
162#define index_to_native_pos_y(mindex) \
163 ((mindex) / wld.map.xsize)
166#define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
168 ? (*(pmap_x) = ((nat_y) + ((nat_y) & 1)) / 2 + (nat_x), \
169 *(pmap_y) = (nat_y) - *(pmap_x) + wld.map.xsize) \
170 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
172#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y) \
174 ? (*(pnat_y) = (map_x) + (map_y) - wld.map.xsize, \
175 *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2) \
176 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
178#define NATURAL_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
180 ? (*(pmap_x) = ((nat_y) + (nat_x)) / 2, \
181 *(pmap_y) = (nat_y) - *(pmap_x) + wld.map.xsize) \
182 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
184#define MAP_TO_NATURAL_POS(pnat_x, pnat_y, map_x, map_y) \
186 ? (*(pnat_y) = (map_x) + (map_y) - wld.map.xsize, \
187 *(pnat_x) = 2 * (map_x) - *(pnat_y)) \
188 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
195#define do_in_native_pos(nat_x, nat_y, map_x, map_y) \
197 int _nat_x, _nat_y; \
198 MAP_TO_NATIVE_POS(&_nat_x, &_nat_y, map_x, map_y); \
200 const int nat_x = _nat_x, nat_y = _nat_y;
202#define do_in_native_pos_end \
210#define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) \
212 int _ntl_x, _ntl_y; \
213 MAP_TO_NATURAL_POS(&_ntl_x, &_ntl_y, map_x, map_y); \
215 const int ntl_x = _ntl_x, ntl_y = _ntl_y;
217#define do_in_natural_pos_end \
222#define NATIVE_WIDTH wld.map.xsize
223#define NATIVE_HEIGHT wld.map.ysize
226#define NATURAL_WIDTH (MAP_IS_ISOMETRIC ? 2 * wld.map.xsize : wld.map.xsize)
227#define NATURAL_HEIGHT wld.map.ysize
233#define index_to_map_pos(pmap_x, pmap_y, mindex) \
234 (CHECK_INDEX(mindex), \
235 index_to_native_pos(pmap_x, pmap_y, mindex), \
236 NATIVE_TO_MAP_POS(pmap_x, pmap_y, *(pmap_x), *(pmap_y)))
240#define DIRSTEP(dest_x, dest_y, dir) \
241( (dest_x) = DIR_DX[(dir)], \
242 (dest_y) = DIR_DY[(dir)])
271#define map_size_checked() MAX(map_num_tiles() / 1000, 1)
275 bool (*filter)(
const struct tile *ptile,
280 const struct tile *src_tile,
286 const struct player *pplayer,
287 const struct tile *t1,
const struct tile *t2);
295 const struct tile *ptile)
306 const struct player *pplayer,
308 const struct tile *src_tile,
320 const struct tile *ptile);
322 const struct tile *ptile);
324 const struct tile *ptile);
326 const struct tile *ptile);
328 const struct tile *ptile,
329 const struct terrain *pterrain);
339#define iterate_outward_dxy(nmap, start_tile, max_dist, _tile, _x, _y) \
341 int _x, _y, _tile##_x, _tile##_y, _start##_x, _start##_y; \
342 struct tile *_tile; \
343 const struct tile *_tile##_start = (start_tile); \
344 int _tile##_max = (max_dist); \
345 int _tile##_index = 0; \
346 index_to_map_pos(&_start##_x, &_start##_y, tile_index(_tile##_start)); \
348 _tile##_index < wld.map.num_iterate_outwards_indices; \
350 if (wld.map.iterate_outwards_indices[_tile##_index].dist > _tile##_max) { \
353 _x = wld.map.iterate_outwards_indices[_tile##_index].dx; \
354 _y = wld.map.iterate_outwards_indices[_tile##_index].dy; \
355 _tile##_x = _x + _start##_x; \
356 _tile##_y = _y + _start##_y; \
357 _tile = map_pos_to_tile(nmap, _tile##_x, _tile##_y); \
358 if (NULL == _tile) { \
362#define iterate_outward_dxy_end \
367#define iterate_outward(nmap, start_tile, max_dist, itr_tile) \
368 iterate_outward_dxy(nmap, start_tile, max_dist, itr_tile, \
369 _dx_itr##itr_tile, _dy_itr##itr_tile)
371#define iterate_outward_end iterate_outward_dxy_end
381#define square_dxy_iterate(nmap, center_tile, radius, tile_itr, dx_itr, dy_itr) \
382 iterate_outward_dxy(nmap, center_tile, radius, tile_itr, dx_itr, dy_itr)
384#define square_dxy_iterate_end iterate_outward_dxy_end
391#define square_iterate(nmap, center_tile, radius, tile_itr) \
392 square_dxy_iterate(nmap, center_tile, radius, tile_itr, _dummy_x, dummy_y)
394#define square_iterate_end square_dxy_iterate_end
401#define circle_iterate(nmap, center_tile, sq_radius, tile_itr) \
402 circle_dxyr_iterate(nmap, center_tile, sq_radius, tile_itr, _dx, _dy, _dr)
404#define circle_iterate_end \
405 circle_dxyr_iterate_end
409#define circle_dxyr_iterate(nmap, center_tile, sq_radius, \
412 const int _tile##_sq_radius = (sq_radius); \
413 const int _tile##_cr_radius = (int)sqrt((double)MAX(_tile##_sq_radius, 0)); \
415 square_dxy_iterate(nmap, center_tile, _tile##_cr_radius, _tile, dx, dy) { \
416 const int dr = map_vector_to_sq_distance(dx, dy); \
418 if (dr <= _tile##_sq_radius) {
420#define circle_dxyr_iterate_end \
422 } square_dxy_iterate_end; \
428#define adjc_iterate(nmap, center_tile, itr_tile) \
432 adjc_dir_iterate(nmap, center_tile, itr_tile, ADJC_ITERATE_dir_itr##itr_tile) {
434#define adjc_iterate_end \
435 } adjc_dir_iterate_end; \
439#define adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr) \
440 adjc_dirlist_iterate(nmap, center_tile, itr_tile, dir_itr, \
441 (nmap)->valid_dirs, (nmap)->num_valid_dirs)
443#define adjc_dir_iterate_end adjc_dirlist_iterate_end
446#define adjc_dir_base_iterate(nmap, center_tile, dir_itr) \
447 adjc_dirlist_base_iterate(nmap, center_tile, dir_itr, \
448 (nmap)->valid_dirs, (nmap)->num_valid_dirs)
450#define adjc_dir_base_iterate_end \
451 adjc_dirlist_base_iterate_end
456#define cardinal_adjc_iterate(nmap, center_tile, itr_tile) \
457 adjc_dirlist_iterate(nmap, center_tile, itr_tile, _dir_itr##itr_tile, \
458 (nmap)->cardinal_dirs, (nmap)->num_cardinal_dirs)
460#define cardinal_adjc_iterate_end adjc_dirlist_iterate_end
463#define cardinal_adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr) \
464 adjc_dirlist_iterate(nmap, center_tile, itr_tile, dir_itr, \
465 (nmap)->cardinal_dirs, (nmap)->num_cardinal_dirs)
467#define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
470#define cardinal_adjc_dir_base_iterate(nmap, center_tile, dir_itr) \
471 adjc_dirlist_base_iterate(nmap, center_tile, dir_itr, \
472 (nmap)->cardinal_dirs, (nmap)->num_cardinal_dirs)
474#define cardinal_adjc_dir_base_iterate_end \
475 adjc_dirlist_base_iterate_end
478#define cardinal_between_iterate(nmap, tile1, tile2, between) \
479 cardinal_adjc_iterate(nmap, tile1, between) { \
480 cardinal_adjc_iterate(nmap, between, second) { \
481 if (same_pos(second, tile2)) {
483#define cardinal_between_iterate_end \
485 } cardinal_adjc_iterate_end; \
486 } cardinal_adjc_iterate_end;
495#define adjc_dirlist_iterate(nmap, center_tile, _tile, _dir, \
498 enum direction8 _dir; \
499 int _tile##_x, _tile##_y, _tile##_cx, _tile##_cy; \
500 struct tile *_tile; \
501 const struct tile *_tile##_center = (center_tile); \
502 int _tile##_index = 0; \
503 index_to_map_pos(&_tile##_cx, &_tile##_cy, tile_index(_tile##_center)); \
505 _tile##_index < (dircount); \
507 _dir = (dirlist)[_tile##_index]; \
508 DIRSTEP(_tile##_x, _tile##_y, _dir); \
509 _tile##_x += _tile##_cx; \
510 _tile##_y += _tile##_cy; \
511 _tile = map_pos_to_tile(nmap, _tile##_x, _tile##_y); \
512 if (NULL == _tile) { \
516#define adjc_dirlist_iterate_end \
521#define adjc_dirlist_base_iterate(nmap, center_tile, _dir, dirlist, dircount) \
523 enum direction8 _dir; \
524 int _tile##_x, _tile##_y, _center##_x, _center##_y; \
525 const struct tile *_tile##_center = (center_tile); \
526 bool _tile##_is_border = is_border_tile(_tile##_center, 1); \
527 int _tile##_index = 0; \
528 index_to_map_pos(&_center##_x, &_center##_y, tile_index(_tile##_center)); \
530 _tile##_index < (dircount); \
532 _dir = (dirlist)[_tile##_index]; \
533 DIRSTEP(_tile##_x, _tile##_y, _dir); \
534 _tile##_x += _center##_x; \
535 _tile##_y += _center##_y; \
536 if (_tile##_is_border && !normalize_map_pos(nmap, &_tile##_x, &_tile##_y)) { \
540#define adjc_dirlist_base_iterate_end \
546#define whole_map_iterate(_map, _tile) \
548 struct tile *_tile; \
549 int _tile##_index = 0; \
551 _tile##_index < MAP_INDEX_SIZE; \
553 _tile = (_map)->tiles + _tile##_index;
555#define whole_map_iterate_end \
562#define DIR_REVERSE(dir) (7 - (dir))
571extern const int DIR_DX[8];
572extern const int DIR_DY[8];
575#define MAP_MAX_LATITUDE 1000
577#define MAP_MAX_LATITUDE_BOUND (MAP_MAX_LATITUDE)
578#define MAP_MIN_LATITUDE_BOUND (-MAP_MAX_LATITUDE)
579#define MAP_DEFAULT_NORTH_LATITUDE MAP_MAX_LATITUDE_BOUND
580#define MAP_DEFAULT_SOUTH_LATITUDE MAP_MIN_LATITUDE_BOUND
583#define MAP_NORTH_LATITUDE(_nmap) ((_nmap).north_latitude)
584#define MAP_SOUTH_LATITUDE(_nmap) ((_nmap).south_latitude)
587#define MAP_MAX_REAL_LATITUDE(_nmap) \
588 MAX(MAP_NORTH_LATITUDE(_nmap), MAP_SOUTH_LATITUDE(_nmap))
589#define MAP_MIN_REAL_LATITUDE(_nmap) \
590 MIN(MAP_NORTH_LATITUDE(_nmap), MAP_SOUTH_LATITUDE(_nmap))
591#define MAP_REAL_LATITUDE_RANGE(_nmap) \
592 (MAP_MAX_REAL_LATITUDE(_nmap) - MAP_MIN_REAL_LATITUDE(_nmap))
595#define MAP_MAX_ABS_LATITUDE(_nmap) \
596 MAX(MAP_MAX_REAL_LATITUDE(_nmap), -MAP_MIN_REAL_LATITUDE(_nmap))
597#define MAP_MIN_ABS_LATITUDE(_nmap) \
598 MAX(0, MAX(MAP_MIN_REAL_LATITUDE(_nmap), -MAP_MAX_REAL_LATITUDE(_nmap)))
603#define MAP_TILE_OWNER_NULL MAX_UINT8
605#define MAP_DEFAULT_HUTS 15
606#define MAP_MIN_HUTS 0
607#define MAP_MAX_HUTS 500
609#define MAP_DEFAULT_ANIMALS 20
610#define MAP_MIN_ANIMALS 0
611#define MAP_MAX_ANIMALS 500
613#define MAP_DEFAULT_MAPSIZE MAPSIZE_FULLSIZE
619#define MAP_DEFAULT_SIZE 3
620#define MAP_MIN_SIZE 0
621#define MAP_MAX_SIZE 38
623#define MAP_DEFAULT_SIZE 4
624#define MAP_MIN_SIZE 0
625#define MAP_MAX_SIZE 2048
632 < (
long unsigned) 1 << 31,
635#define MAP_DEFAULT_TILESPERPLAYER 100
636#define MAP_MIN_TILESPERPLAYER 1
637#define MAP_MAX_TILESPERPLAYER 1000
640#define MAP_DEFAULT_LINEAR_SIZE 64
641#define MAP_MAX_LINEAR_SIZE (MAP_MAX_SIZE * 1000 / MAP_MIN_LINEAR_SIZE)
642#define MAP_MIN_LINEAR_SIZE 16
647#define MAP_DISTANCE_MAX (MAP_MAX_LINEAR_SIZE + MAP_MIN_LINEAR_SIZE)
649#define MAP_ORIGINAL_TOPO TF_WRAPX
652#define MAP_DEFAULT_TOPO 0
653#define MAP_DEFAULT_WRAP WRAP_X
655#define MAP_DEFAULT_TOPO (TF_ISO|TF_HEX)
656#define MAP_DEFAULT_WRAP (WRAP_X)
659#define MAP_DEFAULT_SEED 0
660#define MAP_MIN_SEED 0
661#define MAP_MAX_SEED (MAX_UINT32 >> 1)
663#define MAP_DEFAULT_LANDMASS 30
664#define MAP_MIN_LANDMASS 15
665#define MAP_MAX_LANDMASS 85
667#define MAP_DEFAULT_RICHES 250
668#define MAP_MIN_RICHES 0
669#define MAP_MAX_RICHES 1000
671#define MAP_DEFAULT_STEEPNESS 30
672#define MAP_MIN_STEEPNESS 0
673#define MAP_MAX_STEEPNESS 100
675#define MAP_DEFAULT_WETNESS 50
676#define MAP_MIN_WETNESS 0
677#define MAP_MAX_WETNESS 100
679#define MAP_DEFAULT_GENERATOR MAPGEN_RANDOM
681#define MAP_DEFAULT_STARTPOS MAPSTARTPOS_DEFAULT
683#define MAP_DEFAULT_TINYISLES FALSE
684#define MAP_MIN_TINYISLES FALSE
685#define MAP_MAX_TINYISLES TRUE
687#define MAP_DEFAULT_SEPARATE_POLES TRUE
688#define MAP_MIN_SEPARATE_POLES FALSE
689#define MAP_MAX_SEPARATE_POLES TRUE
691#define MAP_DEFAULT_FLATPOLES 100
692#define MAP_MIN_FLATPOLES 0
693#define MAP_MAX_FLATPOLES 100
695#define MAP_DEFAULT_TEMPERATURE 50
696#define MAP_MIN_TEMPERATURE 0
697#define MAP_MAX_TEMPERATURE 100
699#define MAP_DEFAULT_TEAM_PLACEMENT TEAM_PLACEMENT_CLOSEST
#define BV_DEFINE(name, bits)
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
bool can_channel_land(const struct civ_map *nmap, const struct tile *ptile)
#define native_pos_to_index(nat_x, nat_y)
struct startpos * map_startpos_get(const struct tile *ptile)
bool is_normal_map_pos(int x, int y)
int startpos_number(const struct startpos *psp)
bool can_reclaim_ocean(const struct civ_map *nmap, const struct tile *ptile)
void map_free(struct civ_map *fmap)
bool startpos_disallow(struct startpos *psp, struct nation_type *pnation)
enum direction8 opposite_direction(enum direction8 dir)
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
bool can_freeze_terrain(const struct civ_map *nmap, const struct tile *ptile)
static int index_to_map_pos_y(int mindex)
struct startpos * map_startpos_new(struct tile *ptile)
void map_distance_vector(int *dx, int *dy, const struct tile *ptile0, const struct tile *ptile1)
bool can_thaw_terrain(const struct civ_map *nmap, const struct tile *ptile)
int tile_move_cost_ptrs(const struct civ_map *nmap, const struct unit *punit, const struct unit_type *punittype, const struct player *pplayer, const struct tile *t1, const struct tile *t2)
bool base_get_direction_for_step(const struct civ_map *nmap, const struct tile *src_tile, const struct tile *dst_tile, enum direction8 *dir)
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
static const bool C_PERCENT
static const bool C_NUMBER
struct tile * startpos_tile(const struct startpos *psp)
bool startpos_allows_all(const struct startpos *psp)
const struct nation_hash * startpos_raw_nations(const struct startpos *psp)
FC_STATIC_ASSERT((long unsigned) MAP_MAX_SIZE *1000<(long unsigned) 1<< 31, map_too_big_for_network)
#define CHECK_MAP_POS(x, y)
struct tile * rand_map_pos(const struct civ_map *nmap)
const char * dir_get_name(enum direction8 dir)
enum direction8 dir_ccw(enum direction8 dir)
struct iterator * map_startpos_iter_init(struct map_startpos_iter *iter)
void map_allocate(struct civ_map *amap)
void map_init_topology(struct civ_map *nmap)
#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y)
bool same_pos(const struct tile *tile0, const struct tile *tile1)
static const bool C_ADJACENT
void main_map_allocate(void)
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
static int map_pos_to_index(struct civ_map *nmap, int map_x, int map_y)
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
int map_signed_latitude(const struct tile *ptile)
void base_map_distance_vector(int *dx, int *dy, int x0, int y0, int x1, int y1)
int map_vector_to_sq_distance(int dx, int dy)
bool map_startpos_remove(struct tile *ptile)
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
bool is_move_cardinal(const struct civ_map *nmap, const struct tile *src_tile, const struct tile *dst_tile)
struct tile * rand_map_pos_filtered(const struct civ_map *nmap, void *data, bool(*filter)(const struct tile *ptile, const void *data))
int map_startpos_count(void)
bv_extras get_tile_infrastructure_set(const struct tile *ptile, int *count)
size_t startpos_iter_sizeof(void)
int get_direction_for_step(const struct civ_map *nmap, const struct tile *src_tile, const struct tile *dst_tile)
static int index_to_map_pos_x(int mindex)
bool is_cardinal_dir(enum direction8 dir)
static const bool C_CARDINAL
bool map_untrusted_dir_is_valid(enum direction8 dir)
bool terrain_surroundings_allow_change(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain)
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
bool startpos_unpack(struct startpos *psp, const struct packet_edit_startpos_full *packet)
struct iterator * startpos_iter_init(struct startpos_iter *it, const struct startpos *psp)
static bool is_border_tile(const struct tile *ptile, int dist)
bool is_valid_dir(enum direction8 dir)
enum direction8 dir_cw(enum direction8 dir)
enum direction8 rand_direction(void)
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
struct terrain_misc terrain_control
bool is_tiles_adjacent(const struct tile *ptile0, const struct tile *ptile1)
struct tile * nearest_real_tile(const struct civ_map *nmap, int x, int y)
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int x, int y)
#define index_to_native_pos(pnat_x, pnat_y, mindex)
void map_init(struct civ_map *imap, bool server_side)
bool startpos_is_excluding(const struct startpos *psp)
static int map_move_cost(const struct civ_map *nmap, const struct player *pplayer, const struct unit_type *punittype, const struct tile *src_tile, const struct tile *dst_tile)
int map_distance(const struct tile *tile0, const struct tile *tile1)
struct startpos * map_startpos_by_number(int id)
size_t map_startpos_iter_sizeof(void)
bool startpos_allow(struct startpos *psp, struct nation_type *pnation)
bool normalize_map_pos(const struct civ_map *nmap, int *x, int *y)
bool is_real_map_pos(const struct civ_map *nmap, int x, int y)
#define index_to_map_pos(pmap_x, pmap_y, mindex)
bool is_singular_tile(const struct tile *ptile, int dist)
int map_vector_to_real_distance(int dx, int dy)
const struct unit_type * unit_type_get(const struct unit *punit)