1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Merge pull request #185 from vmarkovtsev/issue/2264

Fix 2264 learning stone & Learning skill
This commit is contained in:
DjWarmonger
2016-01-31 09:17:11 +01:00
2 changed files with 17 additions and 11 deletions

View File

@@ -99,7 +99,7 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
iw.player = h->tempOwner; iw.player = h->tempOwner;
iw.soundID = soundID; iw.soundID = soundID;
iw.text = info[index].message; iw.text = info[index].message;
info[index].reward.loadComponents(iw.components); info[index].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 +112,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()); sd.components.push_back(info[index].reward.getDisplayedComponent(h));
cb->showBlockingDialog(&sd); cb->showBlockingDialog(&sd);
}; };
@@ -341,19 +341,24 @@ bool CRewardableObject::wasVisited (const CGHeroInstance * h) const
} }
} }
void CRewardInfo::loadComponents(std::vector<Component> & comps) const void CRewardInfo::loadComponents(std::vector<Component> & comps,
const CGHeroInstance * h) const
{ {
for (auto comp : extraComponents) for (auto comp : extraComponents)
comps.push_back(comp); comps.push_back(comp);
if (gainedExp) comps.push_back(Component(Component::EXPERIENCE, 0, gainedExp, 0)); if (gainedExp)
{
comps.push_back(Component(
Component::EXPERIENCE, 0, h->calculateXp(gainedExp), 0));
}
if (gainedLevels) comps.push_back(Component(Component::EXPERIENCE, 0, gainedLevels, 0)); if (gainedLevels) comps.push_back(Component(Component::EXPERIENCE, 0, gainedLevels, 0));
if (manaDiff) comps.push_back(Component(Component::PRIM_SKILL, 5, manaDiff, 0)); if (manaDiff) comps.push_back(Component(Component::PRIM_SKILL, 5, manaDiff, 0));
for (size_t i=0; i<primary.size(); i++) for (size_t i=0; i<primary.size(); i++)
{ {
if (primary[i] !=0) if (primary[i] != 0)
comps.push_back(Component(Component::PRIM_SKILL, i, primary[i], 0)); comps.push_back(Component(Component::PRIM_SKILL, i, primary[i], 0));
} }
@@ -376,10 +381,10 @@ void CRewardInfo::loadComponents(std::vector<Component> & comps) const
} }
} }
Component CRewardInfo::getDisplayedComponent() const Component CRewardInfo::getDisplayedComponent(const CGHeroInstance * h) const
{ {
std::vector<Component> comps; std::vector<Component> comps;
loadComponents(comps); loadComponents(comps, h);
assert(!comps.empty()); assert(!comps.empty());
return comps.front(); return comps.front();
} }

View File

@@ -104,9 +104,10 @@ public:
/// if set to true, object will be removed after granting reward /// if set to true, object will be removed after granting reward
bool removeObject; bool removeObject;
/// Generates list of components that describes reward /// Generates list of components that describes reward for a specific hero
virtual void loadComponents(std::vector<Component> & comps) const; virtual void loadComponents(std::vector<Component> & comps,
Component getDisplayedComponent() const; const CGHeroInstance * h) const;
Component getDisplayedComponent(const CGHeroInstance * h) const;
CRewardInfo() : CRewardInfo() :
gainedExp(0), gainedExp(0),