The Battle for Wesnoth  1.19.18+dev
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
editor::editor_map Class Reference

This class adds extra editor-specific functionality to a normal gamemap. More...

#include <editor_map.hpp>

Inheritance diagram for editor::editor_map:

Classes

class  selection_mask
 

Public Member Functions

 editor_map ()
 Empty map constructor. More...
 
 editor_map (std::string_view data)
 Create an editor map from a map data string. More...
 
 editor_map (std::size_t width, std::size_t height, const t_translation::terrain_code &filler)
 Create an editor map with the given dimensions and filler terrain. More...
 
 editor_map (const gamemap &map)
 Create an editor_map by upgrading an existing gamemap. More...
 
std::set< map_locationget_contiguous_terrain_tiles (const map_location &start) const
 Get a contiguous set of tiles having the same terrain as the starting location. More...
 
std::set< map_locationset_starting_position_labels (display &disp)
 Set labels for staring positions in the given display object. More...
 
bool in_selection (const map_location &loc) const
 
bool add_to_selection (const map_location &loc)
 Add a location to the selection. More...
 
bool remove_from_selection (const map_location &loc)
 Remove a location to the selection. More...
 
void set_selection (const std::set< map_location > &area)
 Select the given area. More...
 
std::set< map_locationselection () const
 Return the selection set. More...
 
std::set< map_locationselection_inverse () const
 Returns a set of all hexes not currently selected. More...
 
void clear_selection ()
 Clear the selection. More...
 
void invert_selection ()
 Invert the selection, i.e. More...
 
void select_all ()
 Select all map hexes. More...
 
bool everything_selected () const
 
bool anything_selected () const
 
bool nothing_selected () const
 
std::size_t num_selected () const
 
void resize (int width, int height, int x_offset, int y_offset, const t_translation::terrain_code &filler=t_translation::NONE_TERRAIN)
 Resize the map. More...
 
gamemap mask_to (const gamemap &target) const
 A sort-of diff operation returning a mask that, when applied to the current editor_map, will transform it into the target map. More...
 
bool same_size_as (const gamemap &other) const
 A precondition to several map operations. More...
 
- Public Member Functions inherited from gamemap
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 (std::string_view data)
 Loads a map. More...
 
 gamemap (int w, int h, const terrain_code &default_ter)
 
void read (std::string_view 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...
 
int total_area () const
 Total square area 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
 

Static Public Member Functions

static editor_map from_string (std::string_view data)
 Wrapper around editor_map(cfg, data) that catches possible exceptions and wraps them in a editor_map_load_exception. More...
 

Private Member Functions

void expand_right (int count, const t_translation::terrain_code &filler)
 
void expand_left (int count, const t_translation::terrain_code &filler)
 
void expand_top (int count, const t_translation::terrain_code &filler)
 
void expand_bottom (int count, const t_translation::terrain_code &filler)
 
void shrink_right (int count)
 
void shrink_left (int count)
 
void shrink_top (int count)
 
void shrink_bottom (int count)
 

Private Attributes

selection_mask selection_
 The selected hexes. More...
 

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, const terrain_code &default_ter)
 
terrain_maptiles ()
 
const terrain_maptiles () const
 
- Protected Attributes inherited from gamemap
std::vector< map_locationvillages_
 

Detailed Description

This class adds extra editor-specific functionality to a normal gamemap.

Definition at line 69 of file editor_map.hpp.

Constructor & Destructor Documentation

◆ editor_map() [1/4]

editor::editor_map::editor_map ( )

Empty map constructor.

Definition at line 42 of file editor_map.cpp.

Referenced by from_string().

◆ editor_map() [2/4]

editor::editor_map::editor_map ( std::string_view  data)

Create an editor map from a map data string.

Definition at line 48 of file editor_map.cpp.

◆ editor_map() [3/4]

editor::editor_map::editor_map ( std::size_t  width,
std::size_t  height,
const t_translation::terrain_code filler 
)

Create an editor map with the given dimensions and filler terrain.

Definition at line 67 of file editor_map.cpp.

◆ editor_map() [4/4]

editor::editor_map::editor_map ( const gamemap map)
explicit

Create an editor_map by upgrading an existing gamemap.

The map data is copied. Marked "explicit" to avoid potentially harmful automatic conversions.

Definition at line 73 of file editor_map.cpp.

Member Function Documentation

◆ add_to_selection()

bool editor::editor_map::add_to_selection ( const map_location loc)

Add a location to the selection.

The location should be valid (i.e. on the map)

Returns
true if the selected hexes set was modified

Definition at line 127 of file editor_map.cpp.

References loc, gamemap_base::on_board_with_border(), editor::editor_map::selection_mask::select(), and selection_.

Referenced by editor::editor_action_select::perform_without_undo(), resize(), and set_selection().

◆ anything_selected()

bool editor::editor_map::anything_selected ( ) const
Returns
true if at least one location is selected, false otherwise

Definition at line 175 of file editor_map.cpp.

References editor::editor_map::selection_mask::mask(), and selection_.

Referenced by editor::editor_controller::can_execute_command().

◆ clear_selection()

void editor::editor_map::clear_selection ( )

◆ everything_selected()

bool editor::editor_map::everything_selected ( ) const
Returns
true if the entire map is selected, false otherwise

Definition at line 170 of file editor_map.cpp.

References editor::editor_map::selection_mask::mask(), and selection_.

Referenced by editor::editor_controller::can_execute_command().

◆ expand_bottom()

void editor::editor_map::expand_bottom ( int  count,
const t_translation::terrain_code filler 
)
private

◆ expand_left()

void editor::editor_map::expand_left ( int  count,
const t_translation::terrain_code filler 
)
private

◆ expand_right()

void editor::editor_map::expand_right ( int  count,
const t_translation::terrain_code filler 
)
private

◆ expand_top()

void editor::editor_map::expand_top ( int  count,
const t_translation::terrain_code filler 
)
private

◆ from_string()

editor_map editor::editor_map::from_string ( std::string_view  data)
static

Wrapper around editor_map(cfg, data) that catches possible exceptions and wraps them in a editor_map_load_exception.

Definition at line 54 of file editor_map.cpp.

References data, e, editor_map(), and editor::wrap_exc().

Referenced by editor::map_context::load_scenario(), and editor::map_context::map_context().

◆ get_contiguous_terrain_tiles()

std::set< map_location > editor::editor_map::get_contiguous_terrain_tiles ( const map_location start) const

Get a contiguous set of tiles having the same terrain as the starting location.

Useful for flood fill or magic wand selection

Returns
a contiguous set of locations that will always contain at least the starting element

Definition at line 79 of file editor_map.cpp.

References get_adjacent_tiles(), gamemap_base::get_terrain(), gamemap_base::on_board_with_border(), and editor::start().

Referenced by editor::mouse_action_fill::affected_hexes(), editor::mouse_action_select::affected_hexes(), and editor::editor_action_fill::perform_without_undo().

◆ in_selection()

bool editor::editor_map::in_selection ( const map_location loc) const
Returns
true when the location is part of the selection, false otherwise

Definition at line 122 of file editor_map.cpp.

References loc, gamemap_base::on_board_with_border(), editor::editor_map::selection_mask::selected(), and selection_.

Referenced by editor::editor_action_select::perform(), and editor::editor_action_deselect::perform().

◆ invert_selection()

void editor::editor_map::invert_selection ( )

Invert the selection, i.e.

select all the map hexes that were not selected.

Definition at line 160 of file editor_map.cpp.

References editor::editor_map::selection_mask::invert(), and selection_.

Referenced by editor::editor_action_select_inverse::perform_without_undo().

◆ mask_to()

gamemap editor::editor_map::mask_to ( const gamemap target) const

A sort-of diff operation returning a mask that, when applied to the current editor_map, will transform it into the target map.

Definition at line 263 of file editor_map.cpp.

References _(), gamemap_base::border_size(), t_translation::FOGGED, gamemap_base::get_terrain(), gamemap_base::h(), gamemap::set_terrain(), gamemap_base::w(), map_location::x, and map_location::y.

◆ nothing_selected()

bool editor::editor_map::nothing_selected ( ) const
Returns
true if at no selections are selected, false otherwise

Definition at line 180 of file editor_map.cpp.

References editor::editor_map::selection_mask::mask(), and selection_.

◆ num_selected()

std::size_t editor::editor_map::num_selected ( ) const
Returns
the number of locations selected.
Note
This is more efficient than checking selection().size() since it avoids allocating a full map_location set and simply queries the number of engaged bits in the underlying bitset.

Definition at line 185 of file editor_map.cpp.

References editor::editor_map::selection_mask::mask(), and selection_.

Referenced by editor::editor_controller::can_execute_command().

◆ remove_from_selection()

bool editor::editor_map::remove_from_selection ( const map_location loc)

Remove a location to the selection.

The location does not actually have to be selected

Returns
true if the selected hexes set was modified

Definition at line 150 of file editor_map.cpp.

References editor::editor_map::selection_mask::deselect(), loc, gamemap_base::on_board_with_border(), and selection_.

Referenced by editor::editor_action_deselect::perform_without_undo().

◆ resize()

void editor::editor_map::resize ( int  width,
int  height,
int  x_offset,
int  y_offset,
const t_translation::terrain_code filler = t_translation::NONE_TERRAIN 
)

Resize the map.

If the filler is NONE, the border terrain will be copied when expanding, otherwise the filler terrain will be inserted there

Definition at line 190 of file editor_map.cpp.

References map_location::add(), add_to_selection(), expand_bottom(), expand_left(), expand_right(), expand_top(), gamemap_base::for_each_loc(), gamemap_base::h(), gamemap::is_village(), loc, map_location::plus(), selection(), selection_, shrink_bottom(), shrink_left(), shrink_right(), shrink_top(), gamemap_base::special_locations(), gamemap::villages_, and gamemap_base::w().

◆ same_size_as()

bool editor::editor_map::same_size_as ( const gamemap other) const

A precondition to several map operations.

Returns
true if this map has the same dimensions as the other map

Definition at line 280 of file editor_map.cpp.

References gamemap_base::h(), and gamemap_base::w().

◆ select_all()

void editor::editor_map::select_all ( )

Select all map hexes.

Definition at line 165 of file editor_map.cpp.

References editor::editor_map::selection_mask::select_all(), and selection_.

Referenced by editor::editor_action_select_all::perform_without_undo().

◆ selection()

std::set< map_location > editor::editor_map::selection ( ) const

◆ selection_inverse()

std::set< map_location > editor::editor_map::selection_inverse ( ) const

Returns a set of all hexes not currently selected.

Definition at line 145 of file editor_map.cpp.

References editor::editor_map::selection_mask::get_locations(), editor::editor_map::selection_mask::inverted(), and selection_.

◆ set_selection()

void editor::editor_map::set_selection ( const std::set< map_location > &  area)

Select the given area.

Parameters
areato select.

Definition at line 132 of file editor_map.cpp.

References add_to_selection(), clear_selection(), and loc.

Referenced by editor::map_context::select_area().

◆ set_starting_position_labels()

std::set< map_location > editor::editor_map::set_starting_position_labels ( display disp)

Set labels for staring positions in the given display object.

Returns
the locations where the labels were added

Definition at line 100 of file editor_map.cpp.

References c, utils::find_if(), label, display::labels(), map_labels::set_label(), gamemap_base::special_locations(), and VGETTEXT.

Referenced by editor::map_context::set_starting_position_labels().

◆ shrink_bottom()

void editor::editor_map::shrink_bottom ( int  count)
private

◆ shrink_left()

void editor::editor_map::shrink_left ( int  count)
private

◆ shrink_right()

void editor::editor_map::shrink_right ( int  count)
private

◆ shrink_top()

void editor::editor_map::shrink_top ( int  count)
private

Member Data Documentation

◆ selection_

selection_mask editor::editor_map::selection_
private

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