Author: cazfi Date: Sat Jan 23 08:12:21 2016 New Revision: 31543 URL: http://svn.gna.org/viewcvs/freeciv?rev=31543&view=rev Log: AI does not even try to propose treaties to players who can't accept due to restricted diplomacy.
See patch #6825 Modified: branches/S2_5/ai/default/advdiplomacy.c Modified: branches/S2_5/ai/default/advdiplomacy.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/ai/default/advdiplomacy.c?rev=31543&r1=31542&r2=31543&view=diff ============================================================================== --- branches/S2_5/ai/default/advdiplomacy.c (original) +++ branches/S2_5/ai/default/advdiplomacy.c Sat Jan 23 08:12:21 2016 @@ -1597,175 +1597,178 @@ /*** Try to make peace with everyone we love ***/ players_iterate_alive(aplayer) { - enum diplstate_type ds = player_diplstate_get(pplayer, aplayer)->type; - struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer); - struct Clause clause; - - /* Meaningless values, but rather not have them unset. */ - clause.from = pplayer; - clause.value = 0; - - /* Remove shared vision if we are not allied or it is no longer safe. */ - if (gives_shared_vision(pplayer, aplayer)) { - if (!pplayers_allied(pplayer, aplayer)) { - remove_shared_vision(pplayer, aplayer); - } else if (!shared_vision_is_safe(pplayer, aplayer)) { - notify(aplayer, _("*%s (AI)* Sorry, sharing vision with you " + if (get_player_bonus(aplayer, EFT_NO_DIPLOMACY) <= 0 + && diplomacy_possible(pplayer, aplayer)) { + enum diplstate_type ds = player_diplstate_get(pplayer, aplayer)->type; + struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer); + struct Clause clause; + + /* Meaningless values, but rather not have them unset. */ + clause.from = pplayer; + clause.value = 0; + + /* Remove shared vision if we are not allied or it is no longer safe. */ + if (gives_shared_vision(pplayer, aplayer)) { + if (!pplayers_allied(pplayer, aplayer)) { + remove_shared_vision(pplayer, aplayer); + } else if (!shared_vision_is_safe(pplayer, aplayer)) { + notify(aplayer, _("*%s (AI)* Sorry, sharing vision with you " "is no longer safe."), - player_name(pplayer)); - remove_shared_vision(pplayer, aplayer); - } - } - - /* No peace to enemies of our allies... or pointless peace. */ - if (is_barbarian(aplayer) - || aplayer == pplayer - || aplayer == target /* no mercy */ - || adip->countdown >= 0 - || !could_meet_with_player(pplayer, aplayer)) { - continue; - } - - /* Spam control */ - adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0); - adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0); - adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0); - adip->warned_about_space = MAX(adip->warned_about_space - 1, 0); - adip->spam = MAX(adip->spam - 1, 0); - if (adip->spam > 0) { - /* Don't spam */ - continue; - } - - /* Canvass support from existing friends for our war, and try to - * make friends with enemies. Then we wait some turns until next time - * we spam them with our gibbering chatter. */ - if (!aplayer->ai_controlled) { - if (!pplayers_allied(pplayer, aplayer)) { - adip->spam = fc_rand(4) + 3; /* Bugger allies often. */ - } else { - adip->spam = fc_rand(8) + 6; /* Others are less important. */ - } - } - - switch (ds) { - case DS_TEAM: - dai_share(pplayer, aplayer); - break; - case DS_ALLIANCE: - /* See if our allies are diligently declaring war on our enemies... */ - if (adip->at_war_with_ally) { + player_name(pplayer)); + remove_shared_vision(pplayer, aplayer); + } + } + + /* No peace to enemies of our allies... or pointless peace. */ + if (is_barbarian(aplayer) + || aplayer == pplayer + || aplayer == target /* no mercy */ + || adip->countdown >= 0 + || !could_meet_with_player(pplayer, aplayer)) { + continue; + } + + /* Spam control */ + adip->asked_about_peace = MAX(adip->asked_about_peace - 1, 0); + adip->asked_about_alliance = MAX(adip->asked_about_alliance - 1, 0); + adip->asked_about_ceasefire = MAX(adip->asked_about_ceasefire - 1, 0); + adip->warned_about_space = MAX(adip->warned_about_space - 1, 0); + adip->spam = MAX(adip->spam - 1, 0); + if (adip->spam > 0) { + /* Don't spam */ + continue; + } + + /* Canvass support from existing friends for our war, and try to + * make friends with enemies. Then we wait some turns until next time + * we spam them with our gibbering chatter. */ + if (!aplayer->ai_controlled) { + if (!pplayers_allied(pplayer, aplayer)) { + adip->spam = fc_rand(4) + 3; /* Bugger allies often. */ + } else { + adip->spam = fc_rand(8) + 6; /* Others are less important. */ + } + } + + switch (ds) { + case DS_TEAM: + dai_share(pplayer, aplayer); break; - } - target = NULL; - players_iterate(eplayer) { - if (WAR(pplayer, eplayer) - && !pplayers_at_war(aplayer, eplayer)) { - target = eplayer; + case DS_ALLIANCE: + /* See if our allies are diligently declaring war on our enemies... */ + if (adip->at_war_with_ally) { break; } - } players_iterate_end; - - if ((players_on_same_team(pplayer, aplayer) - || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) { - /* Share techs only with team mates and allies we really like. */ - dai_share(pplayer, aplayer); - } - if (!target || !target->is_alive) { - adip->ally_patience = 0; - break; /* No need to nag our ally */ - } - - if (adip->ally_patience == 0) { - notify(aplayer, _("*%s (AI)* Greetings our most trustworthy " - "ally. We call upon you to destroy our enemy, %s."), - player_name(pplayer), - player_name(target)); - adip->ally_patience--; - } else if (adip->ally_patience == -1) { - if (fc_rand(5) == 1) { - notify(aplayer, _("*%s (AI)* Greetings ally, I see you have not yet " - "made war with our enemy, %s. Why do I need to remind " - "you of your promises?"), + target = NULL; + players_iterate(eplayer) { + if (WAR(pplayer, eplayer) + && !pplayers_at_war(aplayer, eplayer)) { + target = eplayer; + break; + } + } players_iterate_end; + + if ((players_on_same_team(pplayer, aplayer) + || pplayer->ai_common.love[player_index(aplayer)] > MAX_AI_LOVE / 2)) { + /* Share techs only with team mates and allies we really like. */ + dai_share(pplayer, aplayer); + } + if (!target || !target->is_alive) { + adip->ally_patience = 0; + break; /* No need to nag our ally */ + } + + if (adip->ally_patience == 0) { + notify(aplayer, _("*%s (AI)* Greetings our most trustworthy " + "ally. We call upon you to destroy our enemy, %s."), player_name(pplayer), player_name(target)); adip->ally_patience--; + } else if (adip->ally_patience == -1) { + if (fc_rand(5) == 1) { + notify(aplayer, _("*%s (AI)* Greetings ally, I see you have not yet " + "made war with our enemy, %s. Why do I need to remind " + "you of your promises?"), + player_name(pplayer), + player_name(target)); + adip->ally_patience--; + } + } else { + if (fc_rand(5) == 1) { + notify(aplayer, _("*%s (AI)* Dishonored one, we made a pact of " + "alliance, and yet you remain at peace with our mortal " + "enemy, %s! This is unacceptable; our alliance is no " + "more!"), + player_name(pplayer), + player_name(target)); + DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "breaking useless alliance"); + /* to peace */ + handle_diplomacy_cancel_pact(pplayer, player_number(aplayer), + CLAUSE_ALLIANCE); + pplayer->ai_common.love[player_index(aplayer)] = + MIN(pplayer->ai_common.love[player_index(aplayer)], 0); + if (gives_shared_vision(pplayer, aplayer)) { + remove_shared_vision(pplayer, aplayer); + } + fc_assert(!gives_shared_vision(pplayer, aplayer)); + } } - } else { - if (fc_rand(5) == 1) { - notify(aplayer, _("*%s (AI)* Dishonored one, we made a pact of " - "alliance, and yet you remain at peace with our mortal " - "enemy, %s! This is unacceptable; our alliance is no " - "more!"), - player_name(pplayer), - player_name(target)); - DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "breaking useless alliance"); - /* to peace */ - handle_diplomacy_cancel_pact(pplayer, player_number(aplayer), - CLAUSE_ALLIANCE); - pplayer->ai_common.love[player_index(aplayer)] = - MIN(pplayer->ai_common.love[player_index(aplayer)], 0); - if (gives_shared_vision(pplayer, aplayer)) { - remove_shared_vision(pplayer, aplayer); - } - fc_assert(!gives_shared_vision(pplayer, aplayer)); + break; + + case DS_PEACE: + clause.type = CLAUSE_ALLIANCE; + if (adip->at_war_with_ally + || (!aplayer->ai_controlled && adip->asked_about_alliance > 0) + || dai_goldequiv_clause(ait, pplayer, aplayer, &clause, + FALSE, DS_ALLIANCE) < 0) { + break; } - } - break; - - case DS_PEACE: - clause.type = CLAUSE_ALLIANCE; - if (adip->at_war_with_ally - || (!aplayer->ai_controlled && adip->asked_about_alliance > 0) - || dai_goldequiv_clause(ait, pplayer, aplayer, &clause, - FALSE, DS_ALLIANCE) < 0) { + clear_old_treaty(pplayer, aplayer); + dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_ALLIANCE, FALSE, 0); + adip->asked_about_alliance = !aplayer->ai_controlled ? 13 : 0; + notify(aplayer, _("*%s (AI)* Greetings friend, may we suggest " + "making a common cause and join in an alliance?"), + player_name(pplayer)); break; - } - clear_old_treaty(pplayer, aplayer); - dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_ALLIANCE, FALSE, 0); - adip->asked_about_alliance = !aplayer->ai_controlled ? 13 : 0; - notify(aplayer, _("*%s (AI)* Greetings friend, may we suggest " - "making a common cause and join in an alliance?"), - player_name(pplayer)); - break; - - case DS_CEASEFIRE: - clause.type = CLAUSE_PEACE; - if (adip->at_war_with_ally - || (!aplayer->ai_controlled && adip->asked_about_peace > 0) - || dai_goldequiv_clause(ait, pplayer, aplayer, &clause, - FALSE, DS_PEACE) < 0) { + + case DS_CEASEFIRE: + clause.type = CLAUSE_PEACE; + if (adip->at_war_with_ally + || (!aplayer->ai_controlled && adip->asked_about_peace > 0) + || dai_goldequiv_clause(ait, pplayer, aplayer, &clause, + FALSE, DS_PEACE) < 0) { + break; + } + clear_old_treaty(pplayer, aplayer); + dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_PEACE, FALSE, 0); + adip->asked_about_peace = !aplayer->ai_controlled ? 12 : 0; + notify(aplayer, _("*%s (AI)* Greetings neighbor, may we suggest " + "more peaceful relations?"), + player_name(pplayer)); break; - } - clear_old_treaty(pplayer, aplayer); - dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_PEACE, FALSE, 0); - adip->asked_about_peace = !aplayer->ai_controlled ? 12 : 0; - notify(aplayer, _("*%s (AI)* Greetings neighbor, may we suggest " - "more peaceful relations?"), - player_name(pplayer)); - break; - - case DS_NO_CONTACT: /* but we do have embassy! weird. */ - case DS_WAR: - clause.type = CLAUSE_CEASEFIRE; - if ((!aplayer->ai_controlled && adip->asked_about_ceasefire > 0) - || dai_goldequiv_clause(ait, pplayer, aplayer, &clause, - FALSE, DS_CEASEFIRE) < 0) { - break; /* Fight until the end! */ - } - clear_old_treaty(pplayer, aplayer); - dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_CEASEFIRE, FALSE, 0); - adip->asked_about_ceasefire = !aplayer->ai_controlled ? 9 : 0; - notify(aplayer, _("*%s (AI)* We grow weary of this constant " - "bloodshed. May we suggest a cessation of hostilities?"), - player_name(pplayer)); - break; - - case DS_ARMISTICE: - break; - default: - fc_assert_msg(FALSE, "Unknown pact type %d.", ds); - break; + + case DS_NO_CONTACT: /* but we do have embassy! weird. */ + case DS_WAR: + clause.type = CLAUSE_CEASEFIRE; + if ((!aplayer->ai_controlled && adip->asked_about_ceasefire > 0) + || dai_goldequiv_clause(ait, pplayer, aplayer, &clause, + FALSE, DS_CEASEFIRE) < 0) { + break; /* Fight until the end! */ + } + clear_old_treaty(pplayer, aplayer); + dai_diplomacy_suggest(pplayer, aplayer, CLAUSE_CEASEFIRE, FALSE, 0); + adip->asked_about_ceasefire = !aplayer->ai_controlled ? 9 : 0; + notify(aplayer, _("*%s (AI)* We grow weary of this constant " + "bloodshed. May we suggest a cessation of hostilities?"), + player_name(pplayer)); + break; + + case DS_ARMISTICE: + break; + default: + fc_assert_msg(FALSE, "Unknown pact type %d.", ds); + break; + } } } players_iterate_alive_end; } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits