added spell container class
parent
c94d683014
commit
750d79eaf0
@ -0,0 +1,77 @@
|
||||
|
||||
#include "spells.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "../mwworld/environment.hpp"
|
||||
#include "../mwworld/world.hpp"
|
||||
|
||||
#include "magiceffects.hpp"
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Spells::TIterator Spells::begin (ESM::Spell::SpellType type) const
|
||||
{
|
||||
assert (type>=0 && type<sTypes);
|
||||
return mSpells[type].begin();
|
||||
}
|
||||
|
||||
Spells::TIterator Spells::end (ESM::Spell::SpellType type) const
|
||||
{
|
||||
assert (type>=0 && type<sTypes);
|
||||
return mSpells[type].end();
|
||||
}
|
||||
|
||||
void Spells::add (const std::string& spellId, MWWorld::Environment& environment)
|
||||
{
|
||||
const ESM::Spell *spell = environment.mWorld->getStore().spells.find (spellId);
|
||||
|
||||
int type = spell->data.type;
|
||||
|
||||
assert (type>=0 && type<sTypes);
|
||||
|
||||
if (std::find (mSpells[type].begin(), mSpells[type].end(), spell)!=mSpells[type].end())
|
||||
mSpells[type].push_back (spell);
|
||||
}
|
||||
|
||||
void Spells::remove (const std::string& spellId, MWWorld::Environment& environment)
|
||||
{
|
||||
const ESM::Spell *spell = environment.mWorld->getStore().spells.find (spellId);
|
||||
|
||||
int type = spell->data.type;
|
||||
|
||||
TContainer::iterator iter = std::find (mSpells[type].begin(), mSpells[type].end(), spell);
|
||||
|
||||
if (iter!=mSpells[type].end())
|
||||
mSpells[type].erase (iter);
|
||||
}
|
||||
|
||||
MagicEffects Spells::getMagicEffects (MWWorld::Environment& environment) const
|
||||
{
|
||||
MagicEffects effects;
|
||||
|
||||
for (int i=ESM::Spell::ST_Ability; i<=ESM::Spell::ST_Curse; ++i)
|
||||
for (TIterator iter (begin (static_cast<ESM::Spell::SpellType> (i)));
|
||||
iter!=end(static_cast<ESM::Spell::SpellType> (i)); ++iter)
|
||||
addSpell (*iter, effects);
|
||||
|
||||
return effects;
|
||||
}
|
||||
|
||||
void Spells::clear()
|
||||
{
|
||||
for (int i=0; i<sTypes; ++i)
|
||||
mSpells[i].clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
#ifndef GAME_MWMECHANICS_SPELLS_H
|
||||
#define GAME_MWMECHANICS_SPELLS_H
|
||||
|
||||
#include <components/esm/loadspel.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
struct Environment;
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
class MagicEffects;
|
||||
|
||||
/// \brief Spell list
|
||||
///
|
||||
/// This class manages known spells as well as abilities, powers and permanent negative effects like
|
||||
/// diseaes.
|
||||
class Spells
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<const ESM::Spell *> TContainer;
|
||||
typedef TContainer::const_iterator TIterator;
|
||||
|
||||
private:
|
||||
|
||||
static const int sTypes = 6;
|
||||
|
||||
std::vector<const ESM::Spell *> mSpells[sTypes];
|
||||
|
||||
void addSpell (const ESM::Spell *, MagicEffects& effects) const;
|
||||
|
||||
public:
|
||||
|
||||
TIterator begin (ESM::Spell::SpellType type) const;
|
||||
|
||||
TIterator end (ESM::Spell::SpellType type) const;
|
||||
|
||||
void add (const std::string& spell, MWWorld::Environment& environment);
|
||||
/// \note Adding a spell that is already listed in *this is a no-op.
|
||||
|
||||
void remove (const std::string& spell, MWWorld::Environment& environment);
|
||||
|
||||
MagicEffects getMagicEffects (MWWorld::Environment& environment) const;
|
||||
///< Return sum of magic effects resulting from abilities, blights, deseases and curses.
|
||||
|
||||
void clear();
|
||||
///< Remove all spells of al types.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue