57 const int DIR_DX[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
58 const int DIR_DY[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
67 const struct tile *t1,
const struct tile *t2);
84 bool dependency =
false;
91 missingset,
nullptr,
nullptr,
nullptr,
92 nullptr,
nullptr, &pdependant->reqs,
134 imap->
tiles =
nullptr;
152 imap->
server.huts_absolute = -1;
164 imap->
server.have_huts =
false;
165 imap->
server.have_resources =
false;
176 int nat_center_x, nat_center_y, nat_min_x, nat_min_y, nat_max_x, nat_max_y;
177 int map_center_x, map_center_y;
227 tiles = (nat_max_x - nat_min_x + 1) * (nat_max_y - nat_min_y + 1);
234 int map_x, map_y, dx, dy;
242 dx = map_x - map_center_x;
243 dy = map_y - map_center_y;
258 for (i = 0; i < tiles; i++) {
298 for (
int dir = 0; dir < 8; dir++) {
329 ptile->
units = unit_list_new();
330 ptile->
owner =
nullptr;
346 int dx, dy, tile_x, tile_y;
367 static inline struct tile *
401 if (nmap->
tiles ==
nullptr) {
419 if (nmap->
tiles ==
nullptr) {
436 return imap->
tiles + mindex;
449 unit_list_destroy(ptile->
units);
454 delete[] ptile->
label;
455 ptile->
label =
nullptr;
475 ptile->index = ptile - amap->
tiles;
481 amap->
startpos_table =
new QHash<struct tile *, struct startpos *>;
506 delete[] fmap->
tiles;
507 fmap->
tiles =
nullptr;
542 return abs(dx) + abs(dy);
551 const int absdx = abs(dx), absdy = abs(dy);
556 if ((dx < 0 && dy > 0) || (dx > 0 && dy < 0)) {
559 return absdx + absdy;
562 return MAX(absdx, absdy);
566 if ((dx > 0 && dy > 0) || (dx < 0 && dy < 0)) {
569 return absdx + absdy;
572 return MAX(absdx, absdy);
576 return MAX(absdx, absdy);
592 return dx * dx + dy * dy;
707 const struct terrain *pterrain)
745 const struct player *pplayer,
const struct tile *t1,
746 const struct tile *t2)
751 bool cardinality_checked =
false;
788 if (proad->
move_mode == RMM_FAST_ALWAYS) {
791 if (!cardinality_checked) {
794 cardinality_checked =
true;
823 case RMM_FAST_ALWAYS:
844 if (!cardinality_checked) {
848 if (!cardinal_move) {
849 return cost * 181 >> 7;
863 const struct tile *t1,
const struct tile *t2)
867 if (!pplayer || !
game.
info.restrictinfra) {
1013 const struct tile *tile1)
1015 int tx0, ty0, tx1, ty1;
1040 bool (*filter)(
const struct tile *ptile,
1051 }
while (filter && !filter(ptile, data) && ++tries < max_tries);
1055 if (tries == max_tries) {
1056 int count = 0, *positions;
1062 if (filter && filter(check_tile, data)) {
1090 case DIR8_NORTHEAST:
1094 case DIR8_SOUTHEAST:
1098 case DIR8_SOUTHWEST:
1102 case DIR8_NORTHWEST:
1112 enum direction8
dir_cw(
enum direction8 dir)
1117 return DIR8_NORTHEAST;
1118 case DIR8_NORTHEAST:
1121 return DIR8_SOUTHEAST;
1122 case DIR8_SOUTHEAST:
1125 return DIR8_SOUTHWEST;
1126 case DIR8_SOUTHWEST:
1129 return DIR8_NORTHWEST;
1130 case DIR8_NORTHWEST:
1141 enum direction8
dir_ccw(
enum direction8 dir)
1146 return DIR8_NORTHWEST;
1147 case DIR8_NORTHEAST:
1150 return DIR8_NORTHEAST;
1151 case DIR8_SOUTHEAST:
1154 return DIR8_SOUTHEAST;
1155 case DIR8_SOUTHWEST:
1158 return DIR8_SOUTHWEST;
1159 case DIR8_NORTHWEST:
1174 case DIR8_SOUTHEAST:
1175 case DIR8_NORTHWEST:
1179 case DIR8_NORTHEAST:
1180 case DIR8_SOUTHWEST:
1214 if (!direction8_is_valid(dir)) {
1237 case DIR8_SOUTHEAST:
1238 case DIR8_NORTHWEST:
1241 case DIR8_NORTHEAST:
1242 case DIR8_SOUTHWEST:
1268 const struct tile *start_tile,
1269 const struct tile *end_tile,
1270 enum direction8 *dir)
1274 if (
same_pos(end_tile, test_tile)) {
1289 const struct tile *start_tile,
1290 const struct tile *end_tile)
1292 enum direction8 dir;
1307 const struct tile *start_tile,
1308 const struct tile *end_tile)
1312 if (
same_pos(end_tile, test_tile)) {
1355 psp->exclude =
false;
1356 psp->nations =
new QSet<const struct nation_type *>();
1389 bool ret = psp->
nations->contains(pnation);
1390 psp->
nations->remove(pnation);
1393 psp->
nations->insert(pnation);
1406 bool ret = psp->
nations->contains(pnation);
1407 psp->
nations->remove(pnation);
1411 psp->
nations->insert(pnation);
1442 return (psp->
nations->isEmpty());
1450 struct packet_edit_startpos_full *packet)
1456 packet->exclude = psp->
exclude;
1459 for (
const auto *pnation : qAsConst(*psp->
nations)) {
1470 const struct packet_edit_startpos_full *packet)
1475 psp->
exclude = packet->exclude;
1481 for (
const auto &pnation :
nations) {
1483 psp->
nations->insert(&pnation);
1508 QSet<const struct nation_type *> *
1591 return direction8(direction8_max() - dir);
#define CALL_FUNC_EACH_AI(_func,...)
bool BV_ISSET(const BV &bv, int bit)
#define BV_ISSET_ANY(vec)
void generate_city_map_indices()
Fill the arrays city_map_index, city_map_xy and city_map_numtiles.
int compare_iter_index(const void *a, const void *b)
Compare two iter_index values from the city_map_index.
#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)
Return a bitfield of the extras on the tile that are infrastructure.
bool terrain_surroundings_allow_change(const struct tile *ptile, const struct terrain *pterrain)
Returns FALSE if a terrain change to 'pterrain' would be prevented by not having enough similar terra...
bool is_normal_map_pos(int x, int y)
Returns TRUE iff the map position is normal.
int startpos_number(const struct startpos *psp)
Returns the unique ID number for this start position.
void map_free(struct civ_map *fmap)
Frees the allocated memory of the map.
bool startpos_disallow(struct startpos *psp, struct nation_type *pnation)
Disallow the nation to start at the start position.
bool can_thaw_terrain(const struct tile *ptile)
Returns true if the tile at the given location can be thawed from terrain with a 'Frozen' flag to ter...
static int map_vector_to_distance(int dx, int dy)
Return the "distance" (which is really the Manhattan distance, and should rarely be used) for a given...
enum direction8 opposite_direction(enum direction8 dir)
Return direction that is opposite to given one.
bool is_move_cardinal(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
Returns TRUE iff the move from the position (start_x,start_y) to (end_x,end_y) is a cardinal one.
static void generate_map_indices()
Fill the iterate_outwards_indices array.
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Return squared distance between two tiles.
void main_map_free()
Free main map and related global structures.
struct tile * rand_map_pos(const struct civ_map *nmap)
Random square anywhere on the map.
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Return the tile for the given cartesian (map) position.
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)
The basic cost to move punit from tile t1 to tile t2.
static void tile_free(struct tile *ptile)
Free memory associated with one tile.
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
Returns TRUE if the given nation can start here.
static struct tile * base_native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
Return the tile for the given native position, with wrapping.
int get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
Return the direction which is needed for a step on the map from (start_x, start_y) to (end_x,...
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
bool startpos_allows_all(const struct startpos *psp)
Returns TRUE if any nation can start here.
bool can_channel_land(const struct tile *ptile)
This function returns true if the tile at the given location can be "channeled" from land into ocean.
static bool restrict_infra(const struct player *pplayer, const struct tile *t1, const struct tile *t2)
Returns TRUE if there is a restriction with regard to the infrastructure, i.e.
enum direction8 dir_ccw(enum direction8 dir)
Returns the next direction counter-clock-wise.
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Are two tiles adjacent to each other.
int map_startpos_count()
Is there start positions set for map.
struct startpos * map_startpos_get(const struct tile *ptile)
Returns the start position at the given tile, or nullptr if none exists there.
void map_allocate(struct civ_map *amap)
Allocate space for map, and initialise the tiles.
struct tile * nearest_real_tile(const struct civ_map *nmap, int x, int y)
Twiddle *x and *y to point to the nearest real tile, and ensure that the position is normalized.
static bool dir_validity[9]
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Return TRUE if this ocean terrain is adjacent to a safe coastline.
static struct startpos * startpos_new(struct tile *ptile)
Create a new, empty start position.
enum direction8 rand_direction()
Return random direction that is valid in current map.
bool startpos_pack(const struct startpos *psp, struct packet_edit_startpos_full *packet)
Fills the packet with all of the information at this start position.
static bool is_valid_dir_calculate(enum direction8 dir)
Returns TRUE iff the given direction is a valid one.
bool can_reclaim_ocean(const struct tile *ptile)
This function returns true if the tile at the given location can be "reclaimed" from ocean into land.
static bool is_cardinal_dir_calculate(enum direction8 dir)
Returns TRUE iff the given direction is a cardinal one.
int map_vector_to_sq_distance(int dx, int dy)
Return the sq_distance for a given vector.
bool map_startpos_remove(struct tile *ptile)
Remove the start position at the given tile.
bool can_freeze_terrain(const struct tile *ptile)
Returns true if the tile at the given location can be turned from terrain without a 'Frozen' flag to ...
struct startpos * map_startpos_new(struct tile *ptile)
Create a new start position at the given tile and return it.
const char * dir_get_name(enum direction8 dir)
Return the debugging name of the direction.
bool is_cardinal_dir(enum direction8 dir)
Returns TRUE iff the given direction is a cardinal one.
static void tile_init(struct tile *ptile)
Initialize tile structure.
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
bool map_untrusted_dir_is_valid(enum direction8 dir)
Returns TRUE iff the given direction is a valid one.
struct tile * startpos_tile(const struct startpos *psp)
Returns the tile where this start position is located.
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
bool startpos_unpack(struct startpos *psp, const struct packet_edit_startpos_full *packet)
Fills the start position with the nation information in the packet.
bool is_valid_dir(enum direction8 dir)
Returns TRUE iff the given direction is a valid one.
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Finds the difference between the two (unnormalized) positions, in cartesian (map) coordinates.
enum direction8 dir_cw(enum direction8 dir)
Returns the next direction clock-wise.
QSet< const struct nation_type * > * startpos_raw_nations(const struct startpos *psp)
Return a the nations hash, used for the property editor.
void map_init_topology()
map_init_topology needs to be called after map.topology_id is changed.
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
Return the tile for the given native position.
static void startpos_destroy(struct startpos *psp)
Free all memory allocated by the start position.
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Return the tile for the given index position.
struct terrain_misc terrain_control
void main_map_allocate()
Allocate main map and related global structures.
bool base_get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile, enum direction8 *dir)
Return TRUE and sets dir to the direction of the step if (end_x, end_y) can be reached from (start_x,...
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Topology function to find the vector which has the minimum "real" distance between the map positions ...
static bool dir_cardinality[9]
void map_init(struct civ_map *imap, bool server_side)
Put some sensible values into the map structure.
bool startpos_is_excluding(const struct startpos *psp)
Returns TRUE if the nations returned by startpos_raw_nations() are actually excluded from the nations...
int map_distance(const struct tile *tile0, const struct tile *tile1)
Return Manhattan distance between two tiles.
struct tile * rand_map_pos_filtered(const struct civ_map *nmap, void *data, bool(*filter)(const struct tile *ptile, const void *data))
Give a random tile anywhere on the map for which the 'filter' function returns TRUE.
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
bool startpos_allow(struct startpos *psp, struct nation_type *pnation)
Allow the nation to start at the start position.
bool normalize_map_pos(const struct civ_map *nmap, int *x, int *y)
If the position is real, it will be normalized and TRUE will be returned.
bool is_singular_tile(const struct tile *ptile, int dist)
A "SINGULAR" position is any map position that has an abnormal number of tiles in the radius of dist.
int map_vector_to_real_distance(int dx, int dy)
Return the "real" distance for a given vector.
#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)
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
std::vector< nation_type > nations
Nation_type_id nation_index(const struct nation_type *pnation)
Return the nation index.
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Returns true iff players can attack each other.
bool are_reqs_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Check if road provides effect.
#define CLIP(lower, current, upper)
#define FC_WRAP(value, range)
#define BAD_HEURISTIC_INIT(_ini_val_)
struct packet_game_info info
enum direction8 valid_dirs[8]
int num_iterate_outwards_indices
struct iter_index * iterate_outwards_indices
enum direction8 cardinal_dirs[8]
QHash< struct tile *, struct startpos * > * startpos_table
struct civ_map::@39::@41 server
enum road_move_mode move_mode
struct extra_type_list * integrators
QSet< const struct nation_type * > * nations
struct extra_type * resource
struct player * extras_owner
struct extra_type * placing
struct unit_class::@81 cache
struct extra_type_list * bonus_roads
int count_terrain_flag_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_flag_id flag)
Return the number of adjacent tiles that have terrain with the given flag (not including ptile itself...
int count_terrain_class_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_class tclass)
Return the number of adjacent tiles that have given terrain class (not including ptile itself).
#define is_ocean(pterrain)
#define terrain_has_flag(terr, flag)
void tile_virtual_destroy(struct tile *vtile)
Frees all memory used by the virtual tile, including freeing virtual units in the tile's unit list an...
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Removes extra from tile if such exist.
bool tile_virtual_check(const tile *vtile)
Check if the given tile is a virtual one or not.
struct tile * tile_virtual_new(const struct tile *ptile)
Returns a virtual tile.
#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)