2012-05-19 15:01:07 +02:00
|
|
|
#ifndef GAME_MWMECHANICS_ACTIVESPELLS_H
|
|
|
|
#define GAME_MWMECHANICS_ACTIVESPELLS_H
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <list>
|
|
|
|
#include <queue>
|
2012-05-19 15:01:07 +02:00
|
|
|
#include <string>
|
2021-08-27 20:07:50 +02:00
|
|
|
#include <variant>
|
|
|
|
#include <vector>
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/activespells.hpp>
|
2016-06-17 23:07:16 +09:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2012-05-19 15:01:07 +02:00
|
|
|
#include "../mwworld/timestamp.hpp"
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "spellcasting.hpp"
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
struct Enchantment;
|
|
|
|
struct Spell;
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
/// \brief Lasting spell effects
|
2012-06-24 11:39:21 +02:00
|
|
|
///
|
2021-08-27 20:07:50 +02:00
|
|
|
/// \note The name of this class is slightly misleading, since it also handles lasting potion
|
2012-06-24 11:39:21 +02:00
|
|
|
/// effects.
|
2012-05-19 15:01:07 +02:00
|
|
|
class ActiveSpells
|
|
|
|
{
|
|
|
|
public:
|
2021-08-27 20:07:50 +02:00
|
|
|
using ActiveEffect = ESM::ActiveEffect;
|
|
|
|
class ActiveSpellParams
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
ESM::RefId mActiveSpellId;
|
|
|
|
ESM::RefId mSourceSpellId;
|
2021-08-27 20:07:50 +02:00
|
|
|
std::vector<ActiveEffect> mEffects;
|
|
|
|
std::string mDisplayName;
|
|
|
|
int mCasterActorId;
|
2023-07-25 21:23:59 +00:00
|
|
|
ESM::RefNum mItem;
|
2024-03-25 13:50:23 +00:00
|
|
|
ESM::ActiveSpells::Flags mFlags;
|
2021-08-27 20:07:50 +02:00
|
|
|
int mWorsenings;
|
|
|
|
MWWorld::TimeStamp mNextWorsening;
|
2023-07-25 21:23:59 +00:00
|
|
|
MWWorld::Ptr mSource;
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpellParams(const ESM::ActiveSpells::ActiveSpellParams& params);
|
|
|
|
|
|
|
|
ActiveSpellParams(const ESM::Spell* spell, const MWWorld::Ptr& actor, bool ignoreResistances = false);
|
|
|
|
|
2023-07-25 21:23:59 +00:00
|
|
|
ActiveSpellParams(
|
|
|
|
const MWWorld::ConstPtr& item, const ESM::Enchantment* enchantment, const MWWorld::Ptr& actor);
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
ActiveSpellParams(const ActiveSpellParams& params, const MWWorld::Ptr& actor);
|
|
|
|
|
2021-10-10 16:28:45 +02:00
|
|
|
ESM::ActiveSpells::ActiveSpellParams toEsm() const;
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
friend class ActiveSpells;
|
|
|
|
|
|
|
|
public:
|
2024-03-25 13:50:23 +00:00
|
|
|
ActiveSpellParams(
|
|
|
|
const MWWorld::Ptr& caster, const ESM::RefId& id, std::string_view sourceName, ESM::RefNum item);
|
|
|
|
|
|
|
|
ESM::RefId getActiveSpellId() const { return mActiveSpellId; }
|
|
|
|
void setActiveSpellId(ESM::RefId id) { mActiveSpellId = id; }
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
const ESM::RefId& getSourceSpellId() const { return mSourceSpellId; }
|
2013-11-19 18:43:21 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
const std::vector<ActiveEffect>& getEffects() const { return mEffects; }
|
|
|
|
std::vector<ActiveEffect>& getEffects() { return mEffects; }
|
|
|
|
|
|
|
|
int getCasterActorId() const { return mCasterActorId; }
|
|
|
|
|
|
|
|
int getWorsenings() const { return mWorsenings; }
|
|
|
|
|
|
|
|
const std::string& getDisplayName() const { return mDisplayName; }
|
|
|
|
|
2023-07-31 00:02:05 +00:00
|
|
|
ESM::RefNum getItem() const { return mItem; }
|
2024-01-26 17:15:41 +01:00
|
|
|
ESM::RefId getEnchantment() const;
|
2023-07-31 00:02:05 +00:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
const ESM::Spell* getSpell() const;
|
|
|
|
bool hasFlag(ESM::ActiveSpells::Flags flags) const;
|
|
|
|
void setFlag(ESM::ActiveSpells::Flags flags);
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
// Increments worsenings count and sets the next timestamp
|
|
|
|
void worsen();
|
|
|
|
|
|
|
|
bool shouldWorsen() const;
|
2013-11-17 23:15:57 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void resetWorsenings();
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2023-05-20 17:49:32 +02:00
|
|
|
typedef std::list<ActiveSpellParams> Collection;
|
|
|
|
typedef Collection::const_iterator TIterator;
|
2014-05-14 22:16:39 +02:00
|
|
|
|
|
|
|
void readState(const ESM::ActiveSpells& state);
|
2014-06-17 03:54:41 +02:00
|
|
|
void writeState(ESM::ActiveSpells& state) const;
|
|
|
|
|
|
|
|
TIterator begin() const;
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
TIterator end() const;
|
2019-09-18 09:43:32 +04:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
TIterator getActiveSpellById(const ESM::RefId& id);
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void update(const MWWorld::Ptr& ptr, float duration);
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
private:
|
2021-08-27 20:07:50 +02:00
|
|
|
using ParamsPredicate = std::function<bool(const ActiveSpellParams&)>;
|
|
|
|
using EffectPredicate = std::function<bool(const ActiveSpellParams&, const ESM::ActiveEffect&)>;
|
|
|
|
using Predicate = std::variant<ParamsPredicate, EffectPredicate>;
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
struct IterationGuard
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells& mActiveSpells;
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
IterationGuard(ActiveSpells& spells);
|
|
|
|
~IterationGuard();
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
2015-03-01 15:34:18 +13:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
std::list<ActiveSpellParams> mSpells;
|
|
|
|
std::vector<ActiveSpellParams> mQueue;
|
|
|
|
std::queue<Predicate> mPurges;
|
|
|
|
bool mIterating;
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void addToSpells(const MWWorld::Ptr& ptr, const ActiveSpellParams& spell);
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2012-05-19 15:01:07 +02:00
|
|
|
bool applyPurges(const MWWorld::Ptr& ptr, std::list<ActiveSpellParams>::iterator* currentSpell = nullptr,
|
2021-08-27 20:07:50 +02:00
|
|
|
std::vector<ActiveEffect>::iterator* currentEffect = nullptr);
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2012-05-19 15:01:07 +02:00
|
|
|
ActiveSpells();
|
|
|
|
|
2013-11-17 23:15:57 +01:00
|
|
|
/// Add lasting effects
|
2012-06-24 16:23:43 +02:00
|
|
|
///
|
2013-11-17 23:15:57 +01:00
|
|
|
/// \brief addSpell
|
|
|
|
/// \param id ID for stacking purposes.
|
|
|
|
///
|
2021-08-27 20:07:50 +02:00
|
|
|
void addSpell(const ActiveSpellParams& params);
|
|
|
|
|
|
|
|
/// Bypasses resistances
|
|
|
|
void addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor);
|
2013-11-17 23:15:57 +01:00
|
|
|
|
2014-01-03 04:56:54 +01:00
|
|
|
/// Removes the active effects from this spell/potion/.. with \a id
|
2024-03-25 13:50:23 +00:00
|
|
|
void removeEffectsBySourceSpellId(const MWWorld::Ptr& ptr, const ESM::RefId& id);
|
|
|
|
/// Removes the active effects of a specific active spell
|
|
|
|
void removeEffectsByActiveSpellId(const MWWorld::Ptr& ptr, const ESM::RefId& id);
|
2014-01-03 04:56:54 +01:00
|
|
|
|
|
|
|
/// Remove all active effects with this effect id
|
2023-08-03 20:21:44 +02:00
|
|
|
void purgeEffect(const MWWorld::Ptr& ptr, int effectId, ESM::RefId effectArg = {});
|
2015-01-05 18:52:37 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void purge(EffectPredicate predicate, const MWWorld::Ptr& ptr);
|
|
|
|
void purge(ParamsPredicate predicate, const MWWorld::Ptr& ptr);
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
/// Remove all effects that were cast by \a casterActorId
|
|
|
|
void purge(const MWWorld::Ptr& ptr, int casterActorId);
|
2014-01-12 10:21:49 +01:00
|
|
|
|
2014-05-14 22:16:39 +02:00
|
|
|
/// Remove all spells
|
2021-08-27 20:07:50 +02:00
|
|
|
void clear(const MWWorld::Ptr& ptr);
|
2014-05-14 22:16:39 +02:00
|
|
|
|
2023-07-31 00:02:05 +00:00
|
|
|
/// True if a spell associated with this id is active
|
|
|
|
/// \note For enchantments, this is the id of the enchanted item, not the enchantment itself
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
bool isSpellActive(const ESM::RefId& id) const;
|
2023-07-31 00:02:05 +00:00
|
|
|
|
|
|
|
/// True if the enchantment is active
|
|
|
|
bool isEnchantmentActive(const ESM::RefId& id) const;
|
2012-11-25 01:26:29 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void skipWorsenings(double hours);
|
2022-08-21 13:33:21 +02:00
|
|
|
|
|
|
|
void unloadActor(const MWWorld::Ptr& ptr);
|
2012-05-19 15:01:07 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|