The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
editor_map.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Tomasz Sniatowski <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef EDITOR_EDITOR_MAP_HPP_INCLUDED
16 #define EDITOR_EDITOR_MAP_HPP_INCLUDED
17 
18 #include "editor/editor_common.hpp"
19 
20 #include "map/map.hpp"
21 
22 #include <deque>
23 
24 namespace editor {
25 
27 {
29  : editor_exception("Map operation error. Check debug log for details.")
30  {
31  }
32 };
33 
35 {
37  : editor_exception("Map integrity error. Check debug log for details.")
38  {
39  }
40 };
41 
43 {
45  : editor_exception(msg), filename(fn)
46  {
47  }
50 };
51 
53 {
55  : editor_exception(msg)
56  {
57  }
59 };
60 
61 
62 /**
63  * Exception wrapping utility
64  */
65 editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, const std::string& filename);
66 
67 /**
68  * This class adds extra editor-specific functionality to a normal gamemap.
69  */
70 class editor_map : public gamemap
71 {
72 public:
73 
74  /**
75  * Empty map constructor
76  */
77  explicit editor_map(const config& terrain_cfg);
78 
79  /**
80  * Create an editor map from a map data string
81  */
82  editor_map(const config& terrain_cfg, const std::string& data);
83 
84  /**
85  * Wrapper around editor_map(cfg, data) that catches possible exceptions
86  * and wraps them in a editor_map_load_exception
87  */
88  static editor_map from_string(const config& terrain_cfg, const std::string& data);
89 
90  /**
91  * Create an editor map with the given dimensions and filler terrain
92  */
93  editor_map(const config& terrain_cfg, size_t width, size_t height, const t_translation::t_terrain & filler);
94 
95  /**
96  * Create an editor_map by upgrading an existing gamemap. The map data is
97  * copied. Marked "explicit" to avoid potentially harmful automatic conversions.
98  */
99  explicit editor_map(const gamemap& map);
100 
101  /**
102  * editor_map destructor
103  */
104  ~editor_map();
105 
106  /**
107  * Debugging aid. Check if the widths and heights correspond to the actual map data sizes.
108  */
109  void sanity_check();
110 
111  /**
112  * Get a contiguous set of tiles having the same terrain as the starting location.
113  * Useful for flood fill or magic wand selection
114  * @return a contiguous set of locations that will always contain at least the starting element
115  */
116  std::set<map_location> get_contiguous_terrain_tiles(const map_location& start) const;
117 
118  /**
119  * Set labels for staring positions in the given display object.
120  * @return the locations where the labels were added
121  */
122  std::set<map_location> set_starting_position_labels(display& disp);
123 
124  /**
125  * @return true when the location is part of the selection, false otherwise
126  */
127  bool in_selection(const map_location& loc) const;
128 
129  /**
130  * Add a location to the selection. The location should be valid (i.e. on the map)
131  * @return true if the selected hexes set was modified
132  */
133  bool add_to_selection(const map_location& loc);
134 
135  /**
136  * Remove a location to the selection. The location does not actually have to be selected
137  * @return true if the selected hexes set was modified
138  */
139  bool remove_from_selection(const map_location& loc);
140 
141  /**
142  * Select the given area.
143  * @param area to select.
144  */
145  bool set_selection(const std::set<map_location>& area);
146 
147  /**
148  * Return the selection set.
149  */
150  const std::set<map_location>& selection() const { return selection_; }
151 
152  /**
153  * Clear the selection
154  */
155  void clear_selection();
156 
157  /**
158  * Invert the selection, i.e. select all the map hexes that were not selected.
159  */
160  void invert_selection();
161 
162  /**
163  * Select all map hexes
164  */
165  void select_all();
166 
167  /**
168  * @return true if the entire map is selected, false otherwise
169  */
170  bool everything_selected() const;
171 
172  /**
173  * Resize the map. If the filler is NONE, the border terrain will be copied
174  * when expanding, otherwise the filler terrain will be inserted there
175  */
176  void resize(int width, int height, int x_offset, int y_offset,
178 
179  /**
180  * A sort-of diff operation returning a mask that, when applied to the current editor_map,
181  * will transform it into the target map.
182  */
183  gamemap mask_to(const gamemap& target) const;
184 
185  /**
186  * A precondition to several map operations
187  * @return true if this map has the same dimensions as the other map
188  */
189  bool same_size_as(const gamemap& other) const;
190 
191 protected:
193 
194  //helper functions for resizing
195  void expand_right(int count, const t_translation::t_terrain & filler);
196  void expand_left(int count, const t_translation::t_terrain & filler);
197  void expand_top(int count, const t_translation::t_terrain & filler);
198  void expand_bottom(int count, const t_translation::t_terrain & filler);
199  void shrink_right(int count);
200  void shrink_left(int count);
201  void shrink_top(int count);
202  void shrink_bottom(int count);
203 
204  /**
205  * The selected hexes
206  */
207  std::set<map_location> selection_;
208 };
209 
210 
211 } //end namespace editor
212 
213 #endif
editor_map_save_exception(const std::string &msg)
Definition: editor_map.hpp:54
editor_map_load_exception(const std::string &fn, const std::string &msg)
Definition: editor_map.hpp:44
void resize(int width, int height, int x_offset, int y_offset, const t_translation::t_terrain &filler=t_translation::NONE_TERRAIN)
Resize the map.
Definition: editor_map.cpp:226
std::set< map_location > selection_
The selected hexes.
Definition: editor_map.hpp:207
std::set< map_location > set_starting_position_labels(display &disp)
Set labels for staring positions in the given display object.
Definition: editor_map.cpp:149
void shrink_top(int count)
Definition: editor_map.cpp:382
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
const t_terrain NONE_TERRAIN
Definition: translation.hpp:56
void sanity_check()
Debugging aid.
Definition: editor_map.cpp:91
void expand_top(int count, const t_translation::t_terrain &filler)
Definition: editor_map.cpp:328
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
void expand_left(int count, const t_translation::t_terrain &filler)
Definition: editor_map.cpp:318
t_translation::t_list clone_column(int x, const t_translation::t_terrain &filler)
Definition: editor_map.cpp:294
std::set< map_location > get_contiguous_terrain_tiles(const map_location &start) const
Get a contiguous set of tiles having the same terrain as the starting location.
Definition: editor_map.cpp:126
~editor_map()
editor_map destructor
Definition: editor_map.cpp:87
editor_map_load_exception wrap_exc(const char *type, const std::string &e_msg, const std::string &filename)
Exception wrapping utility.
Definition: editor_map.cpp:34
bool everything_selected() const
Definition: editor_map.cpp:220
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.
Definition: editor_map.cpp:271
bool in_selection(const map_location &loc) const
Definition: editor_map.cpp:171
void invert_selection()
Invert the selection, i.e.
Definition: editor_map.cpp:201
bool same_size_as(const gamemap &other) const
A precondition to several map operations.
Definition: editor_map.cpp:288
GLuint start
Definition: glew.h:1221
Encapsulates the map of the game.
Definition: map.hpp:37
Manage the empty-palette in the editor.
Definition: action.cpp:28
void shrink_left(int count)
Definition: editor_map.cpp:372
GLuint GLuint GLsizei count
Definition: glew.h:1221
void expand_bottom(int count, const t_translation::t_terrain &filler)
Definition: editor_map.cpp:345
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
bool add_to_selection(const map_location &loc)
Add a location to the selection.
Definition: editor_map.cpp:176
Encapsulates the map of the game.
Definition: location.hpp:38
static editor_map from_string(const config &terrain_cfg, const std::string &data)
Wrapper around editor_map(cfg, data) that catches possible exceptions and wraps them in a editor_map_...
Definition: editor_map.cpp:59
void expand_right(int count, const t_translation::t_terrain &filler)
Definition: editor_map.cpp:308
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
Main (common) editor header.
editor_map(const config &terrain_cfg)
Empty map constructor.
Definition: editor_map.cpp:46
void clear_selection()
Clear the selection.
Definition: editor_map.cpp:196
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
const std::set< map_location > & selection() const
Return the selection set.
Definition: editor_map.hpp:150
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
void select_all()
Select all map hexes.
Definition: editor_map.cpp:214
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
void shrink_right(int count)
Definition: editor_map.cpp:362
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool set_selection(const std::set< map_location > &area)
Select the given area.
Definition: editor_map.cpp:181
GLenum target
Definition: glew.h:5190
bool remove_from_selection(const map_location &loc)
Remove a location to the selection.
Definition: editor_map.cpp:191
std::vector< t_terrain > t_list
Definition: translation.hpp:75
void shrink_bottom(int count)
Definition: editor_map.cpp:394