pathfind/teleport.hpp

Go to the documentation of this file.
00001 /* $Id: teleport.hpp 51426 2011-10-10 02:43:29Z ai0867 $ */
00002 /*
00003    Copyright (C) 2010 by Fabian Mueller <fabianmueller5@gmx.de>
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 #ifndef TELEPORT_H_INCLUDED
00016 #define TELEPORT_H_INCLUDED
00017 
00018 #include "map.hpp"
00019 
00020 #include "config.hpp"
00021 #include "team.hpp"
00022 #include "terrain_filter.hpp"
00023 #include "savegame_config.hpp"
00024 #include "pathfind/pathfind.hpp"
00025 
00026 
00027 namespace pathfind {
00028 
00029 typedef std::pair<std::set<map_location>, std::set<map_location> >
00030         teleport_pair;
00031 
00032 /*
00033  * Represents the tunnel wml tag.
00034  */
00035 class teleport_group: public savegame::savegame_config {
00036 public:
00037     /*
00038      * Constructs the object from a saved file.
00039      * @param cfg   the contents of a [tunnel] tag
00040      */
00041     teleport_group(const config& cfg);
00042 
00043     /*
00044      * Constructs the object from a config file.
00045      * @param cfg       the contents of a [tunnel] tag
00046      * @param way_back  inverts the direction of the teleport
00047      */
00048     teleport_group(const vconfig& cfg, bool way_back = false);
00049 
00050     /*
00051      * Fills the argument loc_pair if the unit u matches the groups filter.
00052      * @param loc_pair      returned teleport_pair if the unit matches
00053      * @param u             this unit must match the group's filter
00054      * @param ignore_units  don't consider zoc and blocking when calculating the shorted path between
00055      */
00056     void get_teleport_pair(
00057               teleport_pair& loc_pair
00058             , const unit& u
00059             , const bool ignore_units) const;
00060 
00061     /*
00062      * Can be set by the id attribute or is randomly chosen.
00063      * @return unique id of the teleport group
00064      */
00065     const std::string& get_teleport_id() const;
00066 
00067     /*
00068      * Returns whether the group should always be visible,
00069      * even for enemy movement under shroud.
00070      * @return  visibility of the teleport group
00071      */
00072     bool always_visible() const;
00073 
00074     /** Inherited from savegame_config. */
00075     config to_config() const;
00076 
00077 private:
00078 
00079     config cfg_;        // unexpanded contents of a [tunnel] tag
00080     bool reversed_;     // Whether the tunnel's direction is reversed
00081     std::string id_;    // unique id of the group
00082 };
00083 
00084 
00085 class teleport_map {
00086 public:
00087     /*
00088      * @param teleport_groups
00089      * @param u
00090      * @param viewing_team
00091      * @param see_all
00092      * @param ignore_units
00093      */
00094     teleport_map(
00095               const std::vector<teleport_group>& teleport_groups
00096             , const unit& u
00097             , const team &viewing_team
00098             , const bool see_all
00099             , const bool ignore_units);
00100 
00101     /*
00102      * Constructs an empty teleport map.
00103      */
00104     teleport_map() :
00105         teleport_map_(), sources_(), targets_() {};
00106 
00107     /*
00108      * @param adjacents     used to return the adjacent hexes
00109      * @param loc           the map location for which we want to know the adjacent hexes
00110      */
00111     void get_adjacents(std::set<map_location>& adjacents, map_location loc) const;
00112     /*
00113      * @param sources   used to return the locations that are an entrance of the tunnel
00114      */
00115     void get_sources(std::set<map_location>& sources) const;
00116     /*
00117      * @param targets   used to return the locations that are an exit of the tunnel
00118      */
00119     void get_targets(std::set<map_location>& targets) const;
00120 
00121     /*
00122      * @returns whether the teleport_map does contain any defined tunnel
00123      */
00124     bool empty() const {
00125         return sources_.empty();
00126     }
00127 
00128 private:
00129     std::map<map_location, std::set<std::string> > teleport_map_;
00130     std::map<std::string, std::set<map_location> > sources_;
00131     std::map<std::string, std::set<map_location> > targets_;
00132 };
00133 
00134 /*
00135  * @param u                 The unit that is processed by pathfinding
00136  * @param viewing_team      The team the player belongs to
00137  * @param see_all           Whether the teleport can be seen below shroud
00138  * @param ignore_units      Whether to ignore zoc and blocking by units
00139  * @returns a teleport_map
00140  */
00141 const teleport_map get_teleport_locations(const unit &u, const team &viewing_team,
00142         bool see_all = false, bool ignore_units = false);
00143 
00144 class manager: public savegame::savegame_config {
00145 public:
00146     manager(const config &cfg);
00147 
00148     /*
00149      * @param group     teleport_group to be added
00150      */
00151     void add(const teleport_group &group);
00152 
00153     /*
00154      * @param id        id of the teleport_group that is to be removed by the method
00155      */
00156     void remove(const std::string &id);
00157 
00158     /*
00159      * @return  all registered teleport groups on the game field
00160      */
00161     const std::vector<teleport_group>& get() const;
00162 
00163     /** Inherited from savegame_config. */
00164     config to_config() const;
00165 
00166     /*
00167      * @returns the next free unique id for a teleport group
00168      */
00169     std::string next_unique_id();
00170 private:
00171     std::vector<teleport_group> tunnels_;
00172     int id_;
00173 };
00174 
00175 }
00176 
00177 #endif /* TELEPORT_H_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:07 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs