42#define topo_has_flag(topo, flag) (((topo) & (flag)) != 0)
43#define current_topo_has_flag(flag) topo_has_flag((CURRENT_TOPOLOGY), (flag))
45#define wrap_has_flag(wrap, flag) (((wrap) & (flag)) != 0)
46#define current_wrap_has_flag(flag) wrap_has_flag((CURRENT_WRAP), (flag))
48#define ALL_DIRECTIONS_CARDINAL() topo_has_flag((CURRENT_TOPOLOGY), TF_HEX)
66 const struct tile *src_tile,
70 const struct tile *src_tile,
105#define startpos_nations_iterate(ARG_psp, NAME_pnation) \
106 generic_iterate(struct startpos_iter, const struct nation_type *, \
107 NAME_pnation, startpos_iter_sizeof, \
108 startpos_iter_init, (ARG_psp))
109#define startpos_nations_iterate_end generic_iterate_end
125#define map_startpos_iterate(NAME_psp) \
126 generic_iterate(struct map_startpos_iter, struct startpos *, \
127 NAME_psp, map_startpos_iter_sizeof, map_startpos_iter_init)
128#define map_startpos_iterate_end generic_iterate_end
132#define CHECK_MAP_POS(x,y) \
133 fc_assert(is_normal_map_pos((x),(y)))
134#define CHECK_NATIVE_POS(x, y) \
135 fc_assert((x) >= 0 && (x) < MAP_NATIVE_WIDTH && \
136 (y) >= 0 && (y) < MAP_NATIVE_HEIGHT)
137#define CHECK_INDEX(mindex) \
138 fc_assert((mindex) >= 0 && (mindex) < MAP_INDEX_SIZE)
140#define CHECK_MAP_POS(x,y) ((void)0)
141#define CHECK_NATIVE_POS(x, y) ((void)0)
142#define CHECK_INDEX(mindex) ((void)0)
145#define native_pos_to_index_nocheck(nat_x, nat_y) \
146 ((nat_x) + (nat_y) * MAP_NATIVE_WIDTH)
147#define native_pos_to_index(nat_x, nat_y) \
148 (CHECK_NATIVE_POS((nat_x), (nat_y)), \
149 native_pos_to_index_nocheck(nat_x, nat_y))
150#define index_to_native_pos(pnat_x, pnat_y, mindex) \
151 (*(pnat_x) = index_to_native_pos_x(mindex), \
152 *(pnat_y) = index_to_native_pos_y(mindex))
153#define index_to_native_pos_x(mindex) \
154 ((mindex) % MAP_NATIVE_WIDTH)
155#define index_to_native_pos_y(mindex) \
156 ((mindex) / MAP_NATIVE_WIDTH)
159#define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
161 ? (*(pmap_x) = ((nat_y) + ((nat_y) & 1)) / 2 + (nat_x), \
162 *(pmap_y) = (nat_y) - *(pmap_x) + MAP_NATIVE_WIDTH) \
163 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
165#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y) \
167 ? (*(pnat_y) = (map_x) + (map_y) - MAP_NATIVE_WIDTH, \
168 *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2) \
169 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
171#define NATURAL_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
173 ? (*(pmap_x) = ((nat_y) + (nat_x)) / 2, \
174 *(pmap_y) = (nat_y) - *(pmap_x) + MAP_NATIVE_WIDTH) \
175 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
177#define MAP_TO_NATURAL_POS(pnat_x, pnat_y, map_x, map_y) \
179 ? (*(pnat_y) = (map_x) + (map_y) - MAP_NATIVE_WIDTH, \
180 *(pnat_x) = 2 * (map_x) - *(pnat_y)) \
181 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
188#define do_in_native_pos(nat_x, nat_y, map_x, map_y) \
190 int _nat_x, _nat_y; \
191 MAP_TO_NATIVE_POS(&_nat_x, &_nat_y, map_x, map_y); \
193 const int nat_x = _nat_x, nat_y = _nat_y;
195#define do_in_native_pos_end \
203#define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) \
205 int _ntl_x, _ntl_y; \
206 MAP_TO_NATURAL_POS(&_ntl_x, &_ntl_y, map_x, map_y); \
208 const int ntl_x = _ntl_x, ntl_y = _ntl_y;
210#define do_in_natural_pos_end \
218#define index_to_map_pos(pmap_x, pmap_y, mindex) \
219 (CHECK_INDEX(mindex), \
220 index_to_native_pos(pmap_x, pmap_y, mindex), \
221 NATIVE_TO_MAP_POS(pmap_x, pmap_y, *(pmap_x), *(pmap_y)))
225#define DIRSTEP(dest_x, dest_y, dir) \
226( (dest_x) = DIR_DX[(dir)], \
227 (dest_y) = DIR_DY[(dir)])
257#define map_size_checked() MAX(map_num_tiles() / 1000, 1)
261 bool (*filter)(
const struct tile *ptile,
266 const struct tile *src_tile,
272 const struct player *pplayer,
273 const struct tile *t1,
const struct tile *t2);
281 const struct tile *ptile)
292 const struct player *pplayer,
294 const struct tile *src_tile,
306 const struct tile *ptile);
308 const struct tile *ptile);
310 const struct tile *ptile);
312 const struct tile *ptile);
314 const struct tile *ptile,
315 const struct terrain *pterrain);
325#define iterate_outward_dxy(nmap, start_tile, max_dist, _tile, _x, _y) \
327 int _x, _y, _tile##_x, _tile##_y, _start##_x, _start##_y; \
328 struct tile *_tile; \
329 const struct tile *_tile##_start = (start_tile); \
330 int _tile##_max = (max_dist); \
331 int _tile##_index = 0; \
332 index_to_map_pos(&_start##_x, &_start##_y, tile_index(_tile##_start)); \
334 _tile##_index < MAP_NUM_ITERATE_OUTWARDS_INDICES; \
336 if (MAP_ITERATE_OUTWARDS_INDICES[_tile##_index].dist > _tile##_max) { \
339 _x = MAP_ITERATE_OUTWARDS_INDICES[_tile##_index].dx; \
340 _y = MAP_ITERATE_OUTWARDS_INDICES[_tile##_index].dy; \
341 _tile##_x = _x + _start##_x; \
342 _tile##_y = _y + _start##_y; \
343 _tile = map_pos_to_tile(nmap, _tile##_x, _tile##_y); \
344 if (_tile == nullptr) { \
348#define iterate_outward_dxy_end \
353#define iterate_outward(nmap, start_tile, max_dist, itr_tile) \
354 iterate_outward_dxy(nmap, start_tile, max_dist, itr_tile, \
355 _dx_itr##itr_tile, _dy_itr##itr_tile)
357#define iterate_outward_end iterate_outward_dxy_end
367#define square_dxy_iterate(nmap, center_tile, radius, tile_itr, dx_itr, dy_itr) \
368 iterate_outward_dxy(nmap, center_tile, radius, tile_itr, dx_itr, dy_itr)
370#define square_dxy_iterate_end iterate_outward_dxy_end
377#define square_iterate(nmap, center_tile, radius, tile_itr) \
378 square_dxy_iterate(nmap, center_tile, radius, tile_itr, _dummy_x, dummy_y)
380#define square_iterate_end square_dxy_iterate_end
387#define circle_iterate(nmap, center_tile, sq_radius, tile_itr) \
388 circle_dxyr_iterate(nmap, center_tile, sq_radius, tile_itr, _dx, _dy, _dr)
390#define circle_iterate_end \
391 circle_dxyr_iterate_end
395#define circle_dxyr_iterate(nmap, center_tile, sq_radius, \
398 const int _tile##_sq_radius = (sq_radius); \
399 const int _tile##_cr_radius = (int)sqrt((double)MAX(_tile##_sq_radius, 0)); \
401 square_dxy_iterate(nmap, center_tile, _tile##_cr_radius, _tile, dx, dy) { \
402 const int dr = map_vector_to_sq_distance(dx, dy); \
404 if (dr <= _tile##_sq_radius) {
406#define circle_dxyr_iterate_end \
408 } square_dxy_iterate_end; \
414#define adjc_iterate(nmap, center_tile, itr_tile) \
418 adjc_dir_iterate(nmap, center_tile, itr_tile, ADJC_ITERATE_dir_itr##itr_tile) {
420#define adjc_iterate_end \
421 } adjc_dir_iterate_end; \
425#define adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr) \
426 adjc_dirlist_iterate(nmap, center_tile, itr_tile, dir_itr, \
427 MAP_VALID_DIRS, MAP_NUM_VALID_DIRS)
429#define adjc_dir_iterate_end adjc_dirlist_iterate_end
432#define adjc_dir_base_iterate(nmap, center_tile, dir_itr) \
433 adjc_dirlist_base_iterate(nmap, center_tile, dir_itr, \
434 MAP_VALID_DIRS, MAP_NUM_VALID_DIRS)
436#define adjc_dir_base_iterate_end \
437 adjc_dirlist_base_iterate_end
442#define cardinal_adjc_iterate(nmap, center_tile, itr_tile) \
443 adjc_dirlist_iterate(nmap, center_tile, itr_tile, _dir_itr##itr_tile, \
444 MAP_CARDINAL_DIRS, MAP_NUM_CARDINAL_DIRS)
446#define cardinal_adjc_iterate_end adjc_dirlist_iterate_end
449#define cardinal_adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr) \
450 adjc_dirlist_iterate(nmap, center_tile, itr_tile, dir_itr, \
451 MAP_CARDINAL_DIRS, MAP_NUM_CARDINAL_DIRS)
453#define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
456#define cardinal_adjc_dir_base_iterate(nmap, center_tile, dir_itr) \
457 adjc_dirlist_base_iterate(nmap, center_tile, dir_itr, \
458 MAP_CARDINAL_DIRS, MAP_NUM_CARDINAL_DIRS)
460#define cardinal_adjc_dir_base_iterate_end \
461 adjc_dirlist_base_iterate_end
464#define cardinal_between_iterate(nmap, tile1, tile2, between) \
465 cardinal_adjc_iterate(nmap, tile1, between) { \
466 cardinal_adjc_iterate(nmap, between, second) { \
467 if (same_pos(second, tile2)) {
469#define cardinal_between_iterate_end \
471 } cardinal_adjc_iterate_end; \
472 } cardinal_adjc_iterate_end;
481#define adjc_dirlist_iterate(nmap, center_tile, _tile, _dir, \
484 enum direction8 _dir; \
485 int _tile##_x, _tile##_y, _tile##_cx, _tile##_cy; \
486 struct tile *_tile; \
487 const struct tile *_tile##_center = (center_tile); \
488 int _tile##_index = 0; \
489 index_to_map_pos(&_tile##_cx, &_tile##_cy, tile_index(_tile##_center)); \
491 _tile##_index < (dircount); \
493 _dir = dirlist[_tile##_index]; \
494 DIRSTEP(_tile##_x, _tile##_y, _dir); \
495 _tile##_x += _tile##_cx; \
496 _tile##_y += _tile##_cy; \
497 _tile = map_pos_to_tile(nmap, _tile##_x, _tile##_y); \
498 if (_tile == nullptr) { \
502#define adjc_dirlist_iterate_end \
507#define adjc_dirlist_base_iterate(nmap, center_tile, _dir, dirlist, dircount) \
509 enum direction8 _dir; \
510 int _tile##_x, _tile##_y, _center##_x, _center##_y; \
511 const struct tile *_tile##_center = (center_tile); \
512 bool _tile##_is_border = is_border_tile(_tile##_center, 1); \
513 int _tile##_index = 0; \
514 index_to_map_pos(&_center##_x, &_center##_y, tile_index(_tile##_center)); \
516 _tile##_index < (dircount); \
518 _dir = dirlist[_tile##_index]; \
519 DIRSTEP(_tile##_x, _tile##_y, _dir); \
520 _tile##_x += _center##_x; \
521 _tile##_y += _center##_y; \
522 if (_tile##_is_border && !normalize_map_pos(nmap, &_tile##_x, &_tile##_y)) { \
526#define adjc_dirlist_base_iterate_end \
532#define whole_map_iterate(_map, _tile) \
534 struct tile *_tile; \
535 int _tile##_index = 0; \
537 _tile##_index < MAP_INDEX_SIZE; \
539 _tile = (_map)->tiles + _tile##_index;
541#define whole_map_iterate_end \
548#define DIR_REVERSE(dir) (7 - (dir))
557extern const int DIR_DX[8];
558extern const int DIR_DY[8];
561#define MAP_MAX_LATITUDE 1000
563#define MAP_MAX_LATITUDE_BOUND (MAP_MAX_LATITUDE)
564#define MAP_MIN_LATITUDE_BOUND (-MAP_MAX_LATITUDE)
565#define MAP_DEFAULT_NORTH_LATITUDE MAP_MAX_LATITUDE_BOUND
566#define MAP_DEFAULT_SOUTH_LATITUDE MAP_MIN_LATITUDE_BOUND
569#define MAP_NORTH_LATITUDE(_nmap) ((_nmap).north_latitude)
570#define MAP_SOUTH_LATITUDE(_nmap) ((_nmap).south_latitude)
573#define MAP_MAX_REAL_LATITUDE(_nmap) \
574 MAX(MAP_NORTH_LATITUDE(_nmap), MAP_SOUTH_LATITUDE(_nmap))
575#define MAP_MIN_REAL_LATITUDE(_nmap) \
576 MIN(MAP_NORTH_LATITUDE(_nmap), MAP_SOUTH_LATITUDE(_nmap))
577#define MAP_REAL_LATITUDE_RANGE(_nmap) \
578 (MAP_MAX_REAL_LATITUDE(_nmap) - MAP_MIN_REAL_LATITUDE(_nmap))
581#define MAP_MAX_ABS_LATITUDE(_nmap) \
582 MAX(MAP_MAX_REAL_LATITUDE(_nmap), -MAP_MIN_REAL_LATITUDE(_nmap))
583#define MAP_MIN_ABS_LATITUDE(_nmap) \
584 MAX(0, MAX(MAP_MIN_REAL_LATITUDE(_nmap), -MAP_MAX_REAL_LATITUDE(_nmap)))
589#define MAP_TILE_OWNER_NULL MAX_UINT8
591#define MAP_DEFAULT_HUTS 15
592#define MAP_MIN_HUTS 0
593#define MAP_MAX_HUTS 500
595#define MAP_DEFAULT_ANIMALS 20
596#define MAP_MIN_ANIMALS 0
597#define MAP_MAX_ANIMALS 500
599#define MAP_DEFAULT_MAPSIZE MAPSIZE_FULLSIZE
605#define MAP_DEFAULT_SIZE 3
606#define MAP_MIN_SIZE 0
607#define MAP_MAX_SIZE 38
609#define MAP_DEFAULT_SIZE 4
610#define MAP_MIN_SIZE 0
611#define MAP_MAX_SIZE 2048
618 < (
long unsigned) 1 << 31,
621#define MAP_DEFAULT_TILESPERPLAYER 100
622#define MAP_MIN_TILESPERPLAYER 1
623#define MAP_MAX_TILESPERPLAYER 1000
626#define MAP_DEFAULT_LINEAR_SIZE 64
627#define MAP_MAX_LINEAR_SIZE (MAP_MAX_SIZE * 1000 / MAP_MIN_LINEAR_SIZE)
628#define MAP_MIN_LINEAR_SIZE 16
633#define MAP_DISTANCE_MAX (MAP_MAX_LINEAR_SIZE + MAP_MIN_LINEAR_SIZE)
635#define MAP_ORIGINAL_TOPO TF_WRAPX
638#define MAP_DEFAULT_TOPO 0
639#define MAP_DEFAULT_WRAP WRAP_X
641#define MAP_DEFAULT_TOPO (TF_ISO|TF_HEX)
642#define MAP_DEFAULT_WRAP (WRAP_X)
645#define MAP_DEFAULT_SEED 0
646#define MAP_MIN_SEED 0
647#define MAP_MAX_SEED (MAX_UINT32 >> 1)
649#define MAP_DEFAULT_LANDMASS 30
650#define MAP_MIN_LANDMASS 15
651#define MAP_MAX_LANDMASS 85
653#define MAP_DEFAULT_RICHES 250
654#define MAP_MIN_RICHES 0
655#define MAP_MAX_RICHES 1000
657#define MAP_DEFAULT_STEEPNESS 30
658#define MAP_MIN_STEEPNESS 0
659#define MAP_MAX_STEEPNESS 100
661#define MAP_DEFAULT_WETNESS 50
662#define MAP_MIN_WETNESS 0
663#define MAP_MAX_WETNESS 100
665#define MAP_DEFAULT_GENERATOR MAPGEN_RANDOM
667#define MAP_DEFAULT_STARTPOS MAPSTARTPOS_DEFAULT
669#define MAP_DEFAULT_TINYISLES FALSE
670#define MAP_MIN_TINYISLES FALSE
671#define MAP_MAX_TINYISLES TRUE
673#define MAP_DEFAULT_SEPARATE_POLES TRUE
674#define MAP_MIN_SEPARATE_POLES FALSE
675#define MAP_MAX_SEPARATE_POLES TRUE
677#define MAP_DEFAULT_FLATPOLES 100
678#define MAP_MIN_FLATPOLES 0
679#define MAP_MAX_FLATPOLES 100
681#define MAP_DEFAULT_TEMPERATURE 50
682#define MAP_MIN_TEMPERATURE 0
683#define MAP_MAX_TEMPERATURE 100
685#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)
#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)
void map_init_topology(void)
#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)
#define MAP_NATIVE_HEIGHT