1
0
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:
Marc Zinnschlag 2012-05-18 13:17:35 +02:00
parent e56ff9283d
commit e1997b7f04
3 changed files with 23 additions and 7 deletions

View File

@ -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);

View File

@ -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.

View File

@ -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