The Battle for Wesnoth  1.15.0-dev
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
default_map_generator_job Class Reference

#include <default_map_generator_job.hpp>

Public Member Functions

 default_map_generator_job ()
 default_map_generator_job (uint32_t seed)
std::string default_generate_map (generator_data data, std::map< map_location, std::string > *labels, const config &cfg)
 Generate the map. More...

Private Types

typedef std::vector< std::vector< int > > height_map
typedef t_translation::ter_map terrain_map

Private Member Functions

bool generate_river_internal (const height_map &heights, terrain_map &terrain, int x, int y, std::vector< map_location > &river, std::set< map_location > &seen_locations, int river_uphill)
 River generation. More...
std::vector< map_locationgenerate_river (const height_map &heights, terrain_map &terrain, int x, int y, int river_uphill)
height_map generate_height_map (std::size_t width, std::size_t height, std::size_t iterations, std::size_t hill_size, std::size_t island_size, std::size_t island_off_center)
 Generate a height-map. More...
bool generate_lake (t_translation::ter_map &terrain, int x, int y, int lake_fall_off, std::set< map_location > &locs_touched)
 Generate a lake. More...
map_location random_point_at_side (std::size_t width, std::size_t height)
 Returns a random tile at one of the borders of a map that is of the given dimensions. More...

Private Attributes

std::mt19937 rng_
const configgame_config_

Detailed Description

Definition at line 32 of file default_map_generator_job.hpp.

Member Typedef Documentation

◆ height_map

typedef std::vector<std::vector<int> > default_map_generator_job::height_map

Definition at line 42 of file default_map_generator_job.hpp.

◆ terrain_map

Definition at line 43 of file default_map_generator_job.hpp.

Constructor & Destructor Documentation

◆ default_map_generator_job() [1/2]

default_map_generator_job::default_map_generator_job ( )

Definition at line 229 of file default_map_generator_job.cpp.

◆ default_map_generator_job() [2/2]

default_map_generator_job::default_map_generator_job ( uint32_t  seed)

Definition at line 235 of file default_map_generator_job.cpp.

Member Function Documentation

◆ default_generate_map()

std::string default_map_generator_job::default_generate_map ( generator_data  data,
std::map< map_location, std::string > *  labels,
const config cfg 

Generate the map.

Definition at line 691 of file default_map_generator_job.cpp.

References _(), pathfind::a_star_search(), t_translation::ALL_FORESTS, t_translation::ALL_MOUNTAINS, t_translation::ALL_SWAMPS, config::append_attributes(), filesystem::base_name(), c, generator_data::castle_size, config::child(), config::child_range(), config::empty(), ERR_NG, error(), field(), config::find_child(), flood_name(), t_translation::FOREST, game_config_, lg::general(), generate_height_map(), generate_lake(), generate_river(), get_adjacent_tiles(), config::get_old_attribute(), t_translation::GRASS_LAND, h, config::has_attribute(), config::has_child(), generator_data::height, t_translation::HILL, generator_data::hill_size, t_translation::HUMAN_CASTLE, t_translation::HUMAN_KEEP, i, is_even(), editor::is_valid_terrain(), generator_data::island_off_center, generator_data::island_size, mp_ui_alerts::items, generator_data::iterations, generator_data::link_castles, LOG_NG, log_scope, generator_data::max_lakes, t_translation::MOUNTAIN, n, name, next, generator_data::nplayers, generator_data::nvillages, output_map(), place_village(), random_point_at_side(), rank_castle_location(), t_translation::read_list(), t_translation::read_terrain_code(), rng_, generator_data::show_labels, utils::split(), pathfind::plain_route::steps, t_translation::terrain_matches(), VALIDATE, generator_data::width, t_translation::write_terrain_code(), map_location::x, and map_location::y.

Referenced by default_map_generator::generate_map().

◆ generate_height_map()

height_map default_map_generator_job::generate_height_map ( std::size_t  width,
std::size_t  height,
std::size_t  iterations,
std::size_t  hill_size,
std::size_t  island_size,
std::size_t  island_off_center 

Generate a height-map.

Basically we generate a lot of hills, each hill being centered at a certain point, with a certain radius - being a half sphere. Hills are combined additively to form a bumpy surface. The size of each hill varies randomly from 1-hill_size. We generate 'iterations' hills in total. The range of heights is normalized to 0-1000. 'island_size' controls whether or not the map should tend toward an island shape, and if so, how large the island should be. Hills with centers that are more than 'island_size' away from the center of the map will be inverted (i.e. be valleys). 'island_size' as 0 indicates no island.

Definition at line 254 of file default_map_generator_job.cpp.

References DBG_NG, i, LOG_NG, and rng_.

Referenced by default_generate_map().

◆ generate_lake()

bool default_map_generator_job::generate_lake ( t_translation::ter_map terrain,
int  x,
int  y,
int  lake_fall_off,
std::set< map_location > &  locs_touched 

Generate a lake.

It will create water at (x,y), and then have 'lake_fall_off' % chance to make another water tile in each of the directions n,s,e,w. In each of the directions it does make another water tile, it will have 'lake_fall_off'/2 % chance to make another water tile in each of the directions. This will continue recursively.

Definition at line 386 of file default_map_generator_job.cpp.

References t_translation::ter_map::h, rng_, t_translation::SHALLOW_WATER, and t_translation::ter_map::w.

Referenced by default_generate_map().

◆ generate_river()

std::vector< map_location > default_map_generator_job::generate_river ( const height_map heights,
terrain_map terrain,
int  x,
int  y,
int  river_uphill 

Definition at line 486 of file default_map_generator_job.cpp.

References generate_river_internal().

Referenced by default_generate_map().

◆ generate_river_internal()

bool default_map_generator_job::generate_river_internal ( const height_map heights,
terrain_map terrain,
int  x,
int  y,
std::vector< map_location > &  river,
std::set< map_location > &  seen_locations,
int  river_uphill 

River generation.

Rivers have a source, and then keep on flowing until they meet another body of water, which they flow into, or until they reach the edge of the map. Rivers will always flow downhill, except that they can flow a maximum of 'river_uphill' uphill. This is to represent the water eroding the higher ground lower.

Every possible path for a river will be attempted, in random order, and the first river path that can be found that makes the river flow into another body of water or off the map will be used.

If no path can be found, then the river's generation will be aborted, and false will be returned. true is returned if the river is generated successfully.

Definition at line 433 of file default_map_generator_job.cpp.

References t_translation::DEEP_WATER, get_adjacent_tiles(), i, LOG_NG, rng_, t_translation::SHALLOW_WATER, and gui2::tip_of_the_day::shuffle().

Referenced by generate_river().

◆ random_point_at_side()

map_location default_map_generator_job::random_point_at_side ( std::size_t  width,
std::size_t  height 

Returns a random tile at one of the borders of a map that is of the given dimensions.

Definition at line 502 of file default_map_generator_job.cpp.

References rng_.

Referenced by default_generate_map().

Member Data Documentation

◆ game_config_

const config& default_map_generator_job::game_config_

Definition at line 59 of file default_map_generator_job.hpp.

Referenced by default_generate_map().

◆ rng_

std::mt19937 default_map_generator_job::rng_

The documentation for this class was generated from the following files: