From ab6822250d57033828934d1f73b033b74b4408f4 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Tue, 26 May 2026 23:44:36 +0200 Subject: [PATCH] Try to reuse existing logic for Eagle Eye dialog --- client/NetPacksClient.cpp | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 5664c561a..0be8c58a7 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -117,6 +117,16 @@ void callBattleInterfaceIfPresentForBothSides(CClient & cl, const BattleID & bat } } +static void showEagleEyeLearnedSpellsDialog(CClient & cl, ObjectInstanceID heroId, const std::set & spells, PlayerColor player) +{ + if(spells.empty()) + return; + + const auto * hero = cl.gameInfo().getHero(heroId); + assert(hero); + callInterfaceIfPresent(cl, player, &CGameInterface::showInfoDialog, EInfoWindowMode::AUTO, UIHelper::getEagleEyeInfoWindowText(*hero, spells), UIHelper::getSpellsComponents(spells), soundBase::soundID(0)); +} + void ApplyClientNetPackVisitor::visitSetResources(SetResources & pack) { //todo: inform on actual resource set transferred @@ -595,28 +605,10 @@ void ApplyClientNetPackVisitor::visitChangeSpells(ChangeSpells & pack) if(!hero) return; - bool heroInBattle = false; - for(const auto & battlePtr : gs.currentBattles) - { - if(!battlePtr) - continue; - - const auto * attackerHero = battlePtr->battleGetFightingHero(BattleSide::ATTACKER); - const auto * defenderHero = battlePtr->battleGetFightingHero(BattleSide::DEFENDER); - if((attackerHero && attackerHero->id == pack.hid) || (defenderHero && defenderHero->id == pack.hid)) - { - heroInBattle = true; - break; - } - } - - if(!heroInBattle) - return; - if(hero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_CHANCE_PRE_BATTLE) <= 0) return; - callInterfaceIfPresent(cl, hero->tempOwner, &CGameInterface::showInfoDialog, EInfoWindowMode::AUTO, UIHelper::getEagleEyeInfoWindowText(*hero, pack.spells), UIHelper::getSpellsComponents(pack.spells), soundBase::soundID(0)); + showEagleEyeLearnedSpellsDialog(cl, pack.hid, pack.spells, hero->tempOwner); } void ApplyClientNetPackVisitor::visitSetHeroesInTown(SetHeroesInTown & pack) @@ -869,13 +861,7 @@ void ApplyClientNetPackVisitor::visitStacksInjured(StacksInjured & pack) void ApplyClientNetPackVisitor::visitBattleResultsApplied(BattleResultsApplied & pack) { - if(!pack.learnedSpells.spells.empty()) - { - const auto * hero = cl.gameInfo().getHero(pack.learnedSpells.hid); - assert(hero); - callInterfaceIfPresent(cl, pack.victor, &CGameInterface::showInfoDialog, EInfoWindowMode::MODAL, - UIHelper::getEagleEyeInfoWindowText(*hero, pack.learnedSpells.spells), UIHelper::getSpellsComponents(pack.learnedSpells.spells), soundBase::soundID(0)); - } + showEagleEyeLearnedSpellsDialog(cl, pack.learnedSpells.hid, pack.learnedSpells.spells, pack.victor); if(!pack.movingArtifacts.empty()) {