The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
teleport.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Fabian Mueller <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License version 2
7  or at your option any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #ifndef TELEPORT_H_INCLUDED
15 #define TELEPORT_H_INCLUDED
16 
17 #include "config.hpp"
18 #include "map/location.hpp"
19 
20 class team;
21 class unit;
22 class vconfig;
23 
24 
25 namespace pathfind {
26 
27 typedef std::pair<std::set<map_location>, std::set<map_location> >
29 
30 /*
31  * Represents the tunnel wml tag.
32  */
34 {
35 public:
36  /*
37  * Constructs the object from a saved file.
38  * @param cfg the contents of a [tunnel] tag
39  */
40  teleport_group(const config& cfg);
41 
42  /*
43  * Constructs the object from a config file.
44  * @param cfg the contents of a [tunnel] tag
45  * @param way_back inverts the direction of the teleport
46  */
47  teleport_group(const vconfig& cfg, bool way_back = false);
48 
49  /*
50  * Fills the argument loc_pair if the unit u matches the groups filter.
51  * @param loc_pair returned teleport_pair if the unit matches
52  * @param u this unit must match the group's filter
53  * @param ignore_units don't consider zoc and blocking when calculating the shorted path between
54  */
55  void get_teleport_pair(
56  teleport_pair& loc_pair
57  , const unit& u
58  , const bool ignore_units) const;
59 
60  /*
61  * Can be set by the id attribute or is randomly chosen.
62  * @return unique id of the teleport group
63  */
64  const std::string& get_teleport_id() const;
65 
66  /*
67  * Returns whether the group should always be visible,
68  * even for enemy movement under shroud.
69  * @return visibility of the teleport group
70  */
71  bool always_visible() const;
72 
73  /** Inherited from savegame_config. */
74  config to_config() const;
75 
76 private:
77 
78  config cfg_; // unexpanded contents of a [tunnel] tag
79  bool reversed_; // Whether the tunnel's direction is reversed
80  std::string id_; // unique id of the group
81 };
82 
83 
84 class teleport_map {
85 public:
86  /*
87  * @param teleport_groups
88  * @param u
89  * @param viewing_team
90  * @param see_all
91  * @param ignore_units
92  */
94  const std::vector<teleport_group>& teleport_groups
95  , const unit& u
96  , const team &viewing_team
97  , const bool see_all
98  , const bool ignore_units);
99 
100  /*
101  * Constructs an empty teleport map.
102  */
104  teleport_map_(), sources_(), targets_() {}
105 
106  /*
107  * @param adjacents used to return the adjacent hexes
108  * @param loc the map location for which we want to know the adjacent hexes
109  */
110  void get_adjacents(std::set<map_location>& adjacents, map_location loc) const;
111  /*
112  * @param sources used to return the locations that are an entrance of the tunnel
113  */
114  void get_sources(std::set<map_location>& sources) const;
115  /*
116  * @param targets used to return the locations that are an exit of the tunnel
117  */
118  void get_targets(std::set<map_location>& targets) const;
119 
120  /*
121  * @returns whether the teleport_map does contain any defined tunnel
122  */
123  bool empty() const {
124  return sources_.empty();
125  }
126 
127 private:
128  std::map<map_location, std::set<std::string> > teleport_map_;
129  std::map<std::string, std::set<map_location> > sources_;
130  std::map<std::string, std::set<map_location> > targets_;
131 };
132 
133 /*
134  * @param u The unit that is processed by pathfinding
135  * @param viewing_team The team the player belongs to
136  * @param see_all Whether the teleport can be seen below shroud
137  * @param ignore_units Whether to ignore zoc and blocking by units
138  * @returns a teleport_map
139  */
140 const teleport_map get_teleport_locations(const unit &u, const team &viewing_team,
141  bool see_all = false, bool ignore_units = false);
142 
143 class manager
144 {
145 public:
146  manager(const config &cfg);
147 
148  /*
149  * @param group teleport_group to be added
150  */
151  void add(const teleport_group &group);
152 
153  /*
154  * @param id id of the teleport_group that is to be removed by the method
155  */
156  void remove(const std::string &id);
157 
158  /*
159  * @return all registered teleport groups on the game field
160  */
161  const std::vector<teleport_group>& get() const;
162 
163  /** Inherited from savegame_config. */
164  config to_config() const;
165 
166  /*
167  * @returns the next free unique id for a teleport group
168  */
170 private:
171  std::vector<teleport_group> tunnels_;
172  int id_;
173 };
174 
175 }
176 
177 #endif /* TELEPORT_H_INCLUDED */
std::map< std::string, std::set< map_location > > sources_
Definition: teleport.hpp:129
std::pair< std::set< map_location >, std::set< map_location > > teleport_pair
Definition: teleport.hpp:28
Definition: unit.hpp:95
std::string next_unique_id()
Definition: teleport.cpp:299
bool empty() const
Definition: teleport.hpp:123
config to_config() const
Inherited from savegame_config.
Definition: teleport.cpp:149
void get_targets(std::set< map_location > &targets) const
Definition: teleport.cpp:224
bool always_visible() const
Definition: teleport.cpp:145
Definitions for the interface to Wesnoth Markup Language (WML).
teleport_group(const config &cfg)
Definition: teleport.cpp:39
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
void get_sources(std::set< map_location > &sources) const
Definition: teleport.cpp:216
GLuint id
Definition: glew.h:1647
std::map< std::string, std::set< map_location > > targets_
Definition: teleport.hpp:130
config to_config() const
Inherited from savegame_config.
Definition: teleport.cpp:287
Encapsulates the map of the game.
Definition: location.hpp:38
std::map< map_location, std::set< std::string > > teleport_map_
Definition: teleport.hpp:128
const std::string & get_teleport_id() const
Definition: teleport.cpp:141
void add(const teleport_group &group)
Definition: teleport.cpp:268
manager(const config &cfg)
Definition: teleport.cpp:255
GLboolean GLuint group
Definition: glew.h:2589
std::vector< teleport_group > tunnels_
Definition: teleport.hpp:171
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
void get_teleport_pair(teleport_pair &loc_pair, const unit &u, const bool ignore_units) const
Definition: teleport.cpp:107
GLsizei GLenum * sources
Definition: glew.h:3155
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units)
Definition: teleport.cpp:233
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void get_adjacents(std::set< map_location > &adjacents, map_location loc) const
Definition: teleport.cpp:202