51#define SPECHASH_TAG startpos
52#define SPECHASH_IKEY_TYPE struct tile *
53#define SPECHASH_IDATA_TYPE struct startpos *
54#define SPECHASH_IDATA_FREE startpos_destroy
65#define STARTPOS_ITER(p) ((struct startpos_iter *) (p))
86const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
87const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
96 const struct tile *t2);
112 bool dependency =
FALSE;
204 int nat_center_x, nat_center_y, nat_min_x, nat_min_y, nat_max_x, nat_max_y;
205 int map_center_x, map_center_y;
223 nat_center_x, nat_center_y);
251 tiles = (nat_max_x - nat_min_x + 1) * (nat_max_y - nat_min_y + 1);
259 int map_x, map_y, dx, dy;
267 dx = map_x - map_center_x;
268 dy = map_y - map_center_y;
283 for (i = 0; i < tiles; i++) {
325 for (dir = 0; dir < 8; dir++) {
356 ptile->
units = unit_list_new();
370 const struct tile *ptile,
enum direction8 dir)
372 int dx, dy, tile_x, tile_y;
426 if (nmap->
tiles == NULL) {
444 if (nmap->
tiles == NULL) {
461 return imap->
tiles + mindex;
474 unit_list_destroy(ptile->
units);
493 log_debug(
"map_allocate (was %p) (%d,%d)",
503 ptile->index = ptile - amap->
tiles;
569 return abs(dx) + abs(dy);
578 const int absdx = abs(dx), absdy = abs(dy);
583 if ((dx < 0 && dy > 0)
584 || (dx > 0 && dy < 0)) {
587 return absdx + absdy;
590 return MAX(absdx, absdy);
594 if ((dx > 0 && dy > 0)
595 || (dx < 0 && dy < 0)) {
598 return absdx + absdy;
601 return MAX(absdx, absdy);
605 return MAX(absdx, absdy);
621 return dx * dx + dy * dy;
683 const struct tile *ptile)
698 const struct tile *ptile)
712 const struct tile *ptile)
727 const struct tile *ptile)
741 const struct tile *ptile,
742 const struct terrain *pterrain)
781 const struct player *pplayer,
782 const struct tile *t1,
const struct tile *t2)
786 signed char cardinal_move = -1;
844 if (proad->
move_mode == RMM_FAST_ALWAYS) {
847 if (cardinal_move < 0) {
851 if (cardinal_move > 0) {
873 case RMM_FAST_ALWAYS:
891 if (cardinal_move < 0) {
895 if (cardinal_move == 0) {
896 return cost * 181 >> 7;
910 const struct tile *t2)
1023 int x0dv,
int y0dv,
int x1dv,
int y1dv)
1072 const struct tile *tile0,
1073 const struct tile *tile1)
1075 int tx0, ty0, tx1, ty1;
1100 bool (*filter)(
const struct tile *ptile,
1111 }
while (filter != NULL && !filter(ptile, data) && ++tries < max_tries);
1115 if (filter == NULL) {
1117 }
else if (tries == max_tries) {
1118 int count = 0, *positions;
1123 if (filter(check_tile, data)) {
1150 case DIR8_NORTHEAST:
1154 case DIR8_SOUTHEAST:
1158 case DIR8_SOUTHWEST:
1162 case DIR8_NORTHWEST:
1177 return DIR8_NORTHEAST;
1178 case DIR8_NORTHEAST:
1181 return DIR8_SOUTHEAST;
1182 case DIR8_SOUTHEAST:
1185 return DIR8_SOUTHWEST;
1186 case DIR8_SOUTHWEST:
1189 return DIR8_NORTHWEST;
1190 case DIR8_NORTHWEST:
1206 return DIR8_NORTHWEST;
1207 case DIR8_NORTHEAST:
1210 return DIR8_NORTHEAST;
1211 case DIR8_SOUTHEAST:
1214 return DIR8_SOUTHEAST;
1215 case DIR8_SOUTHWEST:
1218 return DIR8_SOUTHWEST;
1219 case DIR8_NORTHWEST:
1234 case DIR8_SOUTHEAST:
1235 case DIR8_NORTHWEST:
1238 case DIR8_NORTHEAST:
1239 case DIR8_SOUTHWEST:
1273 if (!direction8_is_valid(dir)) {
1296 case DIR8_SOUTHEAST:
1297 case DIR8_NORTHWEST:
1300 case DIR8_NORTHEAST:
1301 case DIR8_SOUTHWEST:
1327 const struct tile *start_tile,
1328 const struct tile *end_tile,
1329 enum direction8 *dir)
1332 if (
same_pos(end_tile, test_tile)) {
1346 const struct tile *start_tile,
1347 const struct tile *end_tile)
1349 enum direction8 dir;
1364 const struct tile *start_tile,
1365 const struct tile *end_tile)
1368 if (
same_pos(end_tile, test_tile)) {
1409 psp->
nations = nation_hash_new();
1420 nation_hash_destroy(psp->
nations);
1453 return nation_hash_insert(psp->
nations, pnation, NULL);
1455 return nation_hash_remove(psp->
nations, pnation);
1470 return nation_hash_remove(psp->
nations, pnation);
1472 return nation_hash_insert(psp->
nations, pnation, NULL);
1502 return (0 == nation_hash_size(psp->
nations));
1537 nation_hash_clear(psp->
nations);
1543 nation_hash_insert(psp->
nations, pnation, NULL);
1583 -
sizeof(
struct iterator), nation_hash_iter_sizeof());
1640 return nation_hash_key_iter_init((
struct nation_hash_iter *) iter,
1716 return startpos_hash_iter_sizeof();
1725 return startpos_hash_value_iter_init((
struct startpos_hash_iter *) iter,
1742 return direction8_max() - dir;
#define CALL_FUNC_EACH_AI(_func,...)
#define BV_ISSET(bv, bit)
#define BV_ISSET_ANY(vec)
void generate_city_map_indices(void)
int compare_iter_index(const void *a, const void *b)
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
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 int cost
struct iterator * invalid_iter_init(struct iterator *it)
static void * iterator_get(const struct iterator *it)
static bool iterator_valid(const struct iterator *it)
static void iterator_next(struct iterator *it)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
bv_extras get_tile_infrastructure_set(const struct tile *ptile, int *pcount)
bool can_channel_land(const struct civ_map *nmap, const struct tile *ptile)
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)
static int map_vector_to_distance(int dx, int dy)
enum direction8 opposite_direction(enum direction8 dir)
bool is_move_cardinal(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
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)
struct startpos * map_startpos_new(struct tile *ptile)
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)
static void tile_free(struct tile *ptile)
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
int get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
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)
struct tile * rand_map_pos(const struct civ_map *nmap)
static bool restrict_infra(const struct player *pplayer, const struct tile *t1, const struct tile *t2)
static struct tile * base_native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
static void generate_map_indices(void)
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)
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
void map_allocate(struct civ_map *amap)
void map_init_topology(struct civ_map *nmap)
void main_map_allocate(void)
static bool dir_validity[9]
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
static struct startpos * startpos_new(struct tile *ptile)
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
static bool is_valid_dir_calculate(enum direction8 dir)
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
static bool is_cardinal_dir_calculate(enum direction8 dir)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
int map_vector_to_sq_distance(int dx, int dy)
bool map_startpos_remove(struct tile *ptile)
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)
size_t startpos_iter_sizeof(void)
bool is_cardinal_dir(enum direction8 dir)
static void tile_init(struct tile *ptile)
bool same_pos(const struct tile *tile1, const struct tile *tile2)
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)
bool is_valid_dir(enum direction8 dir)
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
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)
static void startpos_destroy(struct startpos *psp)
struct terrain_misc terrain_control
static void * startpos_exclude_iter_get(const struct iterator *startpos_iter)
struct tile * nearest_real_tile(const struct civ_map *nmap, int x, int y)
bool base_get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile, enum direction8 *dir)
static void startpos_exclude_iter_next(struct iterator *startpos_iter)
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
static bool dir_cardinality[9]
void map_init(struct civ_map *imap, bool server_side)
bool startpos_is_excluding(const struct startpos *psp)
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)
static bool startpos_exclude_iter_valid(const struct iterator *startpos_iter)
struct iterator * startpos_iter_init(struct startpos_iter *iter, const struct startpos *psp)
bool is_real_map_pos(const struct civ_map *nmap, int x, int y)
bool is_singular_tile(const struct tile *ptile, int dist)
int map_vector_to_real_distance(int dx, int dy)
#define current_topo_has_flag(flag)
#define MAP_MAX_LINEAR_SIZE
#define adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr)
#define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y)
#define MAP_DEFAULT_LINEAR_SIZE
#define MAP_DEFAULT_STARTPOS
#define MAP_DEFAULT_ANIMALS
#define MAP_DEFAULT_TEAM_PLACEMENT
#define CHECK_INDEX(mindex)
#define cardinal_between_iterate(nmap, tile1, tile2, between)
#define MAP_DEFAULT_MAPSIZE
#define MAP_MIN_LINEAR_SIZE
#define MAP_DEFAULT_LANDMASS
#define adjc_iterate(nmap, center_tile, itr_tile)
#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y)
#define ALL_DIRECTIONS_CARDINAL()
#define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y)
#define cardinal_adjc_dir_iterate_end
#define MAP_DEFAULT_SINGLE_POLE
#define MAP_DEFAULT_SEPARATE_POLES
#define MAP_DEFAULT_RICHES
#define MAP_DEFAULT_TINYISLES
#define whole_map_iterate(_map, _tile)
#define MAP_DEFAULT_TILESPERPLAYER
#define adjc_dir_iterate_end
#define MAP_DEFAULT_TEMPERATURE
#define MAP_DEFAULT_ALLTEMPERATE
#define cardinal_between_iterate_end
#define MAP_DEFAULT_GENERATOR
#define do_in_natural_pos_end
#define MAP_DEFAULT_WETNESS
#define native_pos_to_index_nocheck(nat_x, nat_y)
#define cardinal_adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr)
#define whole_map_iterate_end
#define index_to_map_pos(pmap_x, pmap_y, mindex)
#define MAP_DEFAULT_STEEPNESS
#define DIRSTEP(dest_x, dest_y, dir)
#define fc_calloc(n, esz)
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
Nation_type_id nation_number(const struct nation_type *pnation)
struct iterator * nation_iter_init(struct nation_iter *it)
size_t nation_iter_sizeof(void)
#define nation_hash_iterate(nationhash, pnation)
#define nations_iterate_end
#define nations_iterate(NAME_pnation)
#define nation_hash_iterate_end
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
#define CLIP(lower, current, upper)
#define FC_WRAP(value, range)
struct packet_game_info info
struct startpos_hash * startpos_table
enum direction8 valid_dirs[8]
int num_iterate_outwards_indices
enum mapsize_type mapsize
enum map_startpos startpos
struct iter_index * iterate_outwards_indices
struct civ_map::@41::@43 server
enum team_placement team_placement
enum direction8 cardinal_dirs[8]
enum map_generator generator
bool(* valid)(const struct iterator *it)
void *(* get)(const struct iterator *it)
void(* next)(struct iterator *it)
bv_startpos_nations nations
enum road_move_mode move_mode
struct extra_type_list * integrators
const struct startpos * psp
struct iterator nation_iter
struct nation_hash * nations
struct extra_type * resource
struct player * extras_owner
struct extra_type * placing
struct unit_class::@85 cache
struct extra_type_list * bonus_roads
int count_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_class tclass)
int count_terrain_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_flag_id flag)
#define is_ocean(pterrain)
#define terrain_has_flag(terr, flag)
void tile_virtual_destroy(struct tile *vtile)
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
struct tile * tile_virtual_new(const struct tile *ptile)
void * tile_hash_key(const struct tile *ptile)
struct city * tile_city(const struct tile *ptile)
#define tile_terrain(_tile)
#define tile_has_extra(ptile, pextra)
#define tile_owner(_tile)
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
static bool utype_has_flag(const struct unit_type *punittype, int flag)