mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
simplifying Spells class
This commit is contained in:
parent
e04ccfced0
commit
77065390d7
3 changed files with 37 additions and 44 deletions
|
@ -71,7 +71,7 @@ namespace MWMechanics
|
|||
for (std::vector<std::string>::const_iterator iter (race->powers.list.begin());
|
||||
iter!=race->powers.list.end(); ++iter)
|
||||
{
|
||||
creatureStats.mSpells.add (*iter, mEnvironment);
|
||||
creatureStats.mSpells.add (*iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ namespace MWMechanics
|
|||
for (std::vector<std::string>::const_iterator iter (sign->powers.list.begin());
|
||||
iter!=sign->powers.list.end(); ++iter)
|
||||
{
|
||||
creatureStats.mSpells.add (*iter, mEnvironment);
|
||||
creatureStats.mSpells.add (*iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "spells.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <components/esm/loadspel.hpp>
|
||||
|
||||
#include "../mwworld/environment.hpp"
|
||||
#include "../mwworld/world.hpp"
|
||||
|
@ -21,57 +21,48 @@ namespace MWMechanics
|
|||
}
|
||||
}
|
||||
|
||||
Spells::TIterator Spells::begin (ESM::Spell::SpellType type) const
|
||||
Spells::TIterator Spells::begin() const
|
||||
{
|
||||
assert (type>=0 && type<sTypes);
|
||||
return mSpells[type].begin();
|
||||
return mSpells.begin();
|
||||
}
|
||||
|
||||
Spells::TIterator Spells::end (ESM::Spell::SpellType type) const
|
||||
Spells::TIterator Spells::end() const
|
||||
{
|
||||
assert (type>=0 && type<sTypes);
|
||||
return mSpells[type].end();
|
||||
return mSpells.end();
|
||||
}
|
||||
|
||||
void Spells::add (const std::string& spellId, MWWorld::Environment& environment)
|
||||
void Spells::add (const std::string& spellId)
|
||||
{
|
||||
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);
|
||||
if (std::find (mSpells.begin(), mSpells.end(), spellId)!=mSpells.end())
|
||||
mSpells.push_back (spellId);
|
||||
}
|
||||
|
||||
void Spells::remove (const std::string& spellId, MWWorld::Environment& environment)
|
||||
void Spells::remove (const std::string& spellId)
|
||||
{
|
||||
const ESM::Spell *spell = environment.mWorld->getStore().spells.find (spellId);
|
||||
TContainer::iterator iter = std::find (mSpells.begin(), mSpells.end(), 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);
|
||||
if (iter!=mSpells.end())
|
||||
mSpells.erase (iter);
|
||||
}
|
||||
|
||||
MagicEffects Spells::getMagicEffects (MWWorld::Environment& environment) const
|
||||
MagicEffects Spells::getMagicEffects (const 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);
|
||||
for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter)
|
||||
{
|
||||
const ESM::Spell *spell = environment.mWorld->getStore().spells.find (*iter);
|
||||
|
||||
if (spell->data.type==ESM::Spell::ST_Ability || spell->data.type==ESM::Spell::ST_Blight ||
|
||||
spell->data.type==ESM::Spell::ST_Disease || spell->data.type==ESM::Spell::ST_Curse)
|
||||
addSpell (spell, effects);
|
||||
}
|
||||
|
||||
return effects;
|
||||
}
|
||||
|
||||
void Spells::clear()
|
||||
{
|
||||
for (int i=0; i<sTypes; ++i)
|
||||
mSpells[i].clear();
|
||||
mSpells.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#ifndef GAME_MWMECHANICS_SPELLS_H
|
||||
#define GAME_MWMECHANICS_SPELLS_H
|
||||
|
||||
#include <components/esm/loadspel.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
struct Spell;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
|
@ -22,29 +26,27 @@ namespace MWMechanics
|
|||
{
|
||||
public:
|
||||
|
||||
typedef std::vector<const ESM::Spell *> TContainer;
|
||||
typedef std::vector<std::string> TContainer;
|
||||
typedef TContainer::const_iterator TIterator;
|
||||
|
||||
private:
|
||||
|
||||
static const int sTypes = 6;
|
||||
|
||||
std::vector<const ESM::Spell *> mSpells[sTypes];
|
||||
std::vector<std::string> mSpells;
|
||||
|
||||
void addSpell (const ESM::Spell *, MagicEffects& effects) const;
|
||||
|
||||
public:
|
||||
|
||||
TIterator begin (ESM::Spell::SpellType type) const;
|
||||
TIterator begin() const;
|
||||
|
||||
TIterator end (ESM::Spell::SpellType type) const;
|
||||
TIterator end() const;
|
||||
|
||||
void add (const std::string& spell, MWWorld::Environment& environment);
|
||||
void add (const std::string& spell);
|
||||
/// \note Adding a spell that is already listed in *this is a no-op.
|
||||
|
||||
void remove (const std::string& spell, MWWorld::Environment& environment);
|
||||
void remove (const std::string& spell);
|
||||
|
||||
MagicEffects getMagicEffects (MWWorld::Environment& environment) const;
|
||||
MagicEffects getMagicEffects (const MWWorld::Environment& environment) const;
|
||||
///< Return sum of magic effects resulting from abilities, blights, deseases and curses.
|
||||
|
||||
void clear();
|
||||
|
|
Loading…
Reference in a new issue