Use struct instead of tuple

pull/593/head
Andrei Kortunov 4 years ago
parent 924f634bda
commit 67eace1028

@ -252,7 +252,7 @@ namespace MWGui
} }
// Clean up summoned creatures as well // Clean up summoned creatures as well
std::map<MWMechanics::CreatureStats::SummonKey, int>& creatureMap = creatureStats.getSummonedCreatureMap(); std::map<ESM::SummonKey, int>& creatureMap = creatureStats.getSummonedCreatureMap();
for (const auto& creature : creatureMap) for (const auto& creature : creatureMap)
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mPtr, creature.second); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mPtr, creature.second);
creatureMap.clear(); creatureMap.clear();

@ -2016,7 +2016,7 @@ namespace MWMechanics
// Remove the summoned creature's summoned creatures as well // Remove the summoned creature's summoned creatures as well
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
std::map<CreatureStats::SummonKey, int>& creatureMap = stats.getSummonedCreatureMap(); std::map<ESM::SummonKey, int>& creatureMap = stats.getSummonedCreatureMap();
for (const auto& creature : creatureMap) for (const auto& creature : creatureMap)
cleanupSummonedCreature(stats, creature.second); cleanupSummonedCreature(stats, creature.second);
creatureMap.clear(); creatureMap.clear();

@ -683,7 +683,7 @@ namespace MWMechanics
return mTimeOfDeath; return mTimeOfDeath;
} }
std::map<CreatureStats::SummonKey, int>& CreatureStats::getSummonedCreatureMap() std::map<ESM::SummonKey, int>& CreatureStats::getSummonedCreatureMap()
{ {
return mSummonedCreatures; return mSummonedCreatures;
} }

@ -13,6 +13,7 @@
#include "drawstate.hpp" #include "drawstate.hpp"
#include <components/esm/attr.hpp> #include <components/esm/attr.hpp>
#include <components/esm/magiceffects.hpp>
namespace ESM namespace ESM
{ {
@ -83,10 +84,8 @@ namespace MWMechanics
// The difference between view direction and lower body direction. // The difference between view direction and lower body direction.
float mSideMovementAngle; float mSideMovementAngle;
public:
typedef std::tuple<int, std::string, int> SummonKey; // <ESM::MagicEffect index, source ID, effect index>
private: private:
std::map<SummonKey, int> mSummonedCreatures; // <SummonKey, ActorId> std::map<ESM::SummonKey, int> mSummonedCreatures; // <SummonKey, ActorId>
// Contains ActorIds of summoned creatures with an expired lifetime that have not been deleted yet. // 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. // This may be necessary when the creature is in an inactive cell.
@ -235,7 +234,7 @@ namespace MWMechanics
void setBlock(bool value); void setBlock(bool value);
bool getBlock() const; bool getBlock() const;
std::map<SummonKey, int>& getSummonedCreatureMap(); // <SummonKey, ActorId of summoned creature> std::map<ESM::SummonKey, int>& getSummonedCreatureMap(); // <SummonKey, ActorId of summoned creature>
std::vector<int>& getSummonedCreatureGraveyard(); // ActorIds std::vector<int>& getSummonedCreatureGraveyard(); // ActorIds
enum Flag enum Flag

@ -270,7 +270,8 @@ namespace MWMechanics
if (isSummoningEffect(effectIt->mEffectID) && !target.isEmpty() && target.getClass().isActor()) if (isSummoningEffect(effectIt->mEffectID) && !target.isEmpty() && target.getClass().isActor())
{ {
CreatureStats& targetStats = target.getClass().getCreatureStats(target); CreatureStats& targetStats = target.getClass().getCreatureStats(target);
std::map<CreatureStats::SummonKey, int>::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()) if (findCreature != targetStats.getSummonedCreatureMap().end())
{ {
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(target, findCreature->second); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(target, findCreature->second);

@ -69,21 +69,21 @@ namespace MWMechanics
{ {
if (isSummoningEffect(key.mId) && magnitude > 0) 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) void UpdateSummonedCreatures::process(bool cleanup)
{ {
MWMechanics::CreatureStats& creatureStats = mActor.getClass().getCreatureStats(mActor); MWMechanics::CreatureStats& creatureStats = mActor.getClass().getCreatureStats(mActor);
std::map<CreatureStats::SummonKey, int>& creatureMap = creatureStats.getSummonedCreatureMap(); std::map<ESM::SummonKey, int>& creatureMap = creatureStats.getSummonedCreatureMap();
for (std::set<CreatureStats::SummonKey>::iterator it = mActiveEffects.begin(); it != mActiveEffects.end(); ++it) for (std::set<ESM::SummonKey>::iterator it = mActiveEffects.begin(); it != mActiveEffects.end(); ++it)
{ {
bool found = creatureMap.find(*it) != creatureMap.end(); bool found = creatureMap.find(*it) != creatureMap.end();
if (!found) if (!found)
{ {
std::string creatureID = getSummonedCreature(std::get<0>(*it)); std::string creatureID = getSummonedCreature(it->mEffectId);
if (!creatureID.empty()) if (!creatureID.empty())
{ {
int creatureActorId = -1; int creatureActorId = -1;
@ -121,7 +121,7 @@ namespace MWMechanics
} }
// Update summon effects // Update summon effects
for (std::map<CreatureStats::SummonKey, int>::iterator it = creatureMap.begin(); it != creatureMap.end(); ) for (std::map<ESM::SummonKey, int>::iterator it = creatureMap.begin(); it != creatureMap.end(); )
{ {
bool found = mActiveEffects.find(it->first) != mActiveEffects.end(); bool found = mActiveEffects.find(it->first) != mActiveEffects.end();
if (!found) if (!found)
@ -143,16 +143,17 @@ namespace MWMechanics
if (!cleanup) if (!cleanup)
return; return;
for (std::map<CreatureStats::SummonKey, int>::iterator it = creatureMap.begin(); it != creatureMap.end(); ) for (std::map<ESM::SummonKey, int>::iterator it = creatureMap.begin(); it != creatureMap.end(); )
{ {
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(it->second); MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(it->second);
if (ptr.isEmpty() || (ptr.getClass().getCreatureStats(ptr).isDead() && ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished())) 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 // 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)); const ESM::SummonKey& key = it->first;
creatureStats.getSpells().purgeEffect(std::get<0>(it->first), std::get<1>(it->first)); creatureStats.getActiveSpells().purgeEffect(key.mEffectId, key.mSourceId, key.mEffectIndex);
creatureStats.getSpells().purgeEffect(key.mEffectId, key.mSourceId);
if (mActor.getClass().hasInventoryStore(mActor)) 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); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mActor, it->second);
creatureMap.erase(it++); creatureMap.erase(it++);

@ -5,6 +5,8 @@
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include <components/esm/magiceffects.hpp>
#include "magiceffects.hpp" #include "magiceffects.hpp"
namespace MWMechanics namespace MWMechanics
@ -30,7 +32,7 @@ namespace MWMechanics
private: private:
MWWorld::Ptr mActor; MWWorld::Ptr mActor;
std::set<std::tuple<int, std::string, int>> mActiveEffects; std::set<ESM::SummonKey> mActiveEffects;
}; };
} }

@ -119,7 +119,7 @@ void ESM::CreatureStats::load (ESMReader &esm)
esm.getHNOT (effectIndex, "EIND"); esm.getHNOT (effectIndex, "EIND");
int actorId; int actorId;
esm.getHNT (actorId, "ACID"); esm.getHNT (actorId, "ACID");
mSummonedCreatureMap[std::make_tuple(magicEffect, source, effectIndex)] = actorId; mSummonedCreatureMap[SummonKey(magicEffect, source, effectIndex)] = actorId;
} }
while (esm.isNextSub("GRAV")) while (esm.isNextSub("GRAV"))
@ -214,19 +214,19 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
mAiSequence.save(esm); mAiSequence.save(esm);
mMagicEffects.save(esm); mMagicEffects.save(esm);
for (std::map<std::tuple<int, std::string, int>, int>::const_iterator it = mSummonedCreatureMap.begin(); it != mSummonedCreatureMap.end(); ++it) for (const auto& summon : mSummonedCreatureMap)
{ {
esm.writeHNT ("SUMM", std::get<0>(it->first)); esm.writeHNT ("SUMM", summon.first.mEffectId);
esm.writeHNString ("SOUR", std::get<1>(it->first)); esm.writeHNString ("SOUR", summon.first.mSourceId);
int effectIndex = std::get<2>(it->first); int effectIndex = summon.first.mEffectIndex;
if (effectIndex != -1) if (effectIndex != -1)
esm.writeHNT ("EIND", effectIndex); esm.writeHNT ("EIND", effectIndex);
esm.writeHNT ("ACID", it->second); esm.writeHNT ("ACID", summon.second);
} }
for (std::vector<int>::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); esm.writeHNT("AISE", mHasAiSettings);
@ -236,11 +236,11 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
mAiSettings[i].save(esm); mAiSettings[i].save(esm);
} }
for (std::map<std::string, CorprusStats>::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("WORS", stats.mWorsenings);
esm.writeHNT("TIME", stats.mNextWorsening); esm.writeHNT("TIME", stats.mNextWorsening);
} }

@ -39,7 +39,7 @@ namespace ESM
bool mHasAiSettings; bool mHasAiSettings;
StatState<int> mAiSettings[4]; StatState<int> mAiSettings[4];
std::map<std::tuple<int, std::string, int>, int> mSummonedCreatureMap; std::map<SummonKey, int> mSummonedCreatureMap;
std::vector<int> mSummonGraveyard; std::vector<int> mSummonGraveyard;
ESM::TimeStamp mTradeTime; ESM::TimeStamp mTradeTime;

@ -2,6 +2,7 @@
#define COMPONENTS_ESM_MAGICEFFECTS_H #define COMPONENTS_ESM_MAGICEFFECTS_H
#include <map> #include <map>
#include <string>
namespace ESM namespace ESM
{ {
@ -18,6 +19,37 @@ namespace ESM
void save (ESMWriter &esm) const; 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 #endif

Loading…
Cancel
Save