mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
invalidate bonus caching on update
This commit is contained in:
parent
f1fd00f005
commit
f867b1a37e
@ -318,13 +318,15 @@ void BonusList::eliminateDuplicates()
|
||||
bonuses.erase( unique( bonuses.begin(), bonuses.end() ), bonuses.end() );
|
||||
}
|
||||
|
||||
void BonusList::updateBonuses(const CBonusSystemNode & context)
|
||||
bool BonusList::updateBonuses(const CBonusSystemNode & context)
|
||||
{
|
||||
bool updated = false;
|
||||
for(std::shared_ptr<Bonus> b : *this)
|
||||
{
|
||||
if(b->updater)
|
||||
b->updater->update(*b, context);
|
||||
updated = b->updater->update(*b, context) || updated;
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
void BonusList::push_back(std::shared_ptr<Bonus> x)
|
||||
@ -808,8 +810,10 @@ void CBonusSystemNode::reduceBonusDurations(const CSelector &s)
|
||||
|
||||
void CBonusSystemNode::updateBonuses()
|
||||
{
|
||||
bonuses.updateBonuses(*this);
|
||||
exportedBonuses.updateBonuses(*this);
|
||||
bool updated = bonuses.updateBonuses(*this);
|
||||
updated = exportedBonuses.updateBonuses(*this) || updated;
|
||||
if(updated)
|
||||
treeHasChanged();
|
||||
}
|
||||
|
||||
void CBonusSystemNode::addNewBonus(const std::shared_ptr<Bonus>& b)
|
||||
@ -1559,15 +1563,21 @@ void LimiterList::add( TLimiterPtr limiter )
|
||||
limiters.push_back(limiter);
|
||||
}
|
||||
|
||||
void ScalingUpdater::update(Bonus & b, const CBonusSystemNode & context)
|
||||
bool ScalingUpdater::update(Bonus & b, const CBonusSystemNode & context)
|
||||
{
|
||||
if(context.getNodeType() == CBonusSystemNode::HERO)
|
||||
{
|
||||
int level = static_cast<const CGHeroInstance &>(context).level;
|
||||
int steps = stepSize ? level / stepSize : level;
|
||||
//rounding follows format for HMM3 creature specialty bonus
|
||||
b.val = (valPer20 * steps + 19) / 20;
|
||||
int newVal = (valPer20 * steps + 19) / 20;
|
||||
if(b.val != newVal)
|
||||
{
|
||||
b.val = newVal;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
|
||||
|
@ -485,7 +485,7 @@ public:
|
||||
int valOfBonuses(const CSelector &select) const;
|
||||
|
||||
void eliminateDuplicates();
|
||||
void updateBonuses(const CBonusSystemNode & node);
|
||||
bool updateBonuses(const CBonusSystemNode & node);
|
||||
|
||||
// remove_if implementation for STL vector types
|
||||
template <class Predicate>
|
||||
@ -1019,7 +1019,7 @@ void BonusList::insert(const int position, InputIterator first, InputIterator la
|
||||
class DLL_LINKAGE IUpdater
|
||||
{
|
||||
public:
|
||||
virtual void update(Bonus & b, const CBonusSystemNode & context) const = 0;
|
||||
virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
@ -1038,5 +1038,5 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater
|
||||
h & stepSize;
|
||||
}
|
||||
|
||||
void update(Bonus & b, const CBonusSystemNode & context);
|
||||
bool update(Bonus & b, const CBonusSystemNode & context);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user