1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
18 #endif /* __cplusplus */
20 #include <math.h> /* sqrt */
23 #include "bitvector.h"
25 #include "log.h" /* fc_assert */
30 #include "map_types.h"
34 /* Parameters for terrain counting functions. */
35 static const bool C_ADJACENT
= FALSE
;
36 static const bool C_CARDINAL
= TRUE
;
37 static const bool C_NUMBER
= FALSE
;
38 static const bool C_PERCENT
= TRUE
;
40 #define MAP_IS_ISOMETRIC (CURRENT_TOPOLOGY & (TF_ISO + TF_HEX))
42 #define CURRENT_TOPOLOGY (wld.map.topology_id)
44 #define topo_has_flag(topo, flag) (((topo) & (flag)) != 0)
45 #define current_topo_has_flag(flag) topo_has_flag((CURRENT_TOPOLOGY), (flag))
47 #define ALL_DIRECTIONS_CARDINAL() topo_has_flag((CURRENT_TOPOLOGY), TF_HEX)
49 bool map_is_empty(void);
50 void map_init(struct civ_map
*imap
, bool server_side
);
51 void map_init_topology(void);
52 void map_allocate(struct civ_map
*amap
);
53 void main_map_allocate(void);
54 void map_free(struct civ_map
*fmap
);
56 int map_vector_to_real_distance(int dx
, int dy
);
57 int map_vector_to_sq_distance(int dx
, int dy
);
58 int map_distance(const struct tile
*tile0
, const struct tile
*tile1
);
59 int real_map_distance(const struct tile
*tile0
, const struct tile
*tile1
);
60 int sq_map_distance(const struct tile
*tile0
,const struct tile
*tile1
);
62 bool same_pos(const struct tile
*tile0
, const struct tile
*tile1
);
63 bool base_get_direction_for_step(const struct tile
*src_tile
,
64 const struct tile
*dst_tile
,
65 enum direction8
*dir
);
66 int get_direction_for_step(const struct tile
*src_tile
,
67 const struct tile
*dst_tile
);
70 /* Specific functions for start positions. */
71 struct startpos
*map_startpos_by_number(int id
);
72 int startpos_number(const struct startpos
*psp
);
74 bool startpos_allow(struct startpos
*psp
, struct nation_type
*pnation
);
75 bool startpos_disallow(struct startpos
*psp
, struct nation_type
*pnation
);
77 struct tile
*startpos_tile(const struct startpos
*psp
);
78 bool startpos_nation_allowed(const struct startpos
*psp
,
79 const struct nation_type
*pnation
);
80 bool startpos_allows_all(const struct startpos
*psp
);
82 bool startpos_pack(const struct startpos
*psp
,
83 struct packet_edit_startpos_full
*packet
);
84 bool startpos_unpack(struct startpos
*psp
,
85 const struct packet_edit_startpos_full
*packet
);
87 /* See comment in "common/map.c". */
88 bool startpos_is_excluding(const struct startpos
*psp
);
89 const struct nation_hash
*startpos_raw_nations(const struct startpos
*psp
);
91 /****************************************************************************
92 Iterate over all nations at the start position for which the function
93 startpos_nation_allowed() would return TRUE. This automatically takes into
94 account the value of startpos_is_excluding() and startpos_allows_all() to
95 iterate over the correct set of nations.
96 ****************************************************************************/
98 size_t startpos_iter_sizeof(void);
99 struct iterator
*startpos_iter_init(struct startpos_iter
*it
,
100 const struct startpos
*psp
);
101 #define startpos_nations_iterate(ARG_psp, NAME_pnation) \
102 generic_iterate(struct startpos_iter, const struct nation_type *, \
103 NAME_pnation, startpos_iter_sizeof, \
104 startpos_iter_init, (ARG_psp))
105 #define startpos_nations_iterate_end generic_iterate_end
108 /* General map start positions functions. */
109 int map_startpos_count(void);
110 struct startpos
*map_startpos_new(struct tile
*ptile
);
111 struct startpos
*map_startpos_get(const struct tile
*ptile
);
112 bool map_startpos_remove(struct tile
*ptile
);
114 /****************************************************************************
115 Iterate over all start positions placed on the map.
116 ****************************************************************************/
117 struct map_startpos_iter
;
118 size_t map_startpos_iter_sizeof(void);
119 struct iterator
*map_startpos_iter_init(struct map_startpos_iter
*iter
);
121 #define map_startpos_iterate(NAME_psp) \
122 generic_iterate(struct map_startpos_iter, struct startpos *, \
123 NAME_psp, map_startpos_iter_sizeof, map_startpos_iter_init)
124 #define map_startpos_iterate_end generic_iterate_end
127 /* Number of index coordinates (for sanity checks and allocations) */
128 #define MAP_INDEX_SIZE (wld.map.xsize * wld.map.ysize)
131 #define CHECK_MAP_POS(x,y) \
132 fc_assert(is_normal_map_pos((x),(y)))
133 #define CHECK_NATIVE_POS(x, y) \
134 fc_assert((x) >= 0 && (x) < wld.map.xsize && (y) >= 0 && (y) < wld.map.ysize)
135 #define CHECK_INDEX(mindex) \
136 fc_assert((mindex) >= 0 && (mindex) < MAP_INDEX_SIZE)
137 #else /* FREECIV_DEBUG */
138 #define CHECK_MAP_POS(x,y) ((void)0)
139 #define CHECK_NATIVE_POS(x, y) ((void)0)
140 #define CHECK_INDEX(mindex) ((void)0)
141 #endif /* FREECIV_DEBUG */
143 #define native_pos_to_index_nocheck(nat_x, nat_y) \
144 ((nat_x) + (nat_y) * wld.map.xsize)
145 #define native_pos_to_index(nat_x, nat_y) \
146 (CHECK_NATIVE_POS((nat_x), (nat_y)), \
147 native_pos_to_index_nocheck(nat_x, nat_y))
148 #define index_to_native_pos(pnat_x, pnat_y, mindex) \
149 (*(pnat_x) = index_to_native_pos_x(mindex), \
150 *(pnat_y) = index_to_native_pos_y(mindex))
151 #define index_to_native_pos_x(mindex) \
152 ((mindex) % wld.map.xsize)
153 #define index_to_native_pos_y(mindex) \
154 ((mindex) / wld.map.xsize)
156 /* Obscure math. See explanation in doc/HACKING. */
157 #define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
159 ? (*(pmap_x) = ((nat_y) + ((nat_y) & 1)) / 2 + (nat_x), \
160 *(pmap_y) = (nat_y) - *(pmap_x) + wld.map.xsize) \
161 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
163 #define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y) \
165 ? (*(pnat_y) = (map_x) + (map_y) - wld.map.xsize, \
166 *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2) \
167 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
169 #define NATURAL_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
171 ? (*(pmap_x) = ((nat_y) + (nat_x)) / 2, \
172 *(pmap_y) = (nat_y) - *(pmap_x) + wld.map.xsize) \
173 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
175 #define MAP_TO_NATURAL_POS(pnat_x, pnat_y, map_x, map_y) \
177 ? (*(pnat_y) = (map_x) + (map_y) - wld.map.xsize, \
178 *(pnat_x) = 2 * (map_x) - *(pnat_y)) \
179 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
182 /* Provide a block to convert from map to native coordinates. This allows
183 * you to use a native version of the map position within the block. Note
184 * that the native position is declared as const and can't be changed
185 * inside the block. */
186 #define do_in_native_pos(nat_x, nat_y, map_x, map_y) \
188 int _nat_x, _nat_y; \
189 MAP_TO_NATIVE_POS(&_nat_x, &_nat_y, map_x, map_y); \
191 const int nat_x = _nat_x, nat_y = _nat_y;
193 #define do_in_native_pos_end \
197 /* Provide a block to convert from map to natural coordinates. This allows
198 * you to use a natural version of the map position within the block. Note
199 * that the natural position is declared as const and can't be changed
200 * inside the block. */
201 #define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) \
203 int _ntl_x, _ntl_y; \
204 MAP_TO_NATURAL_POS(&_ntl_x, &_ntl_y, map_x, map_y); \
206 const int ntl_x = _ntl_x, ntl_y = _ntl_y;
208 #define do_in_natural_pos_end \
212 /* Width and height of the map, in native coordinates. */
213 #define NATIVE_WIDTH wld.map.xsize
214 #define NATIVE_HEIGHT wld.map.ysize
216 /* Width and height of the map, in natural coordinates. */
217 #define NATURAL_WIDTH (MAP_IS_ISOMETRIC ? 2 * wld.map.xsize : wld.map.xsize)
218 #define NATURAL_HEIGHT wld.map.ysize
220 static inline int map_pos_to_index(int map_x
, int map_y
);
222 /* index_to_map_pos(int *, int *, int) inverts map_pos_to_index */
223 #define index_to_map_pos(pmap_x, pmap_y, mindex) \
224 (CHECK_INDEX(mindex), \
225 index_to_native_pos(pmap_x, pmap_y, mindex), \
226 NATIVE_TO_MAP_POS(pmap_x, pmap_y, *(pmap_x), *(pmap_y)))
227 static inline int index_to_map_pos_x(int mindex
);
228 static inline int index_to_map_pos_y(int mindex
);
230 #define DIRSTEP(dest_x, dest_y, dir) \
231 ( (dest_x) = DIR_DX[(dir)], \
232 (dest_y) = DIR_DY[(dir)])
235 * Steps from the tile in the given direction, yielding a new tile (or NULL).
237 * Direct calls to DIR_DXY should be avoided and DIRSTEP should be
238 * used. But to allow dest and src to be the same, as in
239 * MAPSTEP(x, y, x, y, dir)
240 * we bend this rule here.
242 struct tile
*mapstep(const struct tile
*ptile
, enum direction8 dir
);
244 struct tile
*map_pos_to_tile(int x
, int y
);
245 struct tile
*native_pos_to_tile(int nat_x
, int nat_y
);
246 struct tile
*index_to_tile(struct civ_map
*imap
, int mindex
);
248 bool is_real_map_pos(int x
, int y
);
249 bool is_normal_map_pos(int x
, int y
);
251 bool is_singular_tile(const struct tile
*ptile
, int dist
);
252 bool normalize_map_pos(int *x
, int *y
);
253 struct tile
*nearest_real_tile(int x
, int y
);
254 void base_map_distance_vector(int *dx
, int *dy
,
255 int x0
, int y0
, int x1
, int y1
);
256 void map_distance_vector(int *dx
, int *dy
, const struct tile
*ptile0
,
257 const struct tile
*ptile1
);
258 int map_num_tiles(void);
259 #define map_size_checked() MAX(map_num_tiles() / 1000, 1)
261 struct tile
*rand_neighbour(const struct tile
*ptile
);
262 struct tile
*rand_map_pos(void);
263 struct tile
*rand_map_pos_filtered(void *data
,
264 bool (*filter
)(const struct tile
*ptile
,
267 bool can_be_irrigated(const struct tile
*ptile
,
268 const struct unit
*punit
);
269 bool is_tiles_adjacent(const struct tile
*ptile0
, const struct tile
*ptile1
);
270 bool is_move_cardinal(const struct tile
*src_tile
,
271 const struct tile
*dst_tile
);
273 int tile_move_cost_ptrs(const struct unit
*punit
,
274 const struct unit_type
*punittype
,
275 const struct player
*pplayer
,
276 const struct tile
*t1
, const struct tile
*t2
);
278 /***************************************************************
279 The cost to move punit from where it is to tile x,y.
280 It is assumed the move is a valid one, e.g. the tiles are adjacent.
281 ***************************************************************/
282 static inline int map_move_cost_unit(struct unit
*punit
,
283 const struct tile
*ptile
)
285 return tile_move_cost_ptrs(punit
, unit_type_get(punit
), unit_owner(punit
),
286 unit_tile(punit
), ptile
);
289 /***************************************************************
290 Move cost between two tiles
291 ***************************************************************/
292 static inline int map_move_cost(const struct player
*pplayer
,
293 const struct unit_type
*punittype
,
294 const struct tile
*src_tile
,
295 const struct tile
*dst_tile
)
297 return tile_move_cost_ptrs(NULL
, punittype
, pplayer
, src_tile
, dst_tile
);
300 bool is_safe_ocean(const struct tile
*ptile
);
301 bv_extras
get_tile_infrastructure_set(const struct tile
*ptile
,
304 bool can_channel_land(const struct tile
*ptile
);
305 bool can_reclaim_ocean(const struct tile
*ptile
);
306 bool can_thaw_terrain(const struct tile
*ptile
);
307 bool can_freeze_terrain(const struct tile
*ptile
);
308 bool terrain_surroundings_allow_change(const struct tile
*ptile
,
309 const struct terrain
*pterrain
);
311 extern struct terrain_misc terrain_control
;
313 /* This iterates outwards from the starting point. Every tile within max_dist
314 * (including the starting tile) will show up exactly once, in an outward
315 * (based on real map distance) order. The returned values are always real
316 * and are normalized. The starting position must be normal.
318 * See also iterate_outward() */
319 #define iterate_outward_dxy(start_tile, max_dist, _tile, _x, _y) \
321 int _x, _y, _tile##_x, _tile##_y, _start##_x, _start##_y; \
322 struct tile *_tile; \
323 const struct tile *_tile##_start = (start_tile); \
324 int _tile##_max = (max_dist); \
325 int _tile##_index = 0; \
326 index_to_map_pos(&_start##_x, &_start##_y, tile_index(_tile##_start)); \
328 _tile##_index < wld.map.num_iterate_outwards_indices; \
330 if (wld.map.iterate_outwards_indices[_tile##_index].dist > _tile##_max) { \
333 _x = wld.map.iterate_outwards_indices[_tile##_index].dx; \
334 _y = wld.map.iterate_outwards_indices[_tile##_index].dy; \
335 _tile##_x = _x + _start##_x; \
336 _tile##_y = _y + _start##_y; \
337 _tile = map_pos_to_tile(_tile##_x, _tile##_y); \
338 if (NULL == _tile) { \
342 #define iterate_outward_dxy_end \
346 /* See iterate_outward_dxy() */
347 #define iterate_outward(start_tile, max_dist, itr_tile) \
348 iterate_outward_dxy(start_tile, max_dist, itr_tile, _dx_itr, _dy_itr)
350 #define iterate_outward_end iterate_outward_dxy_end
353 * Iterate through all tiles in a square with given center and radius.
354 * The position (x_itr, y_itr) that is returned will be normalized;
355 * unreal positions will be automatically discarded. (dx_itr, dy_itr)
356 * is the standard distance vector between the position and the center
357 * position. Note that when the square is larger than the map the
358 * distance vector may not be the minimum distance vector.
360 #define square_dxy_iterate(center_tile, radius, tile_itr, dx_itr, dy_itr) \
361 iterate_outward_dxy(center_tile, radius, tile_itr, dx_itr, dy_itr)
363 #define square_dxy_iterate_end iterate_outward_dxy_end
366 * Iterate through all tiles in a square with given center and radius.
367 * Positions returned will have adjusted x, and positions with illegal
368 * y will be automatically discarded.
370 #define square_iterate(center_tile, radius, tile_itr) \
371 square_dxy_iterate(center_tile, radius, tile_itr, _dummy_x, dummy_y)
373 #define square_iterate_end square_dxy_iterate_end
376 * Iterate through all tiles in a circle with given center and squared
377 * radius. Positions returned will have adjusted (x, y); unreal
378 * positions will be automatically discarded.
380 #define circle_iterate(center_tile, sq_radius, tile_itr) \
381 circle_dxyr_iterate(center_tile, sq_radius, tile_itr, _dx, _dy, _dr)
383 #define circle_iterate_end \
384 circle_dxyr_iterate_end
386 /* dx, dy, dr are distance from center to tile in x, y and square distance;
387 * do not rely on x, y distance, since they do not work for hex topologies */
388 #define circle_dxyr_iterate(center_tile, sq_radius, \
391 const int _tile##_sq_radius = (sq_radius); \
392 const int _tile##_cr_radius = (int)sqrt((double)MAX(_tile##_sq_radius, 0)); \
394 square_dxy_iterate(center_tile, _tile##_cr_radius, _tile, dx, dy) { \
395 const int dr = map_vector_to_sq_distance(dx, dy); \
397 if (dr <= _tile##_sq_radius) {
399 #define circle_dxyr_iterate_end \
401 } square_dxy_iterate_end; \
404 /* Iterate itr_tile through all map tiles adjacent to the given center map
405 * position, with normalization. Does not include the center position.
406 * The order of positions is unspecified. */
407 #define adjc_iterate(center_tile, itr_tile) \
409 /* Written as a wrapper to adjc_dir_iterate since it's the cleanest and \
410 * most efficient. */ \
411 adjc_dir_iterate(center_tile, itr_tile, ADJC_ITERATE_dir_itr##itr_tile) {
413 #define adjc_iterate_end \
414 } adjc_dir_iterate_end; \
417 /* As adjc_iterate() but also set direction8 iterator variable dir_itr */
418 #define adjc_dir_iterate(center_tile, itr_tile, dir_itr) \
419 adjc_dirlist_iterate(center_tile, itr_tile, dir_itr, \
420 wld.map.valid_dirs, wld.map.num_valid_dirs)
422 #define adjc_dir_iterate_end adjc_dirlist_iterate_end
424 /* Only set direction8 dir_itr (not tile) */
425 #define adjc_dir_base_iterate(center_tile, dir_itr) \
426 adjc_dirlist_base_iterate(center_tile, dir_itr, \
427 wld.map.valid_dirs, wld.map.num_valid_dirs)
429 #define adjc_dir_base_iterate_end \
430 adjc_dirlist_base_iterate_end
432 /* Iterate itr_tile through all map tiles cardinally adjacent to the given
433 * center map position, with normalization. Does not include the center
434 * position. The order of positions is unspecified. */
435 #define cardinal_adjc_iterate(center_tile, itr_tile) \
436 adjc_dirlist_iterate(center_tile, itr_tile, _dir_itr##center_tile, \
437 wld.map.cardinal_dirs, wld.map.num_cardinal_dirs)
439 #define cardinal_adjc_iterate_end adjc_dirlist_iterate_end
441 /* As cardinal_adjc_iterate but also set direction8 variable dir_itr */
442 #define cardinal_adjc_dir_iterate(center_tile, itr_tile, dir_itr) \
443 adjc_dirlist_iterate(center_tile, itr_tile, dir_itr, \
444 wld.map.cardinal_dirs, wld.map.num_cardinal_dirs)
446 #define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
448 /* Only set direction8 dir_itr (not tile) */
449 #define cardinal_adjc_dir_base_iterate(center_tile, dir_itr) \
450 adjc_dirlist_base_iterate(center_tile, dir_itr, \
451 wld.map.cardinal_dirs, wld.map.num_cardinal_dirs)
453 #define cardinal_adjc_dir_base_iterate_end \
454 adjc_dirlist_base_iterate_end
456 /* Iterate through all tiles cardinally adjacent to both tile1 and tile2 */
457 #define cardinal_between_iterate(tile1, tile2, between) \
458 cardinal_adjc_iterate(tile1, between) { \
459 cardinal_adjc_iterate(between, second) { \
460 if (same_pos(second, tile2)) {
462 #define cardinal_between_iterate_end \
464 } cardinal_adjc_iterate_end; \
465 } cardinal_adjc_iterate_end;
467 /* Iterate through all tiles adjacent to a tile using the given list of
468 * directions. _dir is the directional value, (center_x, center_y) is
469 * the center tile (which must be normalized). The center tile is not
470 * included in the iteration.
472 * This macro should not be used directly. Instead, use adjc_iterate,
473 * cardinal_adjc_iterate, or related iterators. */
474 #define adjc_dirlist_iterate(center_tile, _tile, _dir, \
477 enum direction8 _dir; \
478 int _tile##_x, _tile##_y, _tile##_cx, _tile##_cy; \
479 struct tile *_tile; \
480 const struct tile *_tile##_center = (center_tile); \
481 int _tile##_index = 0; \
482 index_to_map_pos(&_tile##_cx, &_tile##_cy, tile_index(_tile##_center)); \
484 _tile##_index < (dircount); \
486 _dir = dirlist[_tile##_index]; \
487 DIRSTEP(_tile##_x, _tile##_y, _dir); \
488 _tile##_x += _tile##_cx; \
489 _tile##_y += _tile##_cy; \
490 _tile = map_pos_to_tile(_tile##_x, _tile##_y); \
491 if (NULL == _tile) { \
495 #define adjc_dirlist_iterate_end \
499 /* Same as above but without setting the tile. */
500 #define adjc_dirlist_base_iterate(center_tile, _dir, dirlist, dircount) \
502 enum direction8 _dir; \
503 int _tile##_x, _tile##_y, _center##_x, _center##_y; \
504 const struct tile *_tile##_center = (center_tile); \
505 bool _tile##_is_border = is_border_tile(_tile##_center, 1); \
506 int _tile##_index = 0; \
507 index_to_map_pos(&_center##_x, &_center##_y, tile_index(_tile##_center)); \
509 _tile##_index < (dircount); \
511 _dir = dirlist[_tile##_index]; \
512 DIRSTEP(_tile##_x, _tile##_y, _dir); \
513 _tile##_x += _center##_x; \
514 _tile##_y += _center##_y; \
515 if (_tile##_is_border && !normalize_map_pos(&_tile##_x, &_tile##_y)) { \
519 #define adjc_dirlist_base_iterate_end \
523 /* Iterate over all positions on the globe.
524 * Use index positions for cache efficiency. */
525 #define whole_map_iterate(_map, _tile) \
527 struct tile *_tile; \
528 int _tile##_index = 0; \
530 _tile##_index < MAP_INDEX_SIZE; \
532 _tile = (_map)->tiles + _tile##_index;
534 #define whole_map_iterate_end \
538 BV_DEFINE(dir_vector
, 8);
540 /* return the reverse of the direction */
541 #define DIR_REVERSE(dir) (7 - (dir))
543 enum direction8
dir_cw(enum direction8 dir
);
544 enum direction8
dir_ccw(enum direction8 dir
);
545 const char* dir_get_name(enum direction8 dir
);
546 bool map_untrusted_dir_is_valid(enum direction8 dir
);
547 bool is_valid_dir(enum direction8 dir
);
548 bool is_cardinal_dir(enum direction8 dir
);
550 extern const int DIR_DX
[8];
551 extern const int DIR_DY
[8];
553 /* Used for network transmission; do not change. */
554 #define MAP_TILE_OWNER_NULL MAX_UINT8
556 #define MAP_DEFAULT_HUTS 15
557 #define MAP_MIN_HUTS 0
558 #define MAP_MAX_HUTS 500
560 #define MAP_DEFAULT_ANIMALS 20
561 #define MAP_MIN_ANIMALS 0
562 #define MAP_MAX_ANIMALS 500
564 #define MAP_DEFAULT_MAPSIZE MAPSIZE_FULLSIZE
566 /* Size of the map in thousands of tiles. If MAP_MAX_SIZE is increased,
567 * MAX_DBV_LENGTH in bitvector.c must be checked; see the static assertion
570 #define MAP_DEFAULT_SIZE 3
571 #define MAP_MIN_SIZE 0
572 #define MAP_MAX_SIZE 18
573 #else /* FREECIV_WEB */
574 #define MAP_DEFAULT_SIZE 4
575 #define MAP_MIN_SIZE 0
576 #define MAP_MAX_SIZE 2048
577 #endif /* FREECIV_WEB */
579 FC_STATIC_ASSERT(MAP_MAX_SIZE
* 1000 <= MAX_DBV_LENGTH
,
580 map_too_big_for_bitvector
);
581 /* We communicate through the network with signed 32-bits integers. */
582 FC_STATIC_ASSERT((long unsigned) MAP_MAX_SIZE
* 1000
583 < (long unsigned) 1 << 31,
584 map_too_big_for_network
);
586 #define MAP_DEFAULT_TILESPERPLAYER 100
587 #define MAP_MIN_TILESPERPLAYER 1
588 #define MAP_MAX_TILESPERPLAYER 1000
590 /* This defines the maximum linear size in _native_ coordinates. */
591 #define MAP_DEFAULT_LINEAR_SIZE 64
592 #define MAP_MAX_LINEAR_SIZE (MAP_MAX_SIZE * 1000 / MAP_MIN_LINEAR_SIZE)
593 #define MAP_MIN_LINEAR_SIZE 16
595 /* The distance between two points at a map shouldn't be larger than this.
596 Adds MAP_MIN_LINEAR_SIZE because hex topologies forbids certain diagonal
597 moves. Includes MAP_MAX_LINEAR_SIZE because a map can be non wrapping. */
598 #define MAP_DISTANCE_MAX (MAP_MAX_LINEAR_SIZE + MAP_MIN_LINEAR_SIZE)
600 #define MAP_ORIGINAL_TOPO TF_WRAPX
602 /* Freeciv-web doesn't support isometric maps yet. */
603 #define MAP_DEFAULT_TOPO TF_WRAPX
604 #else /* FREECIV_WEB */
605 #define MAP_DEFAULT_TOPO (TF_WRAPX|TF_ISO|TF_HEX)
606 #endif /* FREECIV_WEB */
608 #define MAP_DEFAULT_SEED 0
609 #define MAP_MIN_SEED 0
610 #define MAP_MAX_SEED (MAX_UINT32 >> 1)
612 #define MAP_DEFAULT_LANDMASS 30
613 #define MAP_MIN_LANDMASS 15
614 #define MAP_MAX_LANDMASS 85
616 #define MAP_DEFAULT_RICHES 250
617 #define MAP_MIN_RICHES 0
618 #define MAP_MAX_RICHES 1000
620 #define MAP_DEFAULT_STEEPNESS 30
621 #define MAP_MIN_STEEPNESS 0
622 #define MAP_MAX_STEEPNESS 100
624 #define MAP_DEFAULT_WETNESS 50
625 #define MAP_MIN_WETNESS 0
626 #define MAP_MAX_WETNESS 100
628 #define MAP_DEFAULT_GENERATOR MAPGEN_RANDOM
630 #define MAP_DEFAULT_STARTPOS MAPSTARTPOS_DEFAULT
632 #define MAP_DEFAULT_TINYISLES FALSE
633 #define MAP_MIN_TINYISLES FALSE
634 #define MAP_MAX_TINYISLES TRUE
636 #define MAP_DEFAULT_SEPARATE_POLES TRUE
637 #define MAP_MIN_SEPARATE_POLES FALSE
638 #define MAP_MAX_SEPARATE_POLES TRUE
640 #define MAP_DEFAULT_FLATPOLES 100
641 #define MAP_MIN_FLATPOLES 0
642 #define MAP_MAX_FLATPOLES 100
644 #define MAP_DEFAULT_SINGLE_POLE FALSE
645 #define MAP_MIN_SINGLE_POLE FALSE
646 #define MAP_MAX_SINGLE_POLE TRUE
648 #define MAP_DEFAULT_ALLTEMPERATE FALSE
649 #define MAP_MIN_ALLTEMPERATE FALSE
650 #define MAP_MAX_ALLTEMPERATE TRUE
652 #define MAP_DEFAULT_TEMPERATURE 50
653 #define MAP_MIN_TEMPERATURE 0
654 #define MAP_MAX_TEMPERATURE 100
656 #define MAP_DEFAULT_TEAM_PLACEMENT TEAM_PLACEMENT_CLOSEST
659 * Inline function definitions. These are at the bottom because they may use
660 * elements defined above.
663 static inline int map_pos_to_index(int map_x
, int map_y
)
665 /* Note: writing this as a macro is hard; it needs temp variables. */
668 CHECK_MAP_POS(map_x
, map_y
);
669 MAP_TO_NATIVE_POS(&nat_x
, &nat_y
, map_x
, map_y
);
670 return native_pos_to_index(nat_x
, nat_y
);
673 static inline int index_to_map_pos_x(int mindex
)
675 /* Note: writing this as a macro is hard; it needs temp variables. */
678 index_to_map_pos(&map_x
, &map_y
, mindex
);
682 static inline int index_to_map_pos_y(int mindex
)
684 /* Note: writing this as a macro is hard; it needs temp variables. */
687 index_to_map_pos(&map_x
, &map_y
, mindex
);
691 /****************************************************************************
692 A "border position" is any map position that _may have_ positions within
693 real map distance dist that are non-normal. To see its correctness,
694 consider the case where dist is 1 or 0.
695 ****************************************************************************/
696 static inline bool is_border_tile(const struct tile
*ptile
, int dist
)
698 /* HACK: An iso-map compresses the value in the X direction but not in
699 * the Y direction. Hence (x+1,y) is 1 tile away while (x,y+2) is also
702 int ydist
= (MAP_IS_ISOMETRIC
? (2 * dist
) : dist
);
705 index_to_native_pos(&nat_x
, &nat_y
, tile_index(ptile
));
707 return (nat_x
< xdist
709 || nat_x
>= wld
.map
.xsize
- xdist
710 || nat_y
>= wld
.map
.ysize
- ydist
);
713 enum direction8
rand_direction(void);
714 enum direction8
opposite_direction(enum direction8 dir
);
718 #endif /* __cplusplus */
720 #endif /* FC__MAP_H */