The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
map_fragment.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_MAP_FRAGMENT_HPP_INCLUDED
16 #define EDITOR_MAP_FRAGMENT_HPP_INCLUDED
17 
18 #include "editor_map.hpp"
19 
20 namespace editor {
21 
22 /**
23  * This represents a tile along with information about it, namely the terrain,
24  * possibly other information. It is a less compact representation that what
25  * is used in the map, but is more convenient in some situations.
26  */
27 struct tile_info
28 {
29  /**
30  * Create a tile info -- the constructor grabs required data from the map
31  */
32  tile_info(const gamemap& map, const map_location& offset)
33  : offset(offset), terrain(map.get_terrain(offset))
34  {
35  }
36 
39 };
40 
41 /**
42  * A map fragment -- a collection of locations and information abut them.
43  */
45 {
46  public:
47  /**
48  * Create an empty map fragment.
49  */
50  map_fragment();
51 
52  /**
53  * Create a map fragment from the specified locations on the map.
54  */
55  map_fragment(const gamemap& map, const std::set<map_location>& area);
56 
57  /**
58  * Add a single location and pull its info from the map.
59  */
60  void add_tile(const gamemap& map, const map_location& loc);
61 
62  /**
63  * Add many locations and pull their info from the map.
64  */
65  void add_tiles(const gamemap& map, const std::set<map_location>& loc);
66 
67  /**
68  * Get the tile_info vector.
69  */
70  const std::vector<tile_info>& get_items() const { return items_; }
71 
72  /**
73  * Get the area covered by this map fragment.
74  */
75  std::set<map_location> get_area() const;
76 
77  /**
78  * Get the area covered by this map fragment, shifted by an offset.
79  */
80  std::set<map_location> get_offset_area(const map_location& offset) const;
81 
82  /**
83  * Paste the map fragment into the map, treating loc as the (0,0) point (offset).
84  */
85  void paste_into(gamemap& map, const map_location& loc) const;
86 
87  /**
88  * Shift all tiles in the map fragment by the specified offset.
89  */
90  void shift(const map_location& offset);
91 
92  /**
93  * Get the center of the map fragment, mass-wise.
94  */
96 
97  /**
98  * Shift the map fragment so it is roughly centered around the (0,0) point, mass-wise.
99  */
100  void center_by_mass();
101 
102  /**
103  * @return true if the map_fragment is empty
104  */
105  bool empty() const;
106 
107  /**
108  * Rotate the map fragment 60 degrees clockwise around (0,0)
109  */
110  void rotate_60_cw();
111 
112  /**
113  * Rotate the map fragment 60 degrees counter-clockwise around (0,0)
114  */
115  void rotate_60_ccw();
116 
117  /**
118  * Flip the map fragment horizontally
119  */
120  void flip_horizontal();
121 
122  /**
123  * Flip the map fragment vertically
124  */
125  void flip_vertical();
126 
127  /**
128  * Debug dump to a string
129  */
130  std::string dump() const;
131 
132  protected:
133  /**
134  * The data of this map_fragment
135  */
136  std::vector<tile_info> items_;
137  std::set<map_location> area_;
138 };
139 
140 } //end namespace editor
141 
142 #endif
A map fragment – a collection of locations and information abut them.
void flip_horizontal()
Flip the map fragment horizontally.
void paste_into(gamemap &map, const map_location &loc) const
Paste the map fragment into the map, treating loc as the (0,0) point (offset).
std::string dump() const
Debug dump to a string.
void rotate_60_ccw()
Rotate the map fragment 60 degrees counter-clockwise around (0,0)
GLintptr offset
Definition: glew.h:1650
std::set< map_location > get_offset_area(const map_location &offset) const
Get the area covered by this map fragment, shifted by an offset.
Encapsulates the map of the game.
Definition: map.hpp:37
Manage the empty-palette in the editor.
Definition: action.cpp:28
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
Encapsulates the map of the game.
Definition: location.hpp:38
map_location offset
void flip_vertical()
Flip the map fragment vertically.
void shift(const map_location &offset)
Shift all tiles in the map fragment by the specified offset.
map_location center_of_mass() const
Get the center of the map fragment, mass-wise.
const std::vector< tile_info > & get_items() const
Get the tile_info vector.
This represents a tile along with information about it, namely the terrain, possibly other informatio...
t_translation::t_terrain terrain
void add_tiles(const gamemap &map, const std::set< map_location > &loc)
Add many locations and pull their info from the map.
map_fragment()
Create an empty map fragment.
std::set< map_location > area_
tile_info(const gamemap &map, const map_location &offset)
Create a tile info – the constructor grabs required data from the map.
std::set< map_location > get_area() const
Get the area covered by this map fragment.
std::vector< tile_info > items_
The data of this map_fragment.
void center_by_mass()
Shift the map fragment so it is roughly centered around the (0,0) point, mass-wise.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void add_tile(const gamemap &map, const map_location &loc)
Add a single location and pull its info from the map.
void rotate_60_cw()
Rotate the map fragment 60 degrees clockwise around (0,0)