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 */
32 /****************************************************************
33 miscellaneous terrain information
34 *****************************************************************/
35 #define terrain_misc packet_ruleset_terrain_control
37 /* Some types used below. */
40 struct packet_edit_startpos_full
;
45 MAPSIZE_FULLSIZE
= 0, /* Using the number of tiles / 1000. */
46 MAPSIZE_PLAYER
, /* Define the number of (land) tiles per player;
47 * the setting 'landmass' and the number of players
48 * are used to calculate the map size. */
49 MAPSIZE_XYSIZE
/* 'xsize' and 'ysize' are defined. */
60 MAPSTARTPOS_DEFAULT
= 0, /* Generator's choice. */
61 MAPSTARTPOS_SINGLE
, /* One player per continent. */
62 MAPSTARTPOS_2or3
, /* Two on three players per continent. */
63 MAPSTARTPOS_ALL
, /* All players on a single continent. */
64 MAPSTARTPOS_VARIABLE
, /* Depending on size of continents. */
69 enum direction8 valid_dirs
[8], cardinal_dirs
[8];
70 int num_valid_dirs
, num_cardinal_dirs
;
71 struct iter_index
*iterate_outwards_indices
;
72 int num_iterate_outwards_indices
;
73 int xsize
, ysize
; /* native dimensions */
75 int num_oceans
; /* not updated at the client */
77 struct startpos_hash
*startpos_table
;
85 enum mapsize_type mapsize
; /* how the map size is defined */
86 int size
; /* used to calculate [xy]size */
87 int tilesperplayer
; /* tiles per player; used to calculate size */
92 enum map_generator generator
;
93 enum map_startpos startpos
;
101 bool ocean_resources
; /* Resources in the middle of the ocean */
103 bool have_rivers_overlay
; /* only applies if !have_resources */
110 /* Changing these values will break map_init_topology. */
117 /* Parameters for terrain counting functions. */
118 static const bool C_ADJACENT
= FALSE
;
119 static const bool C_CARDINAL
= TRUE
;
120 static const bool C_NUMBER
= FALSE
;
121 static const bool C_PERCENT
= TRUE
;
123 #define MAP_IS_ISOMETRIC (current_topo_has_flag(TF_ISO) || current_topo_has_flag(TF_HEX))
125 #define CURRENT_TOPOLOGY (map.topology_id)
127 #define topo_has_flag(topo, flag) (((topo) & (flag)) != 0)
128 #define current_topo_has_flag(flag) topo_has_flag((CURRENT_TOPOLOGY), (flag))
130 bool map_is_empty(void);
132 void map_init_topology(bool set_sizes
);
133 void map_allocate(void);
136 int map_vector_to_real_distance(int dx
, int dy
);
137 int map_vector_to_sq_distance(int dx
, int dy
);
138 int map_distance(const struct tile
*tile0
, const struct tile
*tile1
);
139 int real_map_distance(const struct tile
*tile0
, const struct tile
*tile1
);
140 int sq_map_distance(const struct tile
*tile0
,const struct tile
*tile1
);
142 bool same_pos(const struct tile
*tile0
, const struct tile
*tile1
);
143 bool base_get_direction_for_step(const struct tile
*src_tile
,
144 const struct tile
*dst_tile
,
145 enum direction8
*dir
);
146 int get_direction_for_step(const struct tile
*src_tile
,
147 const struct tile
*dst_tile
);
150 /* Specific functions for start positions. */
151 struct startpos
*map_startpos_by_number(int id
);
152 int startpos_number(const struct startpos
*psp
);
154 bool startpos_allow(struct startpos
*psp
, struct nation_type
*pnation
);
155 bool startpos_disallow(struct startpos
*psp
, struct nation_type
*pnation
);
157 struct tile
*startpos_tile(const struct startpos
*psp
);
158 bool startpos_nation_allowed(const struct startpos
*psp
,
159 const struct nation_type
*pnation
);
160 bool startpos_allows_all(const struct startpos
*psp
);
162 bool startpos_pack(const struct startpos
*psp
,
163 struct packet_edit_startpos_full
*packet
);
164 bool startpos_unpack(struct startpos
*psp
,
165 const struct packet_edit_startpos_full
*packet
);
167 /* See comment in "common/map.c". */
168 bool startpos_is_excluding(const struct startpos
*psp
);
169 const struct nation_hash
*startpos_raw_nations(const struct startpos
*psp
);
171 /****************************************************************************
172 Iterate over all nations at the start position for which the function
173 startpos_nation_allowed() would return TRUE. This automatically takes into
174 account the value of startpos_is_excluding() and startpos_allows_all() to
175 iterate over the correct set of nations.
176 ****************************************************************************/
177 struct startpos_iter
;
178 size_t startpos_iter_sizeof(void);
179 struct iterator
*startpos_iter_init(struct startpos_iter
*it
,
180 const struct startpos
*psp
);
181 #define startpos_nations_iterate(ARG_psp, NAME_pnation) \
182 generic_iterate(struct startpos_iter, const struct nation_type *, \
183 NAME_pnation, startpos_iter_sizeof, \
184 startpos_iter_init, (ARG_psp))
185 #define startpos_nations_iterate_end generic_iterate_end
188 /* General map start positions functions. */
189 int map_startpos_count(void);
190 struct startpos
*map_startpos_new(struct tile
*ptile
);
191 struct startpos
*map_startpos_get(const struct tile
*ptile
);
192 bool map_startpos_remove(struct tile
*ptile
);
194 /****************************************************************************
195 Iterate over all start positions placed on the map.
196 ****************************************************************************/
197 struct map_startpos_iter
;
198 size_t map_startpos_iter_sizeof(void);
199 struct iterator
*map_startpos_iter_init(struct map_startpos_iter
*iter
);
201 #define map_startpos_iterate(NAME_psp) \
202 generic_iterate(struct map_startpos_iter, struct startpos *, \
203 NAME_psp, map_startpos_iter_sizeof, map_startpos_iter_init)
204 #define map_startpos_iterate_end generic_iterate_end
207 /* Number of index coordinates (for sanity checks and allocations) */
208 #define MAP_INDEX_SIZE (map.xsize * map.ysize)
211 #define CHECK_MAP_POS(x,y) \
212 fc_assert(is_normal_map_pos((x),(y)))
213 #define CHECK_NATIVE_POS(x, y) \
214 fc_assert((x) >= 0 && (x) < map.xsize && (y) >= 0 && (y) < map.ysize)
215 #define CHECK_INDEX(index) \
216 fc_assert((index) >= 0 && (index) < MAP_INDEX_SIZE)
218 #define CHECK_MAP_POS(x,y) ((void)0)
219 #define CHECK_NATIVE_POS(x, y) ((void)0)
220 #define CHECK_INDEX(index) ((void)0)
223 #define native_pos_to_index(nat_x, nat_y) \
224 (CHECK_NATIVE_POS((nat_x), (nat_y)), \
225 (nat_x) + (nat_y) * map.xsize)
226 #define index_to_native_pos(pnat_x, pnat_y, index) \
227 (*(pnat_x) = index_to_native_pos_x(index), \
228 *(pnat_y) = index_to_native_pos_y(index))
229 #define index_to_native_pos_x(index) \
230 ((index) % map.xsize)
231 #define index_to_native_pos_y(index) \
232 ((index) / map.xsize)
234 /* Obscure math. See explanation in doc/HACKING. */
235 #define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
237 ? (*(pmap_x) = ((nat_y) + ((nat_y) & 1)) / 2 + (nat_x), \
238 *(pmap_y) = (nat_y) - *(pmap_x) + map.xsize) \
239 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
241 #define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y) \
243 ? (*(pnat_y) = (map_x) + (map_y) - map.xsize, \
244 *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2) \
245 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
247 #define NATURAL_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y) \
249 ? (*(pmap_x) = ((nat_y) + (nat_x)) / 2, \
250 *(pmap_y) = (nat_y) - *(pmap_x) + map.xsize) \
251 : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
253 #define MAP_TO_NATURAL_POS(pnat_x, pnat_y, map_x, map_y) \
255 ? (*(pnat_y) = (map_x) + (map_y) - map.xsize, \
256 *(pnat_x) = 2 * (map_x) - *(pnat_y)) \
257 : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
260 /* Provide a block to convert from map to native coordinates. This allows
261 * you to use a native version of the map position within the block. Note
262 * that the native position is declared as const and can't be changed
263 * inside the block. */
264 #define do_in_native_pos(nat_x, nat_y, map_x, map_y) \
266 int _nat_x, _nat_y; \
267 MAP_TO_NATIVE_POS(&_nat_x, &_nat_y, map_x, map_y); \
269 const int nat_x = _nat_x, nat_y = _nat_y;
271 #define do_in_native_pos_end \
275 /* Provide a block to convert from map to natural coordinates. This allows
276 * you to use a natural version of the map position within the block. Note
277 * that the natural position is declared as const and can't be changed
278 * inside the block. */
279 #define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) \
281 int _ntl_x, _ntl_y; \
282 MAP_TO_NATURAL_POS(&_ntl_x, &_ntl_y, map_x, map_y); \
284 const int ntl_x = _ntl_x, ntl_y = _ntl_y;
286 #define do_in_natural_pos_end \
290 /* Width and height of the map, in native coordinates. */
291 #define NATIVE_WIDTH map.xsize
292 #define NATIVE_HEIGHT map.ysize
294 /* Width and height of the map, in natural coordinates. */
295 #define NATURAL_WIDTH (MAP_IS_ISOMETRIC ? 2 * map.xsize : map.xsize)
296 #define NATURAL_HEIGHT map.ysize
299 (MAP_IS_ISOMETRIC ? (map.xsize + map.ysize / 2) : map.xsize)
301 (MAP_IS_ISOMETRIC ? (map.xsize + map.ysize / 2) : map.ysize)
303 static inline int map_pos_to_index(int map_x
, int map_y
);
305 /* index_to_map_pos(int *, int *, int) inverts map_pos_to_index */
306 #define index_to_map_pos(pmap_x, pmap_y, index) \
307 (CHECK_INDEX(index), \
308 index_to_native_pos(pmap_x, pmap_y, index), \
309 NATIVE_TO_MAP_POS(pmap_x, pmap_y, *(pmap_x), *(pmap_y)))
310 static inline int index_to_map_pos_x(int index
);
311 static inline int index_to_map_pos_y(int index
);
313 #define DIRSTEP(dest_x, dest_y, dir) \
314 ( (dest_x) = DIR_DX[(dir)], \
315 (dest_y) = DIR_DY[(dir)])
318 * Steps from the tile in the given direction, yielding a new tile (or NULL).
320 * Direct calls to DIR_DXY should be avoided and DIRSTEP should be
321 * used. But to allow dest and src to be the same, as in
322 * MAPSTEP(x, y, x, y, dir)
323 * we bend this rule here.
325 struct tile
*mapstep(const struct tile
*ptile
, enum direction8 dir
);
327 struct tile
*map_pos_to_tile(int x
, int y
);
328 struct tile
*native_pos_to_tile(int nat_x
, int nat_y
);
329 struct tile
*index_to_tile(int index
);
331 bool is_real_map_pos(int x
, int y
);
332 bool is_normal_map_pos(int x
, int y
);
334 bool is_singular_tile(const struct tile
*ptile
, int dist
);
335 bool normalize_map_pos(int *x
, int *y
);
336 struct tile
*nearest_real_tile(int x
, int y
);
337 void base_map_distance_vector(int *dx
, int *dy
,
338 int x0
, int y0
, int x1
, int y1
);
339 void map_distance_vector(int *dx
, int *dy
, const struct tile
*ptile0
,
340 const struct tile
*ptile1
);
341 int map_num_tiles(void);
342 #define map_size_checked() MAX(map_num_tiles() / 1000, 1)
344 struct tile
*rand_neighbour(const struct tile
*ptile
);
345 struct tile
*rand_map_pos(void);
346 struct tile
*rand_map_pos_filtered(void *data
,
347 bool (*filter
)(const struct tile
*ptile
,
350 bool can_be_irrigated(const struct tile
*ptile
,
351 const struct unit
*punit
);
352 bool is_tiles_adjacent(const struct tile
*ptile0
, const struct tile
*ptile1
);
353 bool is_move_cardinal(const struct tile
*src_tile
,
354 const struct tile
*dst_tile
);
355 int map_move_cost_unit(struct unit
*punit
, const struct tile
*ptile
);
356 int map_move_cost(const struct player
*pplayer
, const struct unit_class
*pclass
,
357 const struct tile
*src_tile
,
358 const struct tile
*dst_tile
);
359 bool is_safe_ocean(const struct tile
*ptile
);
360 bv_special
get_tile_infrastructure_set(const struct tile
*ptile
,
362 bv_bases
get_tile_pillageable_base_set(const struct tile
*ptile
, int *pcount
);
363 bv_roads
get_tile_pillageable_road_set(const struct tile
*ptile
, int *pcount
);
365 bool can_channel_land(const struct tile
*ptile
);
366 bool can_reclaim_ocean(const struct tile
*ptile
);
368 extern struct civ_map map
;
370 extern struct terrain_misc terrain_control
;
372 /* This iterates outwards from the starting point. Every tile within max_dist
373 * (including the starting tile) will show up exactly once, in an outward
374 * (based on real map distance) order. The returned values are always real
375 * and are normalized. The starting position must be normal.
377 * See also iterate_outward() */
378 #define iterate_outward_dxy(start_tile, max_dist, _tile, _x, _y) \
380 int _x, _y, _tile##_x, _tile##_y, _start##_x, _start##_y; \
381 struct tile *_tile; \
382 const struct tile *_tile##_start = (start_tile); \
383 int _tile##_max = (max_dist); \
384 int _tile##_index = 0; \
385 index_to_map_pos(&_start##_x, &_start##_y, tile_index(_tile##_start)); \
387 _tile##_index < map.num_iterate_outwards_indices; \
389 if (map.iterate_outwards_indices[_tile##_index].dist > _tile##_max) { \
392 _x = map.iterate_outwards_indices[_tile##_index].dx; \
393 _y = map.iterate_outwards_indices[_tile##_index].dy; \
394 _tile##_x = _x + _start##_x; \
395 _tile##_y = _y + _start##_y; \
396 _tile = map_pos_to_tile(_tile##_x, _tile##_y); \
397 if (NULL == _tile) { \
401 #define iterate_outward_dxy_end \
405 /* See iterate_outward_dxy() */
406 #define iterate_outward(start_tile, max_dist, itr_tile) \
407 iterate_outward_dxy(start_tile, max_dist, itr_tile, _dx_itr, _dy_itr)
409 #define iterate_outward_end iterate_outward_dxy_end
412 * Iterate through all tiles in a square with given center and radius.
413 * The position (x_itr, y_itr) that is returned will be normalized;
414 * unreal positions will be automatically discarded. (dx_itr, dy_itr)
415 * is the standard distance vector between the position and the center
416 * position. Note that when the square is larger than the map the
417 * distance vector may not be the minimum distance vector.
419 #define square_dxy_iterate(center_tile, radius, tile_itr, dx_itr, dy_itr) \
420 iterate_outward_dxy(center_tile, radius, tile_itr, dx_itr, dy_itr)
422 #define square_dxy_iterate_end iterate_outward_dxy_end
425 * Iterate through all tiles in a square with given center and radius.
426 * Positions returned will have adjusted x, and positions with illegal
427 * y will be automatically discarded.
429 #define square_iterate(center_tile, radius, tile_itr) \
430 square_dxy_iterate(center_tile, radius, tile_itr, _dummy_x, dummy_y)
432 #define square_iterate_end square_dxy_iterate_end
435 * Iterate through all tiles in a circle with given center and squared
436 * radius. Positions returned will have adjusted (x, y); unreal
437 * positions will be automatically discarded.
439 #define circle_iterate(center_tile, sq_radius, tile_itr) \
440 circle_dxyr_iterate(center_tile, sq_radius, tile_itr, _dx, _dy, _dr)
442 #define circle_iterate_end \
443 circle_dxyr_iterate_end
445 /* dx, dy, dr are distance from center to tile in x, y and square distance;
446 * do not rely on x, y distance, since they do not work for hex topologies */
447 #define circle_dxyr_iterate(center_tile, sq_radius, \
450 const int _tile##_sq_radius = (sq_radius); \
451 const int _tile##_cr_radius = (int)sqrt((double)MAX(_tile##_sq_radius, 0)); \
453 square_dxy_iterate(center_tile, _tile##_cr_radius, _tile, dx, dy) { \
454 const int dr = map_vector_to_sq_distance(dx, dy); \
456 if (dr <= _tile##_sq_radius) {
458 #define circle_dxyr_iterate_end \
460 } square_dxy_iterate_end; \
463 /* Iterate itr_tile through all map tiles adjacent to the given center map
464 * position, with normalization. Does not include the center position.
465 * The order of positions is unspecified. */
466 #define adjc_iterate(center_tile, itr_tile) \
468 /* Written as a wrapper to adjc_dir_iterate since it's the cleanest and \
469 * most efficient. */ \
470 adjc_dir_iterate(center_tile, itr_tile, ADJC_ITERATE_dir_itr) {
472 #define adjc_iterate_end \
473 } adjc_dir_iterate_end; \
476 /* As adjc_iterate() but also set direction8 iterator variable dir_itr */
477 #define adjc_dir_iterate(center_tile, itr_tile, dir_itr) \
478 adjc_dirlist_iterate(center_tile, itr_tile, dir_itr, \
479 map.valid_dirs, map.num_valid_dirs)
481 #define adjc_dir_iterate_end adjc_dirlist_iterate_end
483 /* Only set direction8 dir_itr (not tile) */
484 #define adjc_dir_base_iterate(center_tile, dir_itr) \
485 adjc_dirlist_base_iterate(center_tile, dir_itr, \
486 map.valid_dirs, map.num_valid_dirs)
488 #define adjc_dir_base_iterate_end \
489 adjc_dirlist_base_iterate_end
491 /* Iterate itr_tile through all map tiles cardinally adjacent to the given
492 * center map position, with normalization. Does not include the center
493 * position. The order of positions is unspecified. */
494 #define cardinal_adjc_iterate(center_tile, itr_tile) \
495 adjc_dirlist_iterate(center_tile, itr_tile, _dir_itr, \
496 map.cardinal_dirs, map.num_cardinal_dirs)
498 #define cardinal_adjc_iterate_end adjc_dirlist_iterate_end
500 /* As cardinal_adjc_iterate but also set direction8 variable dir_itr */
501 #define cardinal_adjc_dir_iterate(center_tile, itr_tile, dir_itr) \
502 adjc_dirlist_iterate(center_tile, itr_tile, dir_itr, \
503 map.cardinal_dirs, map.num_cardinal_dirs)
505 #define cardinal_adjc_dir_iterate_end adjc_dirlist_iterate_end
507 /* Only set direction8 dir_itr (not tile) */
508 #define cardinal_adjc_dir_base_iterate(center_tile, dir_itr) \
509 adjc_dirlist_base_iterate(center_tile, dir_itr, \
510 map.cardinal_dirs, map.num_cardinal_dirs)
512 #define cardinal_adjc_dir_base_iterate_end \
513 adjc_dirlist_base_iterate_end
515 /* Iterate through all tiles cardinally adjacent to both tile1 and tile2 */
516 #define cardinal_between_iterate(tile1, tile2, between) \
517 cardinal_adjc_iterate(tile1, between) { \
518 cardinal_adjc_iterate(between, second) { \
519 if (same_pos(second, tile2)) {
521 #define cardinal_between_iterate_end \
523 } cardinal_adjc_iterate_end; \
524 } cardinal_adjc_iterate_end;
526 /* Iterate through all tiles adjacent to a tile using the given list of
527 * directions. _dir is the directional value, (center_x, center_y) is
528 * the center tile (which must be normalized). The center tile is not
529 * included in the iteration.
531 * This macro should not be used directly. Instead, use adjc_iterate,
532 * cardinal_adjc_iterate, or related iterators. */
533 #define adjc_dirlist_iterate(center_tile, _tile, _dir, \
536 enum direction8 _dir; \
537 int _tile##_x, _tile##_y, _center##_x, _center##_y; \
538 struct tile *_tile; \
539 const struct tile *_tile##_center = (center_tile); \
540 int _tile##_index = 0; \
541 index_to_map_pos(&_center##_x, &_center##_y, tile_index(_tile##_center)); \
543 _tile##_index < (dircount); \
545 _dir = dirlist[_tile##_index]; \
546 DIRSTEP(_tile##_x, _tile##_y, _dir); \
547 _tile##_x += _center##_x; \
548 _tile##_y += _center##_y; \
549 _tile = map_pos_to_tile(_tile##_x, _tile##_y); \
550 if (NULL == _tile) { \
554 #define adjc_dirlist_iterate_end \
558 /* Same as above but without setting the tile. */
559 #define adjc_dirlist_base_iterate(center_tile, _dir, dirlist, dircount) \
561 enum direction8 _dir; \
562 int _tile##_x, _tile##_y, _center##_x, _center##_y; \
563 const struct tile *_tile##_center = (center_tile); \
564 bool _tile##_is_border = is_border_tile(_tile##_center, 1); \
565 int _tile##_index = 0; \
566 index_to_map_pos(&_center##_x, &_center##_y, tile_index(_tile##_center)); \
568 _tile##_index < (dircount); \
570 _dir = dirlist[_tile##_index]; \
571 DIRSTEP(_tile##_x, _tile##_y, _dir); \
572 _tile##_x += _center##_x; \
573 _tile##_y += _center##_y; \
574 if (_tile##_is_border && !normalize_map_pos(&_tile##_x, &_tile##_y)) { \
578 #define adjc_dirlist_base_iterate_end \
582 /* Iterate over all positions on the globe.
583 * Use index positions for cache efficiency. */
584 #define whole_map_iterate(_tile) \
586 struct tile *_tile; \
587 int _tile##_index = 0; \
589 _tile##_index < MAP_INDEX_SIZE; \
591 _tile = map.tiles + _tile##_index;
593 #define whole_map_iterate_end \
597 BV_DEFINE(dir_vector
, 8);
599 /* return the reverse of the direction */
600 #define DIR_REVERSE(dir) (7 - (dir))
602 enum direction8
dir_cw(enum direction8 dir
);
603 enum direction8
dir_ccw(enum direction8 dir
);
604 const char* dir_get_name(enum direction8 dir
);
605 bool is_valid_dir(enum direction8 dir
);
606 bool is_cardinal_dir(enum direction8 dir
);
608 extern const int DIR_DX
[8];
609 extern const int DIR_DY
[8];
611 /* Used for network transmission; do not change. */
612 #define MAP_TILE_OWNER_NULL MAX_UINT8
614 #define MAP_DEFAULT_HUTS 50
615 #define MAP_MIN_HUTS 0
616 #define MAP_MAX_HUTS 500
618 #define MAP_DEFAULT_MAPSIZE MAPSIZE_FULLSIZE
620 /* Size of the map in thousands of tiles. If MAP_MAX_SIZE is increased,
621 * MAX_DBV_LENGTH in bitvector.c must be checked; see the static assertion
623 #define MAP_DEFAULT_SIZE 4
624 #define MAP_MIN_SIZE 0
625 #define MAP_MAX_SIZE 2048
627 FC_STATIC_ASSERT(MAP_MAX_SIZE
* 1000 <= MAX_DBV_LENGTH
,
628 map_too_big_for_bitvector
);
630 #define MAP_DEFAULT_TILESPERPLAYER 100
631 #define MAP_MIN_TILESPERPLAYER 1
632 #define MAP_MAX_TILESPERPLAYER 1000
634 /* This defines the maximum linear size in _map_ coordinates. */
635 #define MAP_DEFAULT_LINEAR_SIZE 64
636 /* 32 * 1024 is 2^15; thus, x*y is <= 2^15 * 2^15 = 2^30. This can be
637 * represented by an signed int as required by the network protocol. */
638 #define MAP_MAX_LINEAR_SIZE (32 * 1024)
639 #define MAP_MIN_LINEAR_SIZE 16
641 #define MAP_ORIGINAL_TOPO TF_WRAPX
642 #define MAP_DEFAULT_TOPO (TF_WRAPX|TF_ISO)
644 #define MAP_DEFAULT_SEED 0
645 #define MAP_MIN_SEED 0
646 #define MAP_MAX_SEED (MAX_UINT32 >> 1)
648 #define MAP_DEFAULT_LANDMASS 30
649 #define MAP_MIN_LANDMASS 15
650 #define MAP_MAX_LANDMASS 85
652 #define MAP_DEFAULT_RICHES 250
653 #define MAP_MIN_RICHES 0
654 #define MAP_MAX_RICHES 1000
656 #define MAP_DEFAULT_STEEPNESS 30
657 #define MAP_MIN_STEEPNESS 0
658 #define MAP_MAX_STEEPNESS 100
660 #define MAP_DEFAULT_WETNESS 50
661 #define MAP_MIN_WETNESS 0
662 #define MAP_MAX_WETNESS 100
664 #define MAP_DEFAULT_GENERATOR MAPGEN_RANDOM
666 #define MAP_DEFAULT_STARTPOS MAPSTARTPOS_DEFAULT
668 #define MAP_DEFAULT_TINYISLES FALSE
669 #define MAP_MIN_TINYISLES FALSE
670 #define MAP_MAX_TINYISLES TRUE
672 #define MAP_DEFAULT_SEPARATE_POLES TRUE
673 #define MAP_MIN_SEPARATE_POLES FALSE
674 #define MAP_MAX_SEPARATE_POLES TRUE
676 #define MAP_DEFAULT_ALLTEMPERATE FALSE
677 #define MAP_MIN_ALLTEMPERATE FALSE
678 #define MAP_MAX_ALLTEMPERATE TRUE
680 #define MAP_DEFAULT_TEMPERATURE 50
681 #define MAP_MIN_TEMPERATURE 0
682 #define MAP_MAX_TEMPERATURE 100
685 * Inline function definitions. These are at the bottom because they may use
686 * elements defined above.
689 static inline int map_pos_to_index(int map_x
, int map_y
)
691 /* Note: writing this as a macro is hard; it needs temp variables. */
694 CHECK_MAP_POS(map_x
, map_y
);
695 MAP_TO_NATIVE_POS(&nat_x
, &nat_y
, map_x
, map_y
);
696 return native_pos_to_index(nat_x
, nat_y
);
699 static inline int index_to_map_pos_x(int index
)
701 /* Note: writing this as a macro is hard; it needs temp variables. */
704 index_to_map_pos(&map_x
, &map_y
, index
);
708 static inline int index_to_map_pos_y(int index
)
710 /* Note: writing this as a macro is hard; it needs temp variables. */
713 index_to_map_pos(&map_x
, &map_y
, index
);
717 /****************************************************************************
718 A "border position" is any map position that _may have_ positions within
719 real map distance dist that are non-normal. To see its correctness,
720 consider the case where dist is 1 or 0.
721 ****************************************************************************/
722 static inline bool is_border_tile(const struct tile
*ptile
, int dist
)
724 /* HACK: An iso-map compresses the value in the X direction but not in
725 * the Y direction. Hence (x+1,y) is 1 tile away while (x,y+2) is also
728 int ydist
= (MAP_IS_ISOMETRIC
? (2 * dist
) : dist
);
731 index_to_native_pos(&nat_x
, &nat_y
, tile_index(ptile
));
733 return (nat_x
< xdist
735 || nat_x
>= map
.xsize
- xdist
736 || nat_y
>= map
.ysize
- ydist
);
739 enum direction8
rand_direction(void);
740 enum direction8
opposite_direction(enum direction8 dir
);
744 #endif /* __cplusplus */
746 #endif /* FC__MAP_H */