From 20eaf17a18eb3625b0dcc5d7f5a45d8ed29ad297 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Wed, 17 Apr 2024 01:25:58 +0200 Subject: [PATCH 1/2] Empty treasure bank does not ask for enter anymore --- lib/mapObjects/CBank.cpp | 40 +++++++++++++++++++++++----------------- lib/mapObjects/CBank.h | 4 ++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index ff00fc9b3..18bfd84f2 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -61,7 +61,7 @@ std::string CBank::getHoverText(PlayerColor player) const if (!wasVisited(player)) return getObjectName(); - return getObjectName() + "\n" + visitedTxt(bc == nullptr); + return getObjectName() + "\n" + visitedTxt(bankConfig == nullptr); } std::vector CBank::getPopupComponents(PlayerColor player) const @@ -72,7 +72,7 @@ std::vector CBank::getPopupComponents(PlayerColor player) const if (!VLC->settings()->getBoolean(EGameSettings::BANKS_SHOW_GUARDS_COMPOSITION)) return {}; - if (bc == nullptr) + if (bankConfig == nullptr) return {}; std::map guardsAmounts; @@ -92,7 +92,7 @@ std::vector CBank::getPopupComponents(PlayerColor player) const void CBank::setConfig(const BankConfig & config) { - bc = std::make_unique(config); + bankConfig = std::make_unique(config); clearSlots(); // remove all stacks, if any for(const auto & stack : config.guards) @@ -112,14 +112,14 @@ void CBank::setPropertyDer (ObjProperty what, ObjPropertyID identifier) daycounter = 1; //yes, 1 since "today" daycounter won't be incremented break; case ObjProperty::BANK_CLEAR: - bc.reset(); + bankConfig.reset(); break; } } void CBank::newTurn(CRandomGenerator & rand) const { - if (bc == nullptr) + if (bankConfig == nullptr) { if (resetDuration != 0) { @@ -141,6 +141,12 @@ void CBank::onHeroVisit(const CGHeroInstance * h) const ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id); cb->sendAndApply(&cov); + if(!bankConfig) + { + blockingDialogAnswered(h, 1); + return; + } + int banktext = 0; switch (ID.toEnum()) { @@ -183,7 +189,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const iw.player = hero->getOwner(); MetaString loot; - if (bc) + if (bankConfig) { switch (ID.toEnum()) { @@ -267,21 +273,21 @@ void CBank::doVisit(const CGHeroInstance * hero) const //grant resources - if (bc) + if (bankConfig) { for (GameResID it : GameResID::ALL_RESOURCES()) { - if (bc->resources[it] != 0) + if (bankConfig->resources[it] != 0) { - iw.components.emplace_back(ComponentType::RESOURCE, it, bc->resources[it]); + iw.components.emplace_back(ComponentType::RESOURCE, it, bankConfig->resources[it]); loot.appendRawString("%d %s"); - loot.replaceNumber(bc->resources[it]); + loot.replaceNumber(bankConfig->resources[it]); loot.replaceName(it); - cb->giveResource(hero->getOwner(), it, bc->resources[it]); + cb->giveResource(hero->getOwner(), it, bankConfig->resources[it]); } } //grant artifacts - for (auto & elem : bc->artifacts) + for (auto & elem : bankConfig->artifacts) { iw.components.emplace_back(ComponentType::ARTIFACT, elem); loot.appendRawString("%s"); @@ -294,7 +300,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID); if (textID == 34) { - const auto * strongest = boost::range::max_element(bc->guards, [](const CStackBasicDescriptor & a, const CStackBasicDescriptor & b) + const auto * strongest = boost::range::max_element(bankConfig->guards, [](const CStackBasicDescriptor & a, const CStackBasicDescriptor & b) { return a.type->getFightValue() < b.type->getFightValue(); })->type; @@ -309,7 +315,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const iw.components.clear(); iw.text.clear(); - if (!bc->spells.empty()) + if (!bankConfig->spells.empty()) { std::set spells; @@ -318,7 +324,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const { iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID); //pyramid } - for(const SpellID & spellId : bc->spells) + for(const SpellID & spellId : bankConfig->spells) { const auto * spell = spellId.toEntity(VLC); iw.text.appendName(spellId); @@ -351,7 +357,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const //grant creatures CCreatureSet ourArmy; - for(const auto & slot : bc->creatures) + for(const auto & slot : bankConfig->creatures) { ourArmy.addToSlot(ourArmy.getSlotFor(slot.type->getId()), slot.type->getId(), slot.count); } @@ -391,7 +397,7 @@ void CBank::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) cons { if (answer) { - if (bc) // not looted bank + if (bankConfig) // not looted bank cb->startBattleI(hero, this, true); else doVisit(hero); diff --git a/lib/mapObjects/CBank.h b/lib/mapObjects/CBank.h index 9377e83ed..411597dbc 100644 --- a/lib/mapObjects/CBank.h +++ b/lib/mapObjects/CBank.h @@ -18,7 +18,7 @@ class CBankInstanceConstructor; class DLL_LINKAGE CBank : public CArmedInstance { - std::unique_ptr bc; + std::unique_ptr bankConfig; ui32 daycounter; ui32 resetDuration; bool coastVisitable; @@ -47,7 +47,7 @@ public: { h & static_cast(*this); h & daycounter; - h & bc; + h & bankConfig; h & resetDuration; h & coastVisitable; } From 98375cc627d3b4573039c5a931ad44f16adba8d9 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Wed, 17 Apr 2024 22:08:17 +0200 Subject: [PATCH 2/2] Limit showing empty message instantly to creature banks and dragon utopia --- lib/mapObjects/CBank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index 18bfd84f2..cecd41307 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -141,7 +141,7 @@ void CBank::onHeroVisit(const CGHeroInstance * h) const ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id); cb->sendAndApply(&cov); - if(!bankConfig) + if(!bankConfig && (ID.toEnum() == Obj::CREATURE_BANK || ID.toEnum() == Obj::DRAGON_UTOPIA)) { blockingDialogAnswered(h, 1); return;