//----- Begin of function Nation::think_surrender -----// // int Nation::think_surrender() { //--- don't surrender if the nation still has a town ---// int rc=0; if( total_population == 0 ) rc = 1; if( cash <= 0 && income_365days()==0 ) rc = 1; if( !rc ) return 0; //---- see if there is any nation worth getting our surrender ---// Nation* nationPtr; int curRating, bestRating=0, bestNationRecno=0; if( !king_unit_recno ) // if there is no successor to the king, the nation will tend more to surrender bestRating = -100; for( int i=nation_array.size() ; i>0 ; i-- ) { if( nation_array.is_deleted(i) || i==nation_recno ) continue; nationPtr = nation_array[i]; if( nationPtr->cash <= 300 ) // don't surrender to an ecnomically handicapped nation continue; curRating = ai_surrender_to_rating(i); //--- if the nation will tend to surrender if there is only a small number of units left ---// curRating += 50 - total_unit_count*5; if( curRating > bestRating ) { bestRating = curRating; bestNationRecno = i; } } //---------------------------------------// if( bestNationRecno ) { surrender(bestNationRecno); 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; }