Ejemplo n.º 1
0
//----- Begin of function Nation::think_exchange_tech -----//
//
int Nation::think_exchange_tech()
{
	if( m.random(10) > 0 )		// only 1/10 chance of calling this function
		return 0;

	Nation* nationPtr;
	int	  totalNation=nation_array.size();
	int	  nationRecno=m.random(totalNation)+1;

	for( int i=totalNation ; i>0 ; i-- )
	{
		if( ++nationRecno > totalNation )
			nationRecno = 1;

		if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno )
			continue;

		nationPtr = nation_array[nationRecno];

		if( nationPtr->total_tech_level() == 0 )
			continue;

		if( !should_diplomacy_retry(TALK_EXCHANGE_TECH, nationRecno) )
			continue;

		//--- don't request from hostile or tense nations -----//

		if( get_relation(nationRecno)->status < RELATION_NEUTRAL )
			continue;

		//---- scan which tech that the nation has but we don't have ----//

		int getTechId=0, getTechLevel=0, giveTechId=0, giveTechLevel=0;

		int techId;
		for( techId=1 ; techId<=tech_res.tech_count ; techId++ )
		{
			TechInfo *techInfo = tech_res[techId];

			// ###### patch begin Gilbert 24/1 #####//
			// human kingdoms won't ask for fryhtan tech
			if( techInfo->is_monster_tech() && (is_human() || nationPtr->is_human())  )
				continue;
			// won't give fryhtan tech to human 
			// ###### patch end Gilbert 24/1 #####//

			// ####### begin Gilbert 24/12 ####//
//			for( int j=1 ; j<=techInfo->max_tech_level ; j++ )
			for( int j=1 ; j<=techInfo->max_tech_level(nation_recno) || j<=techInfo->max_tech_level(nationRecno); j++ )
			// ####### end Gilbert 24/12 ####//
			{
				if( !giveTechId )
				{
					if( techInfo->get_nation_tech_level(nation_recno) >= j &&
						 techInfo->get_nation_tech_level(nationRecno)  <  j )
					{
						giveTechId 	  = techId;
						giveTechLevel = j;
						break;
					}
				}

				if( !getTechId )
				{
					if( techInfo->get_nation_tech_level(nation_recno) <  j &&
						 techInfo->get_nation_tech_level(nationRecno)  >= j )
					{
						getTechId 	  = techId;
						getTechLevel = j;
						break;
					}
				}
			}
		}

		//---- if there is a tech we want to give and one we want to get ----//

		if( !giveTechId || !getTechId )
			continue;

		//--------- send the diplomatic message now --------//

		// ###### patch begin Gilbert 24/1 #####//
//		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_EXCHANGE_TECH,
//			giveTechId, getTechId, giveTechLevel, getTechLevel );
		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_EXCHANGE_TECH,
			giveTechId, getTechId, 0, giveTechLevel, getTechLevel );	// 0=don't force send
		// ###### end begin Gilbert 24/1 #####//

		return 1;
	}

	return 0;
}
Ejemplo n.º 2
0
//---- Begin of function TalkRes::add_exchange_tech_choices ------//
//
// talk_para1 - id. of the tech you offer
// talk_para2 - id. of the tech you request
// talk_para3 - level of the tech you offer
// talk_para4 - level of the tech you request
//
int TalkRes::add_exchange_tech_choices()
{
	int i, j;
	int fromNationRecno = cur_talk_msg.from_nation_recno;
	int toNationRecno   = cur_talk_msg.to_nation_recno;
	TechInfo* techInfo;
	String str;

	if( cur_talk_msg.talk_para1 && cur_talk_msg.talk_para2 )
		return 0;

	if( !cur_talk_msg.talk_para1 )
		choice_question = text_talk.str_ask_offer_tech(); // "Technology you offer?";
	else
		choice_question = text_talk.str_ask_request_tech(); //"Technology you request?";

	for( i=1 ; i<=tech_res.tech_count && talk_choice_count<MAX_TALK_CHOICE-1 ; i++ )	// -1 reserve one free space for "Cancel"
	{
		techInfo = tech_res[i];

		// ---- cannot transfer mega weapon, must kill opponent king to get -----//

		// ###### begin Gilbert 6/5 ######//
		if( techInfo->class_id == TECH_CLASS_MEGA_WEAPON
			|| techInfo->class_id == TECH_CLASS_OFFENSIVE_STRUCTURE )
		{
			continue;
		}
		// ###### end Gilbert 6/5 ######//


		// ###### begin Gilbert 24/12 #######//
		int maxTechLevel = max( techInfo->max_tech_level(fromNationRecno), techInfo->max_tech_level(toNationRecno) );
//		for( j=1 ; j<=techInfo->max_tech_level ; j++ )
		for( j=1 ; j<=maxTechLevel ; j++ )
		// ###### end Gilbert 24/12 #######//
		{
			int rc;

			if( !cur_talk_msg.talk_para1 )			// tech you offer
			{
				rc = techInfo->get_nation_tech_level(fromNationRecno) >= j &&
					  techInfo->get_nation_tech_level(toNationRecno)   <  j;
			}
			else									// tech you request
			{
				rc = techInfo->get_nation_tech_level(fromNationRecno) <  j &&
					  techInfo->get_nation_tech_level(toNationRecno)   >= j;
			}

			if( rc )
			{
				str = techInfo->tech_des();

				if( techInfo->max_tech_level(0)>1 )
				{
					str += " ";
					str += m.roman_number(j);
				}

				add_talk_choice( str, i, j );		// i-techId, j-version id.
				break;
			}
		}
	}

	return 1;
}