The Battle for Wesnoth  1.19.5+dev
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
gamemap Class Reference

Encapsulates the map of the game. More...

#include <map.hpp>

Inheritance diagram for gamemap:

Public Member Functions

const t_translation::ter_listunderlying_mvt_terrain (const map_location &loc) const
 
const t_translation::ter_listunderlying_def_terrain (const map_location &loc) const
 
const t_translation::ter_listunderlying_union_terrain (const map_location &loc) const
 
std::string get_terrain_string (const map_location &loc) const
 
std::string get_terrain_editor_string (const map_location &loc) const
 
bool is_village (const map_location &loc) const
 
int gives_healing (const map_location &loc) const
 
bool is_castle (const map_location &loc) const
 
bool is_keep (const map_location &loc) const
 
const t_translation::ter_listunderlying_mvt_terrain (const t_translation::terrain_code &terrain) const
 
const t_translation::ter_listunderlying_def_terrain (const t_translation::terrain_code &terrain) const
 
const t_translation::ter_listunderlying_union_terrain (const t_translation::terrain_code &terrain) const
 
std::string get_terrain_string (const t_translation::terrain_code &terrain) const
 
std::string get_terrain_editor_string (const t_translation::terrain_code &terrain) const
 
std::string get_underlying_terrain_string (const t_translation::terrain_code &terrain) const
 
bool is_village (const t_translation::terrain_code &terrain) const
 
int gives_healing (const t_translation::terrain_code &terrain) const
 
bool is_castle (const t_translation::terrain_code &terrain) const
 
bool is_keep (const t_translation::terrain_code &terrain) const
 
const terrain_typeget_terrain_info (const t_translation::terrain_code &terrain) const
 
const std::shared_ptr< terrain_type_data > & tdata () const
 
 gamemap (const std::string &data)
 Loads a map. More...
 
void read (const std::string &data, const bool allow_invalid=true)
 
std::string write () const
 
const t_translation::terrain_code operator[] (const map_location &loc) const
 
void set_terrain (const map_location &loc, const terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false) override
 Clobbers over the terrain at location 'loc', with the given terrain. More...
 
void write_terrain (const map_location &loc, config &cfg) const
 Writes the terrain at loc to cfg. More...
 
const std::vector< map_location > & villages () const
 Return a list of the locations of villages on the map. More...
 
const terrain_typeget_terrain_info (const map_location &loc) const
 Shortcut to get_terrain_info(get_terrain(loc)). More...
 
const t_translation::ter_listget_terrain_list () const
 Gets the list of terrains. More...
 
- Public Member Functions inherited from gamemap_base
virtual ~gamemap_base ()
 
std::string to_string () const
 
int w () const
 Effective map width. More...
 
int h () const
 Effective map height. More...
 
int border_size () const
 Size of the map border. More...
 
int total_width () const
 Real width of the map, including borders. More...
 
int total_height () const
 Real height of the map, including borders. More...
 
bool empty () const
 Tell if the map is of 0 size. More...
 
bool on_board (const map_location &loc) const
 Tell if a location is on the map. More...
 
bool on_board_with_border (const map_location &loc) const
 
terrain_code get_terrain (const map_location &loc) const
 Looks up terrain at a particular location. More...
 
location_mapspecial_locations ()
 
const location_mapspecial_locations () const
 
const std::vector< map_locationstarting_positions () const
 
void set_special_location (const std::string &id, const map_location &loc)
 
map_location special_location (const std::string &id) const
 
void set_starting_position (int side, const map_location &loc)
 Manipulate starting positions of the different sides. More...
 
map_location starting_position (int side) const
 
int num_valid_starting_positions () const
 Counts the number of sides that have valid starting positions on this map. More...
 
int is_starting_position (const map_location &loc) const
 returns the side number of the side starting at position loc, 0 if no such side exists. More...
 
const std::string * is_special_location (const map_location &loc) const
 returns the name of the special location at position loc, null if no such location exists. More...
 
std::vector< map_locationparse_location_range (const std::string &xvals, const std::string &yvals, bool with_border=false) const
 Parses ranges of locations into a vector of locations, using this map's dimensions as bounds. More...
 
