1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Make stables message appear if hero has cavaliers but visited stables before

This commit is contained in:
Vadim Markovtsev
2016-02-01 09:41:15 +03:00
parent c30a6f2ff3
commit 88bc21952b
2 changed files with 57 additions and 27 deletions

View File

@ -783,6 +783,32 @@ void CGBonusingObject::onHeroVisit(const CGHeroInstance *h) const
} }
} }
bool CGBonusingObject::wasVisited(const CGHeroInstance * h) const
{
if(ID == Obj::STABLES)
{
for(auto& slot : h->Slots())
{
if(slot.second->type->idNumber == CreatureID::CAVALIER)
{
// always display the reward message if the hero got cavaliers
return false;
}
}
}
return CRewardableObject::wasVisited(h);
}
void CGBonusingObject::grantReward(ui32 rewardID, const CGHeroInstance * hero) const
{
if(ID == Obj::STABLES && CRewardableObject::wasVisited(hero))
{
// reward message has been displayed - do not give the actual bonus
return;
}
CRewardableObject::grantReward(rewardID, hero);
}
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
CGOnceVisitable::CGOnceVisitable() CGOnceVisitable::CGOnceVisitable()

View File

@ -159,8 +159,6 @@ public:
/// Inherits from CArmedInstance for proper trasfer of armies /// Inherits from CArmedInstance for proper trasfer of armies
class DLL_LINKAGE CRewardableObject : public CArmedInstance class DLL_LINKAGE CRewardableObject : public CArmedInstance
{ {
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
/// function that must be called if hero got level-up during grantReward call /// function that must be called if hero got level-up during grantReward call
void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const; void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
@ -188,6 +186,8 @@ protected:
/// filters list of visit info and returns rewards that can be granted to current hero /// filters list of visit info and returns rewards that can be granted to current hero
virtual std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const; virtual std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const;
virtual void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
virtual CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const; virtual CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const;
/// Rewards that can be granted by an object /// Rewards that can be granted by an object
@ -269,6 +269,8 @@ class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving b
protected: protected:
CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const override; CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const override;
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
public: public:
void initObj() override; void initObj() override;
@ -276,6 +278,8 @@ public:
void onHeroVisit(const CGHeroInstance *h) const override; void onHeroVisit(const CGHeroInstance *h) const override;
bool wasVisited(const CGHeroInstance * h) const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & static_cast<CRewardableObject&>(*this); h & static_cast<CRewardableObject&>(*this);