diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 444ce4cb1..a68fddca1 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -252,7 +252,7 @@ namespace MWGui } // Clean up summoned creatures as well - std::map& creatureMap = creatureStats.getSummonedCreatureMap(); + std::map& creatureMap = creatureStats.getSummonedCreatureMap(); for (const auto& creature : creatureMap) MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mPtr, creature.second); creatureMap.clear(); diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 21f71ce5d..271b352ea 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -2016,7 +2016,7 @@ namespace MWMechanics // Remove the summoned creature's summoned creatures as well MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); - std::map& creatureMap = stats.getSummonedCreatureMap(); + std::map& creatureMap = stats.getSummonedCreatureMap(); for (const auto& creature : creatureMap) cleanupSummonedCreature(stats, creature.second); creatureMap.clear(); diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 79b8e23de..1d5fe8347 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -683,7 +683,7 @@ namespace MWMechanics return mTimeOfDeath; } - std::map& CreatureStats::getSummonedCreatureMap() + std::map& CreatureStats::getSummonedCreatureMap() { return mSummonedCreatures; } diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 9a1996ddb..b2c0aec98 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -13,6 +13,7 @@ #include "drawstate.hpp" #include +#include namespace ESM { @@ -83,10 +84,8 @@ namespace MWMechanics // The difference between view direction and lower body direction. float mSideMovementAngle; - public: - typedef std::tuple SummonKey; // private: - std::map mSummonedCreatures; // + std::map mSummonedCreatures; // // Contains ActorIds of summoned creatures with an expired lifetime that have not been deleted yet. // This may be necessary when the creature is in an inactive cell. @@ -235,7 +234,7 @@ namespace MWMechanics void setBlock(bool value); bool getBlock() const; - std::map& getSummonedCreatureMap(); // + std::map& getSummonedCreatureMap(); // std::vector& getSummonedCreatureGraveyard(); // ActorIds enum Flag diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index fb195bb6d..3767acb3f 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -270,7 +270,8 @@ namespace MWMechanics if (isSummoningEffect(effectIt->mEffectID) && !target.isEmpty() && target.getClass().isActor()) { CreatureStats& targetStats = target.getClass().getCreatureStats(target); - std::map::iterator findCreature = targetStats.getSummonedCreatureMap().find(std::make_tuple(effectIt->mEffectID, mId, currentEffectIndex)); + ESM::SummonKey key(effectIt->mEffectID, mId, currentEffectIndex); + auto findCreature = targetStats.getSummonedCreatureMap().find(key); if (findCreature != targetStats.getSummonedCreatureMap().end()) { MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(target, findCreature->second); diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index acb58ea8e..0f699ccad 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -69,21 +69,21 @@ namespace MWMechanics { if (isSummoningEffect(key.mId) && magnitude > 0) { - mActiveEffects.insert(std::make_tuple(key.mId, sourceId, effectIndex)); + mActiveEffects.insert(ESM::SummonKey(key.mId, sourceId, effectIndex)); } } void UpdateSummonedCreatures::process(bool cleanup) { MWMechanics::CreatureStats& creatureStats = mActor.getClass().getCreatureStats(mActor); - std::map& creatureMap = creatureStats.getSummonedCreatureMap(); + std::map& creatureMap = creatureStats.getSummonedCreatureMap(); - for (std::set::iterator it = mActiveEffects.begin(); it != mActiveEffects.end(); ++it) + for (std::set::iterator it = mActiveEffects.begin(); it != mActiveEffects.end(); ++it) { bool found = creatureMap.find(*it) != creatureMap.end(); if (!found) { - std::string creatureID = getSummonedCreature(std::get<0>(*it)); + std::string creatureID = getSummonedCreature(it->mEffectId); if (!creatureID.empty()) { int creatureActorId = -1; @@ -121,7 +121,7 @@ namespace MWMechanics } // Update summon effects - for (std::map::iterator it = creatureMap.begin(); it != creatureMap.end(); ) + for (std::map::iterator it = creatureMap.begin(); it != creatureMap.end(); ) { bool found = mActiveEffects.find(it->first) != mActiveEffects.end(); if (!found) @@ -143,16 +143,17 @@ namespace MWMechanics if (!cleanup) return; - for (std::map::iterator it = creatureMap.begin(); it != creatureMap.end(); ) + for (std::map::iterator it = creatureMap.begin(); it != creatureMap.end(); ) { MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(it->second); if (ptr.isEmpty() || (ptr.getClass().getCreatureStats(ptr).isDead() && ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished())) { // Purge the magic effect so a new creature can be summoned if desired - creatureStats.getActiveSpells().purgeEffect(std::get<0>(it->first), std::get<1>(it->first), std::get<2>(it->first)); - creatureStats.getSpells().purgeEffect(std::get<0>(it->first), std::get<1>(it->first)); + const ESM::SummonKey& key = it->first; + creatureStats.getActiveSpells().purgeEffect(key.mEffectId, key.mSourceId, key.mEffectIndex); + creatureStats.getSpells().purgeEffect(key.mEffectId, key.mSourceId); if (mActor.getClass().hasInventoryStore(mActor)) - mActor.getClass().getInventoryStore(mActor).purgeEffect(std::get<0>(it->first), std::get<1>(it->first), false, std::get<2>(it->first)); + mActor.getClass().getInventoryStore(mActor).purgeEffect(key.mEffectId, key.mSourceId, false, key.mEffectIndex); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mActor, it->second); creatureMap.erase(it++); diff --git a/apps/openmw/mwmechanics/summoning.hpp b/apps/openmw/mwmechanics/summoning.hpp index 78a1969a9..ac820e32f 100644 --- a/apps/openmw/mwmechanics/summoning.hpp +++ b/apps/openmw/mwmechanics/summoning.hpp @@ -5,6 +5,8 @@ #include "../mwworld/ptr.hpp" +#include + #include "magiceffects.hpp" namespace MWMechanics @@ -30,7 +32,7 @@ namespace MWMechanics private: MWWorld::Ptr mActor; - std::set> mActiveEffects; + std::set mActiveEffects; }; } diff --git a/components/esm/creaturestats.cpp b/components/esm/creaturestats.cpp index 4ffe567c6..cb383992c 100644 --- a/components/esm/creaturestats.cpp +++ b/components/esm/creaturestats.cpp @@ -119,7 +119,7 @@ void ESM::CreatureStats::load (ESMReader &esm) esm.getHNOT (effectIndex, "EIND"); int actorId; esm.getHNT (actorId, "ACID"); - mSummonedCreatureMap[std::make_tuple(magicEffect, source, effectIndex)] = actorId; + mSummonedCreatureMap[SummonKey(magicEffect, source, effectIndex)] = actorId; } while (esm.isNextSub("GRAV")) @@ -214,19 +214,19 @@ void ESM::CreatureStats::save (ESMWriter &esm) const mAiSequence.save(esm); mMagicEffects.save(esm); - for (std::map, int>::const_iterator it = mSummonedCreatureMap.begin(); it != mSummonedCreatureMap.end(); ++it) + for (const auto& summon : mSummonedCreatureMap) { - esm.writeHNT ("SUMM", std::get<0>(it->first)); - esm.writeHNString ("SOUR", std::get<1>(it->first)); - int effectIndex = std::get<2>(it->first); + esm.writeHNT ("SUMM", summon.first.mEffectId); + esm.writeHNString ("SOUR", summon.first.mSourceId); + int effectIndex = summon.first.mEffectIndex; if (effectIndex != -1) esm.writeHNT ("EIND", effectIndex); - esm.writeHNT ("ACID", it->second); + esm.writeHNT ("ACID", summon.second); } - for (std::vector::const_iterator it = mSummonGraveyard.begin(); it != mSummonGraveyard.end(); ++it) + for (int key : mSummonGraveyard) { - esm.writeHNT ("GRAV", *it); + esm.writeHNT ("GRAV", key); } esm.writeHNT("AISE", mHasAiSettings); @@ -236,11 +236,11 @@ void ESM::CreatureStats::save (ESMWriter &esm) const mAiSettings[i].save(esm); } - for (std::map::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it) + for (const auto& corprusSpell : mCorprusSpells) { - esm.writeHNString("CORP", it->first); + esm.writeHNString("CORP", corprusSpell.first); - const CorprusStats & stats = it->second; + const CorprusStats & stats = corprusSpell.second; esm.writeHNT("WORS", stats.mWorsenings); esm.writeHNT("TIME", stats.mNextWorsening); } diff --git a/components/esm/creaturestats.hpp b/components/esm/creaturestats.hpp index e79d430ce..13bc50008 100644 --- a/components/esm/creaturestats.hpp +++ b/components/esm/creaturestats.hpp @@ -39,7 +39,7 @@ namespace ESM bool mHasAiSettings; StatState mAiSettings[4]; - std::map, int> mSummonedCreatureMap; + std::map mSummonedCreatureMap; std::vector mSummonGraveyard; ESM::TimeStamp mTradeTime; diff --git a/components/esm/magiceffects.hpp b/components/esm/magiceffects.hpp index 2a6052caa..94ae23a10 100644 --- a/components/esm/magiceffects.hpp +++ b/components/esm/magiceffects.hpp @@ -2,6 +2,7 @@ #define COMPONENTS_ESM_MAGICEFFECTS_H #include +#include namespace ESM { @@ -18,6 +19,37 @@ namespace ESM void save (ESMWriter &esm) const; }; + struct SummonKey + { + SummonKey(int effectId, const std::string& sourceId, int index) + { + mEffectId = effectId; + mSourceId = sourceId; + mEffectIndex = index; + } + + bool operator==(const SummonKey &other) const + { + return mEffectId == other.mEffectId && + mSourceId == other.mSourceId && + mEffectIndex == other.mEffectIndex; + } + + bool operator<(const SummonKey &other) const + { + if (mEffectId < other.mEffectId) + return true; + + if (mSourceId < other.mSourceId) + return true; + + return mEffectIndex < other.mEffectIndex; + } + + int mEffectId; + std::string mSourceId; + int mEffectIndex; + }; } #endif