Freeciv21
Develop your civilization from humble roots to a global empire
map.cpp File Reference
#include <QSet>
#include <cstring>
#include <stdexcept>
#include "log.h"
#include "rand.h"
#include "shared.h"
#include "support.h"
#include "ai.h"
#include "city.h"
#include "game.h"
#include "movement.h"
#include "nation.h"
#include "packets.h"
#include "road.h"
#include "unit.h"
#include "map.h"
+ Include dependency graph for map.cpp:

Go to the source code of this file.

Macros

#define nat_x   map_x
 
#define nat_y   map_y
 

Functions

static struct startposstartpos_new (struct tile *ptile)
 Create a new, empty start position. More...
 
static void startpos_destroy (struct startpos *psp)
 Free all memory allocated by the start position. More...
 
static bool is_valid_dir_calculate (enum direction8 dir)
 Returns TRUE iff the given direction is a valid one. More...
 
static bool is_cardinal_dir_calculate (enum direction8 dir)
 Returns TRUE iff the given direction is a cardinal one. More...
 
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. More...
 
bv_extras get_tile_infrastructure_set (const struct tile *ptile, int *pcount)
 Return a bitfield of the extras on the tile that are infrastructure. More...
 
bool map_is_empty ()
 Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded. More...
 
void map_init (struct civ_map *imap, bool server_side)
 Put some sensible values into the map structure. More...
 
static void generate_map_indices ()
 Fill the iterate_outwards_indices array. More...
 
void map_init_topology ()
 map_init_topology needs to be called after map.topology_id is changed. More...
 
static void tile_init (struct tile *ptile)
 Initialize tile structure. More...
 
struct tilemapstep (const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
 Step from the given tile in the given direction. More...
 
static struct tilebase_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. More...
 
struct tilemap_pos_to_tile (const struct civ_map *nmap, int map_x, int map_y)
 Return the tile for the given cartesian (map) position. More...
 
struct tilenative_pos_to_tile (const struct civ_map *nmap, int nat_x, int nat_y)
 Return the tile for the given native position. More...
 
struct tileindex_to_tile (const struct civ_map *imap, int mindex)
 Return the tile for the given index position. More...
 
static void tile_free (struct tile *ptile)
 Free memory associated with one tile. More...
 
void map_allocate (struct civ_map *amap)
 Allocate space for map, and initialise the tiles. More...
 
void main_map_allocate ()
 Allocate main map and related global structures. More...
 
void map_free (struct civ_map *fmap)
 Frees the allocated memory of the map. More...
 
void main_map_free ()
 Free main map and related global structures. More...
 
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 vector. More...
 
int map_vector_to_real_distance (int dx, int dy)
 Return the "real" distance for a given vector. More...
 
int map_vector_to_sq_distance (int dx, int dy)
 Return the sq_distance for a given vector. More...
 
int real_map_distance (const struct tile *tile0, const struct tile *tile1)
 Return real distance between two tiles. More...
 
int sq_map_distance (const struct tile *tile0, const struct tile *tile1)
 Return squared distance between two tiles. More...
 
int map_distance (const struct tile *tile0, const struct tile *tile1)
 Return Manhattan distance between two tiles. More...
 
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. More...
 
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. More...
 
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. More...
 
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 terrain without. More...
 
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 terrain with. More...
 
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 terrain surrounding ptile. More...
 
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. More...
 
bool is_tiles_adjacent (const struct tile *tile0, const struct tile *tile1)
 Are two tiles adjacent to each other. More...
 
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 places... More...
 
bool is_normal_map_pos (int x, int y)
 Returns TRUE iff the map position is normal. More...
 
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. More...
 
struct tilenearest_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. More...
 
int map_num_tiles ()
 Returns the total number of (real) positions (or tiles) on the map. More...
 
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. More...
 
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 (x0, y0) and (x1, y1). More...
 
struct tilerand_map_pos (const struct civ_map *nmap)
 Random square anywhere on the map. More...
 
struct tilerand_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. More...
 
const char * dir_get_name (enum direction8 dir)
 Return the debugging name of the direction. More...
 
enum direction8 dir_cw (enum direction8 dir)
 Returns the next direction clock-wise. More...
 
enum direction8 dir_ccw (enum direction8 dir)
 Returns the next direction counter-clock-wise. More...
 
bool is_valid_dir (enum direction8 dir)
 Returns TRUE iff the given direction is a valid one. More...
 
bool map_untrusted_dir_is_valid (enum direction8 dir)
 Returns TRUE iff the given direction is a valid one. More...
 
bool is_cardinal_dir (enum direction8 dir)
 Returns TRUE iff the given direction is a cardinal one. More...
 
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, start_y) in one step. More...
 
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, end_y). More...
 
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. More...
 
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. More...
 
