2012-04-11 16:29:36 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_SPELLS_H
|
|
|
|
#define GAME_MWMECHANICS_SPELLS_H
|
|
|
|
|
2020-07-28 06:33:28 +00:00
|
|
|
#include <memory>
|
2013-01-12 12:10:20 +00:00
|
|
|
#include <map>
|
2012-04-11 17:40:42 +00:00
|
|
|
#include <string>
|
2020-07-28 06:33:28 +00:00
|
|
|
#include <vector>
|
2012-04-11 17:40:42 +00:00
|
|
|
|
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"
|
2020-07-28 06:33:28 +00:00
|
|
|
#include "spelllist.hpp"
|
2014-05-12 19:04:02 +00:00
|
|
|
|
2012-04-11 17:40:42 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
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
|
|
|
|
{
|
2020-07-28 06:33:28 +00:00
|
|
|
std::shared_ptr<SpellList> mSpellList;
|
|
|
|
std::map<const ESM::Spell*, SpellParams> 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
|
|
|
|
2020-07-28 06:33:28 +00:00
|
|
|
std::map<const ESM::Spell*, MWWorld::TimeStamp> mUsedPowers;
|
2015-11-27 00:02:29 +00:00
|
|
|
|
2016-07-02 10:50:00 +00:00
|
|
|
mutable bool mSpellsChanged;
|
|
|
|
mutable MagicEffects mEffects;
|
2020-07-28 06:33:28 +00:00
|
|
|
mutable std::map<const ESM::Spell*, MagicEffects> mSourcedEffects;
|
2016-07-02 10:50:00 +00:00
|
|
|
void rebuildEffects() const;
|
|
|
|
|
2020-07-28 06:33:28 +00:00
|
|
|
bool hasDisease(const ESM::Spell::SpellType type) const;
|
2014-08-18 13:33:12 +00:00
|
|
|
|
2020-07-28 06:33:28 +00:00
|
|
|
using SpellFilter = bool (*)(const ESM::Spell*);
|
|
|
|
void purge(const SpellFilter& filter);
|
|
|
|
|
|
|
|
void addSpell(const ESM::Spell* spell);
|
|
|
|
void removeSpell(const ESM::Spell* spell);
|
|
|
|
void removeAllSpells();
|
|
|
|
|
|
|
|
friend class SpellList;
|
2014-08-20 10:40:38 +00:00
|
|
|
public:
|
2020-07-28 06:33:28 +00:00
|
|
|
using TIterator = std::map<const ESM::Spell*, SpellParams>::const_iterator;
|
|
|
|
|
2016-07-02 10:50:00 +00:00
|
|
|
Spells();
|
2014-08-18 13:33:12 +00:00
|
|
|
|
2021-03-14 18:32:03 +00:00
|
|
|
Spells(const Spells&);
|
|
|
|
|
2021-04-23 21:48:55 +00:00
|
|
|
Spells(Spells&& spells);
|
2021-03-14 18:32:03 +00:00
|
|
|
|
2020-07-28 06:33:28 +00:00
|
|
|
~Spells();
|
|
|
|
|
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.
|
|
|
|
|
2020-07-28 06:33:28 +00:00
|
|
|
void clear(bool modifyBase = false);
|
2012-04-11 16:29:36 +00:00
|
|
|
///< 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;
|
2020-07-28 06:33:28 +00:00
|
|
|
|
|
|
|
bool setSpells(const std::string& id);
|
|
|
|
|
|
|
|
void addAllToInstance(const std::vector<std::string>& spells);
|
2012-04-11 16:29:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|