00001 /* $Id: map_manip.hpp 23842 2008-02-16 08:47:16Z mordante $ */ 00002 /* 00003 Copyright (C) 2003 - 2008 by David White <dave@whitevine.net> 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 version 2 00008 or at your option any later version. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 //! @file editor/map_manip.hpp 00016 //! 00017 00018 #ifndef MAP_MANIP_H_INCLUDED 00019 #define MAP_MANIP_H_INCLUDED 00020 00021 #include "global.hpp" 00022 00023 #include "../map.hpp" 00024 00025 #include <vector> 00026 #include <set> 00027 00028 namespace map_editor { 00029 enum FLIP_AXIS {NO_FLIP, FLIP_X, FLIP_Y}; 00030 } 00031 00032 // This object modifies the internal structure of a map, 00033 // most of the time this is done on the real map data. 00034 // This means that the display and mapdata are heavily out of sync. 00035 // Our callers throw a new_map_exception which will invalide the entire 00036 // map object. These callers expect a string with the new raw map data. 00037 // So it's "save" but really not clean. -- Mordante 00038 class editormap : public gamemap 00039 { 00040 public: 00041 editormap(const config& terrain_cfg, const std::string& data) : 00042 gamemap(terrain_cfg, data) 00043 {} 00044 ~editormap(){} 00045 00046 /** 00047 * Resizes the map. 00048 * 00049 * @param width the new width 00050 * @param height the new height 00051 * @param x_offset the offset in x direction (the x coordinate specified will be the new 0 location) 00052 * @param y_offset the offset in y direction (the y coordinate specified will be the new 0 location) 00053 * @param do_expand try to expand the map depending on the current tiles 00054 * @param filler if the map is enlarged the new tiles are set to this terrain, 00055 * unless expand is set 00056 * 00057 * @return if there's been a modification to the map: the new map data as string, 00058 * else an empty string 00059 */ 00060 std::string resize(const size_t width, const size_t height, 00061 const int x_offset, const int y_offset, 00062 const bool do_expand, t_translation::t_terrain filler); 00063 00064 /** 00065 * Flips the map over an axis 00066 * 00067 * @param axis the axis to flip the map over 00068 * 00069 * @return if there's been a modification to the map the new map data as string 00070 * else an empty string 00071 */ 00072 std::string flip(const map_editor::FLIP_AXIS axis); 00073 00074 /** 00075 * Sets the starting position of a player 00076 * 00077 * @param pos the starting position, 1 = player 1 00078 * @param loc a location (same as gamemap location) 00079 */ 00080 void set_starting_position(const int pos, const location loc); 00081 00082 private: 00083 00084 /** 00085 * Exchanges starting positions, 00086 * If there's a starting location on x1, y1 it will be moved to x2, y2. 00087 * If x2, y2 contains a starting location this is moved to x1, y1. 00088 * The function also works if both locations contain 00089 * a starting position. 00090 */ 00091 void swap_starting_position( 00092 const size_t x1, const size_t y1, 00093 const size_t x2, const size_t y2); 00094 00095 /** 00096 * Adds column(s) at the right side. 00097 * 00098 * @param count the number of columns to add 00099 * @param filler the terrain to draw, if equal to NONE_TERRAIN 00100 * the enigne will determine the terrain by itself 00101 */ 00102 void add_tiles_right(const unsigned count, 00103 const t_translation::t_terrain& filler); 00104 00105 /** 00106 * Adds column(s) at the left side 00107 * 00108 * @param count the number of columns to add 00109 * @param filler the terrain to draw, if equal to NONE_TERRAIN 00110 * the enigne will determine the terrain by itself 00111 */ 00112 void add_tiles_left(const unsigned count, 00113 const t_translation::t_terrain& filler); 00114 00115 /** 00116 * Removes column(s) at the right side. 00117 * 00118 * @param count the number of columns to remove 00119 */ 00120 void remove_tiles_right(const unsigned count); 00121 00122 /** 00123 * Removes column(s) at the left side. 00124 * 00125 * @param count the number of columns to remove 00126 */ 00127 void remove_tiles_left(const unsigned count); 00128 00129 /** 00130 * Adds row(s) at the top side. 00131 * 00132 * @param count the number of rows to add 00133 * @param filler the terrain to draw, if equal to NONE_TERRAIN 00134 * the enigne will determine the terrain by itself 00135 */ 00136 void add_tiles_top(const unsigned count, 00137 const t_translation::t_terrain& filler); 00138 00139 /** 00140 * Adds row(s) at the bottom side. 00141 * 00142 * @param count the number of rows to add 00143 * @param filler the terrain to draw, if equal to NONE_TERRAIN 00144 * the enigne will determine the terrain by itself 00145 */ 00146 void add_tiles_bottom(const unsigned count, 00147 const t_translation::t_terrain& filler); 00148 00149 /** 00150 * Removes row(s) at the top side. 00151 * 00152 * @param count the number of rows to remove 00153 */ 00154 void remove_tiles_top(const unsigned count); 00155 00156 /** 00157 * Removes row(s) at the bottom side. 00158 * 00159 * @param count the number of rows to remove 00160 */ 00161 void remove_tiles_bottom(const unsigned count); 00162 }; 00163 00164 namespace map_editor { 00165 00166 //! Return the tiles that are within radius from the location. 00167 std::vector<gamemap::location> get_tiles(const gamemap &map, 00168 const gamemap::location& a, 00169 const unsigned int radius); 00170 00171 typedef std::vector<std::pair<gamemap::location, t_translation::t_terrain> > terrain_log; 00172 00173 /// Flood fill the map with the terrain fill_with 00174 /// starting from the location start_loc. 00175 /// If log is non-null it will contain the positions of the changed tiles 00176 /// and the terrains they had before the filling started. 00177 void flood_fill(gamemap &map, const gamemap::location &start_loc, 00178 const t_translation::t_terrain fill_with, terrain_log *log = NULL); 00179 00180 /// Return the area that would be flood filled 00181 /// if a flood fill was requested. 00182 std::set<gamemap::location> 00183 get_component(const gamemap &map, const gamemap::location &start_loc); 00184 00185 /// Return the string representation of the map after it has been 00186 /// resized to new_w X new_h. If the new dimensions are smaller than the 00187 /// current ones, the map will be cropped from the bottom and from the 00188 /// right. If the map becomes larger than the current dimensions, the 00189 /// new map area appeard at the bottom and/or the right and is filled 00190 /// with the terrain fill_with. 00191 std::string resize_map(editormap &map, const unsigned new_w, 00192 const unsigned new_h, const int off_x, const int off_y, 00193 const bool do_expand, const t_translation::t_terrain fill_with); 00194 00195 /// Return the string representation of the map 00196 /// after it has been flipped around the axis. 00197 std::string flip_map(editormap &map, const FLIP_AXIS axis); 00198 00199 //! Return true if the data is valid to create a map with, 00200 //! othwerwise false. 00201 bool valid_mapdata(const std::string &data, const config &cfg); 00202 00203 00204 //! Returns a string representating a new empty map 00205 //! of width by height of the terrain filler 00206 std::string new_map(const size_t width, const size_t height, const t_translation::t_terrain filler); 00207 00208 } // end namespace map_editor 00209 00210 00211 #endif // MAP_MANIP_H_INCLUDED
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |