2012-04-11 16:29:36 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_SPELLS_H
|
|
|
|
#define GAME_MWMECHANICS_SPELLS_H
|
|
|
|
|
2013-01-12 12:10:20 +00:00
|
|
|
#include <map>
|
2012-04-11 17:40:42 +00:00
|
|
|
#include <string>
|
2016-07-01 16:50:28 +00:00
|
|
|
#include <set>
|
2012-04-11 17:40:42 +00:00
|
|
|
|
2014-02-23 19:11:05 +00:00
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
2013-11-13 14:44:43 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2014-05-12 19:04:02 +00:00
|
|
|
#include "../mwworld/timestamp.hpp"
|
2013-11-13 14:44:43 +00:00
|
|
|
|
2013-11-15 19:29:47 +00:00
|
|
|
#include "magiceffects.hpp"
|
|
|
|
|
2014-05-12 19:04:02 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
struct Spell;
|
2014-05-12 19:04:02 +00:00
|
|
|
|
|
|
|
struct SpellState;
|
2012-04-11 17:40:42 +00:00
|
|
|
}
|
2012-04-11 16:29:36 +00:00
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2019-09-30 16:27:42 +00:00
|
|
|
class CreatureStats;
|
|
|
|
|
2012-04-11 16:29:36 +00:00
|
|
|
class MagicEffects;
|
|
|
|
|
|
|
|
/// \brief Spell list
|
|
|
|
///
|
|
|
|
/// This class manages known spells as well as abilities, powers and permanent negative effects like
|
2014-05-12 19:04:02 +00:00
|
|
|
/// diseases. It also keeps track of used powers (which can only be used every 24h).
|
2012-04-11 16:29:36 +00:00
|
|
|
class Spells
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-11-27 00:02:29 +00:00
|
|
|
typedef const ESM::Spell* SpellKey;
|
2019-09-30 16:27:42 +00:00
|
|
|
struct SpellParams
|
|
|
|
{
|
2016-07-01 16:50:28 +00:00
|
|
|
std::map<int, float> mEffectRands; // <effect index, normalised random magnitude>
|
|
|
|
std::set<int> mPurgedEffects; // indices of purged effects
|
|
|
|
};
|
2015-11-27 00:02:29 +00:00
|
|
|
|
2016-07-01 16:50:28 +00:00
|
|
|
typedef std::map<SpellKey, SpellParams> TContainer;
|
2012-04-11 16:29:36 +00:00
|
|
|
typedef TContainer::const_iterator TIterator;
|
|
|
|
|
|
|
|
private:
|
2013-01-12 12:10:20 +00:00
|
|
|
TContainer mSpells;
|
2014-05-12 19:04:02 +00:00
|
|
|
|
|
|
|
// Note: this is the spell that's about to be cast, *not* the spell selected in the GUI (which may be different)
|
2012-04-13 08:49:45 +00:00
|
|
|
std::string mSelectedSpell;
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2015-11-27 00:02:29 +00:00
|
|
|
std::map<SpellKey, MWWorld::TimeStamp> mUsedPowers;
|
|
|
|
|
2016-07-02 10:50:00 +00:00
|
|
|
mutable bool mSpellsChanged;
|
|
|
|
mutable MagicEffects mEffects;
|
|
|
|
mutable std::map<SpellKey, MagicEffects> mSourcedEffects;
|
|
|
|
void rebuildEffects() const;
|
|
|
|
|
2015-11-27 00:02:29 +00:00
|
|
|
/// Get spell from ID, throws exception if not found
|
|
|
|
const ESM::Spell* getSpell(const std::string& id) const;
|
2014-08-18 13:33:12 +00:00
|
|
|
|
2014-08-20 10:40:38 +00:00
|
|
|
public:
|
2016-07-02 10:50:00 +00:00
|
|
|
Spells();
|
2014-08-18 13:33:12 +00:00
|
|
|
|
2014-08-19 01:17:31 +00:00
|
|
|
static bool hasCorprusEffect(const ESM::Spell *spell);
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2016-07-01 16:50:28 +00:00
|
|
|
void purgeEffect(int effectId);
|
|
|
|
void purgeEffect(int effectId, const std::string & sourceId);
|
|
|
|
|
2015-11-27 00:02:29 +00:00
|
|
|
bool canUsePower (const ESM::Spell* spell) const;
|
|
|
|
void usePower (const ESM::Spell* spell);
|
2014-05-12 19:04:02 +00:00
|
|
|
|
2013-11-17 22:15:57 +00:00
|
|
|
void purgeCommonDisease();
|
|
|
|
void purgeBlightDisease();
|
|
|
|
void purgeCorprusDisease();
|
|
|
|
void purgeCurses();
|
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
TIterator begin() const;
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
TIterator end() const;
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2015-11-27 00:02:29 +00:00
|
|
|
bool hasSpell(const std::string& spell) const;
|
|
|
|
bool hasSpell(const ESM::Spell* spell) const;
|
2014-01-17 12:13:58 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
void add (const std::string& spell);
|
2012-04-13 08:49:45 +00:00
|
|
|
///< Adding a spell that is already listed in *this is a no-op.
|
2014-12-14 00:53:15 +00:00
|
|
|
|
|
|
|
void add (const ESM::Spell* spell);
|
|
|
|
///< Adding a spell that is already listed in *this is a no-op.
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
void remove (const std::string& spell);
|
2012-04-13 08:49:45 +00:00
|
|
|
///< If the spell to be removed is the selected spell, the selected spell will be changed to
|
|
|
|
/// no spell (empty string).
|
2012-04-11 16:29:36 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
MagicEffects getMagicEffects() const;
|
2012-04-11 16:29:36 +00:00
|
|
|
///< Return sum of magic effects resulting from abilities, blights, deseases and curses.
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
///< Remove all spells of al types.
|
2012-04-13 08:49:45 +00:00
|
|
|
|
|
|
|
void setSelectedSpell (const std::string& spellId);
|
|
|
|
///< This function does not verify, if the spell is available.
|
|
|
|
|
|
|
|
const std::string getSelectedSpell() const;
|
|
|
|
///< May return an empty string.
|
2013-01-12 12:10:20 +00:00
|
|
|
|
2015-05-10 11:04:50 +00:00
|
|
|
bool isSpellActive(const std::string& id) const;
|
|
|
|
///< Are we under the effects of the given spell ID?
|
|
|
|
|
2012-11-09 17:16:29 +00:00
|
|
|
bool hasCommonDisease() const;
|
|
|
|
|
2013-01-12 12:10:20 +00:00
|
|
|
bool hasBlightDisease() const;
|
2013-11-15 19:29:47 +00:00
|
|
|
|
2018-08-26 23:17:49 +00:00
|
|
|
void removeEffects(const std::string& id);
|
|
|
|
|
2013-11-15 19:29:47 +00:00
|
|
|
void visitEffectSources (MWMechanics::EffectSourceVisitor& visitor) const;
|
2014-05-12 19:04:02 +00:00
|
|
|
|
2019-09-30 16:27:42 +00:00
|
|
|
void readState (const ESM::SpellState& state, CreatureStats* creatureStats);
|
2014-05-12 19:04:02 +00:00
|
|
|
void writeState (ESM::SpellState& state) const;
|
2012-04-11 16:29:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|