Beispiel #1
0
void recruit_result::do_check_before()
{
	LOG_AI_ACTIONS << " check_before " << *this << std::endl;
	const team& my_team = get_my_team();
	const bool location_specified = recruit_location_.valid();

	//Unit type known ?
	const unit_type *s_type = get_unit_type_known(unit_name_);
	if (!s_type) {
		return;
	}

	//Enough gold?
	if (!test_enough_gold(my_team, *s_type)) {
		return;
	}

	// Leader available for recruiting?
	switch ( ::actions::check_recruit_location(get_side(), recruit_location_,
	                                           recruit_from_, unit_name_) )
	{
	case ::actions::RECRUIT_NO_LEADER:
	case ::actions::RECRUIT_NO_ABLE_LEADER:
		set_error(E_NO_LEADER);
		return;

	case ::actions::RECRUIT_NO_KEEP_LEADER:
		set_error(E_LEADER_NOT_ON_KEEP);
		return;

	case ::actions::RECRUIT_NO_VACANCY:
		set_error(E_BAD_RECRUIT_LOCATION);
		return;

	case ::actions::RECRUIT_ALTERNATE_LOCATION:
		if ( location_specified ) {
			set_error(E_BAD_RECRUIT_LOCATION);
			return;
		}
		// No break. If the location was not specified, this counts as "OK".
	case ::actions::RECRUIT_OK:
		location_checked_ = true;
	}
}
void recruit_result::do_check_before()
{
	LOG_AI_ACTIONS << " check_before " << *this << std::endl;
	const game_info& s_info = get_subjective_info();
	const game_info& info = get_info();

	const unit_map& s_units = s_info.units;
	const unit_map& units = info.units;

	const team& s_my_team = get_my_team(s_info);
	const team& my_team = get_my_team(info);

	//Unit available for recruiting?
	const std::string &s_recruit = get_available_for_recruiting(s_my_team);

	if (s_recruit.empty() ||
	    (is_execution() && using_subjective_info() &&
	     get_available_for_recruiting(my_team, true).empty()))
	{
		return;
	}

	//Unit type known ?
	const unit_type *s_type = get_unit_type_known(s_recruit);
	if (!s_type ||
	    (is_execution() && using_subjective_info() &&
	     !get_unit_type_known(s_recruit, true)))
	{
		return;
	}

	//Enough gold?
	if (!test_enough_gold(s_my_team, *s_type) ||
	    (is_execution() && using_subjective_info() &&
	     !test_enough_gold(my_team, *s_type, true)))
	{
		return;
	}

	//Leader present?
	const unit *s_my_leader = get_leader(s_units);

	if (!s_my_leader ||
	    (is_execution() && using_subjective_info() &&
	     !get_leader(units, true)))
	{
		return;
	}

	//Leader on keep?
	const gamemap& s_map = s_info.map;
	const gamemap& map = info.map;

	if (!test_leader_on_keep(s_map, *s_my_leader) ||
	    (is_execution() && using_subjective_info() &&
	     !test_leader_on_keep(map, *s_my_leader, true)))
	{
		return;
	}

	//Try to get suitable recruit location. Is suitable location available ?
	if (!test_suitable_recruit_location(s_map, s_units, *s_my_leader) ||
	    (is_execution() && using_subjective_info() &&
	     !test_suitable_recruit_location(map, units, *s_my_leader, true)))
	{
		return;
	}

}