Issue #479: Use magnitude specified when adding disease

actorid
Marc Zinnschlag 12 years ago
parent f4ee8e2642
commit 654cd3ab9b

@ -68,7 +68,7 @@ namespace MWMechanics
}
}
void MagicEffects::add (const ESM::EffectList& list)
void MagicEffects::add (const ESM::EffectList& list, float magnitude)
{
for (std::vector<ESM::ENAMstruct>::const_iterator iter (list.mList.begin()); iter!=list.mList.end();
++iter)
@ -78,9 +78,13 @@ namespace MWMechanics
if (iter->mMagnMin>=iter->mMagnMax)
param.mMagnitude = iter->mMagnMin;
else
{
if (magnitude==-1)
magnitude = static_cast<float> (std::rand()) / RAND_MAX;
param.mMagnitude = static_cast<int> (
(iter->mMagnMax-iter->mMagnMin+1)*
(static_cast<float> (std::rand()) / RAND_MAX) + iter->mMagnMin);
(iter->mMagnMax-iter->mMagnMin+1)*magnitude + iter->mMagnMin);
}
add (*iter, param);
}

@ -67,7 +67,8 @@ namespace MWMechanics
void add (const EffectKey& key, const EffectParam& param);
void add (const ESM::EffectList& list);
void add (const ESM::EffectList& list, float magnitude = -1);
///< \param magnitude normalised magnitude (-1: random)
MagicEffects& operator+= (const MagicEffects& effects);

@ -1,22 +1,19 @@
#include "spells.hpp"
#include "../mwworld/esmstore.hpp"
#include <cstdlib>
#include <components/esm/loadspel.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/esmstore.hpp"
#include "magiceffects.hpp"
namespace MWMechanics
{
void Spells::addSpell (const ESM::Spell *spell, MagicEffects& effects) const
{
effects.add (spell->mEffects);
}
Spells::TIterator Spells::begin() const
{
return mSpells.begin();
@ -30,7 +27,7 @@ namespace MWMechanics
void Spells::add (const std::string& spellId)
{
if (mSpells.find (spellId)==mSpells.end())
mSpells.insert (std::make_pair (spellId, -1));
mSpells.insert (std::make_pair (spellId, static_cast<float> (std::rand()) / RAND_MAX));
}
void Spells::remove (const std::string& spellId)
@ -55,7 +52,7 @@ namespace MWMechanics
if (spell->mData.mType==ESM::Spell::ST_Ability || spell->mData.mType==ESM::Spell::ST_Blight ||
spell->mData.mType==ESM::Spell::ST_Disease || spell->mData.mType==ESM::Spell::ST_Curse)
addSpell (spell, effects);
effects.add (spell->mEffects, iter->second);
}
return effects;

@ -21,7 +21,7 @@ namespace MWMechanics
{
public:
typedef std::map<std::string, float> TContainer; // ID, magnitude
typedef std::map<std::string, float> TContainer; // ID, normalised magnitude
typedef TContainer::const_iterator TIterator;
private:
@ -29,8 +29,6 @@ namespace MWMechanics
TContainer mSpells;
std::string mSelectedSpell;
void addSpell (const ESM::Spell *, MagicEffects& effects) const;
public:
TIterator begin() const;

Loading…
Cancel
Save