forked from mirror/openmw-tes3mp
Implement saving/loading of corprus stats, remove redundant code
This commit is contained in:
parent
3722c7adc3
commit
96e7ff666d
5 changed files with 63 additions and 17 deletions
|
@ -483,8 +483,6 @@ namespace MWMechanics
|
|||
{
|
||||
if (spells.mCorprusSpells.find(it->first) != spells.mCorprusSpells.end())
|
||||
{
|
||||
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(it->first);
|
||||
|
||||
if (MWBase::Environment::get().getWorld()->getTimeStamp() >= spells.mCorprusSpells[it->first].mNextWorsening)
|
||||
{
|
||||
spells.worsenCorprus(it->first);
|
||||
|
|
|
@ -44,17 +44,7 @@ namespace MWMechanics
|
|||
}
|
||||
}
|
||||
|
||||
bool hasCorprusEffect = false;
|
||||
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt)
|
||||
{
|
||||
if (effectIt->mEffectID == ESM::MagicEffect::Corprus)
|
||||
{
|
||||
hasCorprusEffect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCorprusEffect)
|
||||
if (hasCorprusEffect(spell))
|
||||
{
|
||||
CorprusStats corprus;
|
||||
corprus.mWorsenings = 0;
|
||||
|
@ -104,15 +94,15 @@ namespace MWMechanics
|
|||
if (iter->second.find(i) != iter->second.end())
|
||||
random = iter->second.at(i);
|
||||
|
||||
int applyTimes = 1;
|
||||
int magnMult = 1;
|
||||
if (mCorprusSpells.find(spell->mId) != mCorprusSpells.end())
|
||||
{
|
||||
const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(spell->mEffects.mList.front().mEffectID);
|
||||
if ((it->mEffectID != ESM::MagicEffect::Corprus) && (effect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) // APPLIED_ONCE
|
||||
applyTimes += mCorprusSpells.at(spell->mId).mWorsenings;
|
||||
magnMult += mCorprusSpells.at(spell->mId).mWorsenings;
|
||||
}
|
||||
for (int j = 0; j < applyTimes; j++)
|
||||
effects.add (*it, it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random);
|
||||
|
||||
effects.add (*it, (it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random) * magnMult);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
@ -253,6 +243,18 @@ namespace MWMechanics
|
|||
mCorprusSpells[corpSpellId].mWorsenings++;
|
||||
}
|
||||
|
||||
bool Spells::hasCorprusEffect(const ESM::Spell *spell)
|
||||
{
|
||||
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt)
|
||||
{
|
||||
if (effectIt->mEffectID == ESM::MagicEffect::Corprus)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Spells::canUsePower(const std::string &power) const
|
||||
{
|
||||
std::map<std::string, MWWorld::TimeStamp>::const_iterator it = mUsedPowers.find(power);
|
||||
|
@ -289,6 +291,16 @@ namespace MWMechanics
|
|||
// No need to discard spells here (doesn't really matter if non existent ids are kept)
|
||||
for (std::map<std::string, ESM::TimeStamp>::const_iterator it = state.mUsedPowers.begin(); it != state.mUsedPowers.end(); ++it)
|
||||
mUsedPowers[it->first] = MWWorld::TimeStamp(it->second);
|
||||
|
||||
mCorprusSpells.clear();
|
||||
for (std::map<std::string, ESM::SpellState::CorprusStats>::const_iterator it = state.mCorprusSpells.begin(); it != state.mCorprusSpells.end(); ++it)
|
||||
{
|
||||
if (mSpells.find(it->first) != mSpells.end()) // Discard unavailable corprus spells
|
||||
{
|
||||
mCorprusSpells[it->first].mWorsenings = state.mCorprusSpells.at(it->first).mWorsenings;
|
||||
mCorprusSpells[it->first].mNextWorsening = MWWorld::TimeStamp(state.mCorprusSpells.at(it->first).mNextWorsening);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Spells::writeState(ESM::SpellState &state) const
|
||||
|
@ -298,5 +310,11 @@ namespace MWMechanics
|
|||
|
||||
for (std::map<std::string, MWWorld::TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
||||
state.mUsedPowers[it->first] = it->second.toEsm();
|
||||
|
||||
for (std::map<std::string, CorprusStats>::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it)
|
||||
{
|
||||
state.mCorprusSpells[it->first].mWorsenings = mCorprusSpells.at(it->first).mWorsenings;
|
||||
state.mCorprusSpells[it->first].mNextWorsening = mCorprusSpells.at(it->first).mNextWorsening.toEsm();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ namespace MWMechanics
|
|||
std::map<std::string, CorprusStats> mCorprusSpells;
|
||||
void worsenCorprus(const std::string &corpSpellId);
|
||||
|
||||
static bool hasCorprusEffect(const ESM::Spell *spell);
|
||||
|
||||
public:
|
||||
|
||||
bool canUsePower (const std::string& power) const;
|
||||
|
|
|
@ -27,6 +27,17 @@ namespace ESM
|
|||
mSpells[id] = random;
|
||||
}
|
||||
|
||||
while (esm.isNextSub("CORP"))
|
||||
{
|
||||
std::string id = esm.getHString();
|
||||
|
||||
CorprusStats stats;
|
||||
esm.getHNT(stats.mWorsenings, "WORS");
|
||||
esm.getHNT(stats.mNextWorsening, "TIME");
|
||||
|
||||
mCorprusSpells[id] = stats;
|
||||
}
|
||||
|
||||
while (esm.isNextSub("USED"))
|
||||
{
|
||||
std::string id = esm.getHString();
|
||||
|
@ -53,6 +64,15 @@ namespace ESM
|
|||
}
|
||||
}
|
||||
|
||||
for (std::map<std::string, CorprusStats>::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it)
|
||||
{
|
||||
esm.writeHNString("CORP", it->first);
|
||||
|
||||
const CorprusStats & stats = it->second;
|
||||
esm.writeHNT("WORS", stats.mWorsenings);
|
||||
esm.writeHNT("TIME", stats.mNextWorsening);
|
||||
}
|
||||
|
||||
for (std::map<std::string, TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
||||
{
|
||||
esm.writeHNString("USED", it->first);
|
||||
|
|
|
@ -13,9 +13,17 @@ namespace ESM
|
|||
|
||||
struct SpellState
|
||||
{
|
||||
struct CorprusStats
|
||||
{
|
||||
int mWorsenings;
|
||||
TimeStamp mNextWorsening;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::map<const int, float> > TContainer;
|
||||
TContainer mSpells;
|
||||
|
||||
std::map<std::string, CorprusStats> mCorprusSpells;
|
||||
|
||||
std::map<std::string, TimeStamp> mUsedPowers;
|
||||
|
||||
std::string mSelectedSpell;
|
||||
|
|
Loading…
Reference in a new issue