From 6ab7002908b66098afc260d6ef3a8f235f58ce17 Mon Sep 17 00:00:00 2001 From: Jordan Ayers Date: Mon, 7 Oct 2013 22:28:55 -0500 Subject: [PATCH] MagicEffect: Put magnitude type into ESM::MagicEffect helper. --- apps/openmw/mwgui/spellicons.cpp | 41 ++++++++++++++------------------ apps/openmw/mwgui/widgets.cpp | 28 ++++++++-------------- components/esm/loadmgef.cpp | 11 +++++++++ components/esm/loadmgef.hpp | 8 +++++++ 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/apps/openmw/mwgui/spellicons.cpp b/apps/openmw/mwgui/spellicons.cpp index 3b3057248..0e59230c7 100644 --- a/apps/openmw/mwgui/spellicons.cpp +++ b/apps/openmw/mwgui/spellicons.cpp @@ -172,30 +172,25 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->getGameSettingString( ESM::Attribute::sGmstAttributeIds[effectIt->mKey.mArg], "") + ")"; - if (!(effect->mData.mFlags & ESM::MagicEffect::NoMagnitude)) + int displayType = effect->getMagnitudeDisplayType(); + if (displayType == ESM::MagicEffect::MDT_TimesInt) { - if (it->first == 84) // special handling for fortify maximum magicka - { - std::string timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", ""); - std::stringstream formatter; - formatter << std::fixed << std::setprecision(1) << " " << (effectIt->mMagnitude / 10.0f) << timesInt; - sourcesDescription += formatter.str(); - } - else - { - std::string pt = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", ""); - std::string pts = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", ""); - std::string pct = MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", ""); - const bool usePct = ( - (it->first >= 28 && it->first <= 36) || // Weakness effects - (it->first >= 90 && it->first <= 99) ); // Resistance effects - - sourcesDescription += ": " + boost::lexical_cast(effectIt->mMagnitude); - if ( usePct ) - sourcesDescription += pct; - else - sourcesDescription += " " + ((effectIt->mMagnitude > 1) ? pts : pt); - } + std::string timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", ""); + std::stringstream formatter; + formatter << std::fixed << std::setprecision(1) << " " << (effectIt->mMagnitude / 10.0f) << timesInt; + sourcesDescription += formatter.str(); + } + else if ( displayType != ESM::MagicEffect::MDT_None ) + { + std::string pt = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", ""); + std::string pts = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", ""); + std::string pct = MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", ""); + + sourcesDescription += ": " + boost::lexical_cast(effectIt->mMagnitude); + if ( displayType == ESM::MagicEffect::MDT_Percentage ) + sourcesDescription += pct; + else // ESM::MagicEffect::MDT_Points + sourcesDescription += " " + ((effectIt->mMagnitude > 1) ? pts : pt); } } diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 9278c1a56..f3eda4b22 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -425,11 +425,9 @@ namespace MWGui spellLine += " " + MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Attribute::sGmstAttributeIds[mEffectParams.mAttribute], ""); } - if ((mEffectParams.mMagnMin >= 0 || mEffectParams.mMagnMax >= 0) && !(magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude)) - { - // Fortify Maximum Magicka display rules: - if ( mEffectParams.mEffectID == 84 ) - { + if (mEffectParams.mMagnMin >= 0 || mEffectParams.mMagnMax >= 0) { + int displayType = magicEffect->getMagnitudeDisplayType(); + if ( displayType == ESM::MagicEffect::MDT_TimesInt ) { std::string timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", ""); std::string times = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimes", ""); std::stringstream formatter; @@ -441,20 +439,14 @@ namespace MWGui spellLine += formatter.str(); } - else - { - const bool usePct = ( - (mEffectParams.mEffectID >= 28 && mEffectParams.mEffectID <= 36) || // Weakness effects - (mEffectParams.mEffectID >= 90 && mEffectParams.mEffectID <= 99) ); // Resistance effects - if (mEffectParams.mMagnMin == mEffectParams.mMagnMax) - spellLine += " " + boost::lexical_cast(mEffectParams.mMagnMin); - else - { - spellLine += " " + boost::lexical_cast(mEffectParams.mMagnMin) + to + boost::lexical_cast(mEffectParams.mMagnMax); - } - if ( usePct ) + else if ( displayType != ESM::MagicEffect::MDT_None ) { + spellLine += " " + boost::lexical_cast(mEffectParams.mMagnMin); + if (mEffectParams.mMagnMin != mEffectParams.mMagnMax) + spellLine += to + boost::lexical_cast(mEffectParams.mMagnMax); + + if ( displayType == ESM::MagicEffect::MDT_Percentage ) spellLine += pct; - else + else // ESM::MagicEffect::MDT_Points spellLine += " " + ((mEffectParams.mMagnMin == 1 && mEffectParams.mMagnMax == 1) ? pt : pts ); } } diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index 060645b5f..0dfc2be9c 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -274,5 +274,16 @@ short MagicEffect::effectStringToId(const std::string &effect) return name->first; } +MagicEffect::MagnitudeDisplayType MagicEffect::getMagnitudeDisplayType() const { + if ( mData.mFlags & NoMagnitude ) + return MDT_None; + if ( mIndex == 84 ) + return MDT_TimesInt; + if ( ( mIndex >= 28 && mIndex <= 36 ) + || ( mIndex >= 90 && mIndex <= 99 ) ) + return MDT_Percentage; + + return MDT_Points; +} } diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index b74efb466..c3af56e3a 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -32,6 +32,13 @@ struct MagicEffect Negative = 0x0800 // A harmful effect. Will determine whether // eg. NPCs regard this spell as an attack. (same as 0x10?) }; + enum MagnitudeDisplayType + { + MDT_None, + MDT_Points, + MDT_Percentage, + MDT_TimesInt + }; struct MEDTstruct { @@ -47,6 +54,7 @@ struct MagicEffect static const std::string &effectIdToString(short effectID); static short effectStringToId(const std::string &effect); + MagnitudeDisplayType getMagnitudeDisplayType() const; MEDTstruct mData;