Encapsulates the map of the game. More...
#include <map.hpp>
Public Member Functions | |
const t_translation::ter_list & | underlying_mvt_terrain (const map_location &loc) const |
const t_translation::ter_list & | underlying_def_terrain (const map_location &loc) const |
const t_translation::ter_list & | underlying_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_list & | underlying_mvt_terrain (const t_translation::terrain_code &terrain) const |
const t_translation::ter_list & | underlying_def_terrain (const t_translation::terrain_code &terrain) const |
const t_translation::ter_list & | underlying_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_type & | get_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_type & | get_terrain_info (const map_location &loc) const |
Shortcut to get_terrain_info(get_terrain(loc)). More... | |
const t_translation::ter_list & | get_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_map & | special_locations () |
const location_map & | special_locations () const |
const std::vector< map_location > | starting_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_location > | 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. 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_location > | villages_ |
Private Member Functions | |
t_translation::terrain_code & | operator[] (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_data > | tdata_ |
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_map & | tiles () |
const terrain_map & | tiles () const |
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.
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.
data | the 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().
std::string gamemap::get_terrain_editor_string | ( | const map_location & | loc | ) | const |
Definition at line 63 of file map.cpp.
References gamemap_base::get_terrain().
Referenced by editor::terrain_palette::get_help_string(), editor::editor_display::layout(), and editor::terrain_palette::setup_item().
std::string gamemap::get_terrain_editor_string | ( | 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 gamemap_base::get_terrain(), and tdata_.
const terrain_type & gamemap::get_terrain_info | ( | const t_translation::terrain_code & | terrain | ) | const |
Definition at line 98 of file map.cpp.
References tdata_.
Referenced by display::draw_overlays_at(), editor::map_context::draw_terrain(), editor::terrain_palette::get_id(), tod_manager::get_illuminated_time_of_day(), unit_animation_component::invalidate(), terrain_filter::match_internal(), terrain_builder::rebuild_terrain(), unit_drawer::redraw_unit(), REPORT_GENERATOR(), editor::mouse_action::set_terrain_mouse_overlay(), editor::terrain_palette::setup(), editor::terrain_palette::setup_item(), editor::editor_controller::terrain_description(), unit_box_at(), unit_defense(), and unit_moves().
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 gamemap_base::get_terrain().
Referenced by REPORT_GENERATOR().
std::string gamemap::get_terrain_string | ( | const t_translation::terrain_code & | terrain | ) | const |
std::string gamemap::get_underlying_terrain_string | ( | const t_translation::terrain_code & | terrain | ) | const |
int gamemap::gives_healing | ( | const map_location & | loc | ) | const |
Definition at line 68 of file map.cpp.
References gamemap_base::get_terrain(), and gamemap_base::on_board().
Referenced by ai::attack_analysis::analyze(), ai::ai_default_rca::aspect_attacks_base::rate_terrain(), and ai::default_ai_context_impl::rate_terrain().
int gamemap::gives_healing | ( | const t_translation::terrain_code & | terrain | ) | const |
bool gamemap::is_castle | ( | const map_location & | loc | ) | const |
Definition at line 70 of file map.cpp.
References gamemap_base::get_terrain(), and gamemap_base::on_board().
Referenced by game_state::can_recruit_on(), pathfind::find_vacant_tile(), ai::keeps_cache::get(), actions::get_recalls(), and actions::get_recruits().
bool gamemap::is_castle | ( | const t_translation::terrain_code & | terrain | ) | const |
bool gamemap::is_keep | ( | const map_location & | loc | ) | const |
Definition at line 72 of file map.cpp.
References gamemap_base::get_terrain(), and gamemap_base::on_board().
Referenced by game_state::can_recruit_from(), game_state::can_recruit_on(), ai::keeps_cache::get(), actions::get_recalls(), actions::get_recruits(), and events::mouse_handler::move_unit_along_route().
bool gamemap::is_keep | ( | const t_translation::terrain_code & | terrain | ) | const |
bool gamemap::is_village | ( | const map_location & | loc | ) | const |
Definition at line 66 of file map.cpp.
References gamemap_base::get_terrain(), and gamemap_base::on_board().
Referenced by ai::attack_analysis::analyze(), battle_context_unit_stats::battle_context_unit_stats(), team::build(), ai::ai_default_rca::retreat_phase::evaluate(), ai::ai_default_rca::get_villages_phase::execute(), ai::ai_default_rca::get_villages_phase::find_villages(), team::fix_villages(), pathfind::mark_route(), terrain_filter::match_internal(), unit_creator::post_create(), ai::readonly_context_impl::power_projection(), ai::ai_default_rca::aspect_attacks_base::rate_terrain(), ai::default_ai_context_impl::rate_terrain(), game_board::replace_map(), REPORT_GENERATOR(), editor::editor_map::resize(), set_terrain(), attack_type::special_active_impl(), editor::mouse_action_village::up_left(), and editor::mouse_action_village::up_right().
bool gamemap::is_village | ( | const t_translation::terrain_code & | terrain | ) | const |
|
inlineprivate |
Definition at line 226 of file map.hpp.
References gamemap_base::border_size(), t_translation::ter_map::get(), gamemap_base::tiles(), map_location::x, and map_location::y.
|
inline |
Definition at line 220 of file map.hpp.
References gamemap_base::border_size(), t_translation::ter_map::get(), gamemap_base::tiles(), map_location::x, and map_location::y.
void gamemap::read | ( | const std::string & | data, |
const bool | allow_invalid = true |
||
) |
Definition at line 133 of file map.cpp.
References gamemap_base::border_size(), data, e, cursor::get(), t_translation::ter_map::get(), t_translation::read_game_map(), read_header(), gamemap_base::special_locations(), t, tdata_, gamemap_base::tiles(), gamemap_base::total_height(), gamemap_base::total_width(), VALIDATE, villages_, and t_translation::write_terrain_code().
Referenced by gamemap(), read_header(), and game_events::WML_HANDLER_FUNCTION().
|
private |
|
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().
|
inline |
Definition at line 204 of file map.hpp.
References tdata_.
Referenced by wfl::gamestate::DEFINE_WFL_FUNCTION(), game_lua_kernel::impl_get_terrain_info(), game_lua_kernel::impl_get_terrain_list(), and image::prep_minimap_for_rendering().
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().
const t_translation::ter_list & gamemap::underlying_def_terrain | ( | const t_translation::terrain_code & | terrain | ) | const |
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().
const t_translation::ter_list & gamemap::underlying_mvt_terrain | ( | const t_translation::terrain_code & | terrain | ) | const |
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().
const t_translation::ter_list & gamemap::underlying_union_terrain | ( | const t_translation::terrain_code & | terrain | ) | const |
|
inline |
Return a list of the locations of villages on the map.
Definition at line 237 of file map.hpp.
References villages_.
Referenced by carryover_show_gold(), ai::default_ai_context_impl::find_targets(), ai::default_recruitment::recruitment::get_estimated_village_gain(), terrain_filter::get_locs_impl(), gui2::dialogs::game_stats::pre_show(), image::prep_minimap_for_rendering(), and ai::default_recruitment::recruitment::update_important_hexes().
std::string gamemap::write | ( | ) | const |
Definition at line 210 of file map.cpp.
References gamemap_base::border_size(), gamemap_base::special_locations(), gamemap_base::tiles(), and t_translation::write_game_map().
Referenced by editor::map_context::save_map(), events::menu_handler::save_map(), and editor::map_context::to_config().
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().
|
private |
Definition at line 254 of file map.hpp.
Referenced by gamemap(), get_terrain_editor_string(), get_terrain_info(), get_terrain_list(), get_terrain_string(), get_underlying_terrain_string(), gives_healing(), is_castle(), is_keep(), is_village(), read(), set_terrain(), tdata(), underlying_def_terrain(), underlying_mvt_terrain(), and underlying_union_terrain().
|
protected |
Definition at line 257 of file map.hpp.
Referenced by read(), editor::editor_map::resize(), set_terrain(), and villages().