team_data display_context::calculate_team_data(const team& tm) const
{
	team_data res;
	res.units = side_units(tm.side());
	res.upkeep = side_upkeep(tm.side());
	res.villages = tm.villages().size();
	res.expenses = std::max<int>(0,res.upkeep - tm.support());
	res.net_income = tm.total_income() - res.expenses;
	res.gold = tm.gold();
	res.teamname = tm.user_team_name();
	return res;
}
Exemple #2
0
static bool check_side_number(const team &t, const std::string &str)
{
		std::vector<std::string> list = utils::split(str);
		std::string side_number = str_cast(t.side());
		if (std::find(list.begin(),list.end(),side_number)==list.end())
		{
			return false;
		}
		return true;
}
Exemple #3
0
bool game_board::team_is_defeated(const team& t) const
{
	switch(t.defeat_condition().v)
	{
	case team::DEFEAT_CONDITION::ALWAYS:
		return true;
	case team::DEFEAT_CONDITION::NO_LEADER:
		return !units_.find_leader(t.side()).valid();
	case team::DEFEAT_CONDITION::NO_UNITS:
		for (const unit& u : units_)
		{
			if(u.side() == t.side())
				return false;
		}
		return true;
	case team::DEFEAT_CONDITION::NEVER:
	default:
		return false;
	}
}
Exemple #4
0
bool side_filter::match_internal(const team &t) const
{
	if (cfg_.has_attribute("side_in")) {
		if (!check_side_number(t,cfg_["side_in"])) {
			return false;
		}
	}
	if (cfg_.has_attribute("side")) {
		if (!check_side_number(t,cfg_["side"])) {
			return false;
		}
	}
	if (!side_string_.empty()) {
		if (!check_side_number(t,side_string_)) {
			return false;
		}
	}

	config::attribute_value cfg_team_name = cfg_["team_name"];
	if (!cfg_team_name.blank()) {
		const std::string& that_team_name = cfg_team_name;
		const std::string& this_team_name = t.team_name();

		if(std::find(this_team_name.begin(), this_team_name.end(), ',') == this_team_name.end()) {
			if(this_team_name != that_team_name) return false;
		}
		else {
			const std::vector<std::string>& these_team_names = utils::split(this_team_name);
			bool search_futile = true;
			BOOST_FOREACH (const std::string& this_single_team_name, these_team_names) {
				if(this_single_team_name == that_team_name) {
					search_futile = false;
					break;
				}
			}
			if(search_futile) return false;
		}
	}

	//Allow filtering on units
	if(cfg_.has_child("has_unit")) {
		const vconfig& unit_filter = cfg_.child("has_unit");
		bool found = false;
		for (unit_map::iterator it = resources::units->begin(); it != resources::units->end(); ++ it) {
			unit* u = dynamic_cast<unit*>(&*it);
			if (u->side() != t.side()) {
				continue;
			}
			if (u->matches_filter(unit_filter, u->get_location(), flat_)) {
				found = true;
				break;
			}
		}

		if (!found) {
			return false;
		}
	}

	const vconfig& enemy_of = cfg_.child("enemy_of");
	if(!enemy_of.null()) {
		side_filter s_filter(enemy_of);
		const std::vector<int>& teams = s_filter.get_teams();
		if(teams.empty()) return false;
		BOOST_FOREACH (const int side, teams) {
			if(!(*resources::teams)[side - 1].is_enemy(t.side()))
				return false;
		}
	}