mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Issue #256: added MagicEffects::add overload for EffectLists
This commit is contained in:
parent
e56ff9283d
commit
e1997b7f04
@ -1,6 +1,8 @@
|
||||
|
||||
#include "magiceffects.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#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
|
||||
{
|
||||
Collection::const_iterator iter = mCollection.find (key);
|
||||
|
@ -6,6 +6,7 @@
|
||||
namespace ESM
|
||||
{
|
||||
struct ENAMstruct;
|
||||
struct EffectList;
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
@ -66,6 +67,8 @@ namespace MWMechanics
|
||||
|
||||
void add (const EffectKey& key, const EffectParam& param);
|
||||
|
||||
void add (const ESM::EffectList& list);
|
||||
|
||||
EffectParam get (const EffectKey& key) const;
|
||||
///< 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
|
||||
{
|
||||
for (std::vector<ESM::ENAMstruct>::const_iterator iter = spell->effects.list.begin();
|
||||
iter!=spell->effects.list.end(); ++iter)
|
||||
{
|
||||
EffectParam param;
|
||||
param.mMagnitude = iter->magnMax; /// \todo calculate magnitude
|
||||
effects.add (EffectKey (*iter), param);
|
||||
}
|
||||
effects.add (spell->effects);
|
||||
}
|
||||
|
||||
Spells::TIterator Spells::begin() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user