//----- 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; }
//----- 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; }
//----- 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; }