editor/map/editor_map.hpp

Go to the documentation of this file.
00001 /* $Id: editor_map.hpp 53726 2012-03-31 18:16:27Z 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_EDITOR_MAP_HPP_INCLUDED
00017 #define EDITOR_EDITOR_MAP_HPP_INCLUDED
00018 
00019 #include "../editor_common.hpp"
00020 
00021 #include "../../map.hpp"
00022 #include "../../map_label.hpp"
00023 #include "unit_map.hpp"
00024 #include "tod_manager.hpp"
00025 #include "gamestatus.hpp"
00026 
00027 #include <deque>
00028 
00029 namespace editor {
00030 
00031 struct editor_map_operation_exception : public editor_exception
00032 {
00033     editor_map_operation_exception()
00034     : editor_exception("Map operation error. Check debug log for details.")
00035     {
00036     }
00037 };
00038 
00039 struct editor_map_integrity_error : public editor_exception
00040 {
00041     editor_map_integrity_error()
00042     : editor_exception("Map integrity error. Check debug log for details.")
00043     {
00044     }
00045 };
00046 
00047 struct editor_map_load_exception : public editor_exception
00048 {
00049     editor_map_load_exception(const std::string& fn, const std::string& msg)
00050     : editor_exception(msg), filename(fn)
00051     {
00052     }
00053     ~editor_map_load_exception() throw() {}
00054     std::string filename;
00055 };
00056 
00057 struct editor_map_save_exception : public editor_exception
00058 {
00059     editor_map_save_exception(const std::string& msg)
00060     : editor_exception(msg)
00061     {
00062     }
00063     ~editor_map_save_exception() throw() {}
00064 };
00065 
00066 
00067 /**
00068  * Exception wrapping utility
00069  */
00070 editor_map_load_exception wrap_exc(const char* type, const std::string& e_msg, const std::string& filename);
00071 
00072 /**
00073  * This class adds extra editor-specific functionality to a normal gamemap.
00074  */
00075 class editor_map : public gamemap
00076 {
00077 public:
00078 
00079     /** Get the team from the current map context object */
00080     std::vector<team>& get_teams() {
00081         return teams_;
00082     }
00083 
00084     /** Get the unit map from the current map context object */
00085     unit_map& get_units() {
00086         return units_;
00087     }
00088 
00089     const unit_map& get_units() const {
00090         return units_;
00091     }
00092 
00093     tod_manager& get_time_manager() {
00094         return tod_manager_;
00095     }
00096 
00097     game_state& get_game_state() {
00098         return state_;
00099     }
00100 
00101 
00102     /**
00103      * Empty map constructor
00104      */
00105     explicit editor_map(const config& terrain_cfg, const display& disp);
00106 
00107     /**
00108      * Create an editor map from a map data string
00109      */
00110     editor_map(const config& terrain_cfg, const config& level, const display& disp);
00111 
00112     editor_map(const config& terrain_cfg, const std::string& data, const display& disp);
00113 
00114     /**
00115      * Wrapper around editor_map(cfg, data) that catches possible exceptions
00116      * and wraps them in a editor_map_load_exception
00117      */
00118     static editor_map from_string(const config& terrain_cfg, const std::string& data, const display& disp);
00119 
00120     /**
00121      * Create an editor map with the given dimensions and filler terrain
00122      */
00123     editor_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler, const display& disp);
00124 
00125     /**
00126      * Create an editor_map by upgrading an existing gamemap. The map data is
00127      * copied. Marked "explicit" to avoid potentially harmful automatic conversions.
00128      */
00129     explicit editor_map(const gamemap& map, const display& disp);
00130 
00131     /**
00132      * editor_map destructor
00133      */
00134     ~editor_map();
00135 
00136     /**
00137      * Debugging aid. Check if the widths and heights correspond to the actual map data sizes.
00138      */
00139     void sanity_check();
00140 
00141     /**
00142      * Get a contiguous set of tiles having the same terrain as the starting location.
00143      * Useful for flood fill or magic wand selection
00144      * @return a contiguous set of locations that will always contain at least the starting element
00145      */
00146     std::set<map_location> get_contiguous_terrain_tiles(const map_location& start) const;
00147 
00148     /**
00149      * @return the map labels of the map
00150      */
00151     map_labels& get_map_labels() { return labels_; };
00152 
00153 
00154     const map_labels& get_map_labels() const { return labels_; };
00155 
00156     /**
00157      * Set labels for staring positions in the given display object.
00158      * @return the locations where the labels were added
00159      */
00160     std::set<map_location> set_starting_position_labels(display& disp);
00161 
00162     /**
00163      * @return true when the location is part of the selection, false otherwise
00164      */
00165     bool in_selection(const map_location& loc) const;
00166 
00167     /**
00168      * Add a location to the selection. The location should be valid (i.e. on the map)
00169      * @return true if the selected hexes set was modified
00170      */
00171     bool add_to_selection(const map_location& loc);
00172 
00173     /**
00174      * Remove a location to the selection. The location does not actually have to be selected
00175      * @return true if the selected hexes set was modified
00176      */
00177     bool remove_from_selection(const map_location& loc);
00178 
00179     /**
00180      * Return the selection set.
00181      */
00182     const std::set<map_location>& selection() const { return selection_; }
00183 
00184     /**
00185      * Clear the selection
00186      */
00187     void clear_selection();
00188 
00189     /**
00190      * Invert the selection, i.e. select all the map hexes that were not selected.
00191      */
00192     void invert_selection();
00193 
00194     /**
00195      * Select all map hexes
00196      */
00197     void select_all();
00198 
00199     /**
00200      * @return true if the entire map is selected, false otherwise
00201      */
00202     bool everything_selected() const;
00203 
00204     /**
00205      * Resize the map. If the filler is NONE, the border terrain will be copied
00206      * when expanding, otherwise the filler terrain will be inserted there
00207      */
00208     void resize(int width, int height, int x_offset, int y_offset,
00209         t_translation::t_terrain filler = t_translation::NONE_TERRAIN);
00210 
00211     /**
00212      * A sort-of diff operation returning a mask that, when applied to the current editor_map,
00213      * will transform it into the target map.
00214      */
00215     editor_map mask_to(const editor_map& target) const;
00216 
00217     /**
00218      * A precondition to several map operations
00219      * @return true if this map has the same dimensions as the other map
00220      */
00221     bool same_size_as(const gamemap& other) const;
00222 
00223     void write(config&) const;
00224 
00225 protected:
00226     t_translation::t_list clone_column(int x, t_translation::t_terrain filler);
00227 
00228     //helper functions for resizing
00229     void expand_right(int count, t_translation::t_terrain filler);
00230     void expand_left(int count, t_translation::t_terrain filler);
00231     void expand_top(int count, t_translation::t_terrain filler);
00232     void expand_bottom(int count, t_translation::t_terrain filler);
00233     void shrink_right(int count);
00234     void shrink_left(int count);
00235     void shrink_top(int count);
00236     void shrink_bottom(int count);
00237 
00238     /**
00239      * The selected hexes
00240      */
00241     std::set<map_location> selection_;
00242 
00243 private:
00244 
00245     /**
00246      * The labels of this map.
00247      */
00248     map_labels labels_;
00249 
00250     /**
00251      * TODO
00252      */
00253     unit_map units_;
00254 
00255     std::vector<team> teams_;
00256 
00257     tod_manager tod_manager_;
00258 
00259     game_state state_;
00260 
00261 };
00262 
00263 
00264 } //end namespace editor
00265 
00266 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:35 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs