Freeciv21
Develop your civilization from humble roots to a global empire
mapgen_utils.cpp File Reference
#include "fcintl.h"
#include "log.h"
#include "rand.h"
#include "support.h"
#include "map.h"
#include "terrain.h"
#include "tile.h"
#include "mapgen_utils.h"
+ Include dependency graph for mapgen_utils.cpp:

Go to the source code of this file.

Macros

#define pmap(_tile)   (placed_map[tile_index(_tile)])
 

Functions

bool placed_map_is_initialized ()
 Return TRUE if initialized. More...
 
void create_placed_map ()
 Create a clean pmap. More...
 
void destroy_placed_map ()
 Free the pmap. More...
 
bool not_placed (const struct tile *ptile)
 Checks if land has not yet been placed on pmap at (x, y) More...
 
void map_set_placed (struct tile *ptile)
 Mark tile terrain as placed. More...
 
void map_unset_placed (struct tile *ptile)
 Mark tile terrain as not placed. More...
 
void set_all_ocean_tiles_placed ()
 Set all oceanics tiles in placed_map. More...
 
void set_placed_near_pos (struct tile *ptile, int dist)
 Set all nearby tiles as placed on pmap. More...
 
void adjust_int_map_filtered (int *int_map, int int_map_max, void *data, bool(*filter)(const struct tile *ptile, const void *data))
 Change the values of the integer map, so that they contain ranking of each tile scaled to [0 . More...
 
void smooth_int_map (int *int_map, bool zeroes_at_edges)
 Apply a Gaussian diffusion filter on the map. More...
 
static void recalculate_lake_surrounders ()
 Calculate lake_surrounders[] array. More...
 
static void assign_continent_flood (struct tile *ptile, bool is_land, int nr)
 Number this tile and nearby tiles with the specified continent number 'nr'. More...
 
void regenerate_lakes ()
 Regenerate all oceanic tiles for small water bodies as lakes. More...
 
int get_lake_surrounders (Continent_id cont)
 Get continent surrounding lake, or -1 if there is multiple continents. More...
 
int get_continent_size (Continent_id id)
 Return size in tiles of the given continent (not ocean) More...
 
int get_ocean_size (Continent_id id)
 Return size in tiles of the given ocean. More...
 
void assign_continent_numbers ()
 Assigns continent and ocean numbers to all tiles, and set map.num_continents and map.num_oceans. More...
 
struct terrainmost_shallow_ocean (bool frozen)
 Return most shallow ocean terrain type. More...
 
struct terrainpick_ocean (int depth, bool frozen)
 Picks an ocean terrain to match the given depth. More...
 
static int real_distance_to_land (const struct tile *ptile, int max)
 Determines the minimal distance to the land. More...
 
static struct terrainmost_adjacent_ocean_type (const struct tile *ptile)
 Determines what is the most popular ocean type arround (need 2/3 of the adjcacent tiles). More...
 
void smooth_water_depth ()
 Makes a simple depth map for all ocean tiles based on their proximity to any land tiles and reassignes ocean terrain types based on their MG_OCEAN_DEPTH property values. More...
 
void generator_free ()
 Free resources allocated by the generator. More...
 
struct terrainpick_terrain_by_flag (enum terrain_flag_id flag)
 Return a random terrain that has the specified flag. More...
 
struct terrainpick_terrain (enum mapgen_terrain_property target, enum mapgen_terrain_property prefer, enum mapgen_terrain_property avoid)
 Pick a terrain based on the target property and a property to avoid. More...
 

Variables

static bool * placed_map
 Map that contains, according to circumstances, information on whether we have already placed terrain (special, hut) here. More...
 
std::vector< Continent_idlake_surrounders
 
std::vector< int > continent_sizes
 
std::vector< int > ocean_sizes
 

Macro Definition Documentation

◆ pmap

#define pmap (   _tile)    (placed_map[tile_index(_tile)])

Definition at line 55 of file mapgen_utils.cpp.

Function Documentation

◆ adjust_int_map_filtered()

void adjust_int_map_filtered ( int *  int_map,
int  int_map_max,
void *  data,
bool(*)(const struct tile *ptile, const void *data)  filter 
)

Change the values of the integer map, so that they contain ranking of each tile scaled to [0 .

. int_map_max]. The lowest 20% of tiles will have values lower than 0.2 * int_map_max.

If filter is non-null then it only tiles for which filter(ptile, data) is TRUE will be considered.

Definition at line 103 of file mapgen_utils.cpp.

Referenced by create_start_positions().

◆ assign_continent_flood()

static void assign_continent_flood ( struct tile ptile,
bool  is_land,
int  nr 
)
static

Number this tile and nearby tiles with the specified continent number 'nr'.

Due to the number of recursion for large maps a non-recursive algorithm is utilised.

is_land tells us whether we are assigning continent numbers or ocean numbers.

Definition at line 270 of file mapgen_utils.cpp.

Referenced by assign_continent_numbers().

◆ assign_continent_numbers()

void assign_continent_numbers ( )

Assigns continent and ocean numbers to all tiles, and set map.num_continents and map.num_oceans.

Recalculates continent and ocean sizes, and lake_surrounders[] arrays.

Continents have numbers 1 to map.num_continents inclusive. Oceans have (negative) numbers -1 to -map.num_oceans inclusive.

Definition at line 437 of file mapgen_utils.cpp.

Referenced by api_edit_change_terrain(), check_edited_tile_terrains(), check_terrain_change(), make_polar_land(), map_generate(), and sg_load_map_tiles().

◆ create_placed_map()

void create_placed_map ( )

Create a clean pmap.

Definition at line 38 of file mapgen_utils.cpp.

Referenced by initworld(), make_huts(), make_land(), and make_rivers().

◆ destroy_placed_map()

void destroy_placed_map ( )

◆ generator_free()

void generator_free ( )

Free resources allocated by the generator.

Definition at line 659 of file mapgen_utils.cpp.

Referenced by server_quit().

◆ get_continent_size()

int get_continent_size ( Continent_id  id)

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

Definition at line 413 of file mapgen_utils.cpp.

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

◆ get_lake_surrounders()

int get_lake_surrounders ( Continent_id  cont)

Get continent surrounding lake, or -1 if there is multiple continents.

Definition at line 405 of file mapgen_utils.cpp.

Referenced by is_claimable_ocean().

◆ 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 423 of file mapgen_utils.cpp.

Referenced by is_claimable_ocean().

◆ map_set_placed()

void map_set_placed ( struct tile ptile)

◆ map_unset_placed()

void map_unset_placed ( struct tile ptile)

Mark tile terrain as not placed.

Definition at line 70 of file mapgen_utils.cpp.

Referenced by place_island().

◆ most_adjacent_ocean_type()

static struct terrain* most_adjacent_ocean_type ( const struct tile ptile)
static

Determines what is the most popular ocean type arround (need 2/3 of the adjcacent tiles).

Definition at line 576 of file mapgen_utils.cpp.

Referenced by smooth_water_depth().

◆ most_shallow_ocean()

struct terrain* most_shallow_ocean ( bool  frozen)

Return most shallow ocean terrain type.

Prefers not to return freshwater terrain, and will ignore 'frozen' rather than do so.

Definition at line 484 of file mapgen_utils.cpp.

Referenced by check_terrain_change(), and remove_tiny_islands().

◆ not_placed()

bool not_placed ( const struct tile ptile)

Checks if land has not yet been placed on pmap at (x, y)

Definition at line 60 of file mapgen_utils.cpp.

Referenced by condition_filter(), fill_island(), make_fracture_relief(), make_plains(), make_relief(), make_terrains(), and place_terrain().

◆ pick_ocean()

struct terrain* pick_ocean ( int  depth,
bool  frozen 
)

Picks an ocean terrain to match the given depth.

Only considers terrains with/without Frozen flag depending on 'frozen'. Return nullptr when there is no available ocean.

Definition at line 532 of file mapgen_utils.cpp.

Referenced by fair_map_island_new(), initworld(), make_land(), make_polar(), and smooth_water_depth().

◆ pick_terrain()

struct terrain* pick_terrain ( enum mapgen_terrain_property  target,
enum mapgen_terrain_property  prefer,
enum mapgen_terrain_property  avoid 
)

Pick a terrain based on the target property and a property to avoid.

If the target property is given, then all terrains with that property will be considered and one will be picked at random based on the amount of the property each terrain has. If no target property is given all terrains will be assigned equal likelihood.

If the preferred property is given, only terrains with (some of) that property will be chosen.

If the avoid property is given, then any terrain with (any of) that property will be avoided.

This function must always return a valid terrain.

Definition at line 716 of file mapgen_utils.cpp.

Referenced by fair_map_island_new(), fill_island(), make_fracture_relief(), make_plain(), make_polar(), make_relief(), and make_terrains().

◆ pick_terrain_by_flag()

struct terrain* pick_terrain_by_flag ( enum terrain_flag_id  flag)

Return a random terrain that has the specified flag.

Returns T_UNKNOWN when there is no matching terrain.

Definition at line 670 of file mapgen_utils.cpp.

Referenced by fair_map_island_new(), and make_rivers().

◆ placed_map_is_initialized()

bool placed_map_is_initialized ( )

Return TRUE if initialized.

Definition at line 33 of file mapgen_utils.cpp.

Referenced by create_placed_map(), destroy_placed_map(), and map_generate_island_variable().

◆ real_distance_to_land()

static int real_distance_to_land ( const struct tile ptile,
int  max 
)
static

Determines the minimal distance to the land.

Definition at line 559 of file mapgen_utils.cpp.

Referenced by smooth_water_depth().

◆ recalculate_lake_surrounders()

static void recalculate_lake_surrounders ( )
static

Calculate lake_surrounders[] array.

Definition at line 230 of file mapgen_utils.cpp.

Referenced by assign_continent_numbers().

◆ regenerate_lakes()

void regenerate_lakes ( )

Regenerate all oceanic tiles for small water bodies as lakes.

Assumes assign_continent_numbers() and recalculate_lake_surrounders() have already been done! FIXME: insufficiently generalized, use terrain property.

Definition at line 332 of file mapgen_utils.cpp.

Referenced by map_generate().

◆ set_all_ocean_tiles_placed()

void set_all_ocean_tiles_placed ( )

Set all oceanics tiles in placed_map.

Definition at line 75 of file mapgen_utils.cpp.

Referenced by make_land(), and make_rivers().

◆ set_placed_near_pos()

void set_placed_near_pos ( struct tile ptile,
int  dist 
)

Set all nearby tiles as placed on pmap.

Definition at line 89 of file mapgen_utils.cpp.

Referenced by make_huts().

◆ smooth_int_map()

void smooth_int_map ( int *  int_map,
bool  zeroes_at_edges 
)

Apply a Gaussian diffusion filter on the map.

The size of the map is MAP_INDEX_SIZE and the map is indexed by native_pos_to_index function. If zeroes_at_edges is set, any unreal position on diffusion has 0 value if zeroes_at_edges in unset the unreal position are not counted.

Definition at line 166 of file mapgen_utils.cpp.

Referenced by create_start_positions(), and make_random_hmap().

◆ smooth_water_depth()

void smooth_water_depth ( )

Makes a simple depth map for all ocean tiles based on their proximity to any land tiles and reassignes ocean terrain types based on their MG_OCEAN_DEPTH property values.

Definition at line 606 of file mapgen_utils.cpp.

Referenced by map_generate().

Variable Documentation

◆ continent_sizes

std::vector<int> continent_sizes

◆ lake_surrounders

std::vector<Continent_id> lake_surrounders

◆ ocean_sizes

std::vector<int> ocean_sizes

◆ placed_map

bool* placed_map
static

Map that contains, according to circumstances, information on whether we have already placed terrain (special, hut) here.

Definition at line 28 of file mapgen_utils.cpp.

Referenced by create_placed_map(), destroy_placed_map(), and placed_map_is_initialized().