The Battle for Wesnoth  1.19.7+dev
map_fragment.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
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
map_location loc
Definition: move.cpp:172
A map fragment – a collection of locations and information abut them.
void flip_vertical()
Flip the map fragment vertically.
std::set< map_location > get_offset_area(const map_location &offset) const
Get the area covered by this map fragment, shifted by an offset.
std::set< map_location > get_area() const
Get the area covered by this map fragment.
map_location center_of_mass() const
Get the center of the map fragment, mass-wise.
std::string dump() const
Debug dump to a string.
std::vector< tile_info > items_
The data of this map_fragment.
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).
void shift(const map_location &offset)
Shift all tiles in the map fragment by the specified offset.
std::set< map_location > area_
void rotate_60_ccw()
Rotate the map fragment 60 degrees counter-clockwise around (0,0)
void center_by_mass()
Shift the map fragment so it is roughly centered around the (0,0) point, mass-wise.
map_fragment()
Create an empty map fragment.
void add_tile(const gamemap &map, const map_location &loc)
Add a single location and pull its info from the map.
void add_tiles(const gamemap &map, const std::set< map_location > &loc)
Add many locations and pull their info from the map.
const std::vector< tile_info > & get_items() const
Get the tile_info vector.
void rotate_60_cw()
Rotate the map fragment 60 degrees clockwise around (0,0)
Encapsulates the map of the game.
Definition: map.hpp:172
Manage the empty-palette in the editor.
Definition: action.cpp:31
This represents a tile along with information about it, namely the terrain, possibly other informatio...
t_translation::terrain_code terrain
map_location offset
tile_info(const gamemap &map, const map_location &offset)
Create a tile info – the constructor grabs required data from the map.
Encapsulates the map of the game.
Definition: location.hpp:45
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49