//----- 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 static function put_nation_rec --------// // static void put_nation_rec(int recNo, int x, int y, int refreshFlag) { int nationRecno = nation_filter(recNo); Nation* nationPtr = nation_array[nationRecno]; Nation* viewingNation = nation_array[info.viewing_nation_recno]; NationRelation* nationRelation = viewingNation->get_relation(nationRecno); x+=3; y+=5; nationPtr->disp_nation_color(x, y+1); font_san.put( x+20 , y, nationPtr->nation_name(), 0, x+215 ); font_san.put( x+220, y, m.format((int) nationPtr->reputation) ); //------- display relation parameters --------// if( nationRecno != info.viewing_nation_recno ) { font_san.put( x+272, y, nationRelation->status_str() ); font_san.put( x+355, y, nationRelation->should_attack ? (char*)"Yes" : (char*)"No" ); font_san.put( x+412, y, nationRelation->trade_treaty ? (char*)"Yes" : (char*)"No" ); font_san.put( x+465, y, m.format( (int) viewingNation->total_year_trade(nationRecno),2) ); if( config.show_ai_info ) { font_san.put( x+510, y, m.format(nationPtr->get_relation(info.viewing_nation_recno)->ai_relation_level) ); font_san.put( x+180, y, m.format( (int) nationPtr->get_relation(info.viewing_nation_recno)->good_relation_duration_rating) ); } } }
//----- 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; }
//----- 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; }
void CampaignEastWest::plot_a3_next_day() { // viking kingdom survive and mongol kingdom destroyed if( !nation_array.is_deleted(plot_nation_recno1) && nation_array.is_deleted(plot_nation_recno2) ) { // fryhtan is not defeated if( !nation_array.is_deleted(plot_enemy_nation_recno) ) { NationRelation* nationRelation = nation_array[plot_nation_recno1]->get_relation(nation_array.player_recno); short resetWStr[] = { TALK_PROPOSE_ALLIANCE_TREATY, 0 }; nationRelation->reset_ai_never_consider(resetWStr); short setWStr[] = { TALK_END_ALLIANCE_TREATY, 0 }; nationRelation->set_ai_never_consider(setWStr); // if alliance is set if( nationRelation->status == RELATION_ALLIANCE ) { // enhance ai relation so it can accept player request declare war with frythan nation_array[plot_nation_recno1]-> change_ai_relation_level(nation_array.player_recno, +100 ); // hardware not to cease fire with fryhtan kingdom short resetWStr2[] = { TALK_REQUEST_CEASE_WAR, 0 }; nation_array[plot_nation_recno1]->get_relation(plot_enemy_nation_recno) ->set_ai_never_consider( resetWStr2 ); } // propose an alliance treaty else if( info.game_date % 15 == 0 ) { if( nationRelation->status == RELATION_FRIENDLY || nationRelation->status == RELATION_NEUTRAL) { talk_res.ai_send_talk_msg( nation_array.player_recno, plot_nation_recno1, TALK_PROPOSE_ALLIANCE_TREATY ); } } } // fryhtan is defeated else { NationRelation* nationRelation = nation_array[plot_nation_recno1]->get_relation(nation_array.player_recno); nationRelation->ai_never_consider[TALK_SURRENDER-1] = 0; talk_res.ai_send_talk_msg( nation_array.player_recno, plot_nation_recno1, TALK_SURRENDER ); plot_nation_recno1 = 0; } } }
//--------- Begin of static function disp_nation_info ---------// // static void disp_nation_info() { vga.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_DET_Y2 ); //----------- display info ------------// int nationRecno = nation_filter(browse_nation.recno()); Nation* nationPtr = nation_array[nationRecno]; Nation* viewingNation = nation_array[info.viewing_nation_recno]; NationRelation* nationRelation = viewingNation->get_relation(nationRecno); int x1=REPORT_DET_X1+6, x2=REPORT_DET_X1+340, x3=REPORT_DET_X2-10; int y=REPORT_DET_Y1+6; //-------- display economic data ----------// String str; if( nationRecno == info.viewing_nation_recno ) { font_san.put_field( x1, y, "Your Food", x2, nationPtr->food_str() ); str = "$"; str += nationPtr->cash_str(); font_san.put_field( x1, y+=16, "Your Treasure", x2, str ); font_san.field( x1, y+=16, "Your Continuous Peace Time", x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" ); } else { str = translate.process("Your Yearly Import from "); str += nationPtr->nation_name(); font_san.field( x1, y , str, x2, (int) viewingNation->get_relation(nationRecno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "IMPORT" ); str = translate.process("Your Yearly Export to "); str += nationPtr->nation_name(); font_san.field( x1, y+=16, str, x2, (int) nationPtr->get_relation(info.viewing_nation_recno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "EXPORT" ); str = translate.process("Continuous Peace Time of "); str += nationPtr->nation_name(); font_san.field( x1, y+=16, str, x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" ); //--------- duration of current status ----------// #if(defined(SPANISH)) str = "Duración del estado de "; str += translate.process(nationRelation->status_str()); #elif(defined(FRENCH)) str = "Duration of "; str += nationRelation->status_str(); str += " Status"; str = translate.process(str); #else // GERMAN and US str = translate.process("Duration of "); str += translate.process(nationRelation->status_str()); str += " Status"; #endif font_san.field( x1, y+=16, str, x2, nationRelation->status_duration_str(), x3, INFO_REPAINT, "STATTIME" ); //------- display the allow_attack field --------// #if(defined(SPANISH)) // str = "Permitir que tus Unidades ataquen al "; str = "Permitir atacar al "; str += nationPtr->nation_name(); #elif(defined(FRENCH)) str = "Autoriser attaque contre le "; str += nationPtr->nation_name(); #elif(defined(GERMAN)) str = "Angriffe auf "; str += nationPtr->nation_name(); str += " erlauben"; #else str = "Allow Your Units to Attack "; str += nationPtr->nation_name(); #endif font_san.field( x1, y+=16, str, x2, "", x3, INFO_REPAINT, "ALLOWATK" ); button_allow_attack[1].create_text( x2+6 , y, x2+50 , y+15, "Yes" ); button_allow_attack[0].create_text( x2+54, y, x2+100, y+15, "No" ); button_allow_attack.paint( viewingNation->get_relation(nationRecno)->should_attack ); //---- if this nation is our ally, display its cash and food ----// if( viewingNation->get_relation(nationRecno)->status == NATION_ALLIANCE ) { #if(defined(SPANISH)) str = "Tesoro del "; str += nationPtr->nation_name(); #elif(defined(FRENCH)) str = "Trésor du "; str += nationPtr->nation_name(); #else // GERMAN and US str = nationPtr->nation_name(); str += " 's Treasure"; #endif font_san.field( x1, y+=16, str, x2, nationPtr->cash, 2, x3, INFO_REPAINT ); #if(defined(SPANISH)) str = "Alimentos del "; str += nationPtr->nation_name(); #elif(defined(FRENCH)) str = "Réserves de nourriture du "; str += nationPtr->nation_name(); #else // GERMAN and US str = nationPtr->nation_name(); str += " 's Food"; #endif font_san.field( x1, y+=16, str, x2, nationPtr->food, 2, x3, INFO_REPAINT ); } } y+=26; //----- display its relation status with other nations -----// if( info.viewing_nation_recno != nationRecno ) { String str; #if(defined(SPANISH)) str = "Estado Diplomático del "; str += nationPtr->nation_name(); str += " con otros Reinos:"; #elif(defined(FRENCH)) str = "Relations diplomatiques de "; str += nationPtr->nation_name(); str += " avec les autres royaumes:"; #else // GERMAN and US str = nationPtr->nation_name(); str += "'s "; str += translate.process( "Diplomatic Status with Other Kingdoms:" ); #endif nationPtr->disp_nation_color(x1, y+1); font_san.put(x1+20, y, str); y+=20; for( int i=1 ; i<=nation_array.size() ; i++ ) { if( nation_array.is_deleted(i) || i == nationRecno || i == info.viewing_nation_recno ) { continue; } nation_array[i]->disp_nation_color(x1, y+1); font_san.put( x1+20, y, nation_array[i]->nation_name() ); font_san.put( x1+240, y, nationPtr->get_relation(i)->status_str() ); if( nationPtr->get_relation(i)->trade_treaty ) { font_san.put( x1+330, y, "Trade Treaty" ); #if(defined(FRENCH)) font_san.put( x1+460, y, m.format((int)nationPtr->total_year_trade(i),2) ); #else // German and US font_san.put( x1+450, y, m.format((int)nationPtr->total_year_trade(i),2) ); #endif } if( config.show_ai_info ) { font_san.put( x1+500, y, nationPtr->get_relation(i)->ai_relation_level ); font_san.put( x1+530, y, (int) nationPtr->get_relation(i)->good_relation_duration_rating ); } y+=16; } } }
//--------- Begin of static function disp_nation_info ---------// // static void disp_nation_info() { vga_util.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_DET_Y2 ); //----------- display info ------------// int nationRecno = info.nation_filter(browse_nation.recno()); Nation* nationPtr = nation_array[nationRecno]; Nation* viewingNation = nation_array[info.viewing_nation_recno]; NationRelation* nationRelation = viewingNation->get_relation(nationRecno); int x1=REPORT_DET_X1+6, x2=REPORT_DET_X1+380, x3=REPORT_DET_X2-10; int y=REPORT_DET_Y1+6; const int lineSpacing = 19; //---- display the nationality of the king ----// if( nationPtr->is_human() ) font_bld.put_field( x1, y, text_reports.str_king_race(nationPtr->race_id), x2, nationPtr->is_human() ? race_res[nationPtr->race_id]->name : monster_res[nationPtr->monster_id()]->name ); y += lineSpacing; //-------- display economic data ----------// String str; if( nationRecno == info.viewing_nation_recno ) { // font_bld.put_field( x1, y, "Your Food", x2, nationPtr->food_str() ); font_bld.put_field( x1, y, text_reports.str_your_food(), x2, nationPtr->food_str() ); str = "$"; str += nationPtr->cash_str(); font_bld.put_field( x1, y+=lineSpacing, text_reports.str_your_treasure(), x2, str ); if( nationPtr->is_monster() ) font_bld.put_field( x1, y+=lineSpacing, text_reports.str_your_live_points(), x2, (int) nationPtr->live_points ); font_bld.field( x1, y+=lineSpacing, text_reports.str_your_peace_time(), x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" ); } else { //str = translate.process("Your Yearly Import from "); //str += nationPtr->nation_name(); // font_bld.field( x1, y , str, x2, (int) viewingNation->get_relation(nationRecno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "IMPORT" ); font_bld.field( x1, y , text_reports.str_enemy_import_from(nationPtr->nation_name()), x2, (int) viewingNation->get_relation(nationRecno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "IMPORT" ); // str = translate.process("Your Yearly Export to "); // str += nationPtr->nation_name(); // font_bld.field( x1, y+=lineSpacing, str, x2, (int) nationPtr->get_relation(info.viewing_nation_recno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "EXPORT" ); font_bld.field( x1, y+=lineSpacing, text_reports.str_enemy_export_to(nationPtr->nation_name()), x2, (int) nationPtr->get_relation(info.viewing_nation_recno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "EXPORT" ); // str = translate.process("Continuous Peace Time of "); // str += nationPtr->nation_name(); // font_bld.field( x1, y+=lineSpacing, str, x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" ); font_bld.field( x1, y+=lineSpacing, text_reports.str_enemy_peace_time(nationPtr->nation_name()), x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" ); //--------- duration of current status ----------// // str = translate.process("Duration of "); // str += translate.process(nationRelation->status_str()); // str += " Status"; // font_bld.field( x1, y+=lineSpacing, str, x2, nationRelation->status_duration_str(), x3, INFO_REPAINT, "STATTIME" ); font_bld.field( x1, y+=lineSpacing, text_reports.str_enemy_status_duration(nationRelation->status_str()), x2, nationRelation->status_duration_str(), x3, INFO_REPAINT, "STATTIME" ); //------- display the allow_attack field --------// // str = "Allow Your Units to Attack "; // str += nationPtr->nation_name(); // font_bld.field( x1, y+=lineSpacing, str, x2, "", x3, INFO_REPAINT, "ALLOWATK" ); font_bld.field( x1, y+=lineSpacing, text_reports.str_enemy_allow_attack(nationPtr->nation_name()), x2, "", x3, INFO_REPAINT, "ALLOWATK" ); // button_allow_attack[0].set_font( &font_bld ); // button_allow_attack[1].set_font( &font_bld ); button_allow_attack[1].create_text( x2+6 , y, x2+50 , y+lineSpacing-1, text_reports.str_no_yes(1)); // "Yes" ); button_allow_attack[0].create_text( x2+54, y, x2+100, y+lineSpacing-1, text_reports.str_no_yes(0)); // "No" ); button_allow_attack.paint( viewingNation->get_relation(nationRecno)->should_attack ); //---- if this nation is our ally, display its cash and food ----// if( viewingNation->get_relation(nationRecno)->status == RELATION_ALLIANCE ) { // str = nationPtr->nation_name(); // str += " 's Treasure"; // font_bld.field( x1, y+=lineSpacing, str, x2, nationPtr->cash, 2, x3, INFO_REPAINT ); font_bld.field( x1, y+=lineSpacing, text_reports.str_ally_cash(nationPtr->nation_name()), x2, nationPtr->cash, 2, x3, INFO_REPAINT ); // str = nationPtr->nation_name(); // str += " 's Food"; // font_bld.field( x1, y+=lineSpacing, str, x2, nationPtr->food, 1, x3, INFO_REPAINT ); font_bld.field( x1, y+=lineSpacing, text_reports.str_ally_food(nationPtr->nation_name()), x2, nationPtr->food, 1, x3, INFO_REPAINT ); } } y+=lineSpacing+10; //----- display its relation status with other nations -----// if( info.viewing_nation_recno != nationRecno ) { // String str; nationPtr->disp_nation_color(x1, y+1); font_bld.put(x1+20, y, text_reports.str_enemy_relation(nationPtr->nation_name())); y+=20; for( int i=1 ; i<=nation_array.size() ; i++ ) { if( nation_array.is_deleted(i) || i == nationRecno || i == info.viewing_nation_recno ) { continue; } nation_array[i]->disp_nation_color(x1, y+1); font_bld.put( x1+20, y, nation_array[i]->nation_name() ); font_bld.put( x1+240, y, nationPtr->get_relation(i)->status_str() ); if( nationPtr->get_relation(i)->trade_treaty ) { int x2 = font_bld.put( x1+330, y, text_talk.str_trade_treaty()); // "Trade Treaty" ); // font_bld.put( x1+450, y, misc.format((int)nationPtr->total_year_trade(i),2) ); font_bld.put( x2+10, y, misc.format((int)nationPtr->total_year_trade(i),2) ); } if( config.show_debug_info ) { font_bld.put( x1+500, y, nationPtr->get_relation(i)->ai_relation_level ); font_bld.put( x1+530, y, (int) nationPtr->get_relation(i)->good_relation_duration_rating ); } y+=16; } } }
//-------- Begin of static function put_nation_rec --------// // static void put_nation_rec(int recNo, int x, int y, int refreshFlag) { int nationRecno = info.nation_filter(recNo); Nation* nationPtr = nation_array[nationRecno]; Nation* viewingNation = nation_array[info.viewing_nation_recno]; NationRelation* nationRelation = viewingNation->get_relation(nationRecno); x+=3; // ###### begin Gilbert 19/10 ######// y+=3; nationPtr->disp_nation_color(x, y+3); // ###### end Gilbert 19/10 ######// font_bld.put( x+20 , y, nationPtr->nation_name(), 0, x+215 ); if( nationPtr->is_human() ) font_bld.put( x+220, y, misc.format((int) nationPtr->reputation) ); //------- display relation parameters --------// if( nationRecno != info.viewing_nation_recno ) { String str; str = nationRelation->status_str(); if( config.show_ai_info ) { if( nationPtr->nation_type == NATION_AI ) { str += " ("; str += nationRelation->ai_relation_level; str += ")"; } } font_bld.put( x+262, y, str, 0, x+350 ); // font_bld.put( x+355, y, nationRelation->should_attack ? "Yes" : "No" ); font_bld.put( x+355, y, text_reports.str_no_yes(nationRelation->should_attack) ); // font_bld.put( x+412, y, nationRelation->trade_treaty ? "Yes" : "No" ); font_bld.put( x+412, y, text_reports.str_no_yes(nationRelation->trade_treaty) ); // ###### begin Gilbert 11/5 ########// // if the player has lost connection, display "disconnect" instead if( remote.is_enable() && nationPtr->is_ai() && nationPtr->player_id != 0 ) { font_red.put( x+465, y, text_reports.str_disconnect() ); //"Disconnect" ); } else { font_bld.put( x+465, y, misc.format( (int) viewingNation->total_year_trade(nationRecno),2) ); } // ###### end Gilbert 11/5 ########// if( config.show_debug_info ) { font_bld.put( x+510, y, misc.format(nationPtr->get_relation(info.viewing_nation_recno)->ai_relation_level) ); font_bld.put( x+180, y, misc.format( (int) nationPtr->get_relation(info.viewing_nation_recno)->good_relation_duration_rating) ); } } }
//------- Begin of function TalkMsg::process_accepted_reply --------// // void TalkMsg::process_accepted_reply() { Nation* toNation = nation_array[to_nation_recno]; Nation* fromNation = nation_array[from_nation_recno]; NationRelation* fromRelation = fromNation->get_relation(to_nation_recno); NationRelation* toRelation = toNation->get_relation(from_nation_recno); int goodRelationDec=0; // whether the message is for requesting help. switch(talk_id) { case TALK_PROPOSE_TRADE_TREATY: toNation->set_trade_treaty(from_nation_recno, 1); break; case TALK_PROPOSE_FRIENDLY_TREATY: toNation->form_friendly_treaty(from_nation_recno); break; case TALK_PROPOSE_ALLIANCE_TREATY: toNation->form_alliance_treaty(from_nation_recno); break; case TALK_END_TRADE_TREATY: toNation->set_trade_treaty(from_nation_recno, 0); //---- set reject date on proposing treaty ----// fromRelation->set_never_accept_until_date(TALK_PROPOSE_TRADE_TREATY, 180); toRelation->set_never_accept_until_date(TALK_PROPOSE_TRADE_TREATY, 180); fromRelation->set_never_accept_until_date(TALK_END_TRADE_TREATY, 180); toRelation->set_never_accept_until_date(TALK_END_TRADE_TREATY, 180); //----- decrease reputation -----// if( toNation->reputation > 0 ) fromNation->change_reputation( -toNation->reputation * 5 / 100 ); break; case TALK_END_FRIENDLY_TREATY: case TALK_END_ALLIANCE_TREATY: fromNation->end_treaty(to_nation_recno, RELATION_NEUTRAL); //---- set reject date on proposing treaty ----// // // If a friendly treaty is rejected, assuming an alliance treaty // is even more impossible. (thus set reject date on both friendly // and alliance treaties.) // // If a alliance treaty is rejected, only set reject date on // alliance treaty, it may still try proposing friendly treaty later. // //---------------------------------------------// fromRelation->set_never_accept_until_date(TALK_PROPOSE_FRIENDLY_TREATY, 300); toRelation->set_never_accept_until_date(TALK_PROPOSE_FRIENDLY_TREATY, 300); fromRelation->set_never_accept_until_date(TALK_PROPOSE_ALLIANCE_TREATY, 300); toRelation->set_never_accept_until_date(TALK_PROPOSE_ALLIANCE_TREATY, 300); break; case TALK_REQUEST_MILITARY_AID: goodRelationDec = 10; break; case TALK_REQUEST_TRADE_EMBARGO: { //--- send an end treaty message to the target kingdom ---// TalkMsg talkMsg; memset(&talkMsg, 0, sizeof(TalkMsg)); talkMsg.to_nation_recno = (char) talk_para1; talkMsg.from_nation_recno = to_nation_recno; talkMsg.talk_id = TALK_END_TRADE_TREATY; talk_res.send_talk_msg( &talkMsg, COMMAND_AUTO ); goodRelationDec = 4; } break; case TALK_REQUEST_CEASE_WAR: unit_array.stop_war_between(to_nation_recno, from_nation_recno); toNation->set_relation_status(from_nation_recno, RELATION_TENSE); fromRelation->set_never_accept_until_date(TALK_DECLARE_WAR, 180); toRelation->set_never_accept_until_date(TALK_DECLARE_WAR, 180); break; case TALK_REQUEST_DECLARE_WAR: if( fromNation->get_relation_status(talk_para1) == RELATION_HOSTILE ) // the requesting nation must be at war with the enemy { //-- if we are currently allied or friendly with the nation, we need to terminate the friendly/alliance treaty first --// TalkMsg talkMsg; if( toNation->get_relation_status(talk_para1) == RELATION_ALLIANCE ) { memset(&talkMsg, 0, sizeof(TalkMsg)); talkMsg.to_nation_recno = (char) talk_para1; talkMsg.from_nation_recno = to_nation_recno; talkMsg.talk_id = TALK_END_ALLIANCE_TREATY; talk_res.send_talk_msg( &talkMsg, COMMAND_AUTO ); } else if( toNation->get_relation_status(talk_para1) == RELATION_FRIENDLY ) { memset(&talkMsg, 0, sizeof(TalkMsg)); talkMsg.to_nation_recno = (char) talk_para1; talkMsg.from_nation_recno = to_nation_recno; talkMsg.talk_id = TALK_END_FRIENDLY_TREATY; talk_res.send_talk_msg( &talkMsg, COMMAND_AUTO ); } //--- send a declare war message to the target kingdom ---// memset(&talkMsg, 0, sizeof(TalkMsg)); talkMsg.to_nation_recno = (char) talk_para1; talkMsg.from_nation_recno = to_nation_recno; talkMsg.talk_id = TALK_DECLARE_WAR; talk_res.send_talk_msg( &talkMsg, COMMAND_AUTO ); //----------------------------------------------------// goodRelationDec = 10; } break; case TALK_REQUEST_BUY_FOOD: { int buyCost = talk_para1 * talk_para2 / 10; fromNation->add_food( (float) talk_para1 ); fromNation->add_expense( EXPENSE_IMPORTS, (float) buyCost, 0 ); toNation->consume_food( (float) talk_para1 ); toNation->add_income( INCOME_EXPORTS, (float) buyCost, 0 ); break; } case TALK_DECLARE_WAR: toRelation->started_war_on_us_count++; // how many times this nation has started a war with us, the more the times the worse this nation is. toNation->set_relation_status(from_nation_recno, RELATION_HOSTILE); fromRelation->set_never_accept_until_date(TALK_REQUEST_CEASE_WAR, 150); toRelation->set_never_accept_until_date(TALK_REQUEST_CEASE_WAR, 150); fromRelation->set_never_accept_until_date(TALK_GIVE_TRIBUTE, 300); toRelation->set_never_accept_until_date(TALK_GIVE_TRIBUTE, 300); //--- decrease reputation of the nation which declares war ---// if( toNation->reputation > 0 ) fromNation->change_reputation( -toNation->reputation * 20 / 100 ); break; case TALK_GIVE_TRIBUTE: case TALK_GIVE_AID: fromNation->give_tribute( to_nation_recno, talk_para1 ); break; case TALK_DEMAND_TRIBUTE: case TALK_DEMAND_AID: toNation->give_tribute( from_nation_recno, talk_para1 ); goodRelationDec = talk_para1/200; break; case TALK_EXCHANGE_TECH: fromNation->give_tech( to_nation_recno, talk_para1, talk_para3 ); // give this tech to the target nation toNation->give_tech( from_nation_recno, talk_para2, talk_para4 ); // receive this tech from the target nation break; case TALK_REQUEST_SURRENDER: { float offeredAmt = (float) talk_para1 * 10; // * 10 is to restore its original value. It has been divided by 10 to cope with the upper limit of <short> toNation->add_income(INCOME_TRIBUTE, offeredAmt); fromNation->add_expense(EXPENSE_TRIBUTE, offeredAmt); toNation->surrender(from_nation_recno); break; } case TALK_SURRENDER: fromNation->surrender(to_nation_recno); break; default: err_here(); } //---- if the nation accepts a message that is requesting help, then decrease its good_relation_duration_rating, so it won't accept so easily next time ---// if( goodRelationDec ) toRelation->good_relation_duration_rating -= (float) goodRelationDec; //-- remove talk messges that are the same but sent from the opposite nation --// TalkMsg talkMsg; talkMsg.from_nation_recno = to_nation_recno; talkMsg.to_nation_recno = from_nation_recno; talkMsg.talk_id = talk_id; int loopCount=0; while(1) { err_when( loopCount++ > 100 ); int talkMsgRecno = talk_res.is_talk_msg_exist(&talkMsg, 0); // don't check talk_para1 & talk_para2 if( talkMsgRecno && talkMsg.talk_id != TALK_DECLARE_WAR ) // Exception handling - Declare War as both nations can send one when a spy creates an incident talk_res.del_talk_msg(talkMsgRecno); else break; } }
//----- Begin of function Nation::notify_talk_msg -----// // // Notify the AI for a notification only message (reply not needed.) // // This function is called directly from TalkRes::send_talk_msg_now() // when the message is sent. // void Nation::notify_talk_msg(TalkMsg* talkMsg) { int relationChange=0; NationRelation* nationRelation = get_relation(talkMsg->from_nation_recno); switch( talkMsg->talk_id ) { case TALK_END_TRADE_TREATY: // it's a notification message only, no accept or reject relationChange = -5; nationRelation->set_never_accept_until_date(TALK_PROPOSE_TRADE_TREATY, 180); break; case TALK_END_FRIENDLY_TREATY: // it's a notification message only, no accept or reject case TALK_END_ALLIANCE_TREATY: relationChange = -5; nationRelation->set_never_accept_until_date(TALK_PROPOSE_FRIENDLY_TREATY, 180); nationRelation->set_never_accept_until_date(TALK_PROPOSE_ALLIANCE_TREATY, 180); break; case TALK_DECLARE_WAR: // it already drops to zero when the status is set to hostile break; case TALK_GIVE_TRIBUTE: case TALK_GIVE_AID: //--------------------------------------------------------------// // The less cash the nation, the more it will appreciate the // tribute. // // $1000 for 100 ai relation increase if the nation's cash is 1000. //--------------------------------------------------------------// relationChange = 100 * talkMsg->talk_para1 / max(1000, (int) cash); break; case TALK_EXCHANGE_TECH: //--------------------------------------------------------------// // The lower tech the nation has, the more it will appreciate the // tech giveaway. // // Giving a level 2 weapon which the nation is unknown of // increase the ai relation by 60 if its pref_use_weapon is 100. // (by 30 if its pref_use_weapon is 0). //--------------------------------------------------------------// { relationChange += 5; break; } case TALK_SURRENDER: break; default: err_here(); } //------- chance relationship now -------// if( relationChange < 0 ) relationChange -= relationChange * pref_forgiveness / 100; if( relationChange != 0 ) change_ai_relation_level( talkMsg->from_nation_recno, relationChange ); }