void overlay (const gamemap_base &m, map_location loc, const std::vector< overlay_rule > &rules=std::vector< overlay_rule >(), bool is_odd=false, bool ignore_special_locations=false)
 Overlays another map onto this one at the given position. More...
 
template<typename F >
void for_each_loc (const F &f) const
 
template<typename F >
void for_each_walkable_loc (const F &f) const
 

Protected Attributes

std::vector< map_locationvillages_
 

Private Member Functions

t_translation::terrain_codeoperator[] (const map_location &loc)
 
int read_header (const std::string &data)
 Reads the header of a map which is saved in the deprecated map_data format. More...
 

Private Attributes

std::shared_ptr< terrain_type_datatdata_
 

Additional Inherited Members

- Public Types inherited from gamemap_base
using terrain_code = t_translation::terrain_code
 
using terrain_map = t_translation::ter_map
 
using location_map = t_translation::starting_positions
 
- Static Public Attributes inherited from gamemap_base
static const int default_border = 1
 The default border style for a map. More...
 
static const int MAX_PLAYERS = 9
 Maximum number of players supported. More...
 
- Protected Member Functions inherited from gamemap_base
 gamemap_base ()=default
 
 gamemap_base (int w, int h, terrain_code default_ter=terrain_code())
 
terrain_maptiles ()
 
const terrain_maptiles () const
 

Detailed Description

Encapsulates the map of the game.

Although the game is hexagonal, the map is stored as a grid. Each type of terrain is represented by a multiletter terrain code.

Todo:
Update for new map-format.

Definition at line 171 of file map.hpp.

Constructor & Destructor Documentation

◆ gamemap()

gamemap::gamemap ( const std::string &  data)

Loads a map.

Data should be a series of lines, with each character representing one hex on the map. Starting locations are represented by numbers.

Parameters
datathe map data to load.

Definition at line 106 of file map.cpp.

References data, DBG_G, game_config_manager::get(), read(), tdata_, and game_config_view::wrap().

Member Function Documentation

◆ get_terrain_editor_string() [1/2]

std::string gamemap::get_terrain_editor_string ( const map_location loc) const

◆ get_terrain_editor_string() [2/2]

std::string gamemap::get_terrain_editor_string ( const t_translation::terrain_code terrain) const

Definition at line 85 of file map.cpp.

References tdata_.

◆ get_terrain_info() [1/2]

const terrain_type & gamemap::get_terrain_info ( const map_location loc) const

Shortcut to get_terrain_info(get_terrain(loc)).

Definition at line 50 of file map.cpp.

References gamemap_base::get_terrain(), and tdata_.

◆ get_terrain_info() [2/2]

const terrain_type & gamemap::get_terrain_info ( const t_translation::terrain_code terrain) const

◆ get_terrain_list()

const t_translation::ter_list & gamemap::get_terrain_list ( ) const

Gets the list of terrains.

Definition at line 44 of file map.cpp.

References tdata_.

Referenced by editor::terrain_palette::setup().

◆ get_terrain_string() [1/2]

std::string gamemap::get_terrain_string ( const map_location loc) const

Definition at line 61 of file map.cpp.

References gamemap_base::get_terrain().

Referenced by REPORT_GENERATOR().

◆ get_terrain_string() [2/2]

std::string gamemap::get_terrain_string ( const t_translation::terrain_code terrain) const

Definition at line 83 of file map.cpp.

References tdata_.

◆ get_underlying_terrain_string()

std::string gamemap::get_underlying_terrain_string ( const t_translation::terrain_code terrain) const

Definition at line 87 of file map.cpp.

References tdata_.

Referenced by REPORT_GENERATOR().

◆ gives_healing() [1/2]

int gamemap::gives_healing ( const map_location loc) const

◆ gives_healing() [2/2]

int gamemap::gives_healing ( const t_translation::terrain_code terrain) const

Definition at line 91 of file map.cpp.

References tdata_.

◆ is_castle() [1/2]

bool gamemap::is_castle ( const map_location loc) const

◆ is_castle() [2/2]

bool gamemap::is_castle ( const t_translation::terrain_code terrain) const

Definition at line 93 of file map.cpp.

References tdata_.

◆ is_keep() [1/2]

