The Battle for Wesnoth  1.19.18+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
 
std::string get_underlying_terrain_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
 
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
 
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_codeoperator[] (const map_location &loc) const
 
gamemap_base::set_terrain_result 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)
 
std::string_view strip_legacy_header (std::string_view data) const
 Returns a subview of data which excludes any legacy headers. More...
 

Private Attributes

std::shared_ptr< terrain_type_datatdata_
 

Additional Inherited Members

- Public Types inherited from gamemap_base
enum class  village_state { unchanged , new_village , former_village }
 What happens to a village hex when its terrain is changed. More...
 
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 172 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 92 of file map.cpp.

References data, DBG_G, and read().

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 79 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 48 of file map.cpp.

References gamemap_base::get_terrain(), loc, 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 42 of file map.cpp.

References tdata_.

Referenced by game_lua_kernel::impl_get_terrain_list(), and editor::terrain_palette::setup().

◆ get_terrain_string() [1/2]

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

Definition at line 59 of file map.cpp.

References gamemap_base::get_terrain(), and loc.

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 77 of file map.cpp.

References tdata_.

◆ get_underlying_terrain_string() [1/2]

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

Definition at line 63 of file map.cpp.

References gamemap_base::get_terrain(), and loc.

Referenced by REPORT_GENERATOR().

◆ get_underlying_terrain_string() [2/2]

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

Definition at line 81 of file map.cpp.

References tdata_.

◆ gives_healing()

int gamemap::gives_healing ( const map_location loc) const

◆ is_castle()

bool gamemap::is_castle ( const map_location loc) const

◆ is_keep()

bool gamemap::is_keep ( const map_location loc) const

◆ is_village()

bool gamemap::is_village ( const map_location loc) const

◆ 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 
)

◆ set_terrain()

gamemap_base::set_terrain_result 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 361 of file map.cpp.

References DBG_G, utils::erase(), gamemap_base::former_village, gamemap_base::get_terrain(), is_village(), loc, gamemap_base::new_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().

◆ strip_legacy_header()

std::string_view gamemap::strip_legacy_header ( std::string_view  data) const
private

Returns a subview of data which excludes any legacy headers.

Parameters
dataThe mapdata to load.

Definition at line 152 of file map.cpp.

References data.

Referenced by read().

◆ tdata()

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

Definition at line 198 of file map.hpp.

References tdata_.

◆ underlying_def_terrain()

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

Definition at line 55 of file map.cpp.

References gamemap_base::get_terrain(), loc, and tdata_.

Referenced by unit_defense().

◆ underlying_mvt_terrain()

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

Definition at line 53 of file map.cpp.

References gamemap_base::get_terrain(), loc, and tdata_.

◆ underlying_union_terrain()

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

Definition at line 57 of file map.cpp.

References gamemap_base::get_terrain(), loc, and tdata_.

Referenced by REPORT_GENERATOR(), and unit_box_at().

◆ 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 87 of file map.cpp.

References cfg, gamemap_base::get_terrain(), loc, 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 254 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: