From 1d83fc15f26411cbc03b2fb5ce92102300d000d9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 26 Aug 2022 17:36:01 +0300 Subject: [PATCH 24/24] Qt: Correct spy_steal behavior when the target city has gone Correct spy_steal_shared() behavior when the unit's target city doesn't exist any more for some reason. See osdn #45411 Signed-off-by: Marko Lindqvist --- client/gui-qt/dialogs.cpp | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/client/gui-qt/dialogs.cpp b/client/gui-qt/dialogs.cpp index b0a5cbf3fb..d572304da6 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -1489,7 +1489,7 @@ void choice_dialog::next_unit() break; } if (ptgt == targeted_unit) { - break_next = true; + break_next = true; } } unit_list_iterate_end; targeted_unit = new_target; @@ -1562,7 +1562,6 @@ void choice_dialog::switch_target() layout->addLayout(unit_skip); } - /*************************************************************************** Run chosen action and close dialog ***************************************************************************/ @@ -2382,57 +2381,60 @@ static void spy_steal_shared(QVariant data1, QVariant data2, choice_dialog *cd; QList actor_and_target; - /* Wait for the player's reply before moving on to the next queued diplomat. */ - is_more_user_input_needed = TRUE; - - if (pvcity) { - pvictim = city_owner(pvcity); - } cd = gui()->get_diplo_dialog(); if (cd != NULL) { cd->close(); } + + if (pvcity == nullptr) { + return; + } + + // Wait for the player's reply before moving on to the next queued diplomat. + is_more_user_input_needed = TRUE; + + pvictim = city_owner(pvcity); + struct astring stra = ASTRING_INIT; cd = new choice_dialog(_("Steal"), _("Steal Technology"), gui()->game_tab_widget, diplomat_queue_handle_secondary); - /* Put both actor and target city in qv1 since qv2 is taken */ + // Put both actor and target city in qv1 since qv2 is taken actor_and_target.append(diplomat_id); actor_and_target.append(diplomat_target_id); actor_and_target.append(act_id); qv1 = QVariant::fromValue(actor_and_target); - struct player *pplayer = client.conn.playing; - if (pvictim) { - const struct research *presearch = research_get(pplayer); - const struct research *vresearch = research_get(pvictim); - - advance_index_iterate(A_FIRST, i) { - if (research_invention_gettable(presearch, i, - game.info.tech_steal_allow_holes) - && research_invention_state(vresearch, i) == TECH_KNOWN - && research_invention_state(presearch, i) != TECH_KNOWN) { - func = spy_steal_something; - // Defeat keyboard shortcut mnemonics - str = QString(research_advance_name_translation(presearch, i)) - .replace("&", "&&"); - cd->add_item(str, func, qv1, i); - } - } advance_index_iterate_end; + struct player *pplayer = client_player(); + const struct research *presearch = research_get(pplayer); + const struct research *vresearch = research_get(pvictim); - if (action_prob_possible(actor_unit->client.act_prob_cache[ - get_non_targeted_action_id(act_id)])) { - astr_set(&stra, _("At %s's Discretion"), - unit_name_translation(actor_unit)); + advance_index_iterate(A_FIRST, i) { + if (research_invention_gettable(presearch, i, + game.info.tech_steal_allow_holes) + && research_invention_state(vresearch, i) == TECH_KNOWN + && research_invention_state(presearch, i) != TECH_KNOWN) { func = spy_steal_something; - str = QString(astr_str(&stra)).replace("&", "&&"); - cd->add_item(str, func, qv1, A_UNSET); + // Defeat keyboard shortcut mnemonics + str = QString(research_advance_name_translation(presearch, i)) + .replace("&", "&&"); + cd->add_item(str, func, qv1, i); } + } advance_index_iterate_end; - cd->set_layout(); - cd->show_me(); + if (action_prob_possible(actor_unit->client.act_prob_cache[ + get_non_targeted_action_id(act_id)])) { + astr_set(&stra, _("At %s's Discretion"), + unit_name_translation(actor_unit)); + func = spy_steal_something; + str = QString(astr_str(&stra)).replace("&", "&&"); + cd->add_item(str, func, qv1, A_UNSET); } + + cd->set_layout(); + cd->show_me(); + astr_free(&stra); } -- 2.35.1