int startpos_number (const struct startpos *psp)
 Returns the unique ID number for this start position. More...
 
bool startpos_allow (struct startpos *psp, struct nation_type *pnation)
 Allow the nation to start at the start position. More...
 
bool startpos_disallow (struct startpos *psp, struct nation_type *pnation)
 Disallow the nation to start at the start position. More...
 
struct tilestartpos_tile (const struct startpos *psp)
 Returns the tile where this start position is located. More...
 
bool startpos_nation_allowed (const struct startpos *psp, const struct nation_type *pnation)
 Returns TRUE if the given nation can start here. More...
 
bool startpos_allows_all (const struct startpos *psp)
 Returns TRUE if any nation can start here. More...
 
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. More...
 
bool startpos_unpack (struct startpos *psp, const struct packet_edit_startpos_full *packet)
 Fills the start position with the nation information in the packet. More...
 
bool startpos_is_excluding (const struct startpos *psp)
 Returns TRUE if the nations returned by startpos_raw_nations() are actually excluded from the nations allowed to start at this position. More...
 
QSet< const struct nation_type * > * startpos_raw_nations (const struct startpos *psp)
 Return a the nations hash, used for the property editor. More...
 
int map_startpos_count ()
 Is there start positions set for map. More...
 
struct startposmap_startpos_new (struct tile *ptile)
 Create a new start position at the given tile and return it. More...
 
struct startposmap_startpos_get (const struct tile *ptile)
 Returns the start position at the given tile, or nullptr if none exists there. More...
 
bool map_startpos_remove (struct tile *ptile)
 Remove the start position at the given tile. More...
 
enum direction8 rand_direction ()
 Return random direction that is valid in current map. More...
 
enum direction8 opposite_direction (enum direction8 dir)
 Return direction that is opposite to given one. More...
 

Variables

struct terrain_misc terrain_control
 
const int DIR_DX [8] = {-1, 0, 1, -1, 1, -1, 0, 1}
 
const int DIR_DY [8] = {-1, -1, -1, 0, 0, 1, 1, 1}
 
static bool dir_cardinality [9]
 
static bool dir_validity [9]
 

Macro Definition Documentation

◆ nat_x

#define nat_x   map_x

◆ nat_y

#define nat_y   map_y

Function Documentation

◆ base_get_direction_for_step()

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, start_y) in one step.

Return FALSE otherwise (value of dir is unchanged in this case).

Definition at line 1267 of file map.cpp.

Referenced by do_attack(), get_direction_for_step(), is_valid_goto_draw_line(), mapdeco_set_gotoroute(), unit_bombard(), and unit_move().

◆ base_map_distance_vector()

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.

Most callers should use map_distance_vector instead.

Definition at line 961 of file map.cpp.

Referenced by client_city_tile(), draw_calculated_trade_routes(), gui_distance_vector(), map_distance_vector(), tile_to_canvas_pos(), and trade_route_to_canvas_lines().

◆ base_native_pos_to_tile()

static struct tile* base_native_pos_to_tile ( const struct civ_map nmap,
int  nat_x,
int  nat_y 
)
inlinestatic

Return the tile for the given native position, with wrapping.

This is a backend function used by map_pos_to_tile and native_pos_to_tile. It is called extremely often so it is made inline.

Definition at line 368 of file map.cpp.

Referenced by map_pos_to_tile(), and native_pos_to_tile().

◆ can_channel_land()

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.

This is the case only when there are a sufficient number of adjacent tiles that are ocean.

Definition at line 668 of file map.cpp.

Referenced by terrain_surroundings_allow_change().

◆ can_freeze_terrain()

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 terrain with.

This requires a sufficient number of adjacent frozen tiles.

Definition at line 694 of file map.cpp.

Referenced by terrain_surroundings_allow_change().

◆ can_reclaim_ocean()

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.

This is the case only when there are a sufficient number of adjacent tiles that are not ocean.

Definition at line 655 of file map.cpp.

Referenced by terrain_surroundings_allow_change().

◆ can_thaw_terrain()

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 terrain without.

This requires a sufficient number of adjacent unfrozen tiles.

Definition at line 681 of file map.cpp.

Referenced by terrain_surroundings_allow_change().

◆ dir_ccw()

enum direction8 dir_ccw ( enum direction8  dir)

Returns the next direction counter-clock-wise.

Definition at line 1084 of file map.cpp.

Referenced by api_utilities_dir_ccw(), and freeciv::layer_terrain::fill_terrain_sprite_array().

◆ dir_cw()

enum direction8 dir_cw ( enum direction8  dir)

Returns the next direction clock-wise.

Definition at line 1084 of file map.cpp.

Referenced by api_utilities_dir_cw(), freeciv::layer_terrain::fill_terrain_sprite_array(), tileset_read_toplevel(), and tileset_setup_unit_direction().

◆ dir_get_name()

const char* dir_get_name ( enum direction8  dir)

Return the debugging name of the direction.

Definition at line 1084 of file map.cpp.

Referenced by handle_unit_orders(), make_path_orders(), and operator<<().

◆ generate_map_indices()

static void generate_map_indices ( )
static

Fill the iterate_outwards_indices array.

This may depend on the topology.

Definition at line 173 of file map.cpp.

Referenced by main_map_allocate().

◆ get_direction_for_step()

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, end_y).

Definition at line 1288 of file map.cpp.

Referenced by make_path_orders(), request_unit_non_action_move(), and mr_menu::slot_execute_orders().

◆ get_tile_infrastructure_set()

bv_extras get_tile_infrastructure_set ( const struct tile ptile,
int *  pcount 
)

Return a bitfield of the extras on the tile that are infrastructure.

Definition at line 72 of file map.cpp.

◆ index_to_tile()

struct tile* index_to_tile ( const struct civ_map imap,
int  mindex 
)

◆ is_cardinal_dir()

bool is_cardinal_dir ( enum direction8  dir)

Returns TRUE iff the given direction is a cardinal one.

Cardinal directions are those in which adjacent tiles share an edge not just a vertex.

Definition at line 1255 of file map.cpp.

Referenced by fair_map_island_new().

◆ is_cardinal_dir_calculate()

static bool is_cardinal_dir_calculate ( enum direction8  dir)
static

Returns TRUE iff the given direction is a cardinal one.

Does not use value from the cache, but can be used to calculate the cache.

Cardinal directions are those in which adjacent tiles share an edge not just a vertex.

Definition at line 1229 of file map.cpp.

Referenced by map_init_topology().

◆ is_move_cardinal()

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.

Definition at line 1306 of file map.cpp.

Referenced by is_native_move(), and tile_move_cost_ptrs().

◆ is_normal_map_pos()

bool is_normal_map_pos ( int  x,
int  y 
)

Returns TRUE iff the map position is normal.

"Normal" here means that it is both a real/valid coordinate set and that the coordinates are in their canonical/proper form. In plain English: the coordinates must be on the map.

Definition at line 902 of file map.cpp.

Referenced by event_cache_load().

◆ is_safe_ocean()

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.

Definition at line 636 of file map.cpp.

Referenced by can_exist_at_tile(), can_unit_survive_at_tile(), is_possible_base_fuel(), is_unit_being_refueled(), and try_summon_barbarians().

◆ is_singular_tile()

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.

(map_x, map_y) must be normalized.

dist is the "real" map distance.

Definition at line 1329 of file map.cpp.

Referenced by near_singularity().

◆ is_tiles_adjacent()

bool is_tiles_adjacent ( const struct tile tile0,
const struct tile tile1 
)

◆ is_valid_dir()

bool is_valid_dir ( enum direction8  dir)

Returns TRUE iff the given direction is a valid one.

If the direction could be out of range you should use map_untrusted_dir_is_valid() in stead.

Definition at line 1199 of file map.cpp.

Referenced by api_utilities_dir_ccw(), api_utilities_dir_cw(), get_unittype_sprite(), luascript_dir(), map_untrusted_dir_is_valid(), and mapstep().

◆ is_valid_dir_calculate()

static bool is_valid_dir_calculate ( enum direction8  dir)
static

Returns TRUE iff the given direction is a valid one.

Does not use value from the cache, but can be used to calculate the cache.

Definition at line 1171 of file map.cpp.

Referenced by map_init_topology().

◆ main_map_allocate()

void main_map_allocate ( )

Allocate main map and related global structures.

Definition at line 487 of file map.cpp.

Referenced by handle_map_info(), map_generate(), sg_load_map_tiles(), and srv_ready().

◆ main_map_free()

void main_map_free ( )

Free main map and related global structures.

Definition at line 525 of file map.cpp.

Referenced by game_free(), game_reset(), and srv_ready().

◆ map_allocate()

void map_allocate ( struct civ_map amap)

Allocate space for map, and initialise the tiles.

Uses current map.xsize and map.ysize.

Definition at line 462 of file map.cpp.

Referenced by main_map_allocate(), and texai_map_init().

◆ map_distance()

int map_distance ( const struct tile tile0,
const struct tile tile1 
)

Return Manhattan distance between two tiles.

Definition at line 623 of file map.cpp.

Referenced by area_is_too_flat(), city_incite_cost(), dai_fill_unit_param(), search_homecity_for_caravan(), and unit_bribe_cost().

◆ map_distance_vector()

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 (x0, y0) and (x1, y1).

If there is more than one vector with equal distance, no guarantee is made about which is found.

Real distance is defined as the larger of the distances in the x and y direction; since units can travel diagonally this is the "real" distance a unit has to travel to get from point to point.

(See also: real_map_distance, map_distance, and sq_map_distance.)

With the standard topology the ranges of the return value are: -map.xsize/2 <= dx <= map.xsize/2 -map.ysize < dy < map.ysize

Definition at line 1012 of file map.cpp.

Referenced by city_tile_to_city_map(), do_move_unit(), edit_buffer_paste(), editor_get_selection_center(), map_claim_border(), map_distance(), real_map_distance(), sq_map_distance(), team_placement_horizontal(), and team_placement_vertical().

◆ map_free()

void map_free ( struct civ_map fmap)

Frees the allocated memory of the map.

Definition at line 498 of file map.cpp.

Referenced by handle_map_info(), main_map_free(), and texai_map_close().

◆ map_init()

void map_init ( struct civ_map imap,
bool  server_side 
)

Put some sensible values into the map structure.

Definition at line 129 of file map.cpp.

Referenced by game_init(), game_reset(), and texai_map_init().

◆ map_init_topology()

void map_init_topology ( )

map_init_topology needs to be called after map.topology_id is changed.

map.xsize and map.ysize must be set before calling map_init_topology(). This is done by the map generator code (server), when loading a savegame or a scenario with map (server), and packhand code (client).

Definition at line 276 of file map.cpp.

Referenced by generator_init_topology(), handle_map_info(), and sg_load_map_tiles().

◆ map_is_empty()

bool map_is_empty ( )

Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.

(To be precise, returns TRUE if map_allocate() has not yet been called.)

Definition at line 124 of file map.cpp.

Referenced by generator_validate(), handle_map_info(), map_canvas_resized(), map_generate(), mapimg_create(), player_limit_to_max_rates(), set_rulesetdir(), setting_is_free_to_change(), sg_save_map(), srv_ready(), texai_thread_start(), tile_virtual_check(), and freeciv::renderer::unqueue_updates().

◆ map_num_tiles()

◆ map_pos_to_tile()

◆ map_startpos_count()

int map_startpos_count ( )

◆ map_startpos_get()

struct startpos* map_startpos_get ( const struct tile ptile)

Returns the start position at the given tile, or nullptr if none exists there.

Definition at line 1548 of file map.cpp.

Referenced by freeciv::layer_editor::fill_sprite_array(), handle_edit_startpos(), and handle_edit_startpos_full().

◆ map_startpos_new()

struct startpos* map_startpos_new ( struct tile ptile)

Create a new start position at the given tile and return it.

If a start position already exists there, it is first removed.

Definition at line 1531 of file map.cpp.

Referenced by create_start_positions(), handle_edit_startpos(), and sg_load_map_startpos().

◆ map_startpos_remove()

bool map_startpos_remove ( struct tile ptile)

Remove the start position at the given tile.

Returns TRUE if the start position was removed.

Definition at line 1565 of file map.cpp.

Referenced by handle_edit_startpos().

◆ map_untrusted_dir_is_valid()

bool map_untrusted_dir_is_valid ( enum direction8  dir)

Returns TRUE iff the given direction is a valid one.

Doesn't trust the input. Can be used to validate a direction from an untrusted source.

Definition at line 1212 of file map.cpp.

Referenced by unit_order_list_is_sane().

◆ map_vector_to_distance()

static int map_vector_to_distance ( int  dx,
int  dy 
)
static

Return the "distance" (which is really the Manhattan distance, and should rarely be used) for a given vector.

Definition at line 535 of file map.cpp.

Referenced by map_distance().

◆ map_vector_to_real_distance()

int map_vector_to_real_distance ( int  dx,
int  dy 
)

Return the "real" distance for a given vector.

Definition at line 549 of file map.cpp.

Referenced by generate_map_indices(), get_closest_safe_tile_distance(), map_vector_to_distance(), map_vector_to_sq_distance(), real_distance_to_land(), and real_map_distance().

◆ map_vector_to_sq_distance()

int map_vector_to_sq_distance ( int  dx,
int  dy 
)

Return the sq_distance for a given vector.

Definition at line 583 of file map.cpp.

Referenced by generate_city_map_indices(), is_valid_city_coords(), map_claim_border(), and sq_map_distance().

◆ mapstep()

◆ native_pos_to_tile()

◆ nearest_real_tile()

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.

Definition at line 935 of file map.cpp.

Referenced by canvas_pos_to_nearest_tile().

◆ normalize_map_pos()

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.

If the position is unreal, it will be left unchanged and FALSE will be returned.

Note, we need to leave x and y with sane values even in the unreal case. Some callers may for instance call nearest_real_pos on these values.

Definition at line 919 of file map.cpp.

Referenced by api_methods_private_tile_for_outward_index(), api_methods_private_tile_next_outward_index(), canvas_pos_to_tile(), fair_map_place_island_team(), and overview_to_map_pos().

◆ opposite_direction()

enum direction8 opposite_direction ( enum direction8  dir)

Return direction that is opposite to given one.

Definition at line 1565 of file map.cpp.

Referenced by api_utilities_opposite_dir(), do_attack(), and is_valid_goto_draw_line().

◆ rand_direction()

enum direction8 rand_direction ( )

Return random direction that is valid in current map.

Definition at line 1565 of file map.cpp.

Referenced by unit_virtual_create().

◆ rand_map_pos()

struct tile* rand_map_pos ( const struct civ_map nmap)

Random square anywhere on the map.

Only normal positions (for which is_normal_map_pos returns true) will be found.

Definition at line 1026 of file map.cpp.

Referenced by climate_change(), place_animal(), place_island(), and try_summon_barbarians().

◆ rand_map_pos_filtered()

struct tile* rand_map_pos_filtered ( const struct civ_map nmap,
void *  data,
bool(*)(const struct tile *ptile, const void *data)  filter 
)

Give a random tile anywhere on the map for which the 'filter' function returns TRUE.

Return FALSE if none can be found. The filter may be nullptr if any position is okay; if non-nullptr it shouldn't have any side effects.

Definition at line 1039 of file map.cpp.

Referenced by create_start_positions(), and rand_map_pos_characteristic().

◆ real_map_distance()

◆ restrict_infra()

static bool restrict_infra ( const struct player pplayer,
const struct tile t1,
const struct tile t2 
)
static

Returns TRUE if there is a restriction with regard to the infrastructure, i.e.

at least one of the tiles t1 and t2 is claimed by a unfriendly nation. This means that one can not use of the infrastructure (road, railroad) on this tile.

Definition at line 862 of file map.cpp.

Referenced by tile_move_cost_ptrs().

◆ same_pos()

◆ sq_map_distance()

int sq_map_distance ( const struct tile tile0,
const struct tile tile1 
)

◆ startpos_allow()

bool startpos_allow ( struct startpos psp,
struct nation_type pnation 
)

Allow the nation to start at the start position.

NB: in "excluding" mode, this remove the nation from the excluded list.

Definition at line 1385 of file map.cpp.

Referenced by sg_load_map_startpos().

◆ startpos_allows_all()

bool startpos_allows_all ( const struct startpos psp)

Returns TRUE if any nation can start here.

Definition at line 1439 of file map.cpp.

Referenced by generate_players(), init_new_game(), and sg_save_map_startpos().

◆ startpos_destroy()

static void startpos_destroy ( struct startpos psp)
static

Free all memory allocated by the start position.

Definition at line 1364 of file map.cpp.

Referenced by map_free(), and map_startpos_remove().

◆ startpos_disallow()

bool startpos_disallow ( struct startpos psp,
struct nation_type pnation 
)

Disallow the nation to start at the start position.

NB: in "excluding" mode, this add the nation to the excluded list.

Definition at line 1402 of file map.cpp.

Referenced by sg_load_map_startpos().

◆ startpos_is_excluding()

bool startpos_is_excluding ( const struct startpos psp)

Returns TRUE if the nations returned by startpos_raw_nations() are actually excluded from the nations allowed to start at this position.

FIXME: This function exposes the internal implementation and should be removed when no longer needed by the property editor system.

Definition at line 1496 of file map.cpp.

Referenced by sg_save_map_startpos().

◆ startpos_nation_allowed()

bool startpos_nation_allowed ( const struct startpos psp,
const struct nation_type pnation 
)

Returns TRUE if the given nation can start here.

Definition at line 1428 of file map.cpp.

Referenced by generate_players(), init_new_game(), and update_nations_with_startpos().

◆ startpos_new()

static struct startpos * startpos_new ( struct tile ptile)
static

Create a new, empty start position.

Definition at line 1350 of file map.cpp.

Referenced by map_startpos_new().

◆ startpos_number()

int startpos_number ( const struct startpos psp)

Returns the unique ID number for this start position.

This is just the tile index of the tile where this start position is located.

Definition at line 1375 of file map.cpp.

Referenced by handle_edit_startpos_full(), and startpos_pack().

◆ startpos_pack()

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.

Returns TRUE if the packet can be sent.

Definition at line 1449 of file map.cpp.

Referenced by edithand_send_initial_packets().

◆ startpos_raw_nations()

QSet<const struct nation_type *>* startpos_raw_nations ( const struct startpos psp)

Return a the nations hash, used for the property editor.

FIXME: This function exposes the internal implementation and should be removed when no longer needed by the property editor system.

Definition at line 1509 of file map.cpp.

Referenced by sg_save_map_startpos().

◆ startpos_tile()

struct tile* startpos_tile ( const struct startpos psp)

Returns the tile where this start position is located.

Definition at line 1419 of file map.cpp.

Referenced by edithand_send_initial_packets(), init_new_game(), is_valid_start_pos(), and sg_save_map_startpos().

◆ startpos_unpack()

bool startpos_unpack ( struct startpos psp,
const struct packet_edit_startpos_full *  packet 
)

Fills the start position with the nation information in the packet.

Returns TRUE if the start position was changed.

Definition at line 1469 of file map.cpp.

Referenced by handle_edit_startpos_full().

◆ terrain_surroundings_allow_change()

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 terrain surrounding ptile.

Definition at line 706 of file map.cpp.

Referenced by adv_calc_transform(), and climate_change().

◆ tile_free()

static void tile_free ( struct tile ptile)
static

Free memory associated with one tile.

Definition at line 447 of file map.cpp.

Referenced by map_free().

◆ tile_init()

static void tile_init ( struct tile ptile)
static

Initialize tile structure.

Definition at line 322 of file map.cpp.

Referenced by map_allocate().

◆ tile_move_cost_ptrs()

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.

That is, tile_move_cost(), with pre-calculated tile pointers; the tiles are assumed to be adjacent, and the (x,y) values are used only to get the river bonus correct.

May also be used with punit == nullptr, in which case punit tests are not done (for unit-independent results).

Definition at line 743 of file map.cpp.

Referenced by map_move_cost(), and map_move_cost_unit().

Variable Documentation

◆ dir_cardinality

bool dir_cardinality[9]
static

Definition at line 60 of file map.cpp.

Referenced by is_cardinal_dir(), and map_init_topology().

◆ DIR_DX

const int DIR_DX[8] = {-1, 0, 1, -1, 1, -1, 0, 1}

Definition at line 57 of file map.cpp.

Referenced by draw_segment().

◆ DIR_DY

const int DIR_DY[8] = {-1, -1, -1, 0, 0, 1, 1, 1}

Definition at line 58 of file map.cpp.

Referenced by draw_segment().

◆ dir_validity

bool dir_validity[9]
static

Definition at line 61 of file map.cpp.

Referenced by is_valid_dir(), and map_init_topology().

◆ terrain_control