|
@@ -140,12 +140,12 @@ void DLL_EXPORT BonusList::eliminateDuplicates()
|
|
|
unique();
|
|
|
}
|
|
|
|
|
|
-int CBonusSystemNode::valOfBonuses(Bonus::BonusType type, const CSelector &selector) const
|
|
|
+int IBonusBearer::valOfBonuses(Bonus::BonusType type, const CSelector &selector) const
|
|
|
{
|
|
|
return valOfBonuses(Selector::type(type) && selector);
|
|
|
}
|
|
|
|
|
|
-int CBonusSystemNode::valOfBonuses(Bonus::BonusType type, int subtype /*= -1*/) const
|
|
|
+int IBonusBearer::valOfBonuses(Bonus::BonusType type, int subtype /*= -1*/) const
|
|
|
{
|
|
|
CSelector s = Selector::type(type);
|
|
|
if(subtype != -1)
|
|
@@ -154,18 +154,18 @@ int CBonusSystemNode::valOfBonuses(Bonus::BonusType type, int subtype /*= -1*/)
|
|
|
return valOfBonuses(s);
|
|
|
}
|
|
|
|
|
|
-int CBonusSystemNode::valOfBonuses(const CSelector &selector) const
|
|
|
+int IBonusBearer::valOfBonuses(const CSelector &selector) const
|
|
|
{
|
|
|
BonusList hlp;
|
|
|
getBonuses(hlp, selector);
|
|
|
return hlp.totalValue();
|
|
|
}
|
|
|
-bool CBonusSystemNode::hasBonus(const CSelector &selector) const
|
|
|
+bool IBonusBearer::hasBonus(const CSelector &selector) const
|
|
|
{
|
|
|
return getBonuses(selector).size() > 0;
|
|
|
}
|
|
|
|
|
|
-bool CBonusSystemNode::hasBonusOfType(Bonus::BonusType type, int subtype /*= -1*/) const
|
|
|
+bool IBonusBearer::hasBonusOfType(Bonus::BonusType type, int subtype /*= -1*/) const
|
|
|
{
|
|
|
CSelector s = Selector::type(type);
|
|
|
if(subtype != -1)
|
|
@@ -174,59 +174,26 @@ bool CBonusSystemNode::hasBonusOfType(Bonus::BonusType type, int subtype /*= -1*
|
|
|
return hasBonus(s);
|
|
|
}
|
|
|
|
|
|
-Bonus * CBonusSystemNode::getBonus(const CSelector &selector)
|
|
|
-{
|
|
|
- Bonus *ret = bonuses.getFirst(selector);
|
|
|
- if(ret)
|
|
|
- return ret;
|
|
|
-
|
|
|
- FOREACH_PARENT(pname)
|
|
|
- {
|
|
|
- ret = pname->getBonus(selector);
|
|
|
- if (ret)
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- return NULL;
|
|
|
-}
|
|
|
-
|
|
|
-const Bonus * CBonusSystemNode::getBonus( const CSelector &selector ) const
|
|
|
-{
|
|
|
- return (const_cast<CBonusSystemNode*>(this))->getBonus(selector);
|
|
|
-}
|
|
|
-
|
|
|
-void CBonusSystemNode::getModifiersWDescr(TModDescr &out, Bonus::BonusType type, int subtype /*= -1 */) const
|
|
|
+void IBonusBearer::getModifiersWDescr(TModDescr &out, Bonus::BonusType type, int subtype /*= -1 */) const
|
|
|
{
|
|
|
getModifiersWDescr(out, subtype != -1 ? Selector::typeSybtype(type, subtype) : Selector::type(type));
|
|
|
}
|
|
|
|
|
|
-void CBonusSystemNode::getModifiersWDescr(TModDescr &out, const CSelector &selector) const
|
|
|
+void IBonusBearer::getModifiersWDescr(TModDescr &out, const CSelector &selector) const
|
|
|
{
|
|
|
getBonuses(selector).getModifiersWDescr(out);
|
|
|
}
|
|
|
-int CBonusSystemNode::getBonusesCount(int from, int id) const
|
|
|
+int IBonusBearer::getBonusesCount(int from, int id) const
|
|
|
{
|
|
|
return getBonusesCount(Selector::source(from, id));
|
|
|
}
|
|
|
|
|
|
-int CBonusSystemNode::getBonusesCount(const CSelector &selector) const
|
|
|
+int IBonusBearer::getBonusesCount(const CSelector &selector) const
|
|
|
{
|
|
|
return getBonuses(selector).size();
|
|
|
}
|
|
|
|
|
|
-void CBonusSystemNode::getParents(TCNodes &out) const /*retreives list of parent nodes (nodes to inherit bonuses from) */
|
|
|
-{
|
|
|
- BOOST_FOREACH(const CBonusSystemNode *parent, parents)
|
|
|
- out.insert(parent);
|
|
|
-}
|
|
|
-
|
|
|
-void CBonusSystemNode::getParents(TNodes &out)
|
|
|
-{
|
|
|
- BOOST_FOREACH(const CBonusSystemNode *parent, parents)
|
|
|
- out.insert(const_cast<CBonusSystemNode*>(parent));
|
|
|
-}
|
|
|
-
|
|
|
-void CBonusSystemNode::getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
+void IBonusBearer::getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
{
|
|
|
getBonuses(out, selector, 0, root);
|
|
|
// FOREACH_CONST_PARENT(p)
|
|
@@ -238,14 +205,14 @@ void CBonusSystemNode::getBonuses(BonusList &out, const CSelector &selector, con
|
|
|
// out.limit(*this);
|
|
|
}
|
|
|
|
|
|
-BonusList CBonusSystemNode::getBonuses(const CSelector &selector) const
|
|
|
+BonusList IBonusBearer::getBonuses(const CSelector &selector) const
|
|
|
{
|
|
|
BonusList ret;
|
|
|
getBonuses(ret, selector);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-void CBonusSystemNode::getBonuses(BonusList &out, const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
+void IBonusBearer::getBonuses(BonusList &out, const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
{
|
|
|
getAllBonuses(out, selector, limit, root);
|
|
|
out.eliminateDuplicates();
|
|
@@ -255,30 +222,19 @@ void CBonusSystemNode::getBonuses(BonusList &out, const CSelector &selector, con
|
|
|
// out.limit(*this); //apply bonuses' limiters
|
|
|
}
|
|
|
|
|
|
-BonusList CBonusSystemNode::getBonuses(const CSelector &selector, const CSelector &limit) const
|
|
|
+BonusList IBonusBearer::getBonuses(const CSelector &selector, const CSelector &limit) const
|
|
|
{
|
|
|
BonusList ret;
|
|
|
getBonuses(ret, selector, limit);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-void CBonusSystemNode::getAllBonuses(BonusList &out, const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
-{
|
|
|
- FOREACH_CONST_PARENT(p)
|
|
|
- p->getBonuses(out, selector, limit, root ? root : this);
|
|
|
-
|
|
|
- bonuses.getBonuses(out, selector, limit);
|
|
|
-
|
|
|
- if(!root)
|
|
|
- out.limit(*this);
|
|
|
-}
|
|
|
-
|
|
|
-bool CBonusSystemNode::hasBonusFrom(ui8 source, ui32 sourceID) const
|
|
|
+bool IBonusBearer::hasBonusFrom(ui8 source, ui32 sourceID) const
|
|
|
{
|
|
|
return hasBonus(Selector::source(source,sourceID));
|
|
|
}
|
|
|
|
|
|
-int CBonusSystemNode::MoraleVal() const
|
|
|
+int IBonusBearer::MoraleVal() const
|
|
|
{
|
|
|
if(hasBonusOfType(Bonus::NON_LIVING) || hasBonusOfType(Bonus::UNDEAD) ||
|
|
|
hasBonusOfType(Bonus::NO_MORALE) || hasBonusOfType(Bonus::SIEGE_WEAPON))
|
|
@@ -292,7 +248,7 @@ int CBonusSystemNode::MoraleVal() const
|
|
|
return abetw(ret, -3, +3);
|
|
|
}
|
|
|
|
|
|
-int CBonusSystemNode::LuckVal() const
|
|
|
+int IBonusBearer::LuckVal() const
|
|
|
{
|
|
|
if(hasBonusOfType(Bonus::NO_LUCK))
|
|
|
return 0;
|
|
@@ -305,7 +261,7 @@ int CBonusSystemNode::LuckVal() const
|
|
|
return abetw(ret, -3, +3);
|
|
|
}
|
|
|
|
|
|
-si32 CBonusSystemNode::Attack() const
|
|
|
+si32 IBonusBearer::Attack() const
|
|
|
{
|
|
|
si32 ret = valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK);
|
|
|
|
|
@@ -317,7 +273,7 @@ si32 CBonusSystemNode::Attack() const
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-si32 CBonusSystemNode::Defense(bool withFrenzy /*= true*/) const
|
|
|
+si32 IBonusBearer::Defense(bool withFrenzy /*= true*/) const
|
|
|
{
|
|
|
si32 ret = valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE);
|
|
|
|
|
@@ -329,20 +285,83 @@ si32 CBonusSystemNode::Defense(bool withFrenzy /*= true*/) const
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-ui16 CBonusSystemNode::MaxHealth() const
|
|
|
+ui16 IBonusBearer::MaxHealth() const
|
|
|
{
|
|
|
return valOfBonuses(Bonus::STACK_HEALTH);
|
|
|
}
|
|
|
|
|
|
-ui32 CBonusSystemNode::getMinDamage() const
|
|
|
+ui32 IBonusBearer::getMinDamage() const
|
|
|
{
|
|
|
return valOfBonuses(Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 1));
|
|
|
}
|
|
|
-ui32 CBonusSystemNode::getMaxDamage() const
|
|
|
+ui32 IBonusBearer::getMaxDamage() const
|
|
|
{
|
|
|
return valOfBonuses(Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 0) || Selector::typeSybtype(Bonus::CREATURE_DAMAGE, 2));
|
|
|
}
|
|
|
|
|
|
+si32 IBonusBearer::manaLimit() const
|
|
|
+{
|
|
|
+ return si32(getPrimSkillLevel(3) * (100.0f + valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, 24)) / 10.0f);
|
|
|
+}
|
|
|
+
|
|
|
+int IBonusBearer::getPrimSkillLevel(int id) const
|
|
|
+{
|
|
|
+ int ret = 0;
|
|
|
+ if(id == PrimarySkill::ATTACK)
|
|
|
+ ret = Attack();
|
|
|
+ else if(id == PrimarySkill::DEFENSE)
|
|
|
+ ret = Defense();
|
|
|
+ else
|
|
|
+ ret = valOfBonuses(Bonus::PRIMARY_SKILL, id);
|
|
|
+
|
|
|
+ amax(ret, id/2); //minimal value is 0 for attack and defense and 1 for spell power and knowledge
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+Bonus * CBonusSystemNode::getBonus(const CSelector &selector)
|
|
|
+{
|
|
|
+ Bonus *ret = bonuses.getFirst(selector);
|
|
|
+ if(ret)
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ FOREACH_PARENT(pname)
|
|
|
+ {
|
|
|
+ ret = pname->getBonus(selector);
|
|
|
+ if (ret)
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
+const Bonus * CBonusSystemNode::getBonus( const CSelector &selector ) const
|
|
|
+{
|
|
|
+ return (const_cast<CBonusSystemNode*>(this))->getBonus(selector);
|
|
|
+}
|
|
|
+
|
|
|
+void CBonusSystemNode::getParents(TCNodes &out) const /*retreives list of parent nodes (nodes to inherit bonuses from) */
|
|
|
+{
|
|
|
+ BOOST_FOREACH(const CBonusSystemNode *parent, parents)
|
|
|
+ out.insert(parent);
|
|
|
+}
|
|
|
+
|
|
|
+void CBonusSystemNode::getParents(TNodes &out)
|
|
|
+{
|
|
|
+ BOOST_FOREACH(const CBonusSystemNode *parent, parents)
|
|
|
+ out.insert(const_cast<CBonusSystemNode*>(parent));
|
|
|
+}
|
|
|
+
|
|
|
+void CBonusSystemNode::getAllBonuses(BonusList &out, const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root /*= NULL*/) const
|
|
|
+{
|
|
|
+ FOREACH_CONST_PARENT(p)
|
|
|
+ p->getBonuses(out, selector, limit, root ? root : this);
|
|
|
+
|
|
|
+ bonuses.getBonuses(out, selector, limit);
|
|
|
+
|
|
|
+ if(!root)
|
|
|
+ out.limit(*this);
|
|
|
+}
|
|
|
+
|
|
|
CBonusSystemNode::CBonusSystemNode()
|
|
|
{
|
|
|
nodeType = UNKNOWN;
|