#include "global.hpp"
#include "gettext.hpp"
#include "language.hpp"
#include "log.hpp"
#include "mapgen.hpp"
#include "pathfind.hpp"
#include "race.hpp"
#include "scoped_resource.hpp"
#include "serialization/string_utils.hpp"
#include "util.hpp"
#include "wml_exception.hpp"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <ctime>
#include <vector>
Go to the source code of this file.
Defines | |
#define | ERR_CF LOG_STREAM(err, config) |
#define | ERR_NG LOG_STREAM(err, engine) |
#define | LOG_NG LOG_STREAM(info, engine) |
Typedefs | |
typedef std::vector < std::vector< int > > | height_map |
typedef t_translation::t_map | terrain_map |
typedef gamemap::location | location |
typedef std::map < t_translation::t_terrain, t_translation::t_list > | tcode_list_cache |
typedef std::map< std::string, map_generator * > | generator_map |
Functions | |
static height_map | generate_height_map (size_t width, size_t height, size_t iterations, size_t hill_size, size_t island_size, size_t island_off_center) |
Generate a height-map. | |
static bool | generate_lake (terrain_map &terrain, int x, int y, int lake_fall_off, std::set< location > &locs_touched) |
Generate a lake. | |
static bool | generate_river_internal (const height_map &heights, terrain_map &terrain, int x, int y, std::vector< location > &river, std::set< location > &seen_locations, int river_uphill) |
River generation. | |
static std::vector< location > | generate_river (const height_map &heights, terrain_map &terrain, int x, int y, int river_uphill) |
static location | random_point_at_side (size_t width, size_t height) |
Return a random tile at one of the borders of a map that is of the given dimensions. | |
static std::string | output_map (const terrain_map &terrain, std::map< int, t_translation::coordinate > starting_positions) |
Function which, given the map will output it in a valid format. | |
static int | rank_castle_location (int x, int y, const is_valid_terrain &valid_terrain, int min_x, int max_x, int min_y, int max_y, size_t min_distance, const std::vector< gamemap::location > &other_castles, int highest_ranking) |
static gamemap::location | place_village (const t_translation::t_map &map, const size_t x, const size_t y, const size_t radius, const config &cfg, tcode_list_cache &adj_liked_cache) |
static std::string | generate_name (const unit_race &name_generator, const std::string &id, std::string *base_name=NULL, utils::string_map *additional_symbols=NULL) |
std::string | default_generate_map (size_t width, size_t height, size_t island_size, size_t island_off_center, size_t iterations, size_t hill_size, size_t max_lakes, size_t nvillages, size_t castle_size, size_t nplayers, bool roads_between_castles, std::map< gamemap::location, std::string > *labels, const config &cfg) |
Generate the map. | |
Variables | |
generator_map | generators |
Definition in file mapgen.cpp.
#define ERR_CF LOG_STREAM(err, config) |
Definition at line 43 of file mapgen.cpp.
#define ERR_NG LOG_STREAM(err, engine) |
Definition at line 44 of file mapgen.cpp.
#define LOG_NG LOG_STREAM(info, engine) |
Definition at line 45 of file mapgen.cpp.
typedef std::map<std::string,map_generator*> generator_map [static] |
Definition at line 1306 of file mapgen.cpp.
typedef std::vector<std::vector<int> > height_map |
Definition at line 54 of file mapgen.cpp.
typedef gamemap::location location |
Definition at line 57 of file mapgen.cpp.
Definition at line 525 of file mapgen.cpp.
typedef t_translation::t_map terrain_map |
Definition at line 55 of file mapgen.cpp.
std::string default_generate_map | ( | size_t | width, | |
size_t | height, | |||
size_t | island_size, | |||
size_t | island_off_center, | |||
size_t | iterations, | |||
size_t | hill_size, | |||
size_t | max_lakes, | |||
size_t | nvillages, | |||
size_t | castle_size, | |||
size_t | nplayers, | |||
bool | roads_between_castles, | |||
std::map< gamemap::location, std::string > * | labels, | |||
const config & | cfg | |||
) |
Generate the map.
Convert grassland terrain to other types of flat terrain. We generate a 'temperature map' which uses the height generation algorithm to generate the temperature levels all over the map. Then we can use a combination of height and terrain to divide terrain up into more interesting types than the default.
Place villages in a 'grid', to make placing fair, but with villages displaced from their position according to terrain and randomness, to add some variety.
Try to find configuration for castles.
Castle configuration tag contains a 'valid_terrain' attribute which is a list of terrains that the castle may appear on.
Attempt to place castles at random. Once we have placed castles, we run a sanity check to make sure that the castles are well-placed. If the castles are not well-placed, we try again. Definition of 'well-placed' is if no two castles are closer than 'min_distance' hexes from each other, and the castles appear on a terrain listed in 'valid_terrain'.
We want the locations to be on the portion of the map we're actually going to use, since roads on other parts of the map won't have any influence, and doing it like this will be quicker.
Definition at line 703 of file mapgen.cpp.
References _, a_star_search(), config::child(), config::empty(), ERR_NG, config::find_child(), t_translation::FOREST, generate_height_map(), generate_lake(), generate_name(), generate_river(), get_adjacent_tiles(), config::get_children(), t_translation::GRASS_LAND, t_translation::HILL, t_translation::HUMAN_CASTLE, t_translation::HUMAN_KEEP, is_even(), loc, LOG_NG, log_scope, t_translation::MOUNTAIN, name, boost::foreach_detail_::next(), output_map(), place_village(), r, random_point_at_side(), rank_castle_location(), t_translation::read_list(), t_translation::read_terrain_code(), utils::split(), paths::route::steps, VALIDATE, t_translation::write_terrain_code(), gamemap::location::x, and gamemap::location::y.
Referenced by default_map_generator::generate_map().
static height_map generate_height_map | ( | size_t | width, | |
size_t | height, | |||
size_t | iterations, | |||
size_t | hill_size, | |||
size_t | island_size, | |||
size_t | island_off_center | |||
) | [static] |
Generate a height-map.
Basically we generate alot 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 72 of file mapgen.cpp.
References LOG_NG, and radius.
Referenced by default_generate_map().
static bool generate_lake | ( | terrain_map & | terrain, | |
int | x, | |||
int | y, | |||
int | lake_fall_off, | |||
std::set< location > & | locs_touched | |||
) | [static] |
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 195 of file mapgen.cpp.
References t_translation::SHALLOW_WATER.
Referenced by default_generate_map().
static std::string generate_name | ( | const unit_race & | name_generator, | |
const std::string & | id, | |||
std::string * | base_name = NULL , |
|||
utils::string_map * | additional_symbols = NULL | |||
) | [static] |
Definition at line 585 of file mapgen.cpp.
References unit_race::generate_name(), utils::interpolate_variables_into_string(), LOG_NG, unit_race::MALE, name, utils::split(), and string_table.
Referenced by default_generate_map().
static std::vector<location> generate_river | ( | const height_map & | heights, | |
terrain_map & | terrain, | |||
int | x, | |||
int | y, | |||
int | river_uphill | |||
) | [static] |
Definition at line 294 of file mapgen.cpp.
References generate_river_internal().
Referenced by default_generate_map().
static bool generate_river_internal | ( | const height_map & | heights, | |
terrain_map & | terrain, | |||
int | x, | |||
int | y, | |||
std::vector< location > & | river, | |||
std::set< location > & | seen_locations, | |||
int | river_uphill | |||
) | [static] |
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 238 of file mapgen.cpp.
References a, t_translation::DEEP_WATER, get_adjacent_tiles(), loc, LOG_NG, t_translation::SHALLOW_WATER, gamemap::location::x, and gamemap::location::y.
Referenced by generate_river().
static std::string output_map | ( | const terrain_map & | terrain, | |
std::map< int, t_translation::coordinate > | starting_positions | |||
) | [static] |
Function which, given the map will output it in a valid format.
Definition at line 323 of file mapgen.cpp.
References gamemap::default_border, gamemap::default_map_header, map, and t_translation::write_game_map().
Referenced by default_generate_map().
static gamemap::location place_village | ( | const t_translation::t_map & | map, | |
const size_t | x, | |||
const size_t | y, | |||
const size_t | radius, | |||
const config & | cfg, | |||
tcode_list_cache & | adj_liked_cache | |||
) | [static] |
Definition at line 528 of file mapgen.cpp.
References config::find_child(), get_adjacent_tiles(), get_tiles_radius(), loc, t_translation::read_list(), size, t_translation::write_terrain_code(), gamemap::location::x, and gamemap::location::y.
Referenced by default_generate_map().
static location random_point_at_side | ( | size_t | width, | |
size_t | height | |||
) | [static] |
Return a random tile at one of the borders of a map that is of the given dimensions.
Definition at line 308 of file mapgen.cpp.
Referenced by default_generate_map().
static int rank_castle_location | ( | int | x, | |
int | y, | |||
const is_valid_terrain & | valid_terrain, | |||
int | min_x, | |||
int | max_x, | |||
int | min_y, | |||
int | max_y, | |||
size_t | min_distance, | |||
const std::vector< gamemap::location > & | other_castles, | |||
int | highest_ranking | |||
) | [static] |
Definition at line 460 of file mapgen.cpp.
References distance_between(), and loc.
Referenced by default_generate_map().
std::map<t_translation::t_terrain, double> cache_ |
Definition at line 377 of file mapgen.cpp.
int calls |
Definition at line 374 of file mapgen.cpp.
Definition at line 668 of file mapgen.cpp.
Referenced by unit_type_data::unit_type_map_wrapper::add_advancement(), ai::do_combat(), and playmp_controller::play_network_turn().
generator_map generators [static] |
Definition at line 1307 of file mapgen.cpp.
Definition at line 373 of file mapgen.cpp.
int max_height |
Definition at line 667 of file mapgen.cpp.
Referenced by dialogs::campaign_preview_pane::draw_contents(), gui::menu::get_item_height(), gui::dialog::layout(), gui::menu::max_items_onscreen(), and default_map_generator::user_config().
int max_temp |
Definition at line 667 of file mapgen.cpp.
int min_height |
Definition at line 667 of file mapgen.cpp.
int min_temp |
Definition at line 667 of file mapgen.cpp.
int seed_ |
Definition at line 376 of file mapgen.cpp.
const t_translation::t_list& terrain_ |
Definition at line 438 of file mapgen.cpp.
int terrain_height |
Definition at line 634 of file mapgen.cpp.
Definition at line 635 of file mapgen.cpp.
Referenced by ai::do_combat(), help::help_text_area::handle_jump_cfg(), and dfool::dfool_ai::moveto().
int windiness_ |
Definition at line 375 of file mapgen.cpp.
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |