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