31 #define ERR_PF LOG_STREAM(err, log_engine)
34 #define ERR_WML LOG_STREAM(err, log_wml)
40 const std::string reversed_suffix =
"-__REVERSED__";
59 if (cfg[
"id"].empty()) {
62 id_ = cfg[
"id"].str();
64 id_ += reversed_suffix;
77 um_ = &empty_unit_map;
81 const std::vector<team> &
teams()
const override {
return *
tm_; }
83 std::vector<std::string>&
hidden_label_categories()
override {
throw "Writable hidden label categories not supported in this context"; }
88 const std::vector<team> *
tm_;
89 const std::vector<std::string> *
lbls_;
116 ,
const bool ignore_units)
const
130 terrain_filter source_filter(source, fc,
false);
131 source_filter.get_locations(
reversed_ ? loc_pair.second : loc_pair.first, u);
133 terrain_filter target_filter(target, fc,
false);
134 target_filter.get_locations(
reversed_ ? loc_pair.first : loc_pair.second, u);
147 return cfg_[
"always_visible"].to_bool(
false);
151 return cfg_[
"pass_allied_units"].to_bool(
true);
155 return cfg_[
"allow_vision"].to_bool(
true);
167 const std::vector<teleport_group>& groups
169 ,
const team &viewing_team
171 ,
const bool ignore_units
172 ,
const bool check_vision)
182 if (check_vision && !group.allow_vision()) {
186 group.get_teleport_pair(locations,
unit, ignore_units);
187 if (!see_all && !group.always_visible() && viewing_team.
is_enemy(
unit.
side())) {
190 if(!viewing_team.
fogged(loc))
191 filter_locs.first.insert(loc);
194 if(!viewing_team.
fogged(loc))
195 filter_locs.second.insert(loc);
197 locations.first.swap(filter_locs.first);
198 locations.second.swap(filter_locs.second);
201 if (!group.pass_allied_units() && !ignore_units && !check_vision) {
203 while(loc != locations.second.end()) {
211 loc = locations.second.erase(loc);
218 std::string teleport_id = group.get_teleport_id();
220 for (; source_it != locations.first.end(); ++source_it ) {
222 std::set<std::string> id_set;
223 id_set.insert(teleport_id);
226 (
teleport_map_.find(*source_it)->second).insert(teleport_id);
229 sources_.emplace(teleport_id, locations.first);
230 targets_.emplace(teleport_id, locations.second);
241 std::set<map_location> res;
242 for(
const std::string& key : iter->second) {
243 const auto& target =
targets_.find(key)->second;
244 res.insert(target.begin(), target.end());
252 std::set<map_location> res;
254 res.insert(src.second.begin(), src.second.end());
262 std::set<map_location> res;
264 res.insert(tgt.second.begin(), tgt.second.end());
271 const team &viewing_team,
272 bool see_all,
bool ignore_units,
bool check_vision)
274 std::vector<teleport_group> groups;
277 const int tunnel_count = (teleport.ability_cfg)->child_count(
"tunnel");
278 for(
int i = 0;
i < tunnel_count; ++
i) {
279 config teleport_group_cfg = (teleport.ability_cfg)->mandatory_child(
"tunnel",
i);
280 groups.emplace_back(
vconfig(teleport_group_cfg,
true),
false);
285 groups.insert(groups.end(), global_groups.begin(), global_groups.end());
287 return teleport_map(groups, u, viewing_team, see_all, ignore_units, check_vision);
291 const int tunnel_count = cfg.
child_count(
"tunnel");
292 for(
int i = 0;
i < tunnel_count; ++
i) {
294 if(!
t[
"saved"].to_bool()) {
295 lg::log_to_chat() <<
"Do not use [tunnel] directly in a [scenario]. Use it in an [event] or [abilities] tag.\n";
296 ERR_WML <<
"Do not use [tunnel] directly in a [scenario]. Use it in an [event] or [abilities] tag.";
311 if (
t->get_teleport_id() ==
id ||
t->get_teleport_id() ==
id + reversed_suffix) {
326 std::vector<teleport_group>::const_iterator tunnel =
tunnels_.begin();
327 for(; tunnel !=
tunnels_.end(); ++tunnel) {
328 store.
add_child(
"tunnel", tunnel->to_config());
330 store[
"next_teleport_group_id"] = std::to_string(
id_);
336 return std::to_string(++
id_);
A config object defines a single node in a WML file, with access to child nodes.
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
std::size_t child_count(config_key_type key) const
bool has_attribute(config_key_type key) const
config & add_child(config_key_type key)
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
virtual const unit_map & units() const override
Encapsulates the map of the game.
std::vector< std::string > & hidden_label_categories() override
const std::vector< team > * tm_
const std::vector< std::string > * lbls_
const gamemap & map() const override
const unit_map & units() const override
const std::vector< team > & teams() const override
ignore_units_display_context(const display_context &dc)
const std::vector< std::string > & hidden_label_categories() const override
const tod_manager & get_tod_man() const override
const display_context & get_disp_context() const override
const ignore_units_display_context dc_
game_lua_kernel * get_lua_kernel() const override
const game_data * get_game_data() const override
ignore_units_filter_context(const filter_context &fc)
config to_config() const
Inherited from savegame_config.
void add(const teleport_group &group)
std::vector< teleport_group > tunnels_
void remove(const std::string &id)
const std::vector< teleport_group > & get() const
manager(const config &cfg)
std::string next_unique_id()
config to_config() const
Inherited from savegame_config.
bool always_visible() const
const std::string & get_teleport_id() const
teleport_group(const config &cfg)
bool pass_allied_units() const
void get_teleport_pair(teleport_pair &loc_pair, const unit &u, const bool ignore_units) const
bool allow_vision() const
std::map< map_location, std::set< std::string > > teleport_map_
std::map< std::string, std::set< map_location > > targets_
std::set< map_location > get_targets() const
Returns the locations that are an exit of the tunnel.
std::map< std::string, std::set< map_location > > sources_
std::set< map_location > get_adjacents(map_location loc) const
std::set< map_location > get_sources() const
Returns the locations that are an entrance of the tunnel.
This class stores all the data for a single 'side' (in game nomenclature).
bool is_enemy(int n) const
bool fogged(const map_location &loc) const
bool matches(const unit &u, const map_location &loc) const
Determine if *this matches filter at a specified location.
Container associating units to locations.
unit_iterator find(std::size_t id)
This class represents a single unit of a specific type.
A variable-expanding proxy for the config class.
unit_ability_list get_abilities(const std::string &tag_name, const map_location &loc) const
Gets the unit's active abilities of a particular type if it were on a specified location.
int side() const
The side this unit belongs to.
Standard logging facilities (interface).
retval
Default window/dialog return values.
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
std::pair< std::set< map_location >, std::set< map_location > > teleport_pair
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units, bool check_vision)
pathfind::manager * tunnels
filter_context * filter_con
std::string::const_iterator iterator
Encapsulates the map of the game.
Data typedef for unit_ability_list.
static lg::log_domain log_engine("engine")
static lg::log_domain log_wml("wml")