Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
map.c File Reference
#include "fcintl.h"
#include "iterator.h"
#include "log.h"
#include "mem.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 "unitlist.h"
#include "map.h"
#include "spechash.h"

Go to the source code of this file.

Data Structures

struct  startpos
 
struct  startpos_iter
 

Macros

#define SPECHASH_TAG   startpos
 
#define SPECHASH_IKEY_TYPE   struct tile *
 
#define SPECHASH_IDATA_TYPE   struct startpos *
 
#define SPECHASH_IDATA_FREE   startpos_destroy
 
#define STARTPOS_ITER(p)   ((struct startpos_iter *) (p))
 
#define nat_x   map_x
 
#define nat_y   map_y
 

Functions

static struct startposstartpos_new (struct tile *ptile)
 
static void startpos_destroy (struct startpos *psp)
 
static bool is_valid_dir_calculate (enum direction8 dir)
 
static bool is_cardinal_dir_calculate (enum direction8 dir)
 
static bool restrict_infra (const struct player *pplayer, const struct tile *t1, const struct tile *t2)
 
bv_extras get_tile_infrastructure_set (const struct tile *ptile, int *pcount)
 
bool map_is_empty (void)
 
void map_init (struct civ_map *imap, bool server_side)
 
static void generate_map_indices (void)
 
void map_init_topology (struct civ_map *nmap)
 
static void tile_init (struct tile *ptile)
 
struct tilemapstep (const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
 
static struct tilebase_native_pos_to_tile (const struct civ_map *nmap, int nat_x, int nat_y)
 
struct tilemap_pos_to_tile (const struct civ_map *nmap, int map_x, int map_y)
 
struct tilenative_pos_to_tile (const struct civ_map *nmap, int nat_x, int nat_y)
 
struct tileindex_to_tile (const struct civ_map *imap, int mindex)
 
static void tile_free (struct tile *ptile)
 
void map_allocate (struct civ_map *amap)
 
void main_map_allocate (void)
 
void map_free (struct civ_map *fmap, bool server_side)
 
void main_map_free (void)
 
static int map_vector_to_distance (int dx, int dy)
 
int map_vector_to_real_distance (int dx, int dy)
 
int map_vector_to_sq_distance (int dx, int dy)
 
int real_map_distance (const struct tile *tile0, const struct tile *tile1)
 
int sq_map_distance (const struct tile *tile0, const struct tile *tile1)
 
int map_distance (const struct tile *tile0, const struct tile *tile1)
 
bool is_safe_ocean (const struct civ_map *nmap, const struct tile *ptile)
 
bool can_reclaim_ocean (const struct civ_map *nmap, const struct tile *ptile)
 
bool can_channel_land (const struct civ_map *nmap, const struct tile *ptile)
 
bool can_thaw_terrain (const struct civ_map *nmap, const struct tile *ptile)
 
bool can_freeze_terrain (const struct civ_map *nmap, const struct tile *ptile)
 
bool terrain_surroundings_allow_change (const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain)
 
int get_continent_size (Continent_id id)
 
int get_ocean_size (Continent_id id)
 
int get_island_surrounder (Continent_id id)
 
int get_lake_surrounder (Continent_id id)
 
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)
 
bool is_tiles_adjacent (const struct tile *tile0, const struct tile *tile1)
 
bool same_pos (const struct tile *tile1, const struct tile *tile2)
 
bool is_real_map_pos (const struct civ_map *nmap, int x, int y)
 
bool is_normal_map_pos (int x, int y)
 
bool normalize_map_pos (const struct civ_map *nmap, int *x, int *y)
 
struct tilenearest_real_tile (const struct civ_map *nmap, int x, int y)
 
int map_num_tiles (void)
 
void base_map_distance_vector (int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
 
void map_distance_vector (int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
 
struct tilerand_map_pos (const struct civ_map *nmap)
 
struct tilerand_map_pos_filtered (const struct civ_map *nmap, void *data, bool(*filter)(const struct tile *ptile, const void *data))
 
const chardir_get_name (enum direction8 dir)
 
enum direction8 dir_cw (enum direction8 dir)
 
enum direction8 dir_ccw (enum direction8 dir)
 
bool is_valid_dir (enum direction8 dir)
 
bool map_untrusted_dir_is_valid (enum direction8 dir)
 
bool is_cardinal_dir (enum direction8 dir)
 
bool base_get_direction_for_step (const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile, enum direction8 *dir)
 
int get_direction_for_step (const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
 
bool is_move_cardinal (const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile)
 
static double map_relative_southness (const struct tile *ptile)
 
int map_signed_latitude (const struct tile *ptile)
 
bool is_singular_tile (const struct tile *ptile, int dist)
 
struct startposmap_startpos_by_number (int id)
 
int startpos_number (const struct startpos *psp)
 
bool startpos_allow (struct startpos *psp, struct nation_type *pnation)
 
bool startpos_disallow (struct startpos *psp, struct nation_type *pnation)
 
struct tilestartpos_tile (const struct startpos *psp)
 
bool startpos_nation_allowed (const struct startpos *psp, const struct nation_type *pnation)
 
bool startpos_allows_all (const struct startpos *psp)
 
bool startpos_pack (const struct startpos *psp, struct packet_edit_startpos_full *packet)
 
bool startpos_unpack (struct startpos *psp, const struct packet_edit_startpos_full *packet)
 
bool startpos_is_excluding (const struct startpos *psp)
 
const struct nation_hashstartpos_raw_nations (const struct startpos *psp)
 
size_t startpos_iter_sizeof (void)
 
static void startpos_exclude_iter_next (struct iterator *startpos_iter)
 
static voidstartpos_exclude_iter_get (const struct iterator *startpos_iter)
 
static bool startpos_exclude_iter_valid (const struct iterator *startpos_iter)
 
struct iteratorstartpos_iter_init (struct startpos_iter *iter, const struct startpos *psp)
 
int map_startpos_count (void)
 
struct startposmap_startpos_new (struct tile *ptile)
 
struct startposmap_startpos_get (const struct tile *ptile)
 
bool map_startpos_remove (struct tile *ptile)
 
size_t map_startpos_iter_sizeof (void)
 
struct iteratormap_startpos_iter_init (struct map_startpos_iter *iter)
 
enum direction8 rand_direction (void)
 
enum direction8 opposite_direction (enum direction8 dir)
 

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

◆ SPECHASH_IDATA_FREE

#define SPECHASH_IDATA_FREE   startpos_destroy

Definition at line 53 of file map.c.

◆ SPECHASH_IDATA_TYPE

#define SPECHASH_IDATA_TYPE   struct startpos *

Definition at line 52 of file map.c.

◆ SPECHASH_IKEY_TYPE

#define SPECHASH_IKEY_TYPE   struct tile *

Definition at line 51 of file map.c.

◆ SPECHASH_TAG

#define SPECHASH_TAG   startpos

Definition at line 50 of file map.c.

◆ STARTPOS_ITER

#define STARTPOS_ITER (   p)    ((struct startpos_iter *) (p))

Definition at line 64 of file map.c.

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 1469 of file map.c.

Referenced by do_attack(), get_direction_for_step(), 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 1162 of file map.c.

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 410 of file map.c.

Referenced by map_pos_to_tile(), and native_pos_to_tile().

◆ can_channel_land()

bool can_channel_land ( const struct civ_map nmap,
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 744 of file map.c.

Referenced by terrain_surroundings_allow_change().

◆ can_freeze_terrain()

bool can_freeze_terrain ( const struct civ_map nmap,
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 773 of file map.c.

Referenced by terrain_surroundings_allow_change().

◆ can_reclaim_ocean()

bool can_reclaim_ocean ( const struct civ_map nmap,
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 729 of file map.c.

Referenced by terrain_surroundings_allow_change().

◆ can_thaw_terrain()

bool can_thaw_terrain ( const struct civ_map nmap,
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 758 of file map.c.

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 1344 of file map.c.

Referenced by api_utilities_dir_ccw(), fill_terrain_sprite_array(), and gui_to_map_dir().

◆ dir_cw()

enum direction8 dir_cw ( enum direction8  dir)

Returns the next direction clock-wise.

Definition at line 1315 of file map.c.

Referenced by api_utilities_dir_cw(), fill_terrain_sprite_array(), map_to_gui_dir(), 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 1287 of file map.c.

Referenced by handle_unit_orders(), make_path_orders(), and pf_path_print_real().

◆ generate_map_indices()

static void generate_map_indices ( void  )
static

Fill the iterate_outwards_indices array. This may depend on the topology.

Definition at line 212 of file map.c.

Referenced by main_map_allocate().

◆ get_continent_size()

int get_continent_size ( Continent_id  id)

Return size in tiles of the given continent (not ocean)

Definition at line 819 of file map.c.

Referenced by calculate_want_for_paratrooper(), initialize_isle_data(), is_valid_start_pos(), and popup_info_text().

◆ 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 1488 of file map.c.

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

◆ get_island_surrounder()

int get_island_surrounder ( Continent_id  id)

Get the single ocean surrounding a given island, a positive value if there isn't one single surrounding ocean, or 0 if client-side and there could still be one but we don't know any concrete candidate.

Definition at line 842 of file map.c.

Referenced by does_region_surrounder_match(), and popup_info_text().

◆ get_lake_surrounder()

int get_lake_surrounder ( Continent_id  id)

Get the single continent surrounding a given lake, a negative value if there isn't one single surrounding continent, or 0 if client-side and there could still be one but we don't know any concrete candidate.

Definition at line 875 of file map.c.

Referenced by does_region_surrounder_match(), and popup_info_text().

◆ get_ocean_size()

int get_ocean_size ( Continent_id  id)

Return size in tiles of the given ocean. You should use positive ocean number.

Definition at line 830 of file map.c.

Referenced by popup_info_text().

◆ 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 100 of file map.c.

Referenced by actres_possible().

◆ index_to_tile()

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

Return the tile for the given index position.

Definition at line 471 of file map.c.

Referenced by act_sel_new_extra_tgt_callback(), act_sel_new_unit_tgt_callback(), chatwdg::anchor_clicked(), api_find_tile_by_index(), attack(), base(), clean(), cultivate(), disembark1(), disembark2(), enter_hut(), enter_hut2(), event_after(), event_after(), event_cache_save(), execute_call(), execute_orders(), fair_map_island_new(), fair_map_make_huts(), frighten_hut(), frighten_hut2(), handle_chat_msg(), handle_city_info(), handle_city_make_specialist(), handle_city_make_worker(), handle_city_short_info(), handle_early_chat_msg(), handle_edit_city_create(), handle_edit_player_vision(), handle_edit_startpos(), handle_edit_startpos(), handle_edit_startpos_full(), handle_edit_startpos_full(), handle_edit_tile(), handle_edit_tile_extra(), handle_edit_tile_terrain(), handle_edit_unit_create(), handle_edit_unit_remove(), handle_nuke_tile_info(), handle_player_diplstate(), handle_player_place_infra(), handle_tile_info(), handle_unit_action_answer(), handle_unit_action_query(), handle_unit_actions(), handle_unit_get_actions(), handle_unit_orders(), handle_unit_sscs_set(), handle_worker_task(), handle_worker_task(), irrigate(), link_mark_tile(), map_startpos_by_number(), mine(), name_new_city_popup_callback(), notify_conn_packet(), nuke(), objtype_get_object_from_id(), paradrop(), paradrop_conquer(), paradrop_enter(), paradrop_enter_conquer(), paradrop_frighten(), paradrop_frighten_conquer(), pf_danger_map_iterate(), pf_fuel_map_iterate(), pf_jumbo_map_iterate(), pf_normal_map_iterate(), pillage(), plant(), popup_newcity_dialog(), regular_move(), request_action_details_callback(), road(), sg_load_map_owner(), sg_load_map_owner(), simple_action_callback(), simple_action_callback(), suicide_attack(), texai_city_info_recv(), texai_tile_info_recv(), texai_unit_info_recv(), texai_unit_moved_recv(), text_tag_start_sequence(), transform_terrain(), unit_order_list_is_sane(), unit_perform_action(), unpackage_short_unit(), unpackage_unit(), and upgrade_unit_order_targets().

◆ 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 1457 of file map.c.

Referenced by api_utilities_direction_is_cardinal(), fair_map_island_new(), and get_connect_irrig().

◆ 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 1431 of file map.c.

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 1507 of file map.c.

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 1099 of file map.c.

Referenced by event_cache_load(), and is_normal_nat_pos().

◆ is_real_map_pos()

bool is_real_map_pos ( const struct civ_map nmap,
int  x,
int  y 
)

Is given position real position

Definition at line 1088 of file map.c.

◆ 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 712 of file map.c.

Referenced by can_exist_at_tile(), can_unit_survive_at_tile(), is_possible_base_fuel(), is_refuel_tile(), pf_get_move_scope(), remove_city(), try_summon_barbarians(), unit_move_to_tile_test(), and unit_teleport_to_tile_test().

◆ 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 1723 of file map.c.

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() instead.

Definition at line 1401 of file map.c.

Referenced by api_utilities_dir2str(), api_utilities_dir_ccw(), api_utilities_dir_cw(), get_unittype_sprite(), goto_path_redraw(), goto_path_undraw(), 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 1374 of file map.c.

Referenced by map_init_topology().

◆ main_map_allocate()

void main_map_allocate ( void  )

Allocate main map and related global structures.

Definition at line 534 of file map.c.

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

◆ main_map_free()

void main_map_free ( void  )

Free main map and related global structures.

Definition at line 599 of file map.c.

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 508 of file map.c.

Referenced by main_map_allocate(), and texai_map_init().

◆ map_distance()

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

◆ 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 1213 of file map.c.

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(), team_placement_vertical(), and update_selection_rectangle().

◆ map_free()

void map_free ( struct civ_map fmap,
bool  server_side 
)

Frees the allocated memory of the map.

Definition at line 545 of file map.c.

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 156 of file map.c.

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

◆ map_init_topology()

void map_init_topology ( struct civ_map nmap)

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 315 of file map.c.

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

◆ map_is_empty()

bool map_is_empty ( void  )

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 148 of file map.c.

Referenced by generator_validate(), handle_map_info(), leave_mapcanvas(), map_canvas_draw(), map_canvas_draw(), map_canvas_resized(), map_fractal_generate(), mapimg_create(), server_remove_player(), set_rulesetdir(), setting_is_free_to_change(), sg_save_map(), srv_ready(), texai_thread_start(), tile_map_check(), and unqueue_mapview_updates().

◆ map_num_tiles()

int map_num_tiles ( void  )

◆ map_pos_to_tile()

struct tile * map_pos_to_tile ( const struct civ_map nmap,
int  map_x,
int  map_y 
)

◆ map_relative_southness()

static double map_relative_southness ( const struct tile ptile)
static

Returns the relative southness of this map position. This is a value in the range of [0.0, 1.0]. This function handles all topology-specific information so that all other generator code can work in a topology-agnostic way.

Relative southness is 0.0 at the northernmost point and 1.0 at the southernmost point on the map. These may or may not be polar regions (depending on various generator settings). On a map representing only a northern hemisphere, southness directly corresponds to colatitude, going from 0.0 at the pole to 1.0 at the equator. On a map representing only a southern hemisphere, it directly corrsponds to (negative) latitude, going from 0.0 at the equator to 1.0 at the pole.

See also map_signed_latitude()

Definition at line 1538 of file map.c.

Referenced by map_signed_latitude().

◆ map_signed_latitude()

int map_signed_latitude ( const struct tile ptile)

Returns the latitude of this map position. This is a value in the range of -MAP_MAX_LATITUDE to MAP_MAX_LATITUDE (inclusive).

Latitude reaches MAP_MAX_LATITUDE in the northern polar region, reaches -MAP_MAX_LATITUDE in the southern polar region, and is around 0 in the tropics.

Definition at line 1692 of file map.c.

Referenced by is_latitude_req_active(), map_colatitude(), and popup_info_text().

◆ map_startpos_by_number()

struct startpos * map_startpos_by_number ( int  id)

Returns the start position associated to the given ID.

Definition at line 1767 of file map.c.

Referenced by objtype_get_object_from_id().

◆ map_startpos_count()

int map_startpos_count ( void  )

◆ map_startpos_get()

struct startpos * map_startpos_get ( const struct tile ptile)

◆ map_startpos_iter_init()

struct iterator * map_startpos_iter_init ( struct map_startpos_iter iter)

Implementation of iterator init function. NB: map_sp_iter just wraps startpos_hash_iter.

Definition at line 2075 of file map.c.

◆ map_startpos_iter_sizeof()

size_t map_startpos_iter_sizeof ( void  )

Implementation of iterator sizeof function. NB: map_sp_iter just wraps startpos_hash_iter.

Definition at line 2066 of file map.c.

◆ 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 2021 of file map.c.

Referenced by create_start_positions(), handle_edit_startpos(), handle_edit_startpos(), map_generate_fair_islands(), sg_load_map_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 2054 of file map.c.

Referenced by handle_edit_startpos(), and 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 1414 of file map.c.

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 609 of file map.c.

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 623 of file map.c.

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 659 of file map.c.

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

◆ mapstep()

struct tile * mapstep ( const struct civ_map nmap,
const struct tile ptile,
enum direction8  dir 
)

◆ native_pos_to_tile()

struct tile * native_pos_to_tile ( const struct civ_map nmap,
int  nat_x,
int  nat_y 
)

◆ 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 1133 of file map.c.

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_tile() on these values.

Definition at line 1117 of file map.c.

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(), is_real_map_pos(), 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 2092 of file map.c.

Referenced by api_utilities_opposite_dir(), and do_attack().

◆ rand_direction()

enum direction8 rand_direction ( void  )

Return random direction that is valid in current map.

Definition at line 2084 of file map.c.

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 1228 of file map.c.

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 not nullptr it shouldn't have any side effects.

Definition at line 1242 of file map.c.

Referenced by create_start_positions(), and rand_map_pos_characteristic().

◆ real_map_distance()

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

◆ 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 1047 of file map.c.

Referenced by tile_move_cost_ptrs().

◆ same_pos()

bool same_pos ( const struct tile tile1,
const struct tile tile2 
)

◆ 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 1787 of file map.c.

Referenced by map_generate_fair_islands(), sg_load_map_startpos(), and 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 1843 of file map.c.

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

◆ startpos_destroy()

static void startpos_destroy ( struct startpos psp)
static

Free all memory allocated by the start position.

Definition at line 1756 of file map.c.

◆ 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 1804 of file map.c.

Referenced by sg_load_map_startpos(), and sg_load_map_startpos().

◆ startpos_exclude_iter_get()

static void * startpos_exclude_iter_get ( const struct iterator startpos_iter)
static

Implementation of iterator 'get' function. Returns a struct nation_type pointer.

NB: This is only used for the case where 'exclude' is set in the start position.

Definition at line 1960 of file map.c.

Referenced by startpos_iter_init().

◆ startpos_exclude_iter_next()

static void startpos_exclude_iter_next ( struct iterator startpos_iter)
static

Implementation of iterator 'next' function.

NB: This is only used for the case where 'exclude' is set in the start position.

Definition at line 1941 of file map.c.

Referenced by startpos_iter_init().

◆ startpos_exclude_iter_valid()

static bool startpos_exclude_iter_valid ( const struct iterator startpos_iter)
static

Implementation of iterator 'valid' function.

Definition at line 1970 of file map.c.

Referenced by startpos_iter_init().

◆ 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 1903 of file map.c.

Referenced by objbind_get_value_from_object(), and sg_save_map_startpos().

◆ startpos_iter_init()

struct iterator * startpos_iter_init ( struct startpos_iter iter,
const struct startpos psp 
)

Initialize and return an iterator for the nations at this start position.

Definition at line 1980 of file map.c.

◆ startpos_iter_sizeof()

size_t startpos_iter_sizeof ( void  )

Implementation of iterator 'sizeof' function.

struct startpos_iter can be either a 'struct nation_hash_iter', a 'struct nation_iter' or 'struct startpos_iter'.

Definition at line 1929 of file map.c.

◆ 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 1830 of file map.c.

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 1742 of file map.c.

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 1776 of file map.c.

Referenced by handle_edit_startpos_full(), objtype_get_id_from_object(), 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 1854 of file map.c.

Referenced by edithand_send_initial_packets(), and objbind_pack_current_values().

◆ startpos_raw_nations()

const struct nation_hash * 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 1916 of file map.c.

Referenced by objbind_get_value_from_object(), and 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 1820 of file map.c.

Referenced by edithand_send_initial_packets(), init_new_game(), is_valid_start_pos(), objbind_get_value_from_object(), 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 1875 of file map.c.

Referenced by handle_edit_startpos_full(), and handle_edit_startpos_full().

◆ terrain_surroundings_allow_change()

bool terrain_surroundings_allow_change ( const struct civ_map nmap,
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 787 of file map.c.

Referenced by actres_possible(), 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 489 of file map.c.

Referenced by map_free().

◆ tile_init()

static void tile_init ( struct tile ptile)
static

Initialize tile structure

Definition at line 363 of file map.c.

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 912 of file map.c.

Referenced by map_move_cost(), and map_move_cost_unit().

Variable Documentation

◆ dir_cardinality

bool dir_cardinality[9]
static

Definition at line 88 of file map.c.

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 85 of file map.c.

Referenced by draw_segment(), and scroll_mapview().

◆ DIR_DY

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

Definition at line 86 of file map.c.

Referenced by draw_segment(), and scroll_mapview().

◆ dir_validity

bool dir_validity[9]
static

Definition at line 89 of file map.c.

Referenced by is_valid_dir(), and map_init_topology().

◆ terrain_control

struct terrain_misc terrain_control