Author: sveinung Date: Wed Nov 11 03:15:17 2015 New Revision: 30537 URL: http://svn.gna.org/viewcvs/freeciv?rev=30537&view=rev Log: Fix asymmetric turns_left when auto canceling
an alliance to two players because their cease fire expired to war. Reported by Marko Lindqvist <cazfi> See bug #24033 Modified: branches/S2_5/common/player.c branches/S2_5/common/player.h branches/S2_5/server/srv_main.c Modified: branches/S2_5/common/player.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/player.c?rev=30537&r1=30536&r2=30537&view=diff ============================================================================== --- branches/S2_5/common/player.c (original) +++ branches/S2_5/common/player.c Wed Nov 11 03:15:17 2015 @@ -294,6 +294,7 @@ diplstate->turns_left = 0; diplstate->has_reason_to_cancel = 0; diplstate->contact_turns_left = 0; + diplstate->auto_cancel_turn = -1; } Modified: branches/S2_5/common/player.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/player.h?rev=30537&r1=30536&r2=30537&view=diff ============================================================================== --- branches/S2_5/common/player.h (original) +++ branches/S2_5/common/player.h Wed Nov 11 03:15:17 2015 @@ -166,6 +166,8 @@ int turns_left; /* until pact (e.g., cease-fire) ends */ int has_reason_to_cancel; /* 0: no, 1: this turn, 2: this or next turn */ int contact_turns_left; /* until contact ends */ + + int auto_cancel_turn; /* used to avoid asymmetric turns_left */ }; /*************************************************************************** Modified: branches/S2_5/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/srv_main.c?rev=30537&r1=30536&r2=30537&view=diff ============================================================================== --- branches/S2_5/server/srv_main.c (original) +++ branches/S2_5/server/srv_main.c Wed Nov 11 03:15:17 2015 @@ -705,7 +705,10 @@ state->has_reason_to_cancel = MAX(state->has_reason_to_cancel - 1, 0); state->contact_turns_left = MAX(state->contact_turns_left - 1, 0); - if (state->type == DS_ARMISTICE) { + if (state->type == DS_ARMISTICE + /* Don't count down if auto canceled this turn. Auto canceling + * happens in this loop. */ + && state->auto_cancel_turn != game.info.turn) { state->turns_left--; if (state->turns_left <= 0) { state->type = DS_PEACE; @@ -755,16 +758,41 @@ if (plr3 != plr1 && plr3 != plr2 && pplayers_allied(plr3, plr1) && pplayers_allied(plr3, plr2)) { + struct player_diplstate *to1 + = player_diplstate_get(plr3, plr1); + struct player_diplstate *from1 + = player_diplstate_get(plr1, plr3); + struct player_diplstate *to2 + = player_diplstate_get(plr3, plr2); + struct player_diplstate *from2 + = player_diplstate_get(plr2, plr3); + notify_player(plr3, NULL, E_TREATY_BROKEN, ftc_server, _("The cease-fire between %s and %s has run out. " "They are at war. You cancel your alliance " "with both."), player_name(plr1), player_name(plr2)); - player_diplstate_get(plr3, plr1)->has_reason_to_cancel = TRUE; - player_diplstate_get(plr3, plr2)->has_reason_to_cancel = TRUE; + + /* Cancel the alliance. */ + to1->has_reason_to_cancel = TRUE; + to2->has_reason_to_cancel = TRUE; handle_diplomacy_cancel_pact(plr3, player_number(plr1), CLAUSE_ALLIANCE); handle_diplomacy_cancel_pact(plr3, player_number(plr2), CLAUSE_ALLIANCE); + + /* Avoid asymmetric turns_left for the armistice. */ + to1->auto_cancel_turn = game.info.turn; + from1->auto_cancel_turn = game.info.turn; + + to2->auto_cancel_turn = game.info.turn; + from2->auto_cancel_turn = game.info.turn; + + /* Count down for this turn. */ + to1->turns_left--; + from1->turns_left--; + + to2->turns_left--; + from2->turns_left--; } } players_iterate_alive_end; break; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits