From c731787267bc3704284b8b7f3413ced5e35fd404 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 22 Jun 2023 17:52:50 +0300 Subject: [PATCH 14/14] AI: Stop cancelling shared vision to team members There are other side effects on the fixed checks of team and/or alliance. - AI no longer tries to declare war on a team member. While it couldn't do that before, it suffered some side-effects of preparing to war. See osdn #48152 Signed-off-by: Marko Lindqvist --- ai/default/daidiplomacy.c | 79 +++++++++++++++++++++------------------ server/maphand.c | 6 ++- server/savegame2.c | 23 ++++++++++++ 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/ai/default/daidiplomacy.c b/ai/default/daidiplomacy.c index 2c0645e13d..2143c0cc50 100644 --- a/ai/default/daidiplomacy.c +++ b/ai/default/daidiplomacy.c @@ -1570,6 +1570,7 @@ void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer) || pplayers_at_war(pplayer, aplayer)) { continue; } + /* A spaceship victory is always one single player's or team's victory */ if (aplayer->spaceship.state == SSHIP_LAUNCHED && adv->dipl.spacerace_leader == aplayer @@ -1579,15 +1580,15 @@ void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer) "yourself alone betrays your true intentions, and I " "will have no more of our alliance!"), player_name(pplayer)); - handle_diplomacy_cancel_pact(pplayer, player_number(aplayer), - CLAUSE_ALLIANCE); + handle_diplomacy_cancel_pact(pplayer, player_number(aplayer), + CLAUSE_ALLIANCE); if (gives_shared_vision(pplayer, aplayer)) { remove_shared_vision(pplayer, aplayer); } /* Never forgive this */ pplayer->ai_common.love[player_index(aplayer)] = -MAX_AI_LOVE; } else if (ship->state == SSHIP_STARTED - && adip->warned_about_space == 0) { + && adip->warned_about_space == 0) { pplayer->ai_common.love[player_index(aplayer)] -= MAX_AI_LOVE / 10; adip->warned_about_space = 10 + fc_rand(6); dai_diplo_notify(aplayer, @@ -1677,22 +1678,24 @@ void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer) /*** Actually declare war (when we have moved units into position) ***/ players_iterate(aplayer) { - struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer); + if (!players_on_same_team(pplayer, aplayer)) { + struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, aplayer); - if (!aplayer->is_alive) { - adip->countdown = -1; - continue; - } - if (adip->countdown > 0) { - adip->countdown--; - } else if (adip->countdown == 0) { - if (!WAR(pplayer, aplayer)) { - DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!"); - dai_go_to_war(ait, pplayer, aplayer, adip->war_reason); + if (!aplayer->is_alive) { + adip->countdown = -1; + continue; + } + if (adip->countdown > 0) { + adip->countdown--; + } else if (adip->countdown == 0) { + if (!WAR(pplayer, aplayer)) { + DIPLO_LOG(ait, LOG_DIPL2, pplayer, aplayer, "Declaring war!"); + dai_go_to_war(ait, pplayer, aplayer, adip->war_reason); + } + } else if (adip->countdown < -1) { + /* Negative countdown less than -1 is war stubbornness */ + adip->countdown++; } - } else if (adip->countdown < -1) { - /* negative countdown less than -1 is war stubbornness */ - adip->countdown++; } } players_iterate_end; @@ -1713,7 +1716,8 @@ void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer) if (gives_shared_vision(pplayer, aplayer)) { if (!pplayers_allied(pplayer, aplayer)) { remove_shared_vision(pplayer, aplayer); - } else if (!shared_vision_is_safe(pplayer, aplayer)) { + } else if (!players_on_same_team(pplayer, aplayer) + && !shared_vision_is_safe(pplayer, aplayer)) { dai_diplo_notify(aplayer, _("*%s (AI)* Sorry, sharing vision with you " "is no longer safe."), @@ -1801,26 +1805,27 @@ void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer) player_name(target)); adip->ally_patience--; } - } else { - if (fc_rand(5) == 1) { - dai_diplo_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 + && !players_on_same_team(pplayer, aplayer)) { + dai_diplo_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; diff --git a/server/maphand.c b/server/maphand.c index 269a5904a1..d56f6c56a3 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -1538,7 +1538,11 @@ static void create_vision_dependencies(void) void give_shared_vision(struct player *pfrom, struct player *pto) { bv_player save_vision[player_slot_count()]; - if (pfrom == pto) return; + + if (pfrom == pto) { + return; + } + if (gives_shared_vision(pfrom, pto)) { log_error("Trying to give shared vision from %s to %s, " "but that vision is already given!", diff --git a/server/savegame2.c b/server/savegame2.c index 3ffa33c5ff..d160a4c564 100644 --- a/server/savegame2.c +++ b/server/savegame2.c @@ -2654,6 +2654,7 @@ static void sg_load_players(struct loaddata *loading) return; } + /* Set up shared vision... */ players_iterate(pplayer) { sg_load_player_main(loading, pplayer); sg_load_player_cities(loading, pplayer); @@ -2756,11 +2757,13 @@ static void sg_load_players(struct loaddata *loading) BV_CLR_ALL(pplayer->server.really_gives_vision); } players_iterate_end; + /* Set up shared vision... */ players_iterate(pplayer) { int plr1 = player_index(pplayer); players_iterate(pplayer2) { int plr2 = player_index(pplayer2); + if (secfile_lookup_bool_default(loading->file, FALSE, "player%d.diplstate%d.gives_shared_vision", plr1, plr2)) { give_shared_vision(pplayer, pplayer2); @@ -2768,6 +2771,26 @@ static void sg_load_players(struct loaddata *loading) } players_iterate_end; } players_iterate_end; + /* ...and check it */ + players_iterate(pplayer1) { + players_iterate(pplayer2) { + if (players_on_same_team(pplayer1, pplayer2)) { + if (!really_gives_vision(pplayer1, pplayer2)) { + sg_regr(3000900, + _("%s did not give shared vision to team member %s."), + player_name(pplayer1), player_name(pplayer2)); + give_shared_vision(pplayer1, pplayer2); + } + if (!really_gives_vision(pplayer2, pplayer1)) { + sg_regr(3000900, + _("%s did not give shared vision to team member %s."), + player_name(pplayer2), player_name(pplayer1)); + give_shared_vision(pplayer2, pplayer1); + } + } + } players_iterate_end; + } players_iterate_end; + initialize_globals(); unit_ordering_apply(); -- 2.39.2