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>
|
|
|
|
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadench.hpp>
|
2022-09-22 21:26:05 +03:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
|
|
|
#include <components/esm3/loadstat.hpp>
|
2014-02-23 20:11:05 +01:00
|
|
|
|
2021-12-21 10:50:28 +01:00
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
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"
|
2022-09-22 21:26:05 +03:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "../mwworld/inventorystore.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
|
2022-09-22 21:26:05 +03:00
|
|
|
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();
|
2021-08-27 20:07:50 +02:00
|
|
|
});
|
2022-09-22 21:26:05 +03:00
|
|
|
if (problem != queued.end())
|
2021-08-27 20:07:50 +02:00
|
|
|
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
|
|
|
|
2022-09-22 21:26:05 +03: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
|
|
|
int currentEffectIndex = 0;
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const auto& enam : list.mList)
|
2012-09-13 11:30:59 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
ESM::ActiveEffect effect;
|
|
|
|
effect.mEffectId = enam.mEffectID;
|
|
|
|
effect.mArg = MWMechanics::EffectKey(enam).mArg;
|
|
|
|
effect.mMagnitude = 0.f;
|
|
|
|
effect.mMinMagnitude = enam.mMagnMin;
|
|
|
|
effect.mMaxMagnitude = enam.mMagnMax;
|
|
|
|
effect.mEffectIndex = currentEffectIndex++;
|
|
|
|
effect.mFlags = ESM::ActiveEffect::Flag_None;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (ignoreResistances)
|
2021-08-27 20:07:50 +02:00
|
|
|
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
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
ActiveSpells::IterationGuard::IterationGuard(ActiveSpells& spells)
|
|
|
|
: mActiveSpells(spells)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(const CastSpell& cast, const MWWorld::Ptr& caster)
|
2022-09-22 21:26:05 +03:00
|
|
|
: mId(cast.mId)
|
|
|
|
, mDisplayName(cast.mSourceName)
|
|
|
|
, mCasterActorId(-1)
|
|
|
|
, mSlot(cast.mSlot)
|
|
|
|
, mType(cast.mType)
|
|
|
|
, mWorsenings(-1)
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (!caster.isEmpty() && caster.getClass().isActor())
|
2021-08-27 20:07:50 +02:00
|
|
|
mCasterActorId = caster.getClass().getCreatureStats(caster).getActorId();
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(
|
|
|
|
const ESM::Spell* spell, const MWWorld::Ptr& actor, bool ignoreResistances)
|
|
|
|
: mId(spell->mId)
|
|
|
|
, mDisplayName(spell->mName)
|
|
|
|
, mCasterActorId(actor.getClass().getCreatureStats(actor).getActorId())
|
|
|
|
, mSlot(0)
|
|
|
|
, mType(spell->mData.mType == ESM::Spell::ST_Ability ? ESM::ActiveSpells::Type_Ability
|
|
|
|
: ESM::ActiveSpells::Type_Permanent)
|
|
|
|
, 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);
|
|
|
|
addEffects(mEffects, spell->mEffects, ignoreResistances);
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(
|
|
|
|
const MWWorld::ConstPtr& item, const ESM::Enchantment* enchantment, int slotIndex, const MWWorld::Ptr& actor)
|
|
|
|
: mId(item.getCellRef().getRefId())
|
|
|
|
, mDisplayName(item.getClass().getName(item))
|
|
|
|
, mCasterActorId(actor.getClass().getCreatureStats(actor).getActorId())
|
|
|
|
, mSlot(slotIndex)
|
|
|
|
, mType(ESM::ActiveSpells::Type_Enchantment)
|
|
|
|
, 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);
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ActiveSpells::ActiveSpellParams::ActiveSpellParams(const ESM::ActiveSpells::ActiveSpellParams& params)
|
2022-09-22 21:26:05 +03:00
|
|
|
: mId(params.mId)
|
|
|
|
, mEffects(params.mEffects)
|
|
|
|
, mDisplayName(params.mDisplayName)
|
|
|
|
, mCasterActorId(params.mCasterActorId)
|
|
|
|
, mSlot(params.mItem.isSet() ? params.mItem.mIndex : 0)
|
|
|
|
, mType(params.mType)
|
|
|
|
, 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)
|
2022-09-22 21:26:05 +03:00
|
|
|
: mId(params.mId)
|
|
|
|
, mDisplayName(params.mDisplayName)
|
|
|
|
, mCasterActorId(actor.getClass().getCreatureStats(actor).getActorId())
|
|
|
|
, mSlot(params.mSlot)
|
|
|
|
, mType(params.mType)
|
|
|
|
, mWorsenings(-1)
|
|
|
|
{
|
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
ESM::ActiveSpells::ActiveSpellParams ActiveSpells::ActiveSpellParams::toEsm() const
|
|
|
|
{
|
|
|
|
ESM::ActiveSpells::ActiveSpellParams params;
|
|
|
|
params.mId = mId;
|
|
|
|
params.mEffects = mEffects;
|
|
|
|
params.mDisplayName = mDisplayName;
|
|
|
|
params.mCasterActorId = mCasterActorId;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (mSlot)
|
2012-05-19 15:01:07 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
// Note that we're storing the inventory slot as a RefNum instead of an int as a matter of future proofing
|
|
|
|
// mSlot needs to be replaced with a RefNum once inventory items get persistent RefNum (#4508 #6148)
|
|
|
|
params.mItem = { static_cast<unsigned int>(mSlot), 0 };
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
params.mType = mType;
|
|
|
|
params.mWorsenings = mWorsenings;
|
|
|
|
params.mNextWorsening = mNextWorsening.toEsm();
|
|
|
|
return params;
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::ActiveSpellParams::worsen()
|
|
|
|
{
|
|
|
|
++mWorsenings;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (!mWorsenings)
|
2021-08-27 20:07:50 +02:00
|
|
|
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
|
|
|
|
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);
|
2022-09-22 21:26:05 +03:00
|
|
|
IterationGuard guard{ *this };
|
2021-08-27 20:07:50 +02:00
|
|
|
// Erase no longer active spells and effects
|
2022-09-22 21:26:05 +03:00
|
|
|
for (auto spellIt = mSpells.begin(); spellIt != mSpells.end();)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (spellIt->mType != ESM::ActiveSpells::Type_Temporary
|
|
|
|
&& spellIt->mType != ESM::ActiveSpells::Type_Consumable)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
++spellIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool removedSpell = false;
|
2022-09-22 21:26:05 +03:00
|
|
|
for (auto effectIt = spellIt->mEffects.begin(); effectIt != spellIt->mEffects.end();)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (effectIt->mFlags & ESM::ActiveEffect::Flag_Remove && effectIt->mTimeLeft <= 0.f)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
auto effect = *effectIt;
|
|
|
|
effectIt = spellIt->mEffects.erase(effectIt);
|
|
|
|
onMagicEffectRemoved(ptr, *spellIt, effect);
|
|
|
|
removedSpell = applyPurges(ptr, &spellIt, &effectIt);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (removedSpell)
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++effectIt;
|
|
|
|
}
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
if (removedSpell)
|
2021-08-27 20:07:50 +02:00
|
|
|
continue;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (spellIt->mEffects.empty())
|
2021-08-27 20:07:50 +02:00
|
|
|
spellIt = mSpells.erase(spellIt);
|
|
|
|
else
|
|
|
|
++spellIt;
|
|
|
|
}
|
2013-11-15 20:29:47 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const auto& spell : mQueue)
|
2021-08-27 20:07:50 +02:00
|
|
|
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();
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const ESM::Spell* spell : spells)
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (spell->mData.mType != ESM::Spell::ST_Spell && spell->mData.mType != ESM::Spell::ST_Power
|
|
|
|
&& !isSpellActive(spell->mId))
|
|
|
|
mSpells.emplace_back(ActiveSpellParams{ spell, ptr });
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2022-09-22 21:26:05 +03: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);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (store.getInvListener() != nullptr)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
bool playNonLooping = !store.isFirstEquip();
|
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
2022-09-22 21:26:05 +03:00
|
|
|
for (int slotIndex = 0; slotIndex < MWWorld::InventoryStore::Slots; slotIndex++)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
auto slot = store.getSlot(slotIndex);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (slot == store.end())
|
2021-08-27 20:07:50 +02:00
|
|
|
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);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (enchantmentId.empty())
|
2021-08-27 20:07:50 +02:00
|
|
|
continue;
|
|
|
|
const ESM::Enchantment* enchantment = world->getStore().get<ESM::Enchantment>().find(enchantmentId);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (enchantment->mData.mType != ESM::Enchantment::ConstantEffect)
|
2021-08-27 20:07:50 +02:00
|
|
|
continue;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (std::find_if(mSpells.begin(), mSpells.end(),
|
|
|
|
[&](const ActiveSpellParams& params) {
|
|
|
|
return params.mSlot == slotIndex && params.mType == ESM::ActiveSpells::Type_Enchantment
|
|
|
|
&& params.mId == slot->getCellRef().getRefId();
|
|
|
|
})
|
|
|
|
!= mSpells.end())
|
2021-08-27 20:07:50 +02:00
|
|
|
continue;
|
2022-09-22 21:26:05 +03:00
|
|
|
// world->breakInvisibility leads to a stack overflow as it calls this method so just break
|
|
|
|
// invisibility manually
|
2022-07-31 09:48:01 +02:00
|
|
|
purgeEffect(ptr, ESM::MagicEffect::Invisibility);
|
|
|
|
applyPurges(ptr);
|
2022-09-22 21:26:05 +03:00
|
|
|
const ActiveSpellParams& params
|
|
|
|
= mSpells.emplace_back(ActiveSpellParams{ *slot, enchantment, slotIndex, ptr });
|
|
|
|
for (const auto& effect : params.mEffects)
|
|
|
|
MWMechanics::playEffects(
|
|
|
|
ptr, *world->getStore().get<ESM::MagicEffect>().find(effect.mEffectId), playNonLooping);
|
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
|
2022-09-22 21:26:05 +03:00
|
|
|
for (auto spellIt = mSpells.begin(); spellIt != mSpells.end();)
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
const auto caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(
|
|
|
|
spellIt->mCasterActorId); // Maybe make this search outside active grid?
|
2021-08-27 20:07:50 +02:00
|
|
|
bool removedSpell = false;
|
2021-10-10 16:28:45 +02:00
|
|
|
std::optional<ActiveSpellParams> reflected;
|
2022-09-22 21:26:05 +03: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-22 21:26:05 +03:00
|
|
|
if (result.mType == MagicApplicationResult::Type::REFLECTED)
|
2021-10-10 16:28:45 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (!reflected)
|
2021-12-21 10:50:28 +01:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
static const bool keepOriginalCaster
|
|
|
|
= Settings::Manager::getBool("classic reflected absorb spells behavior", "Game");
|
|
|
|
if (keepOriginalCaster)
|
|
|
|
reflected = { *spellIt, caster };
|
2021-12-21 10:50:28 +01:00
|
|
|
else
|
2022-09-22 21:26:05 +03:00
|
|
|
reflected = { *spellIt, ptr };
|
2021-12-21 10:50:28 +01:00
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
auto& reflectedEffect = reflected->mEffects.emplace_back(*it);
|
2022-09-22 21:26:05 +03:00
|
|
|
reflectedEffect.mFlags
|
|
|
|
= ESM::ActiveEffect::Flag_Ignore_Reflect | ESM::ActiveEffect::Flag_Ignore_SpellAbsorption;
|
2021-10-10 16:28:45 +02:00
|
|
|
it = spellIt->mEffects.erase(it);
|
|
|
|
}
|
2022-09-22 21:26:05 +03: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-22 21:26:05 +03:00
|
|
|
if (!updatedEnemy && result.mShowHealth && caster == player && ptr != player)
|
2022-09-03 19:49:59 +02:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->setEnemy(ptr);
|
|
|
|
updatedEnemy = true;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
if (!updatedHitOverlay && result.mShowHit && ptr == player)
|
2022-09-03 19:49:59 +02:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
|
|
|
|
updatedHitOverlay = true;
|
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
removedSpell = applyPurges(ptr, &spellIt, &it);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (removedSpell)
|
2015-03-01 15:34:18 +13:00
|
|
|
break;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
if (reflected)
|
2021-10-10 16:28:45 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
const ESM::Static* reflectStatic
|
2022-10-18 09:26:55 +02:00
|
|
|
= MWBase::Environment::get().getWorld()->getStore().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);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (animation && !reflectStatic->mModel.empty())
|
2022-06-29 00:32:11 +02:00
|
|
|
{
|
|
|
|
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
2022-09-22 21:26:05 +03:00
|
|
|
animation->addEffect(Misc::ResourceHelpers::correctMeshPath(reflectStatic->mModel, vfs),
|
2022-08-23 18:25:25 +02:00
|
|
|
ESM::MagicEffect::Reflect, false);
|
2022-06-29 00:32:11 +02:00
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell(*reflected);
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
if (removedSpell)
|
2021-08-27 20:07:50 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bool remove = false;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (spellIt->mType == ESM::ActiveSpells::Type_Ability
|
|
|
|
|| spellIt->mType == ESM::ActiveSpells::Type_Permanent)
|
2021-10-09 12:27:17 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
remove = !spells.hasSpell(spellIt->mId);
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
catch (const std::runtime_error& e)
|
2021-10-09 12:27:17 +02:00
|
|
|
{
|
|
|
|
remove = true;
|
|
|
|
Log(Debug::Error) << "Removing active effect: " << e.what();
|
|
|
|
}
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
else if (spellIt->mType == ESM::ActiveSpells::Type_Enchantment)
|
2015-03-01 15:34:18 +13:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
const auto& store = ptr.getClass().getInventoryStore(ptr);
|
|
|
|
auto slot = store.getSlot(spellIt->mSlot);
|
|
|
|
remove = slot == store.end() || slot->getCellRef().getRefId() != spellIt->mId;
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
if (remove)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
auto params = *spellIt;
|
|
|
|
spellIt = mSpells.erase(spellIt);
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const auto& effect : params.mEffects)
|
2021-08-27 20:07:50 +02:00
|
|
|
onMagicEffectRemoved(ptr, params, effect);
|
|
|
|
applyPurges(ptr, &spellIt);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++spellIt;
|
2015-03-01 15:34:18 +13:00
|
|
|
}
|
2022-11-23 20:59:37 +01:00
|
|
|
|
|
|
|
static const bool keepCalm = Settings::Manager::getBool("classic calm spells behavior", "Game");
|
|
|
|
if (keepCalm)
|
|
|
|
{
|
|
|
|
ESM::MagicEffect::Effects effect
|
|
|
|
= ptr.getClass().isNpc() ? ESM::MagicEffect::CalmHumanoid : ESM::MagicEffect::CalmCreature;
|
|
|
|
if (creatureStats.getMagicEffects().get(effect).getMagnitude() > 0.f)
|
|
|
|
creatureStats.getAiSequence().stopCombat();
|
|
|
|
}
|
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
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (spell.mType != ESM::ActiveSpells::Type_Consumable)
|
2018-08-27 02:17:49 +03:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
auto found = std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& existing) {
|
|
|
|
return spell.mId == existing.mId && spell.mCasterActorId == existing.mCasterActorId
|
|
|
|
&& spell.mSlot == existing.mSlot;
|
2021-08-27 20:07:50 +02:00
|
|
|
});
|
2022-09-22 21:26:05 +03:00
|
|
|
if (found != mSpells.end())
|
2018-08-29 13:40:37 +03:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (merge(found->mEffects, spell.mEffects))
|
2021-08-27 20:07:50 +02:00
|
|
|
return;
|
|
|
|
auto params = *found;
|
|
|
|
mSpells.erase(found);
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const auto& effect : params.mEffects)
|
2021-08-27 20:07:50 +02:00
|
|
|
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);
|
2014-01-03 04:56:54 +01:00
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
ActiveSpells::ActiveSpells()
|
|
|
|
: mIterating(false)
|
|
|
|
{
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
return std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& spell) { return spell.mId == id; })
|
|
|
|
!= mSpells.end();
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2017-08-14 20:39:04 +04:00
|
|
|
|
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)
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
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);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (!mIterating)
|
2013-11-17 23:15:57 +01:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
IterationGuard guard{ *this };
|
2021-08-27 20:07:50 +02:00
|
|
|
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);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (!mIterating)
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
IterationGuard guard{ *this };
|
2021-08-27 20:07:50 +02:00
|
|
|
applyPurges(ptr);
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03: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;
|
2022-09-22 21:26:05 +03:00
|
|
|
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();
|
2022-09-22 21:26:05 +03:00
|
|
|
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;
|
2022-09-22 21:26:05 +03:00
|
|
|
std::visit(
|
|
|
|
[&](auto&& variant) {
|
|
|
|
using T = std::decay_t<decltype(variant)>;
|
|
|
|
if constexpr (std::is_same_v<T, ParamsPredicate>)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (variant(*spellIt))
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
auto params = *spellIt;
|
|
|
|
spellIt = mSpells.erase(spellIt);
|
|
|
|
if (isCurrentSpell)
|
|
|
|
{
|
|
|
|
*currentSpell = spellIt;
|
|
|
|
removedCurrentSpell = true;
|
|
|
|
}
|
|
|
|
for (const auto& effect : params.mEffects)
|
|
|
|
onMagicEffectRemoved(ptr, params, effect);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
|
|
|
++spellIt;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
static_assert(std::is_same_v<T, EffectPredicate>, "Non-exhaustive visitor");
|
|
|
|
for (auto effectIt = spellIt->mEffects.begin(); effectIt != spellIt->mEffects.end();)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (variant(*spellIt, *effectIt))
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
auto effect = *effectIt;
|
|
|
|
if (isCurrentSpell && currentEffect)
|
|
|
|
{
|
|
|
|
auto distance = std::distance(spellIt->mEffects.begin(), *currentEffect);
|
|
|
|
if (effectIt <= *currentEffect)
|
|
|
|
distance--;
|
|
|
|
effectIt = spellIt->mEffects.erase(effectIt);
|
|
|
|
*currentEffect = spellIt->mEffects.begin() + distance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
effectIt = spellIt->mEffects.erase(effectIt);
|
|
|
|
onMagicEffectRemoved(ptr, *spellIt, effect);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
else
|
2022-09-22 21:26:05 +03:00
|
|
|
++effectIt;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
++spellIt;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
},
|
|
|
|
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
|
|
|
|
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
|
|
|
void ActiveSpells::removeEffects(const MWWorld::Ptr& ptr, const ESM::RefId& id)
|
2019-09-30 20:27:42 +04:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
purge([=](const ActiveSpellParams& params) { return params.mId == id; }, ptr);
|
2019-09-30 20:27:42 +04:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void ActiveSpells::purgeEffect(const MWWorld::Ptr& ptr, short effectId)
|
2014-05-14 22:16:39 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
purge([=](const ActiveSpellParams&, const ESM::ActiveEffect& effect) { return effect.mEffectId == effectId; },
|
|
|
|
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
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
purge([=](const ActiveSpellParams& params) { return params.mCasterActorId == casterActorId; }, ptr);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
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();
|
2022-09-22 21:26:05 +03:00
|
|
|
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
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
for (auto& spell : mSpells)
|
2014-05-14 22:16:39 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (spell.mWorsenings >= 0)
|
2021-08-27 20:07:50 +02:00
|
|
|
spell.mNextWorsening += hours;
|
2014-05-14 22:16:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void ActiveSpells::writeState(ESM::ActiveSpells& state) const
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const auto& spell : mSpells)
|
2021-08-27 20:07:50 +02:00
|
|
|
state.mSpells.emplace_back(spell.toEsm());
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const auto& spell : mQueue)
|
2021-08-27 20:07:50 +02:00
|
|
|
state.mQueue.emplace_back(spell.toEsm());
|
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void ActiveSpells::readState(const ESM::ActiveSpells& state)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
for (const ESM::ActiveSpells::ActiveSpellParams& spell : state.mSpells)
|
|
|
|
mSpells.emplace_back(ActiveSpellParams{ spell });
|
|
|
|
for (const ESM::ActiveSpells::ActiveSpellParams& spell : state.mQueue)
|
|
|
|
mQueue.emplace_back(ActiveSpellParams{ spell });
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2022-08-21 13:33:21 +02:00
|
|
|
|
|
|
|
void ActiveSpells::unloadActor(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
purge(
|
|
|
|
[](const auto& spell) {
|
|
|
|
return spell.getType() == ESM::ActiveSpells::Type_Consumable
|
|
|
|
|| spell.getType() == ESM::ActiveSpells::Type_Temporary;
|
|
|
|
},
|
|
|
|
ptr);
|
2022-08-21 13:33:21 +02:00
|
|
|
mQueue.clear();
|
|
|
|
}
|
2012-05-19 15:01:07 +02:00
|
|
|
}
|