diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 714b5a09c..a658c379a 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -172,14 +172,14 @@ namespace MWMechanics const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); std::vector mEffects = mEffectList.mList; - float enchantmentCost = 0; - int effectsLeftCnt = mEffects.size(); + int enchantmentCost = 0; + float cost = 0; for (std::vector::const_iterator it = mEffects.begin(); it != mEffects.end(); ++it) { float baseCost = (store.get().find(it->mEffectID))->mData.mBaseCost; - int magMin = (it->mMagnMin == 0) ? 1 : it->mMagnMin; - int magMax = (it->mMagnMax == 0) ? 1 : it->mMagnMax; - int area = (it->mArea == 0) ? 1 : it->mArea; + int magMin = std::max(1, it->mMagnMin); + int magMax = std::max(1, it->mMagnMax); + int area = std::max(1, it->mArea); float magnitudeCost = (magMin + magMax) * baseCost * 0.05f; if (mCastStyle == ESM::Enchantment::ConstantEffect) @@ -195,16 +195,17 @@ namespace MWMechanics const float fEffectCostMult = store.get().find("fEffectCostMult")->getFloat(); - float cost = (magnitudeCost + areaCost) * fEffectCostMult; + cost += (magnitudeCost + areaCost) * fEffectCostMult; + + cost = std::max(1.f, cost); + if (it->mRange == ESM::RT_Target) cost *= 1.5; - enchantmentCost += cost * effectsLeftCnt; - enchantmentCost = std::max(1.f, enchantmentCost); - --effectsLeftCnt; + enchantmentCost += static_cast(cost); } - return static_cast(enchantmentCost); + return enchantmentCost; }