forked from teamnwah/openmw-tes3coop
Issue #256: added MagicEffects::add overload for EffectLists
This commit is contained in:
parent
e56ff9283d
commit
e1997b7f04
3 changed files with 23 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "magiceffects.hpp"
|
#include "magiceffects.hpp"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <components/esm/defs.hpp>
|
#include <components/esm/defs.hpp>
|
||||||
|
@ -66,6 +68,23 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MagicEffects::add (const ESM::EffectList& list)
|
||||||
|
{
|
||||||
|
for (std::vector<ESM::ENAMstruct>::const_iterator iter (list.list.begin()); iter!=list.list.end();
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
EffectParam param;
|
||||||
|
|
||||||
|
if (iter->magnMin>=iter->magnMax)
|
||||||
|
param.mMagnitude = iter->magnMin;
|
||||||
|
else
|
||||||
|
param.mMagnitude = static_cast<int> (
|
||||||
|
(iter->magnMax-iter->magnMin+1)*(std::rand() / RAND_MAX) + iter->magnMin);
|
||||||
|
|
||||||
|
add (*iter, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EffectParam MagicEffects::get (const EffectKey& key) const
|
EffectParam MagicEffects::get (const EffectKey& key) const
|
||||||
{
|
{
|
||||||
Collection::const_iterator iter = mCollection.find (key);
|
Collection::const_iterator iter = mCollection.find (key);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
struct ENAMstruct;
|
struct ENAMstruct;
|
||||||
|
struct EffectList;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
|
@ -66,6 +67,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
void add (const EffectKey& key, const EffectParam& param);
|
void add (const EffectKey& key, const EffectParam& param);
|
||||||
|
|
||||||
|
void add (const ESM::EffectList& list);
|
||||||
|
|
||||||
EffectParam get (const EffectKey& key) const;
|
EffectParam get (const EffectKey& key) const;
|
||||||
///< This function can safely be used for keys that are not present.
|
///< This function can safely be used for keys that are not present.
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,7 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
void Spells::addSpell (const ESM::Spell *spell, MagicEffects& effects) const
|
void Spells::addSpell (const ESM::Spell *spell, MagicEffects& effects) const
|
||||||
{
|
{
|
||||||
for (std::vector<ESM::ENAMstruct>::const_iterator iter = spell->effects.list.begin();
|
effects.add (spell->effects);
|
||||||
iter!=spell->effects.list.end(); ++iter)
|
|
||||||
{
|
|
||||||
EffectParam param;
|
|
||||||
param.mMagnitude = iter->magnMax; /// \todo calculate magnitude
|
|
||||||
effects.add (EffectKey (*iter), param);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spells::TIterator Spells::begin() const
|
Spells::TIterator Spells::begin() const
|
||||||
|
|
Loading…
Reference in a new issue