bool gamemap::is_keep ( const map_location loc) const

◆ is_keep() [2/2]

bool gamemap::is_keep ( const t_translation::terrain_code terrain) const

Definition at line 95 of file map.cpp.

References tdata_.

◆ is_village() [1/2]

bool gamemap::is_village ( const map_location loc) const

◆ is_village() [2/2]

bool gamemap::is_village ( const t_translation::terrain_code terrain) const

Definition at line 89 of file map.cpp.

References tdata_.

◆ operator[]() [1/2]

t_translation::terrain_code& gamemap::operator[] ( const map_location loc)
inlineprivate

◆ operator[]() [2/2]

const t_translation::terrain_code gamemap::operator[] ( const map_location loc) const
inline

◆ read()

void gamemap::read ( const std::string &  data,
const bool  allow_invalid = true 
)

◆ read_header()

int gamemap::read_header ( const std::string &  data)
private

Reads the header of a map which is saved in the deprecated map_data format.

Parameters
dataThe mapdata to load.

Definition at line 183 of file map.cpp.

References data, and read().

Referenced by read().

◆ set_terrain()

void gamemap::set_terrain ( const map_location loc,
const terrain_code terrain,
const terrain_type_data::merge_mode  mode = terrain_type_data::BOTH,
bool  replace_if_failed = false 
)
overridevirtual

Clobbers over the terrain at location 'loc', with the given terrain.

Uses mode and replace_if_failed like merge_terrains().

Implements gamemap_base.

Definition at line 397 of file map.cpp.

References DBG_G, utils::erase(), gamemap_base::get_terrain(), is_village(), t_translation::NONE_TERRAIN, gamemap_base::on_board(), gamemap_base::on_board_with_border(), tdata_, and villages_.

Referenced by editor::map_context::draw_terrain_actual(), editor::editor_map::mask_to(), and editor::map_fragment::paste_into().

◆ tdata()

const std::shared_ptr<terrain_type_data>& gamemap::tdata ( ) const
inline

◆ underlying_def_terrain() [1/2]

const t_translation::ter_list & gamemap::underlying_def_terrain ( const map_location loc) const

Definition at line 57 of file map.cpp.

References gamemap_base::get_terrain().

Referenced by unit_defense().

◆ underlying_def_terrain() [2/2]

const t_translation::ter_list & gamemap::underlying_def_terrain ( const t_translation::terrain_code terrain) const

Definition at line 79 of file map.cpp.

References tdata_.

◆ underlying_mvt_terrain() [1/2]

const t_translation::ter_list & gamemap::underlying_mvt_terrain ( const map_location loc) const

Definition at line 55 of file map.cpp.

References gamemap_base::get_terrain().

◆ underlying_mvt_terrain() [2/2]

const t_translation::ter_list & gamemap::underlying_mvt_terrain ( const t_translation::terrain_code terrain) const

Definition at line 77 of file map.cpp.

References tdata_.

◆ underlying_union_terrain() [1/2]

const t_translation::ter_list & gamemap::underlying_union_terrain ( const map_location loc) const

Definition at line 59 of file map.cpp.

References gamemap_base::get_terrain().

Referenced by prefs::encounter_map_terrain(), REPORT_GENERATOR(), and unit_box_at().

◆ underlying_union_terrain() [2/2]

const t_translation::ter_list & gamemap::underlying_union_terrain ( const t_translation::terrain_code terrain) const

Definition at line 81 of file map.cpp.

References tdata_.

◆ villages()

const std::vector<map_location>& gamemap::villages ( ) const
inline

◆ write()

std::string gamemap::write ( ) const

◆ write_terrain()

void gamemap::write_terrain ( const map_location loc,
config cfg 
) const

Writes the terrain at loc to cfg.

Definition at line 101 of file map.cpp.

References gamemap_base::get_terrain(), and t_translation::write_terrain_code().

Member Data Documentation

◆ tdata_

std::shared_ptr<terrain_type_data> gamemap::tdata_
private

◆ villages_

std::vector<map_location> gamemap::villages_
protected

Definition at line 257 of file map.hpp.

Referenced by read(), editor::editor_map::resize(), set_terrain(), and villages().


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