The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Static Public Attributes | 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:
Inheritance graph

Public Types

enum  { MAX_PLAYERS = 9 }
 Maximum number of players supported. More...
 
using starting_positions = t_translation::starting_positions
 

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 ter_data_cachetdata () const
 
 gamemap (const ter_data_cache &tdata, const std::string &data)
 Loads a map, with the given terrain configuration. More...
 
virtual ~gamemap ()
 
void read (const std::string &data, const bool allow_invalid=true)
 
std::string write () const
 
void overlay (const gamemap &m, const config &rules, map_location loc)
 Overlays another map onto this one at the given position. More...
 
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...
 
const t_translation::terrain_code operator[] (const map_location &loc) const
 
t_translation::terrain_code get_terrain (const map_location &loc) const
 Looks up terrain at a particular location. More...
 
void write_terrain (const map_location &loc, config &cfg) const
 Writes the terrain at loc to cfg. More...
 
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
 
void set_special_location (const std::string &id, const map_location &loc)
 
map_location special_location (const std::string &id) const
 
const std::string * 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...
 
int num_valid_starting_positions () const
 
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
 
bool empty () const
 Tell if the map is of 0 size. 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...
 
void set_terrain (const map_location &loc, const t_translation::terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false)
 Clobbers over the terrain at location 'loc', with the given terrain. 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...
 
const starting_positionsspecial_locations () const
 
template<typename F >
void for_each_loc (const F &f) const
 
template<typename F >
void for_each_walkable_loc (const F &f) const
 
void add_fog_border ()
 

Static Public Attributes

static const int default_border = 1
 The default border style for a map. More...
 

Protected Attributes

t_translation::ter_map tiles_
 
starting_positions starting_positions_
 
int w_
 Sizes of the map area. More...
 
int h_
 

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

ter_data_cache tdata_
 
std::vector< map_locationvillages_
 

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 34 of file map.hpp.

Member Typedef Documentation

Definition at line 186 of file map.hpp.

Member Enumeration Documentation

anonymous enum

Maximum number of players supported.

Warning: when you increase this, you need to add more definitions to the team_colors.cfg file.

Enumerator
MAX_PLAYERS 

Definition at line 177 of file map.hpp.

Constructor & Destructor Documentation

gamemap::gamemap ( const ter_data_cache tdata,
const std::string &  data 
)

Loads a map, with the given terrain configuration.

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

Parameters
tdatathe terrain data
datathe map data to load.

Definition at line 106 of file map.cpp.

References DBG_G, and read().

gamemap::~gamemap ( )
virtual

Definition at line 118 of file map.cpp.

Member Function Documentation

void gamemap::add_fog_border ( )
int gamemap::border_size ( ) const
inline
bool gamemap::empty ( ) const
inline

Tell if the map is of 0 size.

Definition at line 151 of file map.hpp.

References h_, and w_.

Referenced by team_builder::init().

template<typename F >
void gamemap::for_each_loc ( const F &  f) const
inline

Definition at line 190 of file map.hpp.

References border_size(), f, h(), and w().

Referenced by preferences::encounter_map_terrain().

template<typename F >
void gamemap::for_each_walkable_loc ( const F &  f) const
inline

Definition at line 200 of file map.hpp.

References f, h(), and w().

t_translation::terrain_code gamemap::get_terrain ( const map_location loc) const
std::string gamemap::get_terrain_editor_string ( const map_location loc) const
std::string gamemap::get_terrain_editor_string ( const t_translation::terrain_code terrain) const

Definition at line 85 of file map.cpp.

References tdata_.

const terrain_type & gamemap::get_terrain_info ( const t_translation::terrain_code terrain) const
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 get_terrain(), and tdata_.

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().

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

Definition at line 61 of file map.cpp.

References get_terrain().

Referenced by REPORT_GENERATOR().

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

Definition at line 83 of file map.cpp.

References tdata_.

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().

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

Definition at line 91 of file map.cpp.

References tdata_.

int gamemap::h ( ) const
inline

Effective map height.

Definition at line 93 of file map.hpp.

References h_.

