mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:15:32 +00:00
Store permanent magic effects in savegame (Fixes #1648)
This commit is contained in:
parent
6c9875969a
commit
e2346d7c37
5 changed files with 73 additions and 2 deletions
|
@ -170,9 +170,9 @@ namespace MWWorld
|
|||
|
||||
Ptr search (const std::string& id);
|
||||
|
||||
void writeState (ESM::InventoryState& state) const;
|
||||
virtual void writeState (ESM::InventoryState& state) const;
|
||||
|
||||
void readState (const ESM::InventoryState& state);
|
||||
virtual void readState (const ESM::InventoryState& state);
|
||||
|
||||
friend class ContainerStoreIterator;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <components/esm/loadench.hpp>
|
||||
#include <components/esm/inventorystate.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
@ -654,3 +655,39 @@ bool MWWorld::InventoryStore::isEquipped(const MWWorld::Ptr &item)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MWWorld::InventoryStore::writeState(ESM::InventoryState &state) const
|
||||
{
|
||||
MWWorld::ContainerStore::writeState(state);
|
||||
|
||||
for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin(); it != mPermanentMagicEffectMagnitudes.end(); ++it)
|
||||
{
|
||||
std::vector<std::pair<float, float> > params;
|
||||
for (std::vector<EffectParams>::const_iterator pIt = it->second.begin(); pIt != it->second.end(); ++pIt)
|
||||
{
|
||||
params.push_back(std::make_pair(pIt->mRandom, pIt->mMultiplier));
|
||||
}
|
||||
|
||||
state.mPermanentMagicEffectMagnitudes[it->first] = params;
|
||||
}
|
||||
}
|
||||
|
||||
void MWWorld::InventoryStore::readState(const ESM::InventoryState &state)
|
||||
{
|
||||
MWWorld::ContainerStore::readState(state);
|
||||
|
||||
for (ESM::InventoryState::TEffectMagnitudes::const_iterator it = state.mPermanentMagicEffectMagnitudes.begin();
|
||||
it != state.mPermanentMagicEffectMagnitudes.end(); ++it)
|
||||
{
|
||||
std::vector<EffectParams> params;
|
||||
for (std::vector<std::pair<float, float> >::const_iterator pIt = it->second.begin(); pIt != it->second.end(); ++pIt)
|
||||
{
|
||||
EffectParams p;
|
||||
p.mRandom = pIt->first;
|
||||
p.mMultiplier = pIt->second;
|
||||
params.push_back(p);
|
||||
}
|
||||
|
||||
mPermanentMagicEffectMagnitudes[it->first] = params;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,6 +205,10 @@ namespace MWWorld
|
|||
|
||||
virtual void clear();
|
||||
///< Empty container.
|
||||
|
||||
virtual void writeState (ESM::InventoryState& state) const;
|
||||
|
||||
virtual void readState (const ESM::InventoryState& state);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,21 @@ void ESM::InventoryState::load (ESMReader &esm)
|
|||
esm.getHNT (count, "COUN");
|
||||
mLevelledItemMap[id] = count;
|
||||
}
|
||||
|
||||
while (esm.isNextSub("MAGI"))
|
||||
{
|
||||
std::string id = esm.getHString();
|
||||
|
||||
std::vector<std::pair<float, float> > params;
|
||||
while (esm.isNextSub("RAND"))
|
||||
{
|
||||
float rand, multiplier;
|
||||
esm.getHT (rand);
|
||||
esm.getHNT (multiplier, "MULT");
|
||||
params.push_back(std::make_pair(rand, multiplier));
|
||||
}
|
||||
mPermanentMagicEffectMagnitudes[id] = params;
|
||||
}
|
||||
}
|
||||
|
||||
void ESM::InventoryState::save (ESMWriter &esm) const
|
||||
|
@ -75,4 +90,16 @@ void ESM::InventoryState::save (ESMWriter &esm) const
|
|||
esm.writeHNString ("LEVM", it->first);
|
||||
esm.writeHNT ("COUN", it->second);
|
||||
}
|
||||
|
||||
for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin(); it != mPermanentMagicEffectMagnitudes.end(); ++it)
|
||||
{
|
||||
esm.writeHNString("MAGI", it->first);
|
||||
|
||||
const std::vector<std::pair<float, float> >& params = it->second;
|
||||
for (std::vector<std::pair<float, float> >::const_iterator pIt = params.begin(); pIt != params.end(); ++pIt)
|
||||
{
|
||||
esm.writeHNT ("RAND", pIt->first);
|
||||
esm.writeHNT ("MULT", pIt->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ namespace ESM
|
|||
|
||||
std::map<std::string, int> mLevelledItemMap;
|
||||
|
||||
typedef std::map<std::string, std::vector<std::pair<float, float> > > TEffectMagnitudes;
|
||||
TEffectMagnitudes mPermanentMagicEffectMagnitudes;
|
||||
|
||||
virtual ~InventoryState() {}
|
||||
|
||||
virtual void load (ESMReader &esm);
|
||||
|
|
Loading…
Reference in a new issue