mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
125b21de20
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!
154 lines
4.6 KiB
C++
154 lines
4.6 KiB
C++
#ifndef GAME_MWMECHANICS_ACTIVESPELLS_H
|
|
#define GAME_MWMECHANICS_ACTIVESPELLS_H
|
|
|
|
#include <functional>
|
|
#include <list>
|
|
#include <queue>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
#include <components/esm3/activespells.hpp>
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
#include "../mwworld/timestamp.hpp"
|
|
|
|
#include "spellcasting.hpp"
|
|
|
|
namespace ESM
|
|
{
|
|
struct Enchantment;
|
|
struct Spell;
|
|
}
|
|
|
|
namespace MWMechanics
|
|
{
|
|
/// \brief Lasting spell effects
|
|
///
|
|
/// \note The name of this class is slightly misleading, since it also handles lasting potion
|
|
/// effects.
|
|
class ActiveSpells
|
|
{
|
|
public:
|
|
using ActiveEffect = ESM::ActiveEffect;
|
|
class ActiveSpellParams
|
|
{
|
|
ESM::RefId mId;
|
|
std::vector<ActiveEffect> mEffects;
|
|
std::string mDisplayName;
|
|
int mCasterActorId;
|
|
int mSlot;
|
|
ESM::ActiveSpells::EffectType mType;
|
|
int mWorsenings;
|
|
MWWorld::TimeStamp mNextWorsening;
|
|
|
|
ActiveSpellParams(const ESM::ActiveSpells::ActiveSpellParams& params);
|
|
|
|
ActiveSpellParams(const ESM::Spell* spell, const MWWorld::Ptr& actor, bool ignoreResistances = false);
|
|
|
|
ActiveSpellParams(const MWWorld::ConstPtr& item, const ESM::Enchantment* enchantment, int slotIndex,
|
|
const MWWorld::Ptr& actor);
|
|
|
|
ActiveSpellParams(const ActiveSpellParams& params, const MWWorld::Ptr& actor);
|
|
|
|
ESM::ActiveSpells::ActiveSpellParams toEsm() const;
|
|
|
|
friend class ActiveSpells;
|
|
|
|
public:
|
|
ActiveSpellParams(const CastSpell& cast, const MWWorld::Ptr& caster);
|
|
|
|
const ESM::RefId& getId() const { return mId; }
|
|
|
|
const std::vector<ActiveEffect>& getEffects() const { return mEffects; }
|
|
std::vector<ActiveEffect>& getEffects() { return mEffects; }
|
|
|
|
ESM::ActiveSpells::EffectType getType() const { return mType; }
|
|
|
|
int getCasterActorId() const { return mCasterActorId; }
|
|
|
|
int getWorsenings() const { return mWorsenings; }
|
|
|
|
const std::string& getDisplayName() const { return mDisplayName; }
|
|
|
|
// Increments worsenings count and sets the next timestamp
|
|
void worsen();
|
|
|
|
bool shouldWorsen() const;
|
|
|
|
void resetWorsenings();
|
|
};
|
|
|
|
typedef std::list<ActiveSpellParams>::const_iterator TIterator;
|
|
|
|
void readState(const ESM::ActiveSpells& state);
|
|
void writeState(ESM::ActiveSpells& state) const;
|
|
|
|
TIterator begin() const;
|
|
|
|
TIterator end() const;
|
|
|
|
void update(const MWWorld::Ptr& ptr, float duration);
|
|
|
|
private:
|
|
using ParamsPredicate = std::function<bool(const ActiveSpellParams&)>;
|
|
using EffectPredicate = std::function<bool(const ActiveSpellParams&, const ESM::ActiveEffect&)>;
|
|
using Predicate = std::variant<ParamsPredicate, EffectPredicate>;
|
|
|
|
struct IterationGuard
|
|
{
|
|
ActiveSpells& mActiveSpells;
|
|
|
|
IterationGuard(ActiveSpells& spells);
|
|
~IterationGuard();
|
|
};
|
|
|
|
std::list<ActiveSpellParams> mSpells;
|
|
std::vector<ActiveSpellParams> mQueue;
|
|
std::queue<Predicate> mPurges;
|
|
bool mIterating;
|
|
|
|
void addToSpells(const MWWorld::Ptr& ptr, const ActiveSpellParams& spell);
|
|
|
|
bool applyPurges(const MWWorld::Ptr& ptr, std::list<ActiveSpellParams>::iterator* currentSpell = nullptr,
|
|
std::vector<ActiveEffect>::iterator* currentEffect = nullptr);
|
|
|
|
public:
|
|
ActiveSpells();
|
|
|
|
/// Add lasting effects
|
|
///
|
|
/// \brief addSpell
|
|
/// \param id ID for stacking purposes.
|
|
///
|
|
void addSpell(const ActiveSpellParams& params);
|
|
|
|
/// Bypasses resistances
|
|
void addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor);
|
|
|
|
/// Removes the active effects from this spell/potion/.. with \a id
|
|
void removeEffects(const MWWorld::Ptr& ptr, const ESM::RefId& id);
|
|
|
|
/// Remove all active effects with this effect id
|
|
void purgeEffect(const MWWorld::Ptr& ptr, short effectId);
|
|
|
|
void purge(EffectPredicate predicate, const MWWorld::Ptr& ptr);
|
|
void purge(ParamsPredicate predicate, const MWWorld::Ptr& ptr);
|
|
|
|
/// Remove all effects that were cast by \a casterActorId
|
|
void purge(const MWWorld::Ptr& ptr, int casterActorId);
|
|
|
|
/// Remove all spells
|
|
void clear(const MWWorld::Ptr& ptr);
|
|
|
|
bool isSpellActive(const ESM::RefId& id) const;
|
|
///< case insensitive
|
|
|
|
void skipWorsenings(double hours);
|
|
|
|
void unloadActor(const MWWorld::Ptr& ptr);
|
|
};
|
|
}
|
|
|
|
#endif
|