mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
renamed & reused CBonusSystemNode::updateBonuses; tweaked updater signature
This commit is contained in:
parent
67330efa4a
commit
f1fd00f005
@ -318,6 +318,15 @@ void BonusList::eliminateDuplicates()
|
|||||||
bonuses.erase( unique( bonuses.begin(), bonuses.end() ), bonuses.end() );
|
bonuses.erase( unique( bonuses.begin(), bonuses.end() ), bonuses.end() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BonusList::updateBonuses(const CBonusSystemNode & context)
|
||||||
|
{
|
||||||
|
for(std::shared_ptr<Bonus> b : *this)
|
||||||
|
{
|
||||||
|
if(b->updater)
|
||||||
|
b->updater->update(*b, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BonusList::push_back(std::shared_ptr<Bonus> x)
|
void BonusList::push_back(std::shared_ptr<Bonus> x)
|
||||||
{
|
{
|
||||||
bonuses.push_back(x);
|
bonuses.push_back(x);
|
||||||
@ -782,7 +791,7 @@ void CBonusSystemNode::popBonuses(const CSelector &s)
|
|||||||
child->popBonuses(s);
|
child->popBonuses(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBonusSystemNode::updateBonuses(const CSelector &s)
|
void CBonusSystemNode::reduceBonusDurations(const CSelector &s)
|
||||||
{
|
{
|
||||||
BonusList bl;
|
BonusList bl;
|
||||||
exportedBonuses.getBonuses(bl, s, Selector::all);
|
exportedBonuses.getBonuses(bl, s, Selector::all);
|
||||||
@ -794,7 +803,13 @@ void CBonusSystemNode::updateBonuses(const CSelector &s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(CBonusSystemNode *child : children)
|
for(CBonusSystemNode *child : children)
|
||||||
child->updateBonuses(s);
|
child->reduceBonusDurations(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBonusSystemNode::updateBonuses()
|
||||||
|
{
|
||||||
|
bonuses.updateBonuses(*this);
|
||||||
|
exportedBonuses.updateBonuses(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBonusSystemNode::addNewBonus(const std::shared_ptr<Bonus>& b)
|
void CBonusSystemNode::addNewBonus(const std::shared_ptr<Bonus>& b)
|
||||||
@ -1544,14 +1559,14 @@ void LimiterList::add( TLimiterPtr limiter )
|
|||||||
limiters.push_back(limiter);
|
limiters.push_back(limiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScalingUpdater::update(BonusUpdateContext & context)
|
void ScalingUpdater::update(Bonus & b, const CBonusSystemNode & context)
|
||||||
{
|
{
|
||||||
if(context.node.getNodeType() == CBonusSystemNode::HERO)
|
if(context.getNodeType() == CBonusSystemNode::HERO)
|
||||||
{
|
{
|
||||||
int level = static_cast<const CGHeroInstance &>(context.node).level;
|
int level = static_cast<const CGHeroInstance &>(context).level;
|
||||||
int steps = stepSize ? level / stepSize : level;
|
int steps = stepSize ? level / stepSize : level;
|
||||||
//rounding follows format for HMM3 creature specialty bonus
|
//rounding follows format for HMM3 creature specialty bonus
|
||||||
context.b->val = (valPer20 * steps + 19) / 20;
|
b.val = (valPer20 * steps + 19) / 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,6 +485,7 @@ public:
|
|||||||
int valOfBonuses(const CSelector &select) const;
|
int valOfBonuses(const CSelector &select) const;
|
||||||
|
|
||||||
void eliminateDuplicates();
|
void eliminateDuplicates();
|
||||||
|
void updateBonuses(const CBonusSystemNode & node);
|
||||||
|
|
||||||
// remove_if implementation for STL vector types
|
// remove_if implementation for STL vector types
|
||||||
template <class Predicate>
|
template <class Predicate>
|
||||||
@ -707,7 +708,9 @@ public:
|
|||||||
///removes bonuses by selector
|
///removes bonuses by selector
|
||||||
void popBonuses(const CSelector &s);
|
void popBonuses(const CSelector &s);
|
||||||
///updates count of remaining turns and removes outdated bonuses by selector
|
///updates count of remaining turns and removes outdated bonuses by selector
|
||||||
void updateBonuses(const CSelector &s);
|
void reduceBonusDurations(const CSelector &s);
|
||||||
|
//run update decorators
|
||||||
|
void updateBonuses();
|
||||||
virtual std::string bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const {return "";}; //description or bonus name
|
virtual std::string bonusToString(const std::shared_ptr<Bonus>& bonus, bool description) const {return "";}; //description or bonus name
|
||||||
virtual std::string nodeName() const;
|
virtual std::string nodeName() const;
|
||||||
|
|
||||||
@ -1013,16 +1016,10 @@ void BonusList::insert(const int position, InputIterator first, InputIterator la
|
|||||||
|
|
||||||
// bonus decorators for updating bonuses based on events (e.g. hero gaining level)
|
// bonus decorators for updating bonuses based on events (e.g. hero gaining level)
|
||||||
|
|
||||||
struct BonusUpdateContext
|
|
||||||
{
|
|
||||||
std::shared_ptr<Bonus> b;
|
|
||||||
const CBonusSystemNode & node;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DLL_LINKAGE IUpdater
|
class DLL_LINKAGE IUpdater
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void update(BonusUpdateContext & context) const = 0;
|
virtual void update(Bonus & b, const CBonusSystemNode & context) const = 0;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
@ -1041,5 +1038,5 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater
|
|||||||
h & stepSize;
|
h & stepSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(BonusUpdateContext & context);
|
void update(Bonus & b, const CBonusSystemNode & context);
|
||||||
};
|
};
|
||||||
|
@ -1085,8 +1085,8 @@ DLL_LINKAGE void NewTurn::applyGs(CGameState *gs)
|
|||||||
|
|
||||||
// Update bonuses before doing anything else so hero don't get more MP than needed
|
// Update bonuses before doing anything else so hero don't get more MP than needed
|
||||||
gs->globalEffects.popBonuses(Bonus::OneDay); //works for children -> all game objs
|
gs->globalEffects.popBonuses(Bonus::OneDay); //works for children -> all game objs
|
||||||
gs->globalEffects.updateBonuses(Bonus::NDays);
|
gs->globalEffects.reduceBonusDurations(Bonus::NDays);
|
||||||
gs->globalEffects.updateBonuses(Bonus::OneWeek);
|
gs->globalEffects.reduceBonusDurations(Bonus::OneWeek);
|
||||||
//TODO not really a single root hierarchy, what about bonuses placed elsewhere? [not an issue with H3 mechanics but in the future...]
|
//TODO not really a single root hierarchy, what about bonuses placed elsewhere? [not an issue with H3 mechanics but in the future...]
|
||||||
|
|
||||||
for(NewTurn::Hero h : heroes) //give mana/movement point
|
for(NewTurn::Hero h : heroes) //give mana/movement point
|
||||||
|
@ -765,7 +765,7 @@ void BattleInfo::nextRound(int32_t roundNr)
|
|||||||
for(CStack * s : stacks)
|
for(CStack * s : stacks)
|
||||||
{
|
{
|
||||||
// new turn effects
|
// new turn effects
|
||||||
s->updateBonuses(Bonus::NTurns);
|
s->reduceBonusDurations(Bonus::NTurns);
|
||||||
|
|
||||||
s->afterNewRound();
|
s->afterNewRound();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user