1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #3785 from dydzio0614/bank-revisit-fix

Empty treasure bank does not ask for enter anymore
This commit is contained in:
Ivan Savenko 2024-04-22 11:06:58 +03:00 committed by GitHub
commit 55756dbc43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 19 deletions

View File

@ -61,7 +61,7 @@ std::string CBank::getHoverText(PlayerColor player) const
if (!wasVisited(player)) if (!wasVisited(player))
return getObjectName(); return getObjectName();
return getObjectName() + "\n" + visitedTxt(bc == nullptr); return getObjectName() + "\n" + visitedTxt(bankConfig == nullptr);
} }
std::vector<Component> CBank::getPopupComponents(PlayerColor player) const std::vector<Component> CBank::getPopupComponents(PlayerColor player) const
@ -72,7 +72,7 @@ std::vector<Component> CBank::getPopupComponents(PlayerColor player) const
if (!VLC->settings()->getBoolean(EGameSettings::BANKS_SHOW_GUARDS_COMPOSITION)) if (!VLC->settings()->getBoolean(EGameSettings::BANKS_SHOW_GUARDS_COMPOSITION))
return {}; return {};
if (bc == nullptr) if (bankConfig == nullptr)
return {}; return {};
std::map<CreatureID, int> guardsAmounts; std::map<CreatureID, int> guardsAmounts;
@ -92,7 +92,7 @@ std::vector<Component> CBank::getPopupComponents(PlayerColor player) const
void CBank::setConfig(const BankConfig & config) void CBank::setConfig(const BankConfig & config)
{ {
bc = std::make_unique<BankConfig>(config); bankConfig = std::make_unique<BankConfig>(config);
clearSlots(); // remove all stacks, if any clearSlots(); // remove all stacks, if any
for(const auto & stack : config.guards) 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 daycounter = 1; //yes, 1 since "today" daycounter won't be incremented
break; break;
case ObjProperty::BANK_CLEAR: case ObjProperty::BANK_CLEAR:
bc.reset(); bankConfig.reset();
break; break;
} }
} }
void CBank::newTurn(CRandomGenerator & rand) const void CBank::newTurn(CRandomGenerator & rand) const
{ {
if (bc == nullptr) if (bankConfig == nullptr)
{ {
if (resetDuration != 0) if (resetDuration != 0)
{ {
@ -141,6 +141,12 @@ void CBank::onHeroVisit(const CGHeroInstance * h) const
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id); ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id);
cb->sendAndApply(&cov); cb->sendAndApply(&cov);
if(!bankConfig && (ID.toEnum() == Obj::CREATURE_BANK || ID.toEnum() == Obj::DRAGON_UTOPIA))
{
blockingDialogAnswered(h, 1);
return;
}
int banktext = 0; int banktext = 0;
switch (ID.toEnum()) switch (ID.toEnum())
{ {
@ -183,7 +189,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
iw.player = hero->getOwner(); iw.player = hero->getOwner();
MetaString loot; MetaString loot;
if (bc) if (bankConfig)
{ {
switch (ID.toEnum()) switch (ID.toEnum())
{ {
@ -267,21 +273,21 @@ void CBank::doVisit(const CGHeroInstance * hero) const
//grant resources //grant resources
if (bc) if (bankConfig)
{ {
for (GameResID it : GameResID::ALL_RESOURCES()) 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.appendRawString("%d %s");
loot.replaceNumber(bc->resources[it]); loot.replaceNumber(bankConfig->resources[it]);
loot.replaceName(it); loot.replaceName(it);
cb->giveResource(hero->getOwner(), it, bc->resources[it]); cb->giveResource(hero->getOwner(), it, bankConfig->resources[it]);
} }
} }
//grant artifacts //grant artifacts
for (auto & elem : bc->artifacts) for (auto & elem : bankConfig->artifacts)
{ {
iw.components.emplace_back(ComponentType::ARTIFACT, elem); iw.components.emplace_back(ComponentType::ARTIFACT, elem);
loot.appendRawString("%s"); loot.appendRawString("%s");
@ -294,7 +300,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID); iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID);
if (textID == 34) 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(); return a.type->getFightValue() < b.type->getFightValue();
})->type; })->type;
@ -309,7 +315,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
iw.components.clear(); iw.components.clear();
iw.text.clear(); iw.text.clear();
if (!bc->spells.empty()) if (!bankConfig->spells.empty())
{ {
std::set<SpellID> spells; std::set<SpellID> spells;
@ -318,7 +324,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
{ {
iw.text.appendLocalString(EMetaText::ADVOB_TXT, textID); //pyramid 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); const auto * spell = spellId.toEntity(VLC);
iw.text.appendName(spellId); iw.text.appendName(spellId);
@ -351,7 +357,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
//grant creatures //grant creatures
CCreatureSet ourArmy; 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); 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 (answer)
{ {
if (bc) // not looted bank if (bankConfig) // not looted bank
cb->startBattleI(hero, this, true); cb->startBattleI(hero, this, true);
else else
doVisit(hero); doVisit(hero);

View File

@ -18,7 +18,7 @@ class CBankInstanceConstructor;
class DLL_LINKAGE CBank : public CArmedInstance class DLL_LINKAGE CBank : public CArmedInstance
{ {
std::unique_ptr<BankConfig> bc; std::unique_ptr<BankConfig> bankConfig;
ui32 daycounter; ui32 daycounter;
ui32 resetDuration; ui32 resetDuration;
bool coastVisitable; bool coastVisitable;
@ -47,7 +47,7 @@ public:
{ {
h & static_cast<CArmedInstance&>(*this); h & static_cast<CArmedInstance&>(*this);
h & daycounter; h & daycounter;
h & bc; h & bankConfig;
h & resetDuration; h & resetDuration;
h & coastVisitable; h & coastVisitable;
} }