//----- Begin of function Nation::consider_give_tribute -----// // // talkMsg->talk_para1 - amount of the tribute. // int Nation::consider_give_tribute(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_TRIBUTE-1] ) return 0; //---------------------------------------------// int relationStatus = get_relation_status(talkMsg->from_nation_recno); Nation* fromNation = nation_array[talkMsg->from_nation_recno]; if( true_profit_365days() < 0 ) // don't give tribute if we are losing money return 0; int reserveYears = 1 + 3 * pref_cash_reserve / 100; // 1 to 4 years if( cash-talkMsg->talk_para1 < fixed_expense_365days() * reserveYears ) return 0; int militaryDiff = fromNation->military_rank_rating() - military_rank_rating(); if( militaryDiff > 10+pref_military_courage/2 ) { nationRelation->set_never_accept_until_date(TALK_GIVE_TRIBUTE, 180); return 1; } return 0; }
//--------- Begin of function Nation::ai_supported_inn_count --------// // // Return the number of inns this nation can support. // int Nation::ai_supported_inn_count() { float fixedExpense = fixed_expense_365days(); int innCount = int( cash / 5000 * (100+pref_hire_unit) / 100 ); innCount = MIN( 3+pref_hire_unit/35, innCount); // maximum 3 to 5 inns, minimum 1 inn. return MAX(1, innCount); }
//----- Begin of function Nation::ai_should_spend -----// // // This function returns whether this nation should make // a new spending. // // <int> importanceRating - how important is the spending to the // nation. // [float] spendAmt - if this is not given, then it will // consider generally - whether the // nation should spend money generally. // int Nation::ai_should_spend(int importanceRating, float spendAmt) { if( cash < spendAmt ) return 0; float fixedExpense = fixed_expense_365days(); float stdCashLevel = max(fixedExpense,2000) * (150+pref_cash_reserve) / 100; float trueProfit = true_profit_365days(); //----- if we are losing money, don't spend on non-important things -----// if( trueProfit < 0 ) { if( 400 * (-trueProfit) / fixedExpense > importanceRating ) return 0; } //--------------------------------------// float curCashLevel = 100 * (cash-spendAmt) / (stdCashLevel*2); return importanceRating >= (100-curCashLevel); }
//----- Begin of function Nation::think_demand_tribute_aid -----// // // Demand tribute when the nation's economy is good and its // military is weak. // int Nation::think_demand_tribute_aid() { if( info.game_date < info.game_start_date + 180 + nation_recno*50 ) // don't ask for tribute too soon, as in the beginning, the ranking are all the same for all nations return 0; //--------------------------------------// Nation* nationPtr; int totalNation=nation_array.size(); int nationRecno=m.random(totalNation)+1; int curRating, requestRating; int talkId; int ourMilitary = military_rank_rating(); int ourEconomy = economic_rank_rating(); for( int i=totalNation ; i>0 ; i-- ) { if( ++nationRecno > totalNation ) nationRecno = 1; if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno ) continue; nationPtr = nation_array[nationRecno]; //-- only demand tribute from non-friendly nations --// if( get_relation(nationRecno)->status <= RELATION_NEUTRAL ) talkId = TALK_DEMAND_TRIBUTE; else talkId = TALK_DEMAND_AID; //-----------------------------------------------// float fixedExpense = fixed_expense_365days(); if( talkId == TALK_DEMAND_TRIBUTE ) { if( !should_diplomacy_retry(talkId, nationRecno) ) continue; curRating = ourMilitary - nationPtr->military_rank_rating(); //---- if this is a Fryhtan nation, the tendency to request tribute is higher -----// if( is_monster() && nationPtr->is_human() ) // and the target is a human nation { curRating *= 2; //-- if we are running low of live points, it's time to kill somebody --// if( live_points < 500 * (100+pref_live_points_reserve) / 100 ) curRating *= 2; } if( curRating < 0 ) continue; //----------------------------------------------// // // Some nation will actually consider the ability // of the target nation to pay tribute, so nation // will not and just ask anyway. // //----------------------------------------------// if( pref_economic_development > 50 ) { int addRating = nationPtr->economic_rank_rating()-ourEconomy; if( addRating > 0 ) curRating += addRating; } requestRating = 20 + trade_rating(nationRecno)/2 + (100-pref_peacefulness)/3; if( cash < fixedExpense && fixedExpense != 0 ) requestRating -= int( (float) requestRating * cash / fixedExpense); } else { if( cash >= fixedExpense ) continue; if( cash > fixedExpense * (50+pref_cash_reserve) / 300 && // if the nation is runing short of cash, don't wait a while until next retry, retry immediately !should_diplomacy_retry(talkId, nationRecno) ) { continue; } //----- only ask for aid when the nation is short of cash ----// curRating = (ourMilitary - nationPtr->military_rank_rating())/2 + ( nationPtr->economic_rank_rating()-ourEconomy ); requestRating = 20 + 50 * (int)(cash / fixedExpense); } //----- if the target is a human player's nation -----// if( !nationPtr->is_ai() ) { switch( config.ai_aggressiveness ) { case OPTION_NONE: requestRating += 60; // don't go against the player too easily break; case OPTION_LOW: requestRating += 40; // don't go against the player too easily break; case OPTION_HIGH: requestRating -= 20; break; case OPTION_VERY_HIGH: requestRating -= 40; break; } //--- if the nation has plenty of cash, demand from it ----// if( nationPtr->cash > cash && config.ai_aggressiveness >= OPTION_HIGH ) { requestRating -= (int) (nationPtr->cash - cash)/500; } } //--------------------------------------// if( curRating > requestRating ) { int tributeAmount; if( curRating - requestRating > 120 ) tributeAmount = 4000; else if( curRating - requestRating > 80 ) tributeAmount = 3000; else if( curRating - requestRating > 40 ) tributeAmount = 2000; else if( curRating - requestRating > 20 ) tributeAmount = 1000; else tributeAmount = 500; //------ stop in here if in tutorial mode -----// if( game.game_mode != GAME_TUTORIAL ) { cash += tributeAmount; return 0; } talk_res.ai_send_talk_msg(nationRecno, nation_recno, talkId, tributeAmount); return 1; } } 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_sell_food -----// // // talkMsg->talk_para1 - qty of food wanted to buy. // talkMsg->talk_para2 - buying price offered for 10 food. // int Nation::consider_sell_food(TalkMsg* talkMsg) { int relationStatus = get_relation_status(talkMsg->from_nation_recno); if( relationStatus == RELATION_HOSTILE ) return 0; //--- if after selling the food, the remaining is not enough for its own consumption for ? years ---// float newFood = food-talkMsg->talk_para1; float yearConsumption = (float) yearly_food_consumption(); int offeredAmount = talkMsg->talk_para2; int relationLevel = get_relation(talkMsg->from_nation_recno)->ai_relation_level; if( newFood < 1000 + 1000 * pref_food_reserve / 100 ) return 0; if( relationLevel >= 50 ) offeredAmount += 5; // increase the chance of selling food else if( relationLevel < 30 ) // decrease the chance of selling food offeredAmount -=5 ; //---- if we run short of cash, we tend to accept the offer ---// float fixedExpense = fixed_expense_365days(); if( cash < fixedExpense ) offeredAmount += (int) (20 * (fixedExpense-cash) / fixedExpense); //---------------------------------// float reserveYears = (float) (100+pref_food_reserve) / 100; // 1 to 2 years if( yearly_food_change() > 0 && newFood > yearConsumption * reserveYears ) { if( offeredAmount >= 10 ) // offered >= $10 { return 1; } else // < $10, only if we have plenty of reserve { if( newFood > yearConsumption * reserveYears * 2 ) return 1; } } else { if( offeredAmount >= 20 ) { if( yearly_food_change() > 0 && newFood > yearConsumption * reserveYears / 2 ) { return 1; } } if( offeredAmount >= 30 ) { return yearly_food_change() > 0 || newFood > yearConsumption * reserveYears; } } return 0; }