Example #1
0
void pathfind::teleport_group::get_teleport_pair(
		  teleport_pair& loc_pair
		, const unit& u
		, const bool ignore_units) const
{
	const map_location &loc = u.get_location();
	static unit_map empty_unit_map;
	unit_map *units;
	if (ignore_units) {
		units = &empty_unit_map;
	} else {
		units = resources::units;
	}
	vconfig filter(cfg_.child_or_empty("filter"), true);
	vconfig source(cfg_.child_or_empty("source"), true);
	vconfig target(cfg_.child_or_empty("target"), true);
	if (u.matches_filter(filter, loc)) {

		scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, *resources::units);

		terrain_filter source_filter(source, *units);
		source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first);

		terrain_filter target_filter(target, *units);
		target_filter.get_locations(reversed_ ? loc_pair.first : loc_pair.second);
	}
}
Example #2
0
void teleport_group::get_teleport_pair(
		  teleport_pair& loc_pair
		, const unit& u
		, const bool ignore_units) const
{
	const map_location &loc = u.get_location();

	const filter_context * fc = resources::filter_con;
	assert(fc);

	if (ignore_units) {
		fc = new ignore_units_filter_context(*resources::filter_con);
	}

	vconfig filter(cfg_.child_or_empty("filter"), true);
	vconfig source(cfg_.child_or_empty("source"), true);
	vconfig target(cfg_.child_or_empty("target"), true);
	const unit_filter ufilt(filter, resources::filter_con); //Note: Don't use the ignore units filter context here, only for the terrain filters. (That's how it worked before the filter contexts were introduced)
	if (ufilt.matches(u, loc)) {

		scoped_xy_unit teleport_unit("teleport_unit", loc.x, loc.y, *resources::units);

		terrain_filter source_filter(source, fc);
		source_filter.get_locations(reversed_ ? loc_pair.second : loc_pair.first);

		terrain_filter target_filter(target, fc);
		target_filter.get_locations(reversed_ ? loc_pair.first : loc_pair.second);
	}

	if (ignore_units) {
		delete fc;
	}
}