示例#1
0
bool conditional_passed(const vconfig& cond)
{
	bool matches = internal_conditional_passed(cond);

	// Handle [and], [or], and [not] with in-order precedence
	vconfig::all_children_iterator cond_i = cond.ordered_begin();
	vconfig::all_children_iterator cond_end = cond.ordered_end();
	while(cond_i != cond_end)
	{
		const std::string& cond_name = cond_i.get_key();
		const vconfig& cond_filter = cond_i.get_child();

		// Handle [and]
		if(cond_name == "and")
		{
			matches = matches && conditional_passed(cond_filter);
		}
		// Handle [or]
		else if(cond_name == "or")
		{
			matches = matches || conditional_passed(cond_filter);
		}
		// Handle [not]
		else if(cond_name == "not")
		{
			matches = matches && !conditional_passed(cond_filter);
		}
		++cond_i;
	}
	return matches;
}
示例#2
0
/**
 * Returns whether or not *this is applicable given the context.
 * Assumes game variables x1, y1, and unit have been set.
 * @param[in]  hex  The hex where the menu will appear.
 */
bool wml_menu_item::can_show(const map_location & hex) const
{
	// Failing the [show_if] tag means no show.
	if ( !show_if_.empty() && !conditional_passed(show_if_) )
		return false;

	// Failing the [fiter_location] tag means no show.
	if ( !filter_location_.empty() &&
	     !terrain_filter(filter_location_, *resources::units)(hex) )
		return false;

	// Failing to have a required selection means no show.
	if ( needs_select_ && !resources::gamedata->last_selected.valid() )
		return false;

	// Passed all tests.
	return true;
}
示例#3
0
文件: pump.cpp 项目: niegenug/wesnoth
	/**
	 * Returns true iff the given event passes all its filters.
	 */
	bool t_pump::filter_event(const event_handler& handler, const queued_event& ev)
	{
		const unit_map *units = resources::units;
		unit_map::const_iterator unit1 = units->find(ev.loc1);
		unit_map::const_iterator unit2 = units->find(ev.loc2);
		vconfig filters(handler.get_config());

		BOOST_FOREACH(const vconfig &condition, filters.get_children("filter_condition"))
		{
			if (!conditional_passed(condition)) {
				return false;
			}
		}

		BOOST_FOREACH(const vconfig &f, filters.get_children("filter_side"))
		{
			side_filter ssf(f, &resources::controller->gamestate());
			if ( !ssf.match(resources::controller->current_side()) )
				return false;
		}

		BOOST_FOREACH(const vconfig &f, filters.get_children("filter"))
		{
			if ( !ev.loc1.matches_unit_filter(unit1, f) ) {
				return false;
			}
		}

		vconfig::child_list special_filters = filters.get_children("filter_attack");
		bool special_matches = special_filters.empty();
		if ( !special_matches  &&  unit1 != units->end() )
		{
			const bool matches_unit = ev.loc1.matches_unit(unit1);
			const config & attack = ev.data.child("first");
			BOOST_FOREACH(const vconfig &f, special_filters)
			{
				if ( f.empty() )
					special_matches = true;
				else if ( !matches_unit )
					return false;

				special_matches = special_matches ||
					              matches_special_filter(attack, f);
			}
		}
		if(!special_matches) {
			return false;
		}

		BOOST_FOREACH(const vconfig &f, filters.get_children("filter_second"))
		{
			if ( !ev.loc2.matches_unit_filter(unit2, f) ) {
				return false;
			}
		}

		special_filters = filters.get_children("filter_second_attack");
		special_matches = special_filters.empty();
		if ( !special_matches  &&  unit2 != units->end() )
		{
			const bool matches_unit = ev.loc2.matches_unit(unit2);
			const config & attack = ev.data.child("second");
			BOOST_FOREACH(const vconfig &f, special_filters)
			{
				if ( f.empty() )
					special_matches = true;
				else if ( !matches_unit )
					return false;

				special_matches = special_matches ||
					              matches_special_filter(attack, f);
			}
		}
		if(!special_matches) {
			return false;
		}

		// All filters passed.
		return true;
	}