00001 /* $Id: map_fragment.hpp 53522 2012-03-13 18:19:16Z fendrin $ */ 00002 /* 00003 Copyright (C) 2008 - 2012 by Tomasz Sniatowski <kailoran@gmail.com> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef EDITOR_MAP_FRAGMENT_HPP_INCLUDED 00017 #define EDITOR_MAP_FRAGMENT_HPP_INCLUDED 00018 00019 #include "editor_map.hpp" 00020 00021 namespace editor { 00022 00023 /** 00024 * This represents a tile along with information about it, namely the terrain, 00025 * possibly other information. It is a less compact representation that what 00026 * is used in the map, but is more convenient in some situations. 00027 */ 00028 struct tile_info 00029 { 00030 /** 00031 * Create a tile info -- the constructor grabs required data from the map 00032 */ 00033 tile_info(const gamemap& map, const map_location& offset) 00034 : offset(offset), terrain(map.get_terrain(offset)) 00035 { 00036 } 00037 00038 map_location offset; 00039 t_translation::t_terrain terrain; 00040 }; 00041 00042 /** 00043 * A map fragment -- a collection of locations and information abut them. 00044 */ 00045 class map_fragment 00046 { 00047 public: 00048 /** 00049 * Create an empty map fragment. 00050 */ 00051 map_fragment(); 00052 00053 /** 00054 * Create a map fragment from the specified locations on the map. 00055 */ 00056 map_fragment(const gamemap& map, const std::set<map_location>& area); 00057 00058 /** 00059 * Add a single location and pull its info from the map. 00060 */ 00061 void add_tile(const gamemap& map, const map_location& loc); 00062 00063 /** 00064 * Add many locations and pull their info from the map. 00065 */ 00066 void add_tiles(const gamemap& map, const std::set<map_location>& loc); 00067 00068 /** 00069 * Get the tile_info vector. 00070 */ 00071 const std::vector<tile_info>& get_items() const { return items_; } 00072 00073 /** 00074 * Get the area covered by this map fragment. 00075 */ 00076 std::set<map_location> get_area() const; 00077 00078 /** 00079 * Get the area covered by this map fragment, shifted by an offset. 00080 */ 00081 std::set<map_location> get_offset_area(const map_location& offset) const; 00082 00083 /** 00084 * Paste the map fragment into the map, treating loc as the (0,0) point (offset). 00085 */ 00086 void paste_into(gamemap& map, const map_location& loc) const; 00087 00088 /** 00089 * Shift all tiles in the map fragment by the specified offset. 00090 */ 00091 void shift(const map_location& offset); 00092 00093 /** 00094 * Get the center of the map fragment, mass-wise. 00095 */ 00096 map_location center_of_mass() const; 00097 00098 /** 00099 * Shift the map fragment so it is roughly centered around the (0,0) point, mass-wise. 00100 */ 00101 void center_by_mass(); 00102 00103 /** 00104 * @return true if the map_fragment is empty 00105 */ 00106 bool empty() const; 00107 00108 /** 00109 * Rotate the map fragment 60 degrees clockwise around (0,0) 00110 */ 00111 void rotate_60_cw(); 00112 00113 /** 00114 * Rotate the map fragment 60 degrees counter-clockwise around (0,0) 00115 */ 00116 void rotate_60_ccw(); 00117 00118 /** 00119 * Flip the map fragment horizontally 00120 */ 00121 void flip_horizontal(); 00122 00123 /** 00124 * Flip the map fragment vertically 00125 */ 00126 void flip_vertical(); 00127 00128 /** 00129 * Debug dump to a string 00130 */ 00131 std::string dump() const; 00132 00133 protected: 00134 /** 00135 * The data of this map_fragment 00136 */ 00137 std::vector<tile_info> items_; 00138 std::set<map_location> area_; 00139 }; 00140 00141 } //end namespace editor 00142 00143 #endif
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:50 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |