From 3b628005c6fe96b1c87faff86e15634a95e7b6a6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 11 Feb 2023 02:44:42 +0200 Subject: [PATCH 9/9] sdl/2: Make Alliance clause available in diplomacy dialog See osdn #46604 Signed-off-by: Marko Lindqvist --- client/gui-sdl/diplodlg.c | 14 ++++++------- client/gui-sdl2/diplodlg.c | 4 ++-- common/player.c | 43 ++++++++++++++++++++------------------ common/player.h | 2 +- server/sanitycheck.c | 1 + server/savegame2.c | 3 ++- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/client/gui-sdl/diplodlg.c b/client/gui-sdl/diplodlg.c index 86e8e32855..7798bf6dad 100644 --- a/client/gui-sdl/diplodlg.c +++ b/client/gui-sdl/diplodlg.c @@ -529,9 +529,9 @@ static struct ADVANCED_DLG * popup_diplomatic_objects(struct player *pPlayer0, count++; } - if (pplayer_can_make_treaty(pPlayer0, pPlayer1, DS_ALLIANCE)) { + if (pplayer_can_make_treaty(pPlayer0, pPlayer1, DS_ALLIANCE) == DIPL_OK) { fc_snprintf(cBuf, sizeof(cBuf), " %s", Q_("?diplomatic_state:Alliance")); - + pBuf = create_iconlabel_from_chars(NULL, pWindow->dst, cBuf, adj_font(12), (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE)); pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_DIPLODLG_MEETING_TEXT); @@ -543,12 +543,12 @@ static struct ADVANCED_DLG * popup_diplomatic_objects(struct player *pPlayer0, add_to_gui_list(MAX_ID, pBuf); count++; } - + } - + /* ---------------------------- */ if (!gives_shared_vision(pPlayer0, pPlayer1)) { - + pBuf = create_iconlabel_from_chars(NULL, pWindow->dst, _("Give shared vision"), adj_font(12), (WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE)); @@ -560,7 +560,7 @@ static struct ADVANCED_DLG * popup_diplomatic_objects(struct player *pPlayer0, set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(ID_LABEL, pBuf); count++; - + /* ---------------------------- */ /* you can't give maps if you give shared vision */ pBuf = create_iconlabel_from_chars(NULL, pWindow->dst, @@ -1548,7 +1548,7 @@ void popup_diplomacy_dialog(struct player *pPlayer) fc_snprintf(cBuf, sizeof(cBuf), _("Cancel Treaty")); } - /* cancel treaty */ + /* Cancel treaty */ pBuf = create_themeicon_button_from_chars(current_theme->UNITS2_Icon, pWindow->dst, cBuf, adj_font(12), 0); diff --git a/client/gui-sdl2/diplodlg.c b/client/gui-sdl2/diplodlg.c index 33af18cebd..f1bb704c2c 100644 --- a/client/gui-sdl2/diplodlg.c +++ b/client/gui-sdl2/diplodlg.c @@ -536,7 +536,7 @@ static struct ADVANCED_DLG *popup_diplomatic_objects(struct player *pPlayer0, count++; } - if (pplayer_can_make_treaty(pPlayer0, pPlayer1, DS_ALLIANCE)) { + if (pplayer_can_make_treaty(pPlayer0, pPlayer1, DS_ALLIANCE) == DIPL_OK) { fc_snprintf(cBuf, sizeof(cBuf), " %s", Q_("?diplomatic_state:Alliance")); pBuf = create_iconlabel_from_chars(NULL, pWindow->dst, @@ -1555,7 +1555,7 @@ void popup_diplomacy_dialog(struct player *pPlayer) fc_snprintf(cBuf, sizeof(cBuf), _("Cancel Treaty")); } - /* cancel treaty */ + /* Cancel treaty */ pBuf = create_themeicon_button_from_chars(current_theme->UNITS2_Icon, pWindow->dst, cBuf, adj_font(12), 0); diff --git a/common/player.c b/common/player.c index 09683223d5..87ea3c3626 100644 --- a/common/player.c +++ b/common/player.c @@ -85,10 +85,10 @@ enum diplstate_type cancel_pact_result(enum diplstate_type oldstate) } /*************************************************************** - The senate may not allow you to break the treaty. In this - case you must first dissolve the senate then you can break - it. This is waived if you have statue of liberty since you - could easily just dissolve and then recreate it. + The senate may not allow you to break the treaty. In this + case you must first dissolve the senate then you can break + it. This is waived if you have statue of liberty since you + could easily just dissolve and then recreate it. ***************************************************************/ enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2) @@ -109,21 +109,22 @@ enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, && get_player_bonus(p1, EFT_NO_ANARCHY) <= 0) { return DIPL_SENATE_BLOCKING; } + return DIPL_OK; } /*************************************************************** - Returns true iff p1 can be in alliance with p2. + Returns TRUE iff p1 can be in alliance with p2. - Check that we are not at war with any of p2's allies. Note - that for an alliance to be made, we need to check this both + Check that we are not at war with any of p2's allies. Note + that for an alliance to be made, we need to check this both ways. - The reason for this is to avoid the dread 'love-love-hate' + The reason for this is to avoid the dread 'love-love-hate' triad, in which p1 is allied to p2 is allied to p3 is at war with p1. These lead to strange situations. ***************************************************************/ -static bool is_valid_alliance(const struct player *p1, +static bool is_valid_alliance(const struct player *p1, const struct player *p2) { players_iterate_alive(pplayer) { @@ -131,7 +132,7 @@ static bool is_valid_alliance(const struct player *p1, if (pplayer != p1 && pplayer != p2 - && ds == DS_WAR /* do not count 'never met' as war here */ + && ds == DS_WAR /* Do not count 'never met' as war here */ && pplayers_allied(p2, pplayer)) { return FALSE; } @@ -141,12 +142,13 @@ static bool is_valid_alliance(const struct player *p1, } /*************************************************************** - Returns true iff p1 can make given treaty with p2. + Returns the reason p1 can't make given treaty with p2, + or DIPL_OK if they can. We cannot regress in a treaty chain. So we cannot suggest 'Peace' if we are in 'Alliance'. Then you have to cancel. - For alliance there is only one condition: We are not at war + For alliance there is only one condition: We are not at war with any of p2's allies. ***************************************************************/ enum dipl_reason pplayer_can_make_treaty(const struct player *p1, @@ -163,17 +165,17 @@ enum dipl_reason pplayer_can_make_treaty(const struct player *p1, || get_player_bonus(p2, EFT_NO_DIPLOMACY) > 0) { return DIPL_ERROR; } - if (treaty == DS_WAR - || treaty == DS_NO_CONTACT - || treaty == DS_ARMISTICE + if (treaty == DS_WAR + || treaty == DS_NO_CONTACT + || treaty == DS_ARMISTICE || treaty == DS_TEAM || treaty == DS_LAST) { - return DIPL_ERROR; /* these are not negotiable treaties */ + return DIPL_ERROR; /* These are not negotiable treaties */ } if (treaty == DS_CEASEFIRE && existing != DS_WAR) { - return DIPL_ERROR; /* only available from war */ + return DIPL_ERROR; /* Only available from war */ } - if (treaty == DS_PEACE + if (treaty == DS_PEACE && (existing != DS_WAR && existing != DS_CEASEFIRE)) { return DIPL_ERROR; } @@ -186,15 +188,16 @@ enum dipl_reason pplayer_can_make_treaty(const struct player *p1, return DIPL_ALLIANCE_PROBLEM_THEM; } } - /* this check must be last: */ + /* This check must be last: */ if (treaty == existing) { return DIPL_ERROR; } + return DIPL_OK; } /*************************************************************** - Check if pplayer has an embassy with pplayer2. We always have + Check if pplayer has an embassy with pplayer2. We always have an embassy with ourselves. ***************************************************************/ bool player_has_embassy(const struct player *pplayer, diff --git a/common/player.h b/common/player.h index 1b2aa0657d..79b5b20b2d 100644 --- a/common/player.h +++ b/common/player.h @@ -185,7 +185,7 @@ enum dipl_reason { DIPL_ALLIANCE_PROBLEM_US, DIPL_ALLIANCE_PROBLEM_THEM }; -/* the following are for "pacts" */ +/* The following are for "pacts" */ struct player_diplstate { enum diplstate_type type; /* this player's disposition towards other */ enum diplstate_type max_state; /* maximum treaty level ever had */ diff --git a/server/sanitycheck.c b/server/sanitycheck.c index 43737b8faf..da4b03aa69 100644 --- a/server/sanitycheck.c +++ b/server/sanitycheck.c @@ -524,6 +524,7 @@ static void check_players(const char *file, const char *function, int line) && pplayers_allied(pplayer, pplayer2)) { enum dipl_reason allied_players_can_be_allied = pplayer_can_make_treaty(pplayer, pplayer2, DS_ALLIANCE); + SANITY_CHECK(allied_players_can_be_allied != DIPL_ALLIANCE_PROBLEM_US); SANITY_CHECK(allied_players_can_be_allied diff --git a/server/savegame2.c b/server/savegame2.c index 50d1428060..5214e322d0 100644 --- a/server/savegame2.c +++ b/server/savegame2.c @@ -3982,6 +3982,7 @@ static void sg_load_players(struct loaddata *loading) if (pplayers_allied(plr, aplayer)) { enum dipl_reason can_ally = pplayer_can_make_treaty(plr, aplayer, DS_ALLIANCE); + if (can_ally == DIPL_ALLIANCE_PROBLEM_US || can_ally == DIPL_ALLIANCE_PROBLEM_THEM) { log_sg("Illegal alliance structure detected: " @@ -4005,7 +4006,7 @@ static void sg_load_players(struct loaddata *loading) } cities_iterate_end; } - /* Update all city information. This must come after all cities are + /* Update all city information. This must come after all cities are * loaded (in player_load) but before player (dumb) cities are loaded * in player_load_vision(). */ players_iterate(plr) { -- 2.39.1