From ce5b7c73be320c742b4c2f0464eb7e6b911c8190 Mon Sep 17 00:00:00 2001 From: ArseniyShestakov Date: Sat, 28 Nov 2015 23:03:26 +0300 Subject: [PATCH] CGEvent: avoid permanent event removal after visit. Fix issue 2339 --- lib/mapObjects/CGPandoraBox.cpp | 17 ++++++++++++++++- lib/mapObjects/CGPandoraBox.h | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/CGPandoraBox.cpp b/lib/mapObjects/CGPandoraBox.cpp index e9532ae46..2d0b4d321 100644 --- a/lib/mapObjects/CGPandoraBox.cpp +++ b/lib/mapObjects/CGPandoraBox.cpp @@ -51,7 +51,7 @@ void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const void CGPandoraBox::giveContentsUpToExp(const CGHeroInstance *h) const { - cb->removeAfterVisit(this); + afterSuccessfulVisit(); InfoWindow iw; iw.player = h->getOwner(); @@ -331,6 +331,11 @@ void CGPandoraBox::heroLevelUpDone(const CGHeroInstance *hero) const giveContentsAfterExp(hero); } +void CGPandoraBox::afterSuccessfulVisit() const +{ + cb->removeAfterVisit(this); +} + void CGEvent::onHeroVisit( const CGHeroInstance * h ) const { if(!(availableFor & (1 << h->tempOwner.getNum()))) @@ -362,3 +367,13 @@ void CGEvent::activated( const CGHeroInstance * h ) const giveContentsUpToExp(h); } } + +void CGEvent::afterSuccessfulVisit() const +{ + if(removeAfterVisit) + { + cb->removeAfterVisit(this); + } + else if(hasGuardians) + hasGuardians = false; +} diff --git a/lib/mapObjects/CGPandoraBox.h b/lib/mapObjects/CGPandoraBox.h index 79ab0a417..13be53add 100644 --- a/lib/mapObjects/CGPandoraBox.h +++ b/lib/mapObjects/CGPandoraBox.h @@ -20,7 +20,7 @@ class DLL_LINKAGE CGPandoraBox : public CArmedInstance { public: std::string message; - bool hasGuardians; //helper - after battle even though we have no stacks, allows us to know that there was battle + mutable bool hasGuardians; //helper - after battle even though we have no stacks, allows us to know that there was battle //gained things: ui32 gainedExp; @@ -54,6 +54,7 @@ protected: private: void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const; void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const; + virtual void afterSuccessfulVisit() const; }; class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects @@ -74,4 +75,5 @@ public: void onHeroVisit(const CGHeroInstance * h) const override; private: void activated(const CGHeroInstance * h) const; + void afterSuccessfulVisit() const override; };