Example #1
0
//----- Begin of function Nation::think_deal_with_all_enemy -----//
//
// Think about dealing with the enemy. The following are the
// actions a nation can take to deal with its enemies.
//
// >ask our allies to attack the enemy.
//
// >try to break the enemy's existing alliance/friendly treaty with other
//	 nations - to reduce its alliance strength.
//
// >convert enemy's allies to ours.
//
// >ask other nations to impose trade embargos on the enemy.
//
void Nation::think_deal_with_all_enemy()
{
	Nation* nationPtr;

	int ourMilitary = military_rank_rating();
	int enemyCount  = total_enemy_count();

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

		if( get_relation_status(i) != NATION_HOSTILE )
			continue;

		nationPtr = nation_array[i];

		//------- think about eliminating the enemy ------//

		int rc = 0;

		if( nationPtr->total_population==0 ) 		// the enemy has no towns left
			rc = 1;

		if( enemyCount==1 &&
			 ourMilitary > 100-pref_military_courage/5 ) 		// 80 to 100
		{
			int enemyMilitary = nationPtr->military_rank_rating();

			if( enemyMilitary < 20 && ai_should_spend_war(enemyMilitary) )
				rc = 1;
		}

		if( rc )
		{
			if( think_eliminate_enemy_firm(i) )
				continue;

			if( think_eliminate_enemy_town(i) )
				continue;

			think_eliminate_enemy_unit(i);
			continue;
		}

		//----- think about dealing with the enemy with diplomacy -----//

		think_deal_with_one_enemy(i);
	}
}
Example #2
0
//--------- Begin of function Nation::think_capture_enemy_town_target --------//
//
// <Town*> capturerTown - our town to capture enemy towns.
//
// Motives for attacking another nation:
//
// 1. Capture towns
// 2. Conquer land
// 3. Defeat enemies
//
Town* Nation::think_capture_enemy_town_target(Town* capturerTown)
{
	int   townRecno, curRating;
	Town* targetTown, *bestTown=NULL;
	Firm* firmPtr;
	int   ourMilitary = military_rank_rating();
	Nation* ownNation = nation_array[nation_recno];
	int   bestRating = -1000;
	int  	hasWar;
	int   neededCombatLevel=0;

	for( townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
	{
		if( town_array.is_deleted(townRecno) )
			continue;

		targetTown = town_array[townRecno];

		if( targetTown->nation_recno == 0 ||
			 targetTown->nation_recno == nation_recno )
		{
			continue;
		}

		if( targetTown->region_id != capturerTown->region_id )
			continue;

		//----- if we have already built a camp next to this town -----//

		if( targetTown->has_linked_camp(nation_recno, 0) )		//0-count both camps with or without overseers
			continue;

		//--------- only attack enemies -----------//

		NationRelation* nationRelation = get_relation(targetTown->nation_recno);

		int rc=0;

		if( nationRelation->status == NATION_HOSTILE )
			rc = 1;

		else if( nationRelation->ai_relation_level < 10 )			// even if the relation is not hostile, if the ai_relation_level is < 10, attack anyway
			rc = 1;

		else if( nationRelation->status <= NATION_NEUTRAL &&
			 targetTown->nation_recno == nation_array.max_overall_nation_recno &&		// if this is our biggest enemy
			 nationRelation->ai_relation_level < 30 )
		{
			rc = 1;
		}

		if( !rc )
			continue;

		//----- if this town does not have any linked camps, capture this town immediately -----//

		if( targetTown->has_linked_camp(targetTown->nation_recno, 0) )		//0-count both camps with or without overseers
			return targetTown;

		//--- if the enemy is very powerful overall, don't attack it yet ---//

		if( nation_array[targetTown->nation_recno]->military_rank_rating() >
			 ourMilitary * (80+pref_military_courage/2) / 100 )
		{
			continue;
		}

		//------ only attack if we have enough money to support the war ----//

		if( !ai_should_spend_war( nation_array[targetTown->nation_recno]->military_rank_rating() ) )
			continue;

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

		int townCombatLevel = enemy_town_combat_level(targetTown, 1, hasWar);		// 1-return a rating if there is war with the town

		if( townCombatLevel == -1 )      // do not attack this town because a battle is already going on
			continue;

		//------- calculate the rating --------------//

		curRating = world.distance_rating(capturerTown->center_x, capturerTown->center_y,
						targetTown->center_x, targetTown->center_y);

		curRating -= townCombatLevel/10;

		curRating -= targetTown->average_loyalty();

		curRating += targetTown->population;		// put a preference on capturing villages with large population

		//----- the power of between the nation also affect the rating ----//

		curRating += 2 * (ourMilitary - nation_array[targetTown->nation_recno]->military_rank_rating());

		//-- AI Aggressive is set above Low, than the AI will try to capture the player's town first ---//

		if( !targetTown->ai_town )
		{
			if( game.game_mode == GAME_TUTORIAL )		// next attack the player in a tutorial game
			{
				continue;
			}
			else
			{
				switch( config.ai_aggressiveness )
				{
					case OPTION_MODERATE:
						curRating += 100;
						break;

					case OPTION_HIGH:
						curRating += 300;
						break;

					case OPTION_VERY_HIGH:
						curRating += 500;
						break;
				}
			}
		}

		//--- if there are mines linked to this town, increase its rating ---//

		for( int i=targetTown->linked_firm_count-1 ; i>=0 ; i-- )
		{
			firmPtr = firm_array[ targetTown->linked_firm_array[i] ];

			if( firmPtr->nation_recno != targetTown->nation_recno )
				continue;

			if( firmPtr->firm_id == FIRM_MINE )
			{
				//--- if this mine's raw materials is one that we don't have --//

				if( raw_count_array[ ((FirmMine*)firmPtr)->raw_id-1 ]==0 )
					curRating += 150 * (int) ((FirmMine*)firmPtr)->reserve_qty / MAX_RAW_RESERVE_QTY;
			}
		}

		//--- more linked towns increase the attractiveness rating ---//

		curRating += targetTown->linked_firm_count*5;

		//-------- compare with the current best rating ---------//

		if( curRating > bestRating )
		{
			bestRating    = curRating;
			bestTown      = targetTown;
			neededCombatLevel = townCombatLevel;
		}
	}

	return bestTown;
}
Example #3
0
//----- Begin of function Nation::consider_cease_war -----//
//
// This function is shared by think_request_cease_war().
//
int Nation::consider_cease_war(int withNationRecno)
{
	NationRelation* nationRelation = get_relation(withNationRecno);

	if( nationRelation->status != RELATION_HOSTILE )
		return -1;			// -1 means don't reply

   //---- if we are attacking the nation, don't cease fire ----//

	if( ai_attack_target_nation_recno == withNationRecno )
		return -1;

	//---- if we are planning to capture the enemy's town ---//

	if( ai_capture_enemy_town_recno &&
		 !town_array.is_deleted(ai_capture_enemy_town_recno) &&
		 town_array[ai_capture_enemy_town_recno]->nation_recno == withNationRecno )
	{
		return -1;
	}

	//--- don't cease fire too soon after a war is declared ---//

	if( info.game_date < nationRelation->last_change_status_date + 60 + (100-pref_peacefulness) )		// more peaceful nation may cease fire sooner (but the minimum is 60 days).
		return -1;

	//------ if we're run short of money for war -----//

	Nation* withNation = nation_array[withNationRecno];

	if( !ai_should_spend_war(withNation->military_rank_rating(), 1) )		// if we shouldn't spend any more on war, then return 1
		return 1;

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

	int curRating = consider_alliance_rating(withNationRecno);

	//------------------------------------//
	//
	// Tend to be easilier to accept cease-fire if this nation's
	// military strength is weak.
	//
	// If the nation's peacefulness concern is high, it will
	// also be more likely to accept cease-fire.
	//
	//-------------------------------------//

	//--- if the enemy is more power than us, tend more to request cease-fire ---//
	
	curRating += total_enemy_military() - military_rank_rating();
	
	curRating += ai_trade_with_rating(withNationRecno) * (100+pref_trading_tendency) / 300;				// when we have excessive supply, we may want to cease-fire with our enemy

	curRating -= (military_rank_rating()-50)/2;					// if our military ranking is high, we may like to continue the war, otherwise the nation should try to cease-fire

	curRating -= nationRelation->started_war_on_us_count*10;		// the number of times this nation has started a war with us, the higher the number, the more unlikely we will accept cease-fire

	int acceptRating = pref_peacefulness/4;

	return curRating - acceptRating;
}