Пример #1
0
//--------- Begin of function Nation::should_use_cash_to_capture --------//
//
int Nation::should_use_cash_to_capture()
{
	//--- if we have plenty of cash, use cash to decrease the resistance of the villagers ---//

	return military_rank_rating() < 50+pref_peacefulness/5 &&		// 50 to 70
			 ai_should_spend(pref_loyalty_concern/4);
}
Пример #2
0
//--------- Begin of function Nation::think_marine --------//
//
void Nation::think_marine()
{
	if( pref_use_marine < 50 )		// don't use marine at all
		return;

	if( !ai_should_spend(20+pref_use_marine/2) )		// 20 to 70 importance rating
		return;

	//--- think over building harbor network ---//

	think_build_harbor_network();

	if( ai_harbor_count == 0 )
		return;

	//------ think about sea attack enemies -------//

	if( misc.random(3)==0 )				// 33% chance
	{
		if( think_sea_attack_enemy() )
			return;
	}

	//---- check if it is safe for sea travel now ----//

	if( !ai_is_sea_travel_safe() )
		return;

	//----- think over moving between regions -----//

	think_move_between_region();

//	think_move_to_region_with_mine();
}
Пример #3
0
//--------- Begin of function Nation::ai_should_hire_unit --------//
//
// <int> importantRating - importance of hiring the unit.
//
int Nation::ai_should_hire_unit(int importanceRating)
{
	if( !ai_inn_count )		// don't hire any body in the cash is too low
		return 0;

	return ai_should_spend(importanceRating + pref_hire_unit/5 - 10 );		// -10 to +10 depending on pref_hire_unit
}
Пример #4
0
//----- Begin of function Nation::consider_give_aid -----//
//
// talkMsg->talk_para1 - amount of the tribute.
//
int Nation::consider_give_aid(TalkMsg* talkMsg)
{
	//-------- don't give tribute too frequently -------//

	NationRelation* nationRelation = get_relation(talkMsg->from_nation_recno);

	if( info.game_date < nationRelation->never_accept_until_date_array[TALK_GIVE_AID-1] )
		return 0;

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

	int importanceRating = (int) nationRelation->good_relation_duration_rating;

	if( nationRelation->status >= RELATION_FRIENDLY &&
		 ai_should_spend( importanceRating, talkMsg->talk_para1 ) )        // 0-importance is 0
	{
		if( info.game_date > nationRelation->last_change_status_date
			 + 720 - pref_allying_tendency )						// we have allied with this nation for quite some while
		{
			nationRelation->set_never_accept_until_date(TALK_GIVE_AID, 180);		// don't give aid again too soon 
			return 1;
		}
	}

	return 0;
}
Пример #5
0
//----- Begin of function Nation::ai_should_spend_war -----//
//
// This function returns whether the nation should spend money
// or war.
//
// <int> enemyMilitaryRating - the military_rank_rating() of the enemy
// [int] considerCeaseFire	  - whether this function is called when considering ceasing fire
//										 (default:0)
//
int Nation::ai_should_spend_war(int enemyMilitaryRating, int considerCeaseFire)
{
	int importanceRating = 30 + pref_military_development/5;		// 30 to 50

	importanceRating += military_rank_rating() - enemyMilitaryRating*2;

	if( considerCeaseFire )    	// only when we are very powerful, we will start a battle. So won't cease fire too soon after declaring war
		importanceRating += 20;		// less eary to return 0, for cease fire

	return ai_should_spend(importanceRating);
}
Пример #6
0
//--------- Begin of function Nation::think_build_mine --------//
//
int Nation::think_build_mine()
{
    //------- queue to build the new mine -------//

    short xLoc, yLoc, refXLoc, refYLoc;

    int rawId = seek_mine(xLoc, yLoc, refXLoc, refYLoc);	//reference location is the raw material location

    if( !rawId )
        return 0;

    //--- if we have a mine producing that raw type already ---//

    if( raw_count_array[rawId-1] > 0 )
    {
        if( !ai_should_spend(20) )		// then it's not important to build it
            return 0;
    }

    //-------------------------------------------//
    // If the map is set to unexplored, wait for a
    // reasonable amount of time before moving out
    // to build the mine.
    //-------------------------------------------//

    if( !config.explore_whole_map )
    {
        int i;
        for( i=0 ; i<ai_town_count ; i++ )
        {
            Town* townPtr = town_array[ ai_town_array[i] ];

            int rawDistance = misc.points_distance(xLoc, yLoc, townPtr->center_x, townPtr->center_y);

            if( info.game_date-info.game_start_date >
                    rawDistance * (5-config.ai_aggressiveness) / 5 )		// 3 to 5 / 5
            {
                break;
            }
        }

        if( i==ai_town_count )
            return 0;
    }

    return add_action(xLoc, yLoc, refXLoc, refYLoc, ACTION_AI_BUILD_FIRM, FIRM_MINE);
}
Пример #7
0
//----- Begin of function Nation::think_give_tribute_aid -----//
//
// This function is called when a nation rejected our request
// which is important to us and we want to give tribute to the
// nation so it may accept next time.
//
// <TalkMsg*> rejectedMsg - the TalkMsg that has been rejected.
//
int Nation::think_give_tribute_aid(TalkMsg* rejectedMsg)
{
	//-----------get the talk id. ------------//

	int talkId;
	int talkNationRecno = rejectedMsg->to_nation_recno;
	int rejectedTalkId  = rejectedMsg->talk_id;
	NationRelation* nationRelation = get_relation(talkNationRecno);

	if( nationRelation->status >= RELATION_FRIENDLY )
		talkId = TALK_GIVE_AID;
	else
		talkId = TALK_GIVE_TRIBUTE;

	//-------- don't give tribute too frequently -------//

	if( info.game_date < nationRelation->never_accept_until_date_array[talkId-1] )
		return 0;

	//---- think if the nation should spend money now ----//

	static short tributeAmountArray[] = { 500, 1000 };
	int tributeAmount = tributeAmountArray[m.random(2)];

	if( !ai_should_spend(0, (float) tributeAmount) )		// importance rating is 0
		return 0;

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

	Nation* talkNation = nation_array[talkNationRecno];
	int	  rc;

	if( rejectedTalkId == TALK_PROPOSE_TRADE_TREATY )
	{
		rc = ai_trade_with_rating(talkNationRecno) > 100-pref_trading_tendency/2;
	}

	else if ( rejectedTalkId == TALK_PROPOSE_FRIENDLY_TREATY ||
				 rejectedTalkId == TALK_PROPOSE_ALLIANCE_TREATY )
	{
		int curRating = talkNation->trade_rating(talkNationRecno) +
							 ai_trade_with_rating(talkNationRecno) +
							 talkNation->overall_rating - overall_rating;

		int acceptRating = 200-pref_trading_tendency/4
									 -pref_allying_tendency/4;

		rc = curRating >= acceptRating;
	}

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

	else if( rejectedTalkId == TALK_REQUEST_CEASE_WAR )
	{
		rc = talkNation->military_rank_rating() >
			  military_rank_rating() + (100-pref_peacefulness)/2;
	}

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

	if( rc )
	{
		//------ give tribute --------//

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

		nationRelation->set_never_accept_until_date(talkId, 100);		// don't offer tribute too often

		//------ request again after giving tribute ----//

		nationRelation->last_talk_reject_date_array[rejectedTalkId-1] = 0;		// reset the rejected talk id.
		nationRelation->never_accept_until_date_array[rejectedTalkId-1] = 0;		// reset the rejected talk id.

		talk_res.ai_send_talk_msg(talkNationRecno, nation_recno, rejectedTalkId, rejectedMsg->talk_para1, rejectedMsg->talk_para2 );
	}

	return rc;
}
Пример #8
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;
}