Example #1
0
//----- Begin of function Nation::think_trade_treaty -----//
//
int Nation::think_trade_treaty()
{
	Nation* 			nationPtr;
	NationRelation *ourRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationPtr = nation_array[i];

		ourRelation = get_relation(i);

		if( !ourRelation->has_contact )
			continue;

		//------- propose a trade treaty --------//

		if( !ourRelation->trade_treaty )
		{
			if( consider_trade_treaty(i) > 0 )
			{
				if( should_diplomacy_retry(TALK_PROPOSE_TRADE_TREATY, i) )
				{
					talk_res.ai_send_talk_msg(i, nation_recno, TALK_PROPOSE_TRADE_TREATY);
					ourRelation->ai_demand_trade_treaty = 0;
					return 1;
				}
			}
		}
	}

	return 0;
}
Example #2
0
//----- Begin of function Nation::think_demand_tech -----//
//
int Nation::think_demand_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_DEMAND_TECH, nationRecno) )
			continue;

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

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

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

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

			if( techInfo->get_nation_tech_level(nation_recno)==0 &&
				 techInfo->get_nation_tech_level(nationRecno) > 0 )
			{
				break;
			}
		}

		if( techId > tech_res.tech_count )
			continue;

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

		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_DEMAND_TECH, techId);
		return 1;
	}

	return 0;
}
Example #3
0
//----- Begin of function Nation::think_request_cease_war -----//
//
int Nation::think_request_cease_war()
{
	Nation* 			 nationPtr;
	NationRelation* nationRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationPtr = nation_array[i];

		nationRelation = get_relation(i);

		if( nationRelation->status != RELATION_HOSTILE )
			continue;

		if( !should_diplomacy_retry(TALK_REQUEST_CEASE_WAR, i) )
			continue;

		//----- think about if it should cease war with the nation ------//

		if( consider_cease_war(i) > 0 )
		{
			talk_res.ai_send_talk_msg(i, nation_recno, TALK_REQUEST_CEASE_WAR);
		}

		//--------------------------------------------//
		// The relation improves slowly if there is
		// no attack. However, if there is any battles
		// started between the two nations, the status will be
		// set to hostile and ai_relation_level will be set to 0 again.
		//--------------------------------------------//

		else
		{
			change_ai_relation_level(i, 1);
		}
	}

	return 0;
}
Example #4
0
//----- Begin of function Nation::think_propose_alliance_treaty -----//
//
int Nation::think_propose_alliance_treaty()
{
	//--- think about which nation this nation should propose treaty to ---//

	int				 curRating, bestRating=0, bestNationRecno=0;
	NationRelation* nationRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		if( nation_array[i]->is_human() != is_human() )
			continue;

		nationRelation = get_relation(i);

		if( !nationRelation->has_contact || nationRelation->status == RELATION_ALLIANCE )
			continue;

		if( !should_diplomacy_retry(TALK_PROPOSE_ALLIANCE_TREATY, i) )
			continue;

		curRating = consider_alliance_treaty(i);

		if( curRating > bestRating )
		{
			bestRating 	 	 = curRating;
			bestNationRecno = i;
		}
	}

	if( bestNationRecno )
	{
		talk_res.ai_send_talk_msg(bestNationRecno, nation_recno, TALK_PROPOSE_ALLIANCE_TREATY );
		return 1;
	}

	return 0;
}
Example #5
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;
}
Example #6
0
//----- Begin of function Nation::think_demand_tribute_aid -----//
//
// Demand tribute when the nation's economy is good and its
// military is weak.
//
int Nation::think_demand_tribute_aid()
{
	if( info.game_date < info.game_start_date + 180 + nation_recno*50 )		// don't ask for tribute too soon, as in the beginning, the ranking are all the same for all nations
		return 0;

	//--------------------------------------//

	Nation* nationPtr;
	int	  totalNation=nation_array.size();
	int	  nationRecno=m.random(totalNation)+1;
	int	  curRating, requestRating;
	int	  talkId;
	int	  ourMilitary = military_rank_rating();
	int	  ourEconomy  = economic_rank_rating();

	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];

		//-- only demand tribute from non-friendly nations --//

		if( get_relation(nationRecno)->status <= RELATION_NEUTRAL )
			talkId = TALK_DEMAND_TRIBUTE;
		else
			talkId = TALK_DEMAND_AID;

		//-----------------------------------------------//

		float fixedExpense = fixed_expense_365days();

		if( talkId == TALK_DEMAND_TRIBUTE )
		{
			if( !should_diplomacy_retry(talkId, nationRecno) )
				continue;

			curRating = ourMilitary - nationPtr->military_rank_rating();

			//---- if this is a Fryhtan nation, the tendency to request tribute is higher -----//

			if( is_monster() && nationPtr->is_human() )	// and the target is a human nation
			{
				curRating *= 2;

				//-- if we are running low of live points, it's time to kill somebody --//

				if( live_points < 500 * (100+pref_live_points_reserve) / 100 )
					curRating *= 2;
			}

			if( curRating < 0 )
				continue;

			//----------------------------------------------//
			//
			// Some nation will actually consider the ability
			// of the target nation to pay tribute, so nation
			// will not and just ask anyway.
			//
			//----------------------------------------------//

			if( pref_economic_development > 50 )
			{
				int addRating = nationPtr->economic_rank_rating()-ourEconomy;

				if( addRating > 0 )
					curRating += addRating;
			}

			requestRating = 20 + trade_rating(nationRecno)/2 +
								(100-pref_peacefulness)/3;

			if( cash < fixedExpense && fixedExpense != 0 )
				requestRating -= int( (float) requestRating * cash / fixedExpense);

		}
		else
		{
			if( cash >= fixedExpense )
				continue;

			if( cash > fixedExpense * (50+pref_cash_reserve) / 300 &&		// if the nation is runing short of cash, don't wait a while until next retry, retry immediately
				 !should_diplomacy_retry(talkId, nationRecno) )
			{
				continue;
			}

			//----- only ask for aid when the nation is short of cash ----//

			curRating = (ourMilitary - nationPtr->military_rank_rating())/2 +
							( nationPtr->economic_rank_rating()-ourEconomy );

			requestRating = 20 + 50 * (int)(cash / fixedExpense);
		}

		//----- if the target is a human player's nation -----//

		if( !nationPtr->is_ai() )
		{
			switch( config.ai_aggressiveness )
			{
				case OPTION_NONE:
					requestRating += 60;		// don't go against the player too easily
					break;

				case OPTION_LOW:
					requestRating += 40;		// don't go against the player too easily
					break;

				case OPTION_HIGH:
					requestRating -= 20;
					break;

				case OPTION_VERY_HIGH:
					requestRating -= 40;
					break;
			}

			//--- if the nation has plenty of cash, demand from it ----//

			if( nationPtr->cash > cash && config.ai_aggressiveness >= OPTION_HIGH )
			{
				requestRating -= (int) (nationPtr->cash - cash)/500;
			}
		}

		//--------------------------------------//

		if( curRating > requestRating )
		{
			int tributeAmount;

			if( curRating - requestRating > 120 )
				tributeAmount = 4000;

			else if( curRating - requestRating > 80 )
				tributeAmount = 3000;

			else if( curRating - requestRating > 40 )
				tributeAmount = 2000;

			else if( curRating - requestRating > 20 )
				tributeAmount = 1000;

			else
				tributeAmount = 500;

			//------ stop in here if in tutorial mode -----//
			if( game.game_mode != GAME_TUTORIAL )
			{	
				cash += tributeAmount;
				return 0;
			}

			talk_res.ai_send_talk_msg(nationRecno, nation_recno, talkId, tributeAmount);

			return 1;
		}
	}

	return 0;
}
Example #7
0
//----- Begin of function Nation::think_declare_war -----//
//
int Nation::think_declare_war()
{
	NationRelation* nationRelation;
	int rc=0;

	//---- don't declare a new war if we already has enemies ---//

	int i;
	for( i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		if( get_relation(i)->status == RELATION_HOSTILE )
			return 0;
	}

	//------------------------------------------------//

	int targetStrength, minStrength=0x1000, bestTargetNation=0;

	for( i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationRelation = get_relation(i);

		if( !nationRelation->has_contact )
			continue;

		if( nationRelation->status == RELATION_HOSTILE )		// already at war
			continue;

		if( nationRelation->ai_relation_level >= 10 )
			continue;

		if( !ai_should_spend( 100-trade_rating(i) ) )		// if trade_rating is 0, importanceRating will be 100, if trade_rating is 100, importanceRating will be 0
			continue;

		//----------------------------------------//

		Nation* targetNation = nation_array[i];

		targetStrength = targetNation->military_rank_rating() +
							  targetNation->population_rank_rating()/2 +
							  targetNation->economic_rank_rating()/3;

		if( targetStrength < minStrength )
		{
			minStrength = targetStrength;
			bestTargetNation = i;
		}
	}

	//------------------------------------------//

	if( bestTargetNation )
	{
		if( should_diplomacy_retry(TALK_DECLARE_WAR, bestTargetNation) )
		{
			talk_res.ai_send_talk_msg(bestTargetNation, nation_recno, TALK_DECLARE_WAR);
			return 1;
		}
	}

	return 0;
}
Example #8
0
//----- Begin of function Nation::think_request_buy_food -----//
//
int Nation::think_request_buy_food()
{
	//------ first see if we need to buy food ------//

	int yearFoodChange = yearly_food_change();
	int neededFoodLevel;

	if( yearFoodChange > 0 )
	{
		if( food > 0 )
			return 0;
		else
			neededFoodLevel = (int) -food;		// if the food is negative
	}
	else
	{
		neededFoodLevel = -yearFoodChange * (100+pref_food_reserve) / 50;

		if( food > neededFoodLevel )		// one to three times (based on pref_food_reserve) of the food needed in a year,
			return 0;
	}

	//----- think about which nation to buy food from -----//

	Nation  *nationPtr, *bestNation=NULL;
	int	  curRating, bestRating=0;
	int	  relationStatus;

	int i;
	for( i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationPtr = nation_array[i];

		if( nationPtr->food < 500 )		// if the nation is short of food itself. The minimum request purchase qty is 500
			continue;

		relationStatus = get_relation_status(i);

		if( relationStatus == RELATION_HOSTILE || !get_relation(i)->has_contact )
			continue;

		if( nationPtr->yearly_food_change() < 0 &&
			 nationPtr->food < 1500 )
		{
			continue;
		}

		if( !should_diplomacy_retry(TALK_REQUEST_BUY_FOOD, i) )
			continue;

		//-----------------------------------//

		curRating = relationStatus*20 +
						(int)nationPtr->food / 100 +
						(int)nationPtr->yearly_food_change() / 10;

		if( curRating > bestRating )
		{
			bestRating = curRating;
			bestNation = nationPtr;
		}
	}

	if( !bestNation )
		return 0;

	//------------------------------------//

	static short buyQtyArray[] = { 500, 1000, 2000, 4000 };

	int buyQty=0, buyPrice;

	for( i=3 ; i>=0 ; i-- )
	{
		if( bestNation->food/2 > buyQtyArray[i] )
		{
			buyQty = buyQtyArray[i];
			break;
		}
	}

	if( buyQty == 0 )
		return 0;

	//------- set the offering price ------//

	if( food < neededFoodLevel/4 )		// if we need the food badly
	{
		buyPrice = 30;
	}
	else if( food < neededFoodLevel/3 )
	{
		buyPrice = 20;
	}
	else
	{
		if( bestNation->food > bestNation->all_population() * UNIT_FOOD_YEAR_CONSUMPTION * 5 &&		// if the nation has plenty of food
			 bestNation->cash < bestNation->fixed_expense_365days() / 2 )										// if the nation runs short of cash
		{
			buyPrice = 5;
		}
		else
			buyPrice = 10;
	}

	talk_res.ai_send_talk_msg(bestNation->nation_recno, nation_recno, TALK_REQUEST_BUY_FOOD, buyQty, buyPrice);
	return 1;
}
Example #9
0
//----- Begin of function Nation::think_request_surrender -----//
//
int Nation::think_request_surrender()
{
	if( info.game_date < info.game_start_date + 365 * 2 )		// don't offer to buy throne in the first 2 years of the game
		return 0;

	if( m.random(5) != 0 )		// don't do this too often
		return 0;

	//---- only do so when we have enough cash ----//

	if( cash < fixed_expense_365days() + 5000 + 10000 * pref_cash_reserve / 100 )
		return 0;

	if( profit_365days() < 0 && cash < 20000 )		// don't ask if we are losing money and the cash isn't plenty
		return 0;

	//----- calculate the amount this nation can offer ----//

	int offerAmount = (int)cash - min(5000, (int)fixed_expense_365days());

	static int amtArray[] = { 5000, 10000, 20000, 35000, 50000, 75000, 100000, 150000 };

	int i;
	for( i=7 ; i>=0 ; i-- )
	{
		if( offerAmount >= amtArray[i] )
		{
			offerAmount = amtArray[i];
			break;
		}
	}

	if( i<0 )
		return 0;

	//---------------------------------------------//

	Nation* nationPtr;
	int     ourOverallRankRating = overall_rank_rating();
	int	  totalNation = nation_array.size();

	int nationRecno = m.random(totalNation)+1;

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

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

		nationPtr = nation_array[nationRecno];

		//--- don't ask for a kingdom that is more powerful to surrender to us ---//

		if( nationPtr->cash > 100 )	// unless it is running short of cash
		{
			if( nationPtr->overall_rank_rating() > ourOverallRankRating )
				continue;
		}

		//-------------------------------------------//

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

		//-------------------------------------------//

		talk_res.ai_send_talk_msg(nationRecno, nation_recno,
			TALK_REQUEST_SURRENDER, offerAmount/10 );			// divide by 10 to cope with <short>'s upper limit

		return 1;
	}

	return 0;
}
Example #10
0
//----- Begin of function Nation::think_against_mine_monopoly -----//
//
int Nation::think_against_mine_monopoly()
{
	//-- only think this after the game has been running for at least one year --//

	if( config.ai_aggressiveness < OPTION_HIGH )		// only attack if aggressiveness >= high
		return 0;

	if( info.game_date - info.game_start_date > 365 )
		return 0;

	if( profit_365days() > 0 )		// if we are making a profit, don't attack
		return 0;

	//-- for high aggressiveness, it will check cash before attack, for very high aggressiveness, it won't check cash before attack ---//

	if( config.ai_aggressiveness < OPTION_VERY_HIGH )		// only attack if aggressiveness >= high
	{
		if( cash > 2000 + 1000 * pref_cash_reserve / 100 )		// only attack if we run short of cash
			return 0;
	}

	//--------------------------------------------------------//

	if( !largest_town_recno )
		return 0;

	//--------------------------------------------------//

	int baseRegionId = town_array[largest_town_recno]->region_id;

	// no region stat (region is too small), don't care
	if( !region_array[baseRegionId]->region_stat_id )
		return 0;

	RegionStat* regionStat = region_array.get_region_stat(baseRegionId);

	//---- if we already have a mine in this region ----//

	if( regionStat->mine_nation_count_array[nation_recno-1] > 0 )
		return 0;

	//----- if there is no mine in this region -----//

	if( regionStat->raw_count == 0 )
		return 0;

	//----- if enemies have occupied all mines -----//

	int mineCount, totalMineCount=0;
	int curRating, bestRating=0, targetNationRecno=0;

	int i;
	for( i=nation_array.size() ; i>0 ; i-- )
	{
		if( nation_array.is_deleted(i) )
			continue;

		//------ only deal with human players ------//

		if( nation_array[i]->is_ai() || i==nation_recno )
			continue;

		//------------------------------------------//

		mineCount = regionStat->mine_nation_count_array[i-1];
		totalMineCount += mineCount;

		curRating = mineCount * 100
						- get_relation(i)->ai_relation_level
						- trade_rating(i);

		if( curRating > bestRating )
		{
			bestRating 		   = curRating;
			targetNationRecno = i;
		}
	}

	if( !targetNationRecno )
		return 0;

	//--- if the relationship with this nation is still good, don't attack yet, ask for aid first ---//

	NationRelation* nationRelation = get_relation(targetNationRecno);

	if( nationRelation->ai_relation_level > 30 )
	{
		int talkId;

		if( nationRelation->status >= NATION_FRIENDLY )
			talkId = TALK_DEMAND_AID;
		else
			talkId = TALK_DEMAND_TRIBUTE;

		if( should_diplomacy_retry(talkId, targetNationRecno) )
		{
			static short aidAmountArray[] = { 500, 1000, 2000 };

			int aidAmount = aidAmountArray[misc.random(3)];

			talk_res.ai_send_talk_msg(targetNationRecno, nation_recno, talkId, aidAmount);
		}

		return 0;
	}

	//------- attack one of the target enemy's mines -------//

	Firm* firmPtr;

	for( i=firm_array.size() ; i>0 ; i-- )
	{
		if( firm_array.is_deleted(i) )
			continue;

		firmPtr = firm_array[i];

		if( firmPtr->firm_id != FIRM_MINE ||
			 firmPtr->nation_recno != targetNationRecno ||
			 firmPtr->region_id != baseRegionId )
		{
			continue;
		}

		//--------------------------------------------//

		int hasWar;
		int targetCombatLevel = enemy_firm_combat_level(firmPtr, 1, hasWar);

		return ai_attack_target( firmPtr->loc_x1, firmPtr->loc_y1,
										 targetCombatLevel, 0, 0, 0, 0, 1 );		// 1-use all camps
	}

	return 0;
}
Example #11
0
//----- Begin of function Nation::think_ally_against_big_enemy -----//
//
// Think about allying against a big enemy
//
int Nation::think_ally_against_big_enemy()
{
	if( info.game_date < info.game_start_date + 365 + nation_recno*70 )		// don't ask for tribute too soon, as in the beginning, the ranking are all the same for all nations
		return 0;

	//---------------------------------------//

	int enemyNationRecno = nation_array.max_overall_nation_recno;

	if( enemyNationRecno == nation_recno )
		return 0;

	//-- if AI aggressiveness > high, only deal against the player, but not other kingdoms ---//

	if( config.ai_aggressiveness >= OPTION_HIGH )
	{
		if( nation_array[enemyNationRecno]->is_ai() )
			return 0;
	}

	//-- if AI aggressiveness is low, don't do this against the human player --//

	else if( config.ai_aggressiveness == OPTION_LOW )
	{
		if( !nation_array[enemyNationRecno]->is_ai() )
			return 0;
	}

	//--- increase the ai_relation_level towards other nations except the enemy so we can ally against the enemy ---//

	Nation* enemyNation = nation_array[enemyNationRecno];
	int     incRelationLevel = (100-overall_rank_rating())/10;

	int i;
	for( i=nation_array.size() ; i>0 ; i-- )
	{
		if( nation_array.is_deleted(i) )
			continue;

		if( i==nation_recno || i==enemyNationRecno )
			continue;

		int thisIncLevel = incRelationLevel * (100-get_relation(i)->ai_relation_level) / 100;

		change_ai_relation_level( i, thisIncLevel );
	}

	//---- don't have all nations doing it the same time ----//

	if( misc.random(nation_array.ai_nation_count)==0 )
		return 0;

	//---- if the trade rating is high, stay war-less with it ----//

	if( trade_rating(enemyNationRecno) +
		 ai_trade_with_rating(enemyNationRecno) > 100 - pref_trading_tendency/3 )
	{
		return 0;
	}

	//---- if the nation relation level is still high, then request aid/tribute ----//

	NationRelation* nationRelation = get_relation(enemyNationRecno);

	if( nationRelation->ai_relation_level > 30 )
	{
		int talkId;

		if( nationRelation->status >= NATION_FRIENDLY )
			talkId = TALK_DEMAND_AID;
		else
			talkId = TALK_DEMAND_TRIBUTE;

		if( should_diplomacy_retry(talkId, enemyNationRecno) )
		{
			static short aidAmountArray[] = { 500, 1000, 2000 };

			int aidAmount = aidAmountArray[misc.random(3)];

			talk_res.ai_send_talk_msg(enemyNationRecno, nation_recno, talkId, aidAmount);
		}

		return 0;
	}

	//-------------------------------------//

	Nation* nationPtr;

	NationRelation *ourNationRelation, *enemyNationRelation;

	for( i=nation_array.size() ; i>0 ; i-- )
	{
		if( nation_array.is_deleted(i) )
			continue;

		if( i==nation_recno || i==enemyNationRecno )
			continue;

		nationPtr = nation_array[i];

		ourNationRelation   = get_relation(i);
		enemyNationRelation = enemyNation->get_relation(i);

	}

	return 0;
}
Example #12
0
//----- Begin of function Nation::think_deal_with_one_enemy -----//
//
void Nation::think_deal_with_one_enemy(int enemyNationRecno)
{
	Nation* nationPtr;
	NationRelation* nationRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || nation_recno == i )
			continue;

		nationPtr = nation_array[i];

		nationRelation = nationPtr->get_relation(nation_recno);

		//--- if this nation is already allied to us, request it to declare war with the enemy ---//

		if( nationRelation->status == NATION_ALLIANCE &&
			 nationPtr->get_relation_status(enemyNationRecno) != NATION_HOSTILE )
		{
			if( should_diplomacy_retry(TALK_REQUEST_DECLARE_WAR, i) )
			{
				talk_res.ai_send_talk_msg(i, nation_recno, TALK_REQUEST_DECLARE_WAR, enemyNationRecno);
				continue;
			}
		}

		//---- if this nation is not friendly or alliance to our enemy ----//

		if( nationPtr->get_relation_status(enemyNationRecno) < NATION_FRIENDLY )
		{
			//--- and this nation is neutral or friendly with us ---//

			if( nationRelation->status >= NATION_NEUTRAL &&
				 nationPtr->get_relation(enemyNationRecno)->trade_treaty )
			{
				//--- ask it to join a trade embargo on the enemy ---//

				if( should_diplomacy_retry(TALK_REQUEST_TRADE_EMBARGO, i) )
					talk_res.ai_send_talk_msg(i, nation_recno, TALK_REQUEST_TRADE_EMBARGO, enemyNationRecno );
			}
		}
		else 	//---- if this nation is friendly or alliance to our enemy ----//
		{
			//----- and this nation is not at war with us -----//

			if( nationRelation->status != NATION_HOSTILE )
			{
				//--- if we do not have trade treaty with this nation, propose one ---//

				if( !nationRelation->trade_treaty )
				{
					if( should_diplomacy_retry(TALK_PROPOSE_TRADE_TREATY, i) )
						talk_res.ai_send_talk_msg(i, nation_recno, TALK_PROPOSE_TRADE_TREATY );
				}
				else //--- if we already have a trade treaty with this nation ---//
				{
					// if this nation is already friendly to us, propose an alliance treaty now --//

					if( nationRelation->status == NATION_FRIENDLY )
					{
						if( should_diplomacy_retry(TALK_PROPOSE_ALLIANCE_TREATY, i) )
							talk_res.ai_send_talk_msg(i, nation_recno, TALK_PROPOSE_ALLIANCE_TREATY );
					}

					//-- if the nation has significiant trade with us, propose a friendly treaty now --//

					else if( nationPtr->trade_rating(nation_recno) > 10 ||
								nationPtr->ai_trade_with_rating(nation_recno) >= 50 )		// or if the product complement each other very well
					{
						if( should_diplomacy_retry(TALK_PROPOSE_FRIENDLY_TREATY, i) )
							talk_res.ai_send_talk_msg(i, nation_recno, TALK_PROPOSE_FRIENDLY_TREATY );
					}
				}
			}
		}
	}
}