Beispiel #1
0
//----- Begin of function Nation::should_consider_friendly -----//
//
int Nation::should_consider_friendly(int withNationRecno)
{
	Nation* withNation = nation_array[withNationRecno];

	//------- if this is a larger nation -------//

	if( overall_rank_rating() / 100 > 50 )
	{
		//--- big nations don't ally with their biggest opponents ---//

		int maxOverallRating=0;
		int biggestOpponentNationRecno=0;

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

			int overallRating = nation_array[i]->overall_rating;

			if( overallRating > maxOverallRating )
			{
				maxOverallRating = overallRating;
				biggestOpponentNationRecno = i;
			}
		}

		if( biggestOpponentNationRecno == withNationRecno )
			return 0;
	}

	//--- don't ally with nations with too low reputation ---//

	return withNation->reputation >= min(20, reputation) - 20;
}
Beispiel #2
0
//----- Begin of function Nation::ai_surrender_to_rating -----//
//
// return a rating on how much the nation will tend to surrender
// to the specific nation.
//
int Nation::ai_surrender_to_rating(int nationRecno)
{
	Nation* 			 nationPtr = nation_array[nationRecno];
	NationRelation* nationRelation = get_relation(nationRecno);

	//--- higher tendency to surrender to a powerful nation ---//

	int curRating = nationPtr->overall_rank_rating() - overall_rank_rating();

	curRating += (nationRelation->ai_relation_level-40);

	curRating += (int) nationRelation->good_relation_duration_rating*3;

	curRating += (int) nationPtr->reputation/2;

	//------ shouldn't surrender to an enemy --------//

	if( nationRelation->status == NATION_HOSTILE )
		curRating -= 100;

	//--- if the race of the kings are the same, the chance is higher ---//

	if( race_res.is_same_race( nationPtr->race_id, race_id ) )
		curRating += 20;

	return curRating;
}
Beispiel #3
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;
}
Beispiel #4
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;
}
Beispiel #5
0
//----- Begin of function Nation::consider_accept_surrender_request -----//
//
// Consider accepting the cash offer and sell the throne to another kingdom.
//
// talkMsg->talk_para1 - the amount offered.
//
int Nation::consider_accept_surrender_request(TalkMsg* talkMsg)
{
	Nation* nationPtr = nation_array[talkMsg->from_nation_recno];
	int    offeredAmt = talkMsg->talk_para1 * 10;			// *10 to restore its original value which has been divided by 10 to cope with <short> upper limit

	//--- if the nation does not have any towns, camps or generals, it will have a larger tendency to surrender. ---//

	int weakNation = (ai_town_count==0 && ai_camp_count==0 && ai_general_count==0);

	//---- only surrender to nations of the same nationality or Fryhtan species ----//

	if( is_human() != nationPtr->is_human() )
		return 0;

	//---- don't surrender to the player if the player is already the most powerful nation ---//

	if( !weakNation && !nationPtr->is_ai() && config.ai_aggressiveness >= OPTION_HIGH )
	{
		if( nation_array.max_overall_nation_recno == nationPtr->nation_recno )
			return 0;
	}

	//--- if we are running out of cash, ignore all normal thinking ---//

	if( !(cash < 100 && profit_365days() < 0) && !weakNation )
	{
		//----- never surrender to a weaker nation ------//

		if( nationPtr->overall_rank_rating() < overall_rank_rating() )
			return 0;

		//------ don't surrender if we are still strong -----//

		if( overall_rank_rating() > 30 + pref_peacefulness/4 )		// 30 to 55
			return 0;

		//---- don't surrender if our cash is more than the amount they offered ----//

		if( offeredAmt < cash * (75+pref_cash_reserve/2) / 100 )		// 75% to 125%
			return 0;

		//-- if there are only two nations left, don't surrender if we still have some power --//

		if( nation_array.nation_count == 2 )
		{
			if( overall_rank_rating() > 20 - 10 * pref_military_courage / 100 )
				return 0;
		}
	}

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

	int surrenderToRating = ai_surrender_to_rating(talkMsg->from_nation_recno);

	surrenderToRating += 100 * offeredAmt / 10000;

	int acceptRating = overall_rank_rating()*13 + 100;

	//------ AI aggressiveness effects -------//

	switch( config.ai_aggressiveness )
	{
		case OPTION_HIGH:
			if( nationPtr->is_ai() )		// tend to accept AI kingdom offer easier
				acceptRating -= 75;
			else
				acceptRating += 75;
			break;

		case OPTION_VERY_HIGH:
			if( nationPtr->is_ai() )		// tend to accept AI kingdom offer easier
				acceptRating -= 150;
			else
				acceptRating += 150;
			break;
	}

	return surrenderToRating > acceptRating;
}