//----- 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_should_build_mine --------// // int Nation::ai_should_build_mine() { //---- only build mines when it has enough population ----// if( total_jobless_population < (100-pref_economic_development)/2 ) return 0; if( total_jobless_population < 16 ) // only build mine when you have enough population to support the economic chain: mine + factory + camp return 0; if( site_array.untapped_raw_count==0 ) return 0; if( !can_ai_build(FIRM_MINE) ) return 0; //--- don't build additional mines unless we have enough population and demand to support it ----// if( ai_mine_count >= 1 ) { if( true_profit_365days() < 0 || total_population < 40+pref_economic_development/5 ) return 0; } //-- if the nation is already in the process of building a new one --// if( is_action_exist( ACTION_AI_BUILD_FIRM, FIRM_MINE ) ) return 0; //--- if the population is low, make sure existing mines are in full production before building a new one ---// if( total_jobless_population < 30 ) { FirmMine* firmMine; for( int i=0 ; i<ai_mine_count ; i++ ) { firmMine = firm_array[ ai_mine_array[i] ]->cast_to_FirmMine(); err_when( !firmMine ); if( firmMine->worker_count < MAX_WORKER ) return 0; if( firmMine->linked_firm_count==0 && !firmMine->no_neighbor_space ) // if the firm does not have any linked firms, that means the firm is still not in full operation return 0; } } return 1; }
//----- Begin of function Nation::consider_take_aid -----// // // talkMsg->talk_para1 - amount of the tribute. // int Nation::consider_take_aid(TalkMsg* talkMsg) { int cashSignificance = 100 * talkMsg->talk_para1 / max(1000, (int) cash); //--- It does not necessarily want the tribute ---// int aiRelationLevel = get_relation(talkMsg->from_nation_recno)->ai_relation_level; if( true_profit_365days() > 0 && cashSignificance < (100-aiRelationLevel)/5 ) { return 0; } //----------- take the tribute ------------// int relationChange = cashSignificance * (100+pref_cash_reserve) / 200; change_ai_relation_level( talkMsg->from_nation_recno, relationChange ); return 1; }
void Nation::think_reduce_expense() { if( true_profit_365days() > 0 || cash > 5000 * pref_cash_reserve / 100 ) return; //-------- close down firms ---------// int curRating, bestRating=0; Firm *firmPtr, *bestFirm=NULL; for( int i=firm_array.size() ; i>0 ; i-- ) { if( firm_array.is_deleted(i) ) continue; firmPtr = firm_array[i]; if( firmPtr->nation_recno != nation_recno ) continue; if( firmPtr->firm_id == FIRM_WAR_FACTORY || firmPtr->firm_id == FIRM_RESEARCH ) { curRating = 100-(int)firmPtr->productivity; } else continue; if( curRating > bestRating ) { bestRating = curRating; bestFirm = firmPtr; } } if( bestFirm ) bestFirm->ai_del_firm(); }
//----- 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); }