Referenced by ai::ai_default_rca::move_to_targets_phase::access_points(), display::bounds_check_position(), terrain_builder::build_terrains(), game_state::can_recruit_on(), ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_loc(), ai::default_recruitment::recruitment::compare_cost_maps_and_update_important_hexes(), events::menu_handler::do_search(), display::draw_minimap(), display::draw_minimap_units(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::move_leader_to_goals_phase::evaluate(), ai::ai_default_rca::move_leader_to_keep_phase::evaluate(), pathfind::find_routes(), ai::default_ai_context_impl::find_targets(), for_each_loc(), for_each_walkable_loc(), pathfind::full_cost_map::full_cost_map(), mp::game_info::game_info(), ai::keeps_cache::get(), terrain_filter::get_locs_impl(), pathfind::full_cost_map::get_pair_at(), events::mouse_handler::get_route(), get_tiles_radius(), wfl::gamemap_callable::get_value(), image::getMinimap(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_get_map_size(), editor::editor_map::invert_selection(), editor::editor_map::mask_to(), display::max_map_area(), display::minimap_location_on(), editor::context_manager::new_map_dialog(), editor::context_manager::new_scenario_dialog(), overlay(), parse_location_range(), terrain_builder::rebuild_cache_all(), editor::editor_map::resize(), editor::context_manager::resize_map_dialog(), editor::editor_map::same_size_as(), editor::editor_map::sanity_check(), editor::map_context::set_map(), ai::move_result::test_route(), and ai::default_recruitment::recruitment::update_average_local_cost().

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

Definition at line 93 of file map.cpp.

References tdata_.

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

Definition at line 95 of file map.cpp.

References tdata_.

const std::string * gamemap::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.

Definition at line 341 of file map.cpp.

References starting_positions_.

Referenced by editor::mouse_action::key_event(), editor::editor_action_starting_position::perform_without_undo(), editor::mouse_action_starting_position::up_left(), and editor::mouse_action_starting_position::up_right().

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

Definition at line 89 of file map.cpp.

References tdata_.

int gamemap::num_valid_starting_positions ( ) const

Definition at line 328 of file map.cpp.

References c, and starting_positions_.

Referenced by game_state::place_sides_in_preferred_locations().

bool gamemap::on_board ( const map_location loc) const

Tell if a location is on the map.

Should be called before indexing using [].

Todo:
inline for performance? – Ilor

Definition at line 369 of file map.cpp.

References h_, map_location::valid(), w_, map_location::x, and map_location::y.

Referenced by ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_loc(), editor::mouse_action_item::click_left(), editor::mouse_action_unit::click_left(), pathfind::shortest_path_calculator::cost(), pathfind::move_type_path_calculator::cost(), pathfind::emergency_path_calculator::cost(), events::mouse_handler::current_unit_attacks_from(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), events::console_handler::do_create(), editor::mouse_action_item::drag_end_left(), editor::mouse_action_unit::drag_end_left(), game_display::draw_hex(), display::draw_hex(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::move_to_targets_phase::execute(), unit_creator::find_location(), ai::default_ai_context_impl::find_targets(), pathfind::find_vacant_tile(), terrain_filter::get_locs_impl(), get_tiles_radius(), gives_healing(), game_lua_kernel::intf_teleport(), is_castle(), is_keep(), is_village(), unit::is_visible_to_team(), editor::mouse_action::key_event(), terrain_filter::match_impl(), terrain_filter::match_internal(), events::mouse_handler::mouse_motion(), ai::ai_default_rca::move_to_targets_phase::move_group(), ai::ai_default_rca::remove_wrong_targets::operator()(), placing_score(), controller_base::play_slice(), ai::readonly_context_impl::power_projection(), game_board::replace_map(), REPORT_GENERATOR(), events::mouse_handler::select_or_action(), set_terrain(), events::mouse_handler::show_attack_options(), display_context::unit_can_move(), unit_defense(), unit_status(), editor::mouse_action_village::up_left(), editor::mouse_action_map_label::up_left(), editor::mouse_action_unit::up_left(), editor::mouse_action_item::up_left(), editor::mouse_action_starting_position::up_left(), editor::mouse_action_village::up_right(), and ai::default_recruitment::recruitment::update_important_hexes().

bool gamemap::on_board_with_border ( const map_location loc) const
const t_translation::terrain_code gamemap::operator[] ( const map_location loc) const
inline
t_translation::terrain_code& gamemap::operator[] ( const map_location loc)
inlineprivate
void gamemap::overlay ( const gamemap m,
const config rules,
map_location  loc 
)
std::vector< map_location > gamemap::parse_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.

Definition at line 407 of file map.cpp.

References border_size(), h(), i, utils::parse_range(), utils::split(), and w().

Referenced by tod_manager::add_time_area(), team::build(), terrain_filterimpl::filter_xy(), and terrain_filter::get_locs_impl().

void gamemap::read ( const std::string &  data,
const bool  allow_invalid = true 
)
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 179 of file map.cpp.

References read().

Referenced by read().

void gamemap::set_special_location ( const std::string &  id,
const map_location loc 
)
void gamemap::set_starting_position ( int  side,
const map_location loc 
)

Manipulate starting positions of the different sides.

Definition at line 364 of file map.cpp.

References set_special_location().

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

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

Uses mode and replace_if_failed like merge_terrains().

Definition at line 381 of file map.cpp.

References get_terrain(), is_village(), t_translation::NONE_TERRAIN, on_board(), on_board_with_border(), gui2::dialogs::tip::remove(), tdata_, and villages_.

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

map_location gamemap::special_location ( const std::string &  id) const
const starting_positions& gamemap::special_locations ( ) const
inline

Definition at line 187 of file map.hpp.

References starting_positions_.

map_location gamemap::starting_position ( int  side) const
const ter_data_cache& gamemap::tdata ( ) const
inline
int gamemap::total_height ( ) const
inline

Real height of the map, including borders.

Definition at line 102 of file map.hpp.

References t_translation::ter_map::h, and tiles_.

Referenced by editor::editor_map::everything_selected(), image::getMinimap(), read(), editor::editor_map::sanity_check(), and game_events::WML_HANDLER_FUNCTION().

int gamemap::total_width ( ) const
inline

Real width of the map, including borders.

Definition at line 99 of file map.hpp.

References tiles_, and t_translation::ter_map::w.

Referenced by editor::editor_map::everything_selected(), image::getMinimap(), read(), editor::editor_map::sanity_check(), and game_events::WML_HANDLER_FUNCTION().

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

Definition at line 57 of file map.cpp.

References get_terrain().

Referenced by unit_defense().

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_.

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

Definition at line 55 of file map.cpp.

References get_terrain().

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_.

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

Definition at line 59 of file map.cpp.

References get_terrain().

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

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_.

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

Effective map width.

Definition at line 90 of file map.hpp.

References w_.

Referenced by ai::ai_default_rca::move_to_targets_phase::access_points(), display::bounds_check_position(), terrain_builder::build_terrains(), game_state::can_recruit_on(), ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_loc(), ai::default_recruitment::recruitment::compare_cost_maps_and_update_important_hexes(), events::menu_handler::do_search(), display::draw_minimap(), display::draw_minimap_units(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::move_leader_to_goals_phase::evaluate(), ai::ai_default_rca::move_leader_to_keep_phase::evaluate(), pathfind::find_routes(), ai::default_ai_context_impl::find_targets(), for_each_loc(), for_each_walkable_loc(), pathfind::full_cost_map::full_cost_map(), mp::game_info::game_info(), ai::keeps_cache::get(), terrain_filter::get_locs_impl(), pathfind::full_cost_map::get_pair_at(), events::mouse_handler::get_route(), get_tiles_radius(), wfl::gamemap_callable::get_value(), image::getMinimap(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_get_map_size(), editor::editor_map::invert_selection(), editor::editor_map::mask_to(), display::max_map_area(), display::minimap_location_on(), editor::context_manager::new_map_dialog(), editor::context_manager::new_scenario_dialog(), overlay(), parse_location_range(), terrain_builder::rebuild_cache_all(), editor::editor_map::resize(), editor::context_manager::resize_map_dialog(), editor::editor_map::same_size_as(), editor::editor_map::sanity_check(), editor::map_context::set_map(), ai::move_result::test_route(), and ai::default_recruitment::recruitment::update_average_local_cost().

std::string gamemap::write ( ) const
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 get_terrain(), and t_translation::write_terrain_code().

Member Data Documentation

const int gamemap::default_border = 1
static
int gamemap::h_
protected
starting_positions gamemap::starting_positions_
protected
ter_data_cache gamemap::tdata_
private
t_translation::ter_map gamemap::tiles_
protected
std::vector<map_location> gamemap::villages_
private

Definition at line 224 of file map.hpp.

Referenced by read(), set_terrain(), and villages().

int gamemap::w_
protected

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