2012-04-11 16:29:36 +00:00
|
|
|
|
|
|
|
#include "spells.hpp"
|
|
|
|
|
2013-01-13 13:52:55 +00:00
|
|
|
#include <cstdlib>
|
2012-07-03 10:30:50 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
#include <components/esm/loadspel.hpp>
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2013-01-13 13:52:55 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2012-04-11 16:29:36 +00:00
|
|
|
#include "magiceffects.hpp"
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2012-04-11 17:40:42 +00:00
|
|
|
Spells::TIterator Spells::begin() const
|
2012-04-11 16:29:36 +00:00
|
|
|
{
|
2012-04-11 17:40:42 +00:00
|
|
|
return mSpells.begin();
|
2012-04-11 16:29:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
Spells::TIterator Spells::end() const
|
2012-04-11 16:29:36 +00:00
|
|
|
{
|
2012-04-11 17:40:42 +00:00
|
|
|
return mSpells.end();
|
2012-04-11 16:29:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
void Spells::add (const std::string& spellId)
|
2012-04-11 16:29:36 +00:00
|
|
|
{
|
2013-01-12 12:10:20 +00:00
|
|
|
if (mSpells.find (spellId)==mSpells.end())
|
2013-01-13 13:52:55 +00:00
|
|
|
mSpells.insert (std::make_pair (spellId, static_cast<float> (std::rand()) / RAND_MAX));
|
2012-04-11 16:29:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
void Spells::remove (const std::string& spellId)
|
2012-04-11 16:29:36 +00:00
|
|
|
{
|
2013-01-12 12:10:20 +00:00
|
|
|
TContainer::iterator iter = mSpells.find (spellId);
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
if (iter!=mSpells.end())
|
|
|
|
mSpells.erase (iter);
|
2012-04-13 08:49:45 +00:00
|
|
|
|
|
|
|
if (spellId==mSelectedSpell)
|
|
|
|
mSelectedSpell.clear();
|
2012-04-11 16:29:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
MagicEffects Spells::getMagicEffects() const
|
2012-04-11 16:29:36 +00:00
|
|
|
{
|
|
|
|
MagicEffects effects;
|
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter)
|
|
|
|
{
|
2012-11-06 10:44:56 +00:00
|
|
|
const ESM::Spell *spell =
|
2013-01-12 12:10:20 +00:00
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
2012-04-11 17:40:42 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
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)
|
2013-01-13 13:52:55 +00:00
|
|
|
effects.add (spell->mEffects, iter->second);
|
2012-04-11 17:40:42 +00:00
|
|
|
}
|
2012-04-11 16:29:36 +00:00
|
|
|
|
|
|
|
return effects;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spells::clear()
|
|
|
|
{
|
2012-04-11 17:40:42 +00:00
|
|
|
mSpells.clear();
|
2012-04-11 16:29:36 +00:00
|
|
|
}
|
2012-04-13 08:49:45 +00:00
|
|
|
|
|
|
|
void Spells::setSelectedSpell (const std::string& spellId)
|
|
|
|
{
|
|
|
|
mSelectedSpell = spellId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string Spells::getSelectedSpell() const
|
|
|
|
{
|
|
|
|
return mSelectedSpell;
|
|
|
|
}
|
2013-01-12 12:10:20 +00:00
|
|
|
|
2012-11-09 17:16:29 +00:00
|
|
|
bool Spells::hasCommonDisease() const
|
|
|
|
{
|
|
|
|
for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter)
|
|
|
|
{
|
|
|
|
const ESM::Spell *spell =
|
2013-01-12 12:10:20 +00:00
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
|
|
|
|
2013-04-14 15:51:17 +00:00
|
|
|
if (spell->mData.mType == ESM::Spell::ST_Disease)
|
2012-11-09 17:16:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-12 12:10:20 +00:00
|
|
|
|
2012-11-09 17:16:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Spells::hasBlightDisease() const
|
|
|
|
{
|
|
|
|
for (TIterator iter = mSpells.begin(); iter!=mSpells.end(); ++iter)
|
|
|
|
{
|
|
|
|
const ESM::Spell *spell =
|
2013-01-12 12:10:20 +00:00
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
|
|
|
|
2013-04-14 15:51:17 +00:00
|
|
|
if (spell->mData.mType == ESM::Spell::ST_Blight)
|
2012-11-09 17:16:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-12 12:10:20 +00:00
|
|
|
|
|
|
|
return false;
|
2012-11-09 17:16:29 +00:00
|
|
|
}
|
2012-04-11 16:29:36 +00:00
|
|
|
}
|