1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-15 20:03:15 +02:00

Merge pull request #183 from vmarkovtsev/issue/1989

Fix 1989 cavaliers -> champions in stables
This commit is contained in:
ArseniyShestakov
2016-02-02 03:56:11 +03:00
2 changed files with 116 additions and 52 deletions

View File

@@ -87,19 +87,25 @@ std::vector<ui32> CRewardableObject::getAvailableRewards(const CGHeroInstance *
return ret; return ret;
} }
CVisitInfo CRewardableObject::getVisitInfo(int index, const CGHeroInstance *) const
{
return info[index];
}
void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
{ {
auto grantRewardWithMessage = [&](int index) -> void auto grantRewardWithMessage = [&](int index) -> void
{ {
logGlobal->debugStream() << "Granting reward " << index << ". Message says: " << info[index].message.toString(); auto vi = getVisitInfo(index, h);
logGlobal->debugStream() << "Granting reward " << index << ". Message says: " << vi.message.toString();
// show message only if it is not empty // show message only if it is not empty
if (!info[index].message.toString().empty()) if (!vi.message.toString().empty())
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
iw.soundID = soundID; iw.soundID = soundID;
iw.text = info[index].message; iw.text = vi.message;
info[index].reward.loadComponents(iw.components, h); vi.reward.loadComponents(iw.components, h);
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
} }
// grant reward afterwards. Note that it may remove object // grant reward afterwards. Note that it may remove object
@@ -112,7 +118,7 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
sd.soundID = soundID; sd.soundID = soundID;
sd.text = onSelect; sd.text = onSelect;
for (auto index : rewards) for (auto index : rewards)
sd.components.push_back(info[index].reward.getDisplayedComponent(h)); sd.components.push_back(getVisitInfo(index, h).reward.getDisplayedComponent(h));
cb->showBlockingDialog(&sd); cb->showBlockingDialog(&sd);
}; };
@@ -175,7 +181,7 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
void CRewardableObject::heroLevelUpDone(const CGHeroInstance *hero) const void CRewardableObject::heroLevelUpDone(const CGHeroInstance *hero) const
{ {
grantRewardAfterLevelup(info[selectedReward], hero); grantRewardAfterLevelup(getVisitInfo(selectedReward, hero), hero);
} }
void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
@@ -205,7 +211,7 @@ void CRewardableObject::grantReward(ui32 rewardID, const CGHeroInstance * hero)
cb->sendAndApply(&cov); cb->sendAndApply(&cov);
cb->setObjProperty(id, ObjProperty::REWARD_SELECT, rewardID); cb->setObjProperty(id, ObjProperty::REWARD_SELECT, rewardID);
grantRewardBeforeLevelup(info[rewardID], hero); grantRewardBeforeLevelup(getVisitInfo(rewardID, hero), hero);
} }
void CRewardableObject::grantRewardBeforeLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const void CRewardableObject::grantRewardBeforeLevelup(const CVisitInfo & info, const CGHeroInstance * hero) const
@@ -733,30 +739,76 @@ void CGBonusingObject::initObj()
break; break;
case Obj::STABLES: case Obj::STABLES:
configureMessage(info[0], 137, 136, soundBase::STORE); configureMessage(info[0], 137, 136, soundBase::STORE);
configureBonusDuration(info[0], Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 400, 0); configureBonusDuration(info[0], Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, 400, 0);
info[0].reward.movePoints = 400; info[0].reward.movePoints = 400;
//TODO: upgrade champions to cavaliers
/*
bool someUpgradeDone = false;
for (auto i = h->Slots().begin(); i != h->Slots().end(); ++i)
{
if(i->second->type->idNumber == CreatureID::CAVALIER)
{
cb->changeStackType(StackLocation(h, i->first), VLC->creh->creatures[CreatureID::CHAMPION]);
someUpgradeDone = true;
}
}
if (someUpgradeDone)
{
grantMessage.addTxt(MetaString::ADVOB_TXT, 138);
iw.components.push_back(Component(Component::CREATURE,11,0,1));
}*/
break; break;
} }
} }
CVisitInfo CGBonusingObject::getVisitInfo(int index, const CGHeroInstance *h) const
{
if(ID == Obj::STABLES)
{
assert(index == 0);
for(auto& slot : h->Slots())
{
if(slot.second->type->idNumber == CreatureID::CAVALIER)
{
CVisitInfo vi(info[0]);
vi.message.clear();
vi.message.addTxt(MetaString::ADVOB_TXT, 138);
vi.reward.extraComponents.push_back(Component(
Component::CREATURE, CreatureID::CHAMPION, 0, 1));
return std::move(vi);
}
}
}
return info[index];
}
void CGBonusingObject::onHeroVisit(const CGHeroInstance *h) const
{
CRewardableObject::onHeroVisit(h);
if(ID == Obj::STABLES)
{
//regardless of whether this hero visited stables or not, cavaliers must be upgraded
for(auto& slot : h->Slots())
{
if(slot.second->type->idNumber == CreatureID::CAVALIER)
{
cb->changeStackType(StackLocation(h, slot.first),
VLC->creh->creatures[CreatureID::CHAMPION]);
}
}
}
}
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

@@ -164,6 +164,7 @@ class DLL_LINKAGE CRewardableObject : public CArmedInstance
/// grants reward to hero /// grants reward to hero
void grantRewardBeforeLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const; void grantRewardBeforeLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
protected: protected:
/// controls selection of reward granted to player /// controls selection of reward granted to player
enum ESelectMode enum ESelectMode
@@ -185,9 +186,11 @@ 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;
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const; virtual void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
/// Rewars that can be granted by an object virtual CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const;
/// Rewards that can be granted by an object
std::vector<CVisitInfo> info; std::vector<CVisitInfo> info;
/// MetaString's that contain text for messages for specific situations /// MetaString's that contain text for messages for specific situations
@@ -263,11 +266,20 @@ public:
class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving bonuses to luck/morale/movement class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving bonuses to luck/morale/movement
{ {
protected:
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;
CGBonusingObject(); CGBonusingObject();
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);