2012-05-19 15:01:07 +02:00
|
|
|
#include "activespells.hpp"
|
|
|
|
|
2021-10-10 16:28:45 +02:00
|
|
|
#include <optional>
|
|
|
|
|
2021-10-09 12:27:17 +02:00
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
2022-06-29 00:32:11 +02:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
2014-02-23 20:11:05 +01:00
|
|
|
|
2022-08-03 00:00:54 +02:00
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
#include <components/esm/generatedrefid.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadench.hpp>
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadstat.hpp>
|
2014-02-23 20:11:05 +01:00
|
|
|
|
2023-06-27 23:41:06 +02:00
|
|
|
#include <components/settings/values.hpp>
|
2021-12-21 10:50:28 +01:00
|
|
|
|
2022-09-03 19:49:59 +02:00
|
|
|
#include "actorutil.hpp"
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "creaturestats.hpp"
|
|
|
|
#include "spellcasting.hpp"
|
|
|
|
#include "spelleffects.hpp"
|
|
|
|
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2022-09-03 19:49:59 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-09-13 11:30:59 +02:00
|
|
|
|
2021-10-10 16:28:45 +02:00
|
|
|
#include "../mwrender/animation.hpp"
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "../mwworld/class.hpp"
|
2014-02-23 20:11:05 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2023-07-31 00:02:05 +00:00
|
|
|
#include "../mwworld/manualref.hpp"
|
2014-02-23 20:11:05 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
namespace
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
bool merge(std::vector<ESM::ActiveEffect>& present, const std::vector<ESM::ActiveEffect>& queued)
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
// Can't merge if we already have an effect with the same effect index
|
|
|
|
auto problem = std::find_if(queued.begin(), queued.end(), [&](const auto& qEffect) {
|
|
|
|
return std::find_if(present.begin(), present.end(), [&](const auto& pEffect) {
|
|
|
|
return pEffect.mEffectIndex == qEffect.mEffectIndex;
|
|
|
|
}) != present.end();
|
|
|
|
});
|
|
|
|
if (problem != queued.end())
|
|
|
|
return false;
|
|
|
|
present.insert(present.end(), queued.begin(), queued.end());
|
|
|
|
return true;
|
2012-09-13 11:30:59 +02:00
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void addEffects(
|
|
|
|
std::vector<ESM::ActiveEffect>& effects, const ESM::EffectList& list, bool ignoreResistances = false)
|
2012-09-13 11:30:59 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
for (const auto& enam : list.mList)
|
2012-09-13 11:30:59 +02:00
|
|
|
{
|
2024-06-13 18:00:44 +02:00
|
|
|
if (enam.mData.mRange != ESM::RT_Self)
|
|
|
|
continue;
|
2021-08-27 20:07:50 +02:00
|
|
|
ESM::ActiveEffect effect;
|
2024-03-25 13:50:23 +00:00
|
|
|
effect.mEffectId = enam.mData.mEffectID;
|
|
|
|
effect.mArg = MWMechanics::EffectKey(enam.mData).mArg;
|
2021-08-27 20:07:50 +02:00
|
|
|
effect.mMagnitude = 0.f;
|
2024-03-25 13:50:23 +00:00
|
|
|
effect.mMinMagnitude = enam.mData.mMagnMin;
|
|
|
|
effect.mMaxMagnitude = enam.mData.mMagnMax;
|
|
|
|
effect.mEffectIndex = enam.mIndex;
|
2021-08-27 20:07:50 +02:00
|
|
|
effect.mFlags = ESM::ActiveEffect::Flag_None;
|
|
|
|
if (ignoreResistances)
|
|
|
|
effect.mFlags |= ESM::ActiveEffect::Flag_Ignore_Resistances;
|
|
|
|
effect.mDuration = -1;
|
|
|
|
effect.mTimeLeft = -1;
|
|
|
|
effects.emplace_back(effect);
|
2014-02-23 20:11:05 +01:00
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
ActiveSpells::IterationGuard::IterationGuard(ActiveSpells& spells)
|
|
|
|
: mActiveSpells(spells)
|
|
|
|
{
|
|
|
|
mActiveSpells.mIterating = true;
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::IterationGuard::~IterationGuard()
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
mActiveSpells.mIterating = false;
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(
|
|
|
|
const MWWorld::Ptr& caster, const ESM::RefId& id, std::string_view sourceName, ESM::RefNum item)
|
|
|
|
: mSourceSpellId(id)
|
|
|
|
, mDisplayName(sourceName)
|
2021-08-27 20:07:50 +02:00
|
|
|
, mCasterActorId(-1)
|
2024-03-25 13:50:23 +00:00
|
|
|
, mItem(item)
|
|
|
|
, mFlags()
|
2021-08-27 20:07:50 +02:00
|
|
|
, mWorsenings(-1)
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (!caster.isEmpty() && caster.getClass().isActor())
|
|
|
|
mCasterActorId = caster.getClass().getCreatureStats(caster).getActorId();
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(
|
|
|
|
const ESM::Spell* spell, const MWWorld::Ptr& actor, bool ignoreResistances)
|
2024-03-25 13:50:23 +00:00
|
|
|
: mSourceSpellId(spell->mId)
|
2021-08-27 20:07:50 +02:00
|
|
|
, mDisplayName(spell->mName)
|
|
|
|
, mCasterActorId(actor.getClass().getCreatureStats(actor).getActorId())
|
2024-03-25 13:50:23 +00:00
|
|
|
, mFlags()
|
2021-08-27 20:07:50 +02:00
|
|
|
, mWorsenings(-1)
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
assert(spell->mData.mType != ESM::Spell::ST_Spell && spell->mData.mType != ESM::Spell::ST_Power);
|
2024-03-25 13:50:23 +00:00
|
|
|
setFlag(ESM::ActiveSpells::Flag_SpellStore);
|
|
|
|
if (spell->mData.mType == ESM::Spell::ST_Ability)
|
|
|
|
setFlag(ESM::ActiveSpells::Flag_AffectsBaseValues);
|
2021-08-27 20:07:50 +02:00
|
|
|
addEffects(mEffects, spell->mEffects, ignoreResistances);
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(
|
2023-07-25 21:23:59 +00:00
|
|
|
const MWWorld::ConstPtr& item, const ESM::Enchantment* enchantment, const MWWorld::Ptr& actor)
|
2024-03-25 13:50:23 +00:00
|
|
|
: mSourceSpellId(item.getCellRef().getRefId())
|
2021-08-27 20:07:50 +02:00
|
|
|
, mDisplayName(item.getClass().getName(item))
|
|
|
|
, mCasterActorId(actor.getClass().getCreatureStats(actor).getActorId())
|
2023-07-25 21:23:59 +00:00
|
|
|
, mItem(item.getCellRef().getRefNum())
|
2024-03-25 13:50:23 +00:00
|
|
|
, mFlags()
|
2021-08-27 20:07:50 +02:00
|
|
|
, mWorsenings(-1)
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
assert(enchantment->mData.mType == ESM::Enchantment::ConstantEffect);
|
|
|
|
addEffects(mEffects, enchantment->mEffects);
|
2024-03-25 13:50:23 +00:00
|
|
|
setFlag(ESM::ActiveSpells::Flag_Equipment);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(const ESM::ActiveSpells::ActiveSpellParams& params)
|
2024-03-25 13:50:23 +00:00
|
|
|
: mActiveSpellId(params.mActiveSpellId)
|
|
|
|
, mSourceSpellId(params.mSourceSpellId)
|
2021-08-27 20:07:50 +02:00
|
|
|
, mEffects(params.mEffects)
|
|
|
|
, mDisplayName(params.mDisplayName)
|
|
|
|
, mCasterActorId(params.mCasterActorId)
|
2023-07-25 21:23:59 +00:00
|
|
|
, mItem(params.mItem)
|
2024-03-25 13:50:23 +00:00
|
|
|
, mFlags(params.mFlags)
|
2021-08-27 20:07:50 +02:00
|
|
|
, mWorsenings(params.mWorsenings)
|
|
|
|
, mNextWorsening({ params.mNextWorsening })
|
|
|
|
{
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-10-10 16:28:45 +02:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(const ActiveSpellParams& params, const MWWorld::Ptr& actor)
|
2024-03-25 13:50:23 +00:00
|
|
|
: mSourceSpellId(params.mSourceSpellId)
|
2021-10-10 16:28:45 +02:00
|
|
|
, mDisplayName(params.mDisplayName)
|
|
|
|
, mCasterActorId(actor.getClass().getCreatureStats(actor).getActorId())
|
2023-07-25 21:23:59 +00:00
|
|
|
, mItem(params.mItem)
|
2024-03-25 13:50:23 +00:00
|
|
|
, mFlags(params.mFlags)
|
2021-10-10 16:28:45 +02:00
|
|
|
, mWorsenings(-1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ESM::ActiveSpells::ActiveSpellParams ActiveSpells::ActiveSpellParams::toEsm() const
|
|
|
|
{
|
|
|
|
ESM::ActiveSpells::ActiveSpellParams params;
|
2024-03-25 13:50:23 +00:00
|
|
|
params.mActiveSpellId = mActiveSpellId;
|
|
|
|
params.mSourceSpellId = mSourceSpellId;
|
2021-08-27 20:07:50 +02:00
|
|
|
params.mEffects = mEffects;
|
|
|
|
params.mDisplayName = mDisplayName;
|
|
|
|
params.mCasterActorId = mCasterActorId;
|
2023-07-25 21:23:59 +00:00
|
|
|
params.mItem = mItem;
|
2024-03-25 13:50:23 +00:00
|
|
|
params.mFlags = mFlags;
|
2021-08-27 20:07:50 +02:00
|
|
|
params.mWorsenings = mWorsenings;
|
|
|
|
params.mNextWorsening = mNextWorsening.toEsm();
|
|
|
|
return params;
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
void ActiveSpells::ActiveSpellParams::setFlag(ESM::ActiveSpells::Flags flag)
|
|
|
|
{
|
|
|
|
mFlags = static_cast<ESM::ActiveSpells::Flags>(mFlags | flag);
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::ActiveSpellParams::worsen()
|
|
|
|
{
|
|
|
|
++mWorsenings;
|
|
|
|
if (!mWorsenings)
|
|
|
|
mNextWorsening = MWBase::Environment::get().getWorld()->getTimeStamp();
|
|
|
|
mNextWorsening += CorprusStats::sWorseningPeriod;
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
2012-11-25 01:26:29 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
bool ActiveSpells::ActiveSpellParams::shouldWorsen() const
|
2012-11-25 01:26:29 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
return mWorsenings >= 0 && MWBase::Environment::get().getWorld()->getTimeStamp() >= mNextWorsening;
|
2012-11-25 01:26:29 +01:00
|
|
|
}
|
2013-03-03 12:01:19 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::ActiveSpellParams::resetWorsenings()
|
2013-03-03 12:01:19 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
mWorsenings = -1;
|
2013-03-03 12:01:19 +01:00
|
|
|
}
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2024-01-26 17:15:41 +01:00
|
|
|
ESM::RefId ActiveSpells::ActiveSpellParams::getEnchantment() const
|
|
|
|
{
|
|
|
|
// Enchantment id is not stored directly. Instead the enchanted item is stored.
|
|
|
|
const auto& store = MWBase::Environment::get().getESMStore();
|
2024-03-25 13:50:23 +00:00
|
|
|
switch (store->find(mSourceSpellId))
|
2024-01-26 17:15:41 +01:00
|
|
|
{
|
|
|
|
case ESM::REC_ARMO:
|
2024-03-25 13:50:23 +00:00
|
|
|
return store->get<ESM::Armor>().find(mSourceSpellId)->mEnchant;
|
2024-01-26 17:15:41 +01:00
|
|
|
case ESM::REC_BOOK:
|
2024-03-25 13:50:23 +00:00
|
|
|
return store->get<ESM::Book>().find(mSourceSpellId)->mEnchant;
|
2024-01-26 17:15:41 +01:00
|
|
|
case ESM::REC_CLOT:
|
2024-03-25 13:50:23 +00:00
|
|
|
return store->get<ESM::Clothing>().find(mSourceSpellId)->mEnchant;
|
2024-01-26 17:15:41 +01:00
|
|
|
case ESM::REC_WEAP:
|
2024-03-25 13:50:23 +00:00
|
|
|
return store->get<ESM::Weapon>().find(mSourceSpellId)->mEnchant;
|
2024-01-26 17:15:41 +01:00
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
const ESM::Spell* ActiveSpells::ActiveSpellParams::getSpell() const
|
|
|
|
{
|
|
|
|
return MWBase::Environment::get().getESMStore()->get<ESM::Spell>().search(getSourceSpellId());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ActiveSpells::ActiveSpellParams::hasFlag(ESM::ActiveSpells::Flags flags) const
|
|
|
|
{
|
|
|
|
return static_cast<ESM::ActiveSpells::Flags>(mFlags & flags) == flags;
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::update(const MWWorld::Ptr& ptr, float duration)
|
2013-11-15 20:29:47 +01:00
|
|
|
{
|
2022-09-24 18:13:45 +02:00
|
|
|
if (mIterating)
|
|
|
|
return;
|
2022-11-23 20:59:37 +01:00
|
|
|
auto& creatureStats = ptr.getClass().getCreatureStats(ptr);
|
2021-08-27 20:07:50 +02:00
|
|
|
assert(&creatureStats.getActiveSpells() == this);
|
|
|
|
IterationGuard guard{ *this };
|
|
|
|
// Erase no longer active spells and effects
|
|
|
|
for (auto spellIt = mSpells.begin(); spellIt != mSpells.end();)
|
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
if (!spellIt->hasFlag(ESM::ActiveSpells::Flag_Temporary))
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
++spellIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool removedSpell = false;
|
|
|
|
for (auto effectIt = spellIt->mEffects.begin(); effectIt != spellIt->mEffects.end();)
|
|
|
|
{
|
|
|
|
if (effectIt->mFlags & ESM::ActiveEffect::Flag_Remove && effectIt->mTimeLeft <= 0.f)
|
|
|
|
{
|
|
|
|
auto effect = *effectIt;
|
|
|
|
effectIt = spellIt->mEffects.erase(effectIt);
|
|
|
|
onMagicEffectRemoved(ptr, *spellIt, effect);
|
|
|
|
removedSpell = applyPurges(ptr, &spellIt, &effectIt);
|
|
|
|
if (removedSpell)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++effectIt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (removedSpell)
|
|
|
|
continue;
|
|
|
|
if (spellIt->mEffects.empty())
|
|
|
|
spellIt = mSpells.erase(spellIt);
|
|
|
|
else
|
|
|
|
++spellIt;
|
|
|
|
}
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
for (const auto& spell : mQueue)
|
|
|
|
addToSpells(ptr, spell);
|
|
|
|
mQueue.clear();
|
2013-11-17 23:15:57 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
// Vanilla only does this on cell change I think
|
|
|
|
const auto& spells = creatureStats.getSpells();
|
|
|
|
for (const ESM::Spell* spell : spells)
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (spell->mData.mType != ESM::Spell::ST_Spell && spell->mData.mType != ESM::Spell::ST_Power
|
|
|
|
&& !isSpellActive(spell->mId))
|
2024-03-25 13:50:23 +00:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
mSpells.emplace_back(ActiveSpellParams{ spell, ptr });
|
2024-03-25 13:50:23 +00:00
|
|
|
mSpells.back().setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId());
|
|
|
|
}
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2024-01-06 02:05:07 +03:00
|
|
|
bool updateSpellWindow = false;
|
2021-08-27 20:07:50 +02:00
|
|
|
if (ptr.getClass().hasInventoryStore(ptr)
|
|
|
|
&& !(creatureStats.isDead() && !creatureStats.isDeathAnimationFinished()))
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto& store = ptr.getClass().getInventoryStore(ptr);
|
|
|
|
if (store.getInvListener() != nullptr)
|
|
|
|
{
|
|
|
|
bool playNonLooping = !store.isFirstEquip();
|
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
|
|
|
for (int slotIndex = 0; slotIndex < MWWorld::InventoryStore::Slots; slotIndex++)
|
|
|
|
{
|
|
|
|
auto slot = store.getSlot(slotIndex);
|
|
|
|
if (slot == store.end())
|
|
|
|
continue;
|
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
|
|
|
const ESM::RefId& enchantmentId = slot->getClass().getEnchantment(*slot);
|
2021-08-27 20:07:50 +02:00
|
|
|
if (enchantmentId.empty())
|
|
|
|
continue;
|
|
|
|
const ESM::Enchantment* enchantment = world->getStore().get<ESM::Enchantment>().find(enchantmentId);
|
|
|
|
if (enchantment->mData.mType != ESM::Enchantment::ConstantEffect)
|
|
|
|
continue;
|
|
|
|
if (std::find_if(mSpells.begin(), mSpells.end(),
|
|
|
|
[&](const ActiveSpellParams& params) {
|
2023-07-25 21:23:59 +00:00
|
|
|
return params.mItem == slot->getCellRef().getRefNum()
|
2024-03-25 13:50:23 +00:00
|
|
|
&& params.hasFlag(ESM::ActiveSpells::Flag_Equipment)
|
|
|
|
&& params.mSourceSpellId == slot->getCellRef().getRefId();
|
2021-08-27 20:07:50 +02:00
|
|
|
})
|
|
|
|
!= mSpells.end())
|
|
|
|
continue;
|
2022-07-31 09:48:01 +02:00
|
|
|
// world->breakInvisibility leads to a stack overflow as it calls this method so just break
|
|
|
|
// invisibility manually
|
|
|
|
purgeEffect(ptr, ESM::MagicEffect::Invisibility);
|
|
|
|
applyPurges(ptr);
|
2024-03-25 13:50:23 +00:00
|
|
|
ActiveSpellParams& params = mSpells.emplace_back(ActiveSpellParams{ *slot, enchantment, ptr });
|
|
|
|
params.setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId());
|
2021-08-27 20:07:50 +02:00
|
|
|
for (const auto& effect : params.mEffects)
|
|
|
|
MWMechanics::playEffects(
|
|
|
|
ptr, *world->getStore().get<ESM::MagicEffect>().find(effect.mEffectId), playNonLooping);
|
2024-01-06 02:05:07 +03:00
|
|
|
updateSpellWindow = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2013-11-17 23:15:57 +01:00
|
|
|
|
2022-09-03 19:49:59 +02:00
|
|
|
const MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
bool updatedHitOverlay = false;
|
|
|
|
bool updatedEnemy = false;
|
2021-08-27 20:07:50 +02:00
|
|
|
// Update effects
|
|
|
|
for (auto spellIt = mSpells.begin(); spellIt != mSpells.end();)
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
const auto caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(
|
|
|
|
spellIt->mCasterActorId); // Maybe make this search outside active grid?
|
|
|
|
bool removedSpell = false;
|
2021-10-10 16:28:45 +02:00
|
|
|
std::optional<ActiveSpellParams> reflected;
|
2021-08-27 20:07:50 +02:00
|
|
|
for (auto it = spellIt->mEffects.begin(); it != spellIt->mEffects.end();)
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2021-10-10 16:28:45 +02:00
|
|
|
auto result = applyMagicEffect(ptr, caster, *spellIt, *it, duration);
|
2022-09-03 19:49:59 +02:00
|
|
|
if (result.mType == MagicApplicationResult::Type::REFLECTED)
|
2021-10-10 16:28:45 +02:00
|
|
|
{
|
|
|
|
if (!reflected)
|
2021-12-21 10:50:28 +01:00
|
|
|
{
|
2023-06-27 23:41:06 +02:00
|
|
|
if (Settings::game().mClassicReflectedAbsorbSpellsBehavior)
|
2021-12-21 10:50:28 +01:00
|
|
|
reflected = { *spellIt, caster };
|
|
|
|
else
|
|
|
|
reflected = { *spellIt, ptr };
|
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
auto& reflectedEffect = reflected->mEffects.emplace_back(*it);
|
|
|
|
reflectedEffect.mFlags
|
|
|
|
= ESM::ActiveEffect::Flag_Ignore_Reflect | ESM::ActiveEffect::Flag_Ignore_SpellAbsorption;
|
|
|
|
it = spellIt->mEffects.erase(it);
|
|
|
|
}
|
2022-09-03 19:49:59 +02:00
|
|
|
else if (result.mType == MagicApplicationResult::Type::REMOVED)
|
2021-08-27 20:07:50 +02:00
|
|
|
it = spellIt->mEffects.erase(it);
|
|
|
|
else
|
2022-09-03 19:49:59 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
++it;
|
2022-09-03 19:49:59 +02:00
|
|
|
if (!updatedEnemy && result.mShowHealth && caster == player && ptr != player)
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->setEnemy(ptr);
|
|
|
|
updatedEnemy = true;
|
|
|
|
}
|
|
|
|
if (!updatedHitOverlay && result.mShowHit && ptr == player)
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
|
|
|
|
updatedHitOverlay = true;
|
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
removedSpell = applyPurges(ptr, &spellIt, &it);
|
|
|
|
if (removedSpell)
|
2015-03-01 15:34:18 +13:00
|
|
|
break;
|
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
if (reflected)
|
|
|
|
{
|
2023-04-20 21:07:53 +02:00
|
|
|
const ESM::Static* reflectStatic = MWBase::Environment::get().getESMStore()->get<ESM::Static>().find(
|
|
|
|
ESM::RefId::stringRefId("VFX_Reflect"));
|
2021-10-10 16:28:45 +02:00
|
|
|
MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
|
|
|
if (animation && !reflectStatic->mModel.empty())
|
2024-11-15 01:25:40 +01:00
|
|
|
{
|
|
|
|
const VFS::Path::Normalized reflectStaticModel
|
|
|
|
= Misc::ResourceHelpers::correctMeshPath(VFS::Path::Normalized(reflectStatic->mModel));
|
|
|
|
animation->addEffect(
|
|
|
|
reflectStaticModel, ESM::MagicEffect::indexToName(ESM::MagicEffect::Reflect), false);
|
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell(*reflected);
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
if (removedSpell)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool remove = false;
|
2024-03-25 13:50:23 +00:00
|
|
|
if (spellIt->hasFlag(ESM::ActiveSpells::Flag_SpellStore))
|
2021-10-09 12:27:17 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
remove = !spells.hasSpell(spellIt->mSourceSpellId);
|
2021-10-09 12:27:17 +02:00
|
|
|
}
|
|
|
|
catch (const std::runtime_error& e)
|
|
|
|
{
|
|
|
|
remove = true;
|
|
|
|
Log(Debug::Error) << "Removing active effect: " << e.what();
|
|
|
|
}
|
|
|
|
}
|
2024-03-25 13:50:23 +00:00
|
|
|
else if (spellIt->hasFlag(ESM::ActiveSpells::Flag_Equipment))
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
// Remove effects tied to equipment that has been unequipped
|
2021-08-27 20:07:50 +02:00
|
|
|
const auto& store = ptr.getClass().getInventoryStore(ptr);
|
2023-07-25 21:23:59 +00:00
|
|
|
remove = true;
|
|
|
|
for (int slotIndex = 0; slotIndex < MWWorld::InventoryStore::Slots; slotIndex++)
|
|
|
|
{
|
|
|
|
auto slot = store.getSlot(slotIndex);
|
|
|
|
if (slot != store.end() && slot->getCellRef().getRefNum().isSet()
|
|
|
|
&& slot->getCellRef().getRefNum() == spellIt->mItem)
|
|
|
|
{
|
|
|
|
remove = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
if (remove)
|
|
|
|
{
|
|
|
|
auto params = *spellIt;
|
|
|
|
spellIt = mSpells.erase(spellIt);
|
|
|
|
for (const auto& effect : params.mEffects)
|
|
|
|
onMagicEffectRemoved(ptr, params, effect);
|
|
|
|
applyPurges(ptr, &spellIt);
|
2024-01-06 02:05:07 +03:00
|
|
|
updateSpellWindow = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++spellIt;
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2022-11-23 20:59:37 +01:00
|
|
|
|
2023-06-27 23:41:06 +02:00
|
|
|
if (Settings::game().mClassicCalmSpellsBehavior)
|
2022-11-23 20:59:37 +01:00
|
|
|
{
|
|
|
|
ESM::MagicEffect::Effects effect
|
|
|
|
= ptr.getClass().isNpc() ? ESM::MagicEffect::CalmHumanoid : ESM::MagicEffect::CalmCreature;
|
2023-05-23 19:06:08 +02:00
|
|
|
if (creatureStats.getMagicEffects().getOrDefault(effect).getMagnitude() > 0.f)
|
2022-11-23 20:59:37 +01:00
|
|
|
creatureStats.getAiSequence().stopCombat();
|
|
|
|
}
|
2024-01-06 02:05:07 +03:00
|
|
|
|
|
|
|
if (ptr == player && updateSpellWindow)
|
|
|
|
{
|
|
|
|
// Something happened with the spell list -- possibly while the game is paused,
|
|
|
|
// so we want to make the spell window get the memo.
|
|
|
|
// We don't normally want to do this, so this targets constant enchantments.
|
|
|
|
MWBase::Environment::get().getWindowManager()->updateSpellWindow();
|
|
|
|
}
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::addToSpells(const MWWorld::Ptr& ptr, const ActiveSpellParams& spell)
|
2014-01-03 04:56:54 +01:00
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
if (!spell.hasFlag(ESM::ActiveSpells::Flag_Stackable))
|
2018-08-27 02:17:49 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto found = std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& existing) {
|
2024-03-25 13:50:23 +00:00
|
|
|
return spell.mSourceSpellId == existing.mSourceSpellId
|
|
|
|
&& spell.mCasterActorId == existing.mCasterActorId && spell.mItem == existing.mItem;
|
2021-08-27 20:07:50 +02:00
|
|
|
});
|
|
|
|
if (found != mSpells.end())
|
2018-08-29 13:40:37 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (merge(found->mEffects, spell.mEffects))
|
|
|
|
return;
|
|
|
|
auto params = *found;
|
|
|
|
mSpells.erase(found);
|
|
|
|
for (const auto& effect : params.mEffects)
|
|
|
|
onMagicEffectRemoved(ptr, params, effect);
|
2018-08-29 13:40:37 +03:00
|
|
|
}
|
2018-08-27 02:17:49 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
mSpells.emplace_back(spell);
|
2024-03-25 13:50:23 +00:00
|
|
|
mSpells.back().setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId());
|
2014-01-03 04:56:54 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::ActiveSpells()
|
|
|
|
: mIterating(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ActiveSpells::TIterator ActiveSpells::begin() const
|
2013-11-17 23:15:57 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
return mSpells.begin();
|
|
|
|
}
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::TIterator ActiveSpells::end() const
|
|
|
|
{
|
|
|
|
return mSpells.end();
|
2013-11-17 23:15:57 +01:00
|
|
|
}
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
ActiveSpells::TIterator ActiveSpells::getActiveSpellById(const ESM::RefId& id)
|
|
|
|
{
|
|
|
|
for (TIterator it = begin(); it != end(); it++)
|
|
|
|
if (it->getActiveSpellId() == id)
|
|
|
|
return it;
|
|
|
|
return end();
|
|
|
|
}
|
|
|
|
|
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 ActiveSpells::isSpellActive(const ESM::RefId& id) const
|
2013-11-17 23:15:57 +01:00
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
return std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& spell) {
|
|
|
|
return spell.mSourceSpellId == id;
|
|
|
|
}) != mSpells.end();
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2017-08-14 20:39:04 +04:00
|
|
|
|
2023-07-31 00:02:05 +00:00
|
|
|
bool ActiveSpells::isEnchantmentActive(const ESM::RefId& id) const
|
|
|
|
{
|
|
|
|
const auto& store = MWBase::Environment::get().getESMStore();
|
|
|
|
if (store->get<ESM::Enchantment>().search(id) == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& spell) {
|
2024-01-26 17:15:41 +01:00
|
|
|
return spell.getEnchantment() == id;
|
2023-07-31 00:02:05 +00:00
|
|
|
}) != mSpells.end();
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::addSpell(const ActiveSpellParams& params)
|
|
|
|
{
|
|
|
|
mQueue.emplace_back(params);
|
|
|
|
}
|
2017-08-14 20:39:04 +04:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor)
|
|
|
|
{
|
|
|
|
mQueue.emplace_back(ActiveSpellParams{ spell, actor, true });
|
2013-11-17 23:15:57 +01:00
|
|
|
}
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::purge(ParamsPredicate predicate, const MWWorld::Ptr& ptr)
|
2013-11-17 23:15:57 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
assert(&ptr.getClass().getCreatureStats(ptr).getActiveSpells() == this);
|
|
|
|
mPurges.emplace(predicate);
|
|
|
|
if (!mIterating)
|
2013-11-17 23:15:57 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
IterationGuard guard{ *this };
|
|
|
|
applyPurges(ptr);
|
2013-11-15 20:29:47 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-12 10:21:49 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::purge(EffectPredicate predicate, const MWWorld::Ptr& ptr)
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
assert(&ptr.getClass().getCreatureStats(ptr).getActiveSpells() == this);
|
|
|
|
mPurges.emplace(predicate);
|
|
|
|
if (!mIterating)
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
IterationGuard guard{ *this };
|
|
|
|
applyPurges(ptr);
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
bool ActiveSpells::applyPurges(const MWWorld::Ptr& ptr, std::list<ActiveSpellParams>::iterator* currentSpell,
|
|
|
|
std::vector<ActiveEffect>::iterator* currentEffect)
|
2014-01-12 10:21:49 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
bool removedCurrentSpell = false;
|
|
|
|
while (!mPurges.empty())
|
2014-01-12 10:21:49 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto predicate = mPurges.front();
|
|
|
|
mPurges.pop();
|
|
|
|
for (auto spellIt = mSpells.begin(); spellIt != mSpells.end();)
|
2014-01-12 10:21:49 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
bool isCurrentSpell = currentSpell && *currentSpell == spellIt;
|
|
|
|
std::visit(
|
|
|
|
[&](auto&& variant) {
|
|
|
|
using T = std::decay_t<decltype(variant)>;
|
|
|
|
if constexpr (std::is_same_v<T, ParamsPredicate>)
|
|
|
|
{
|
|
|
|
if (variant(*spellIt))
|
|
|
|
{
|
|
|
|
auto params = *spellIt;
|
|
|
|
spellIt = mSpells.erase(spellIt);
|
|
|
|
if (isCurrentSpell)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
*currentSpell = spellIt;
|
|
|
|
removedCurrentSpell = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
for (const auto& effect : params.mEffects)
|
|
|
|
onMagicEffectRemoved(ptr, params, effect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++spellIt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static_assert(std::is_same_v<T, EffectPredicate>, "Non-exhaustive visitor");
|
|
|
|
for (auto effectIt = spellIt->mEffects.begin(); effectIt != spellIt->mEffects.end();)
|
|
|
|
{
|
|
|
|
if (variant(*spellIt, *effectIt))
|
|
|
|
{
|
|
|
|
auto effect = *effectIt;
|
|
|
|
if (isCurrentSpell && currentEffect)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto distance = std::distance(spellIt->mEffects.begin(), *currentEffect);
|
|
|
|
if (effectIt <= *currentEffect)
|
|
|
|
distance--;
|
|
|
|
effectIt = spellIt->mEffects.erase(effectIt);
|
|
|
|
*currentEffect = spellIt->mEffects.begin() + distance;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
else
|
2021-08-27 20:07:50 +02:00
|
|
|
effectIt = spellIt->mEffects.erase(effectIt);
|
|
|
|
onMagicEffectRemoved(ptr, *spellIt, effect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++effectIt;
|
|
|
|
}
|
|
|
|
++spellIt;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
predicate);
|
2014-01-12 10:21:49 +01:00
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
return removedCurrentSpell;
|
2014-01-12 10:21:49 +01:00
|
|
|
}
|
2014-05-14 22:16:39 +02:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
void ActiveSpells::removeEffectsBySourceSpellId(const MWWorld::Ptr& ptr, const ESM::RefId& id)
|
|
|
|
{
|
|
|
|
purge([=](const ActiveSpellParams& params) { return params.mSourceSpellId == id; }, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveSpells::removeEffectsByActiveSpellId(const MWWorld::Ptr& ptr, const ESM::RefId& id)
|
2019-09-30 20:27:42 +04:00
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
purge([=](const ActiveSpellParams& params) { return params.mActiveSpellId == id; }, ptr);
|
2019-09-30 20:27:42 +04:00
|
|
|
}
|
|
|
|
|
2023-08-03 20:21:44 +02:00
|
|
|
void ActiveSpells::purgeEffect(const MWWorld::Ptr& ptr, int effectId, ESM::RefId effectArg)
|
2014-05-14 22:16:39 +02:00
|
|
|
{
|
2023-06-17 16:34:40 +00:00
|
|
|
purge(
|
|
|
|
[=](const ActiveSpellParams&, const ESM::ActiveEffect& effect) {
|
2023-08-03 20:21:44 +02:00
|
|
|
if (effectArg.empty())
|
2023-06-17 16:34:40 +00:00
|
|
|
return effect.mEffectId == effectId;
|
2023-08-03 20:21:44 +02:00
|
|
|
return effect.mEffectId == effectId && effect.getSkillOrAttribute() == effectArg;
|
2023-06-17 16:34:40 +00:00
|
|
|
},
|
2021-08-27 20:07:50 +02:00
|
|
|
ptr);
|
2014-05-14 22:16:39 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::purge(const MWWorld::Ptr& ptr, int casterActorId)
|
2014-05-14 22:16:39 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
purge([=](const ActiveSpellParams& params) { return params.mCasterActorId == casterActorId; }, ptr);
|
|
|
|
}
|
2014-05-14 22:16:39 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::clear(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
mQueue.clear();
|
|
|
|
purge([](const ActiveSpellParams& params) { return true; }, ptr);
|
2014-05-14 22:16:39 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::skipWorsenings(double hours)
|
2014-05-14 22:16:39 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
for (auto& spell : mSpells)
|
2014-05-14 22:16:39 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (spell.mWorsenings >= 0)
|
|
|
|
spell.mNextWorsening += hours;
|
2014-05-14 22:16:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
void ActiveSpells::writeState(ESM::ActiveSpells& state) const
|
|
|
|
{
|
|
|
|
for (const auto& spell : mSpells)
|
|
|
|
state.mSpells.emplace_back(spell.toEsm());
|
|
|
|
for (const auto& spell : mQueue)
|
|
|
|
state.mQueue.emplace_back(spell.toEsm());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActiveSpells::readState(const ESM::ActiveSpells& state)
|
|
|
|
{
|
|
|
|
for (const ESM::ActiveSpells::ActiveSpellParams& spell : state.mSpells)
|
2024-03-25 13:50:23 +00:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
mSpells.emplace_back(ActiveSpellParams{ spell });
|
2024-03-25 13:50:23 +00:00
|
|
|
// Generate ID for older saves that didn't have any.
|
|
|
|
if (mSpells.back().getActiveSpellId().empty())
|
|
|
|
mSpells.back().setActiveSpellId(MWBase::Environment::get().getESMStore()->generateId());
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
for (const ESM::ActiveSpells::ActiveSpellParams& spell : state.mQueue)
|
|
|
|
mQueue.emplace_back(ActiveSpellParams{ spell });
|
|
|
|
}
|
2022-08-21 13:33:21 +02:00
|
|
|
|
|
|
|
void ActiveSpells::unloadActor(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
2024-03-25 13:50:23 +00:00
|
|
|
purge([](const auto& spell) { return spell.hasFlag(ESM::ActiveSpells::Flag_Temporary); }, ptr);
|
2022-08-21 13:33:21 +02:00
|
|
|
mQueue.clear();
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|