From 56edc1b2139bbcf152c0a8285b92352f923d3c93 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 12:26:06 +0200 Subject: [PATCH 1/9] Correction of getting spell range "Target". --- apps/openmw/mwmechanics/enchanting.cpp | 2 +- apps/openmw/mwmechanics/enchanting.hpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index ded75f03a..e53a14120 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -160,7 +160,7 @@ namespace MWMechanics cost1 *= constDurationMultipler; cost2 *= 2; } - if(effect->mData.mFlags & ESM::MagicEffect::CastTarget) + if(it->mRange == ESM::RT_Target) cost1 *= 1.5; float fullcost = cost1+cost2; diff --git a/apps/openmw/mwmechanics/enchanting.hpp b/apps/openmw/mwmechanics/enchanting.hpp index 2831f9ddb..d7acf60e7 100644 --- a/apps/openmw/mwmechanics/enchanting.hpp +++ b/apps/openmw/mwmechanics/enchanting.hpp @@ -3,6 +3,7 @@ #include #include "../mwworld/ptr.hpp" #include +#include #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" namespace MWMechanics From 4788b5e2261c6ab0d1b8a63f1d3a6d70c6f87f7b Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 14:42:08 +0200 Subject: [PATCH 2/9] Better formula for enchantment cost and code refactorization. --- apps/openmw/mwgui/enchantingdialog.cpp | 6 +- apps/openmw/mwmechanics/enchanting.cpp | 101 +++++++++++++++---------- apps/openmw/mwmechanics/enchanting.hpp | 6 +- components/esm/defs.hpp | 9 +++ 4 files changed, 75 insertions(+), 47 deletions(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 799a89ab5..3672c2aec 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -70,7 +70,7 @@ namespace MWGui mPrice->setCaption(boost::lexical_cast(mEnchanting.getEnchantPrice())); - switch(mEnchanting.getEnchantType()) + switch(mEnchanting.getCastStyle()) { case 0: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastOnce","Cast Once")); @@ -169,7 +169,7 @@ namespace MWGui image->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onRemoveItem); mEnchanting.setOldItem(item); - mEnchanting.nextEnchantType(); + mEnchanting.nextCastStyle(); updateLabels(); } @@ -248,7 +248,7 @@ namespace MWGui void EnchantingDialog::onTypeButtonClicked(MyGUI::Widget* sender) { - mEnchanting.nextEnchantType(); + mEnchanting.nextCastStyle(); updateLabels(); } diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index e53a14120..8efbf3c8c 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -12,7 +12,7 @@ namespace MWMechanics { Enchanting::Enchanting(): - mEnchantType(0) + mCastStyle(ESM::CS_CastOnce) {} void Enchanting::setOldItem(MWWorld::Ptr oldItem) @@ -41,9 +41,9 @@ namespace MWMechanics mEffectList=effectList; } - int Enchanting::getEnchantType() const + int Enchanting::getCastStyle() const { - return mEnchantType; + return mCastStyle; } void Enchanting::setSoulGem(MWWorld::Ptr soulGem) @@ -74,11 +74,11 @@ namespace MWMechanics MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 1); } - if(mEnchantType==3) + if(mCastStyle==3) { enchantment.mData.mCharge=0; } - enchantment.mData.mType = mEnchantType; + enchantment.mData.mType = mCastStyle; enchantment.mData.mCost = getEnchantCost(); enchantment.mEffects = mEffectList; @@ -98,78 +98,97 @@ namespace MWMechanics return true; } - void Enchanting::nextEnchantType() + void Enchanting::nextCastStyle() { - mEnchantType++; + mCastStyle++; if (itemEmpty()) { - mEnchantType = 0; + mCastStyle = 0; return; } if ((mObjectType == typeid(ESM::Armor).name())||(mObjectType == typeid(ESM::Clothing).name())) { int soulConstAmount = MWBase::Environment::get().getWorld()->getStore().get().find ("iSoulAmountForConstantEffect")->getInt(); - switch(mEnchantType) + switch(mCastStyle) { case 1: - mEnchantType = 2; + mCastStyle = 2; case 3: if(getGemCharge() 2 or (2 + 0) == (1 + 2) => 3 + * + * Formula on UESPWiki is not entirely correct. + */ float Enchanting::getEnchantCost() const { - const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); - float cost = 0; - std::vector mEffects = mEffectList.mList; - int i=mEffects.size(); - if(i<=0) - return 0; + if (mEffectList.mList.empty()) + // No effects added, cost = 0 + return 0; - /* - Formula from http://www.uesp.net/wiki/Morrowind:Enchant - */ + const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); + std::vector mEffects = mEffectList.mList; + + float enchantmentCost = 0; + int effectsLeftCnt = mEffects.size(); + float baseCost, magnitudeCost, areaCost; + int magMin, magMax, area; for (std::vector::const_iterator it = mEffects.begin(); it != mEffects.end(); ++it) { - const ESM::MagicEffect* effect = store.get().find(it->mEffectID); + baseCost = (store.get().find(it->mEffectID))->mData.mBaseCost; + // To reflect vanilla behavior + magMin = (it->mMagnMin == 0) ? 1 : it->mMagnMin; + magMax = (it->mMagnMax == 0) ? 1 : it->mMagnMax; + area = (it->mArea == 0) ? 1 : it->mArea; - float cost1 = ((it->mMagnMin + it->mMagnMax)*it->mDuration*effect->mData.mBaseCost*0.025); - - float cost2 = (std::max(1, it->mArea)*0.125*effect->mData.mBaseCost); - - if(mEnchantType==3) + if (mCastStyle == ESM::CS_ConstantEffect) { - int constDurationMultipler = MWBase::Environment::get().getWorld()->getStore().get().find ("fEnchantmentConstantDurationMult")->getFloat(); - cost1 *= constDurationMultipler; - cost2 *= 2; + magnitudeCost = (magMin + magMax) * baseCost * 2.5; + } + else + { + magnitudeCost = (magMin + magMax) * it->mDuration * baseCost * 0.025; + if(it->mRange == ESM::RT_Target) + magnitudeCost *= 1.5; } - if(it->mRange == ESM::RT_Target) - cost1 *= 1.5; - float fullcost = cost1+cost2; - fullcost*= i; - i--; + areaCost = area * 0.025 * baseCost; + if (it->mRange == ESM::RT_Target) + areaCost *= 1.5; - cost+=fullcost; + enchantmentCost += (magnitudeCost + areaCost) * effectsLeftCnt; + --effectsLeftCnt; } - return cost; + + return enchantmentCost; } int Enchanting::getEnchantPrice() const @@ -236,7 +255,7 @@ namespace MWMechanics + (0.125 * creatureStats.getAttribute (ESM::Attribute::Luck).getModified())); float chance2 = 2.5 * getEnchantCost(); - if(mEnchantType==3) + if(mCastStyle==3) { float constantChance = MWBase::Environment::get().getWorld()->getStore().get().find ("fEnchantmentConstantChanceMult")->getFloat(); chance2 /= constantChance; diff --git a/apps/openmw/mwmechanics/enchanting.hpp b/apps/openmw/mwmechanics/enchanting.hpp index d7acf60e7..a04bd86e9 100644 --- a/apps/openmw/mwmechanics/enchanting.hpp +++ b/apps/openmw/mwmechanics/enchanting.hpp @@ -14,7 +14,7 @@ namespace MWMechanics MWWorld::Ptr mSoulGemPtr; MWWorld::Ptr mEnchanter; - int mEnchantType; + int mCastStyle; bool mSelfEnchanting; @@ -34,8 +34,8 @@ namespace MWMechanics void setEffect(ESM::EffectList effectList); void setSoulGem(MWWorld::Ptr soulGem); bool create(); //Return true if created, false if failed. - void nextEnchantType(); //Set enchant type to next possible type (for mOldItemPtr object) - int getEnchantType() const; + void nextCastStyle(); //Set enchant type to next possible type (for mOldItemPtr object) + int getCastStyle() const; float getEnchantCost() const; int getEnchantPrice() const; float getMaxEnchantValue() const; diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index bd86f9ba0..f47463891 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -23,6 +23,15 @@ enum RangeType RT_Target = 2 }; +// Casting style (in enchanting) +enum Type +{ + CS_CastOnce = 0, + CS_WhenStrikes = 1, + CS_WhenUsed = 2, + CS_ConstantEffect = 3 +}; + #pragma pack(push) #pragma pack(1) From cfbdf3f7797427e2bf9004ef05209adc06e05a0e Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 15:37:31 +0200 Subject: [PATCH 3/9] Enum Type renamed to CastingStyle --- components/esm/defs.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index f47463891..7586413a6 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -24,7 +24,7 @@ enum RangeType }; // Casting style (in enchanting) -enum Type +enum CastingStyle { CS_CastOnce = 0, CS_WhenStrikes = 1, From 252a1d92231777ddf66247caba69a4abe62e59f8 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 15:50:47 +0200 Subject: [PATCH 4/9] Replacement of some magical constants --- apps/openmw/mwgui/enchantingdialog.cpp | 8 ++++---- apps/openmw/mwmechanics/enchanting.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 3672c2aec..86bdc25fc 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -72,19 +72,19 @@ namespace MWGui switch(mEnchanting.getCastStyle()) { - case 0: + case ESM::CS_CastOnce: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastOnce","Cast Once")); mAddEffectDialog.constantEffect=false; break; - case 1: + case ESM::CS_WhenStrikes: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenStrikes", "When Strikes")); mAddEffectDialog.constantEffect=false; break; - case 2: + case ESM::CS_WhenUsed: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenUsed", "When Used")); mAddEffectDialog.constantEffect=false; break; - case 3: + case ESM::CS_ConstantEffect: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastConstant", "Cast Constant")); mAddEffectDialog.constantEffect=true; break; diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 8efbf3c8c..c7a67e7cb 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -74,7 +74,7 @@ namespace MWMechanics MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 1); } - if(mCastStyle==3) + if(mCastStyle==ESM::CS_ConstantEffect) { enchantment.mData.mCharge=0; } @@ -255,7 +255,7 @@ namespace MWMechanics + (0.125 * creatureStats.getAttribute (ESM::Attribute::Luck).getModified())); float chance2 = 2.5 * getEnchantCost(); - if(mCastStyle==3) + if(mCastStyle==ESM::CS_ConstantEffect) { float constantChance = MWBase::Environment::get().getWorld()->getStore().get().find ("fEnchantmentConstantChanceMult")->getFloat(); chance2 /= constantChance; From 1c7b94e94f27df9d8d078db7178109650ccb4cfd Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 16:08:58 +0200 Subject: [PATCH 5/9] Switching in nextCastStyle() is now based on enum CastingStyle. --- apps/openmw/mwmechanics/enchanting.cpp | 49 +++++++++++++++++--------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index c7a67e7cb..25aa0ea64 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -100,38 +100,53 @@ namespace MWMechanics void Enchanting::nextCastStyle() { - mCastStyle++; if (itemEmpty()) { - mCastStyle = 0; + mCastStyle = ESM::CS_WhenUsed; return; } - if ((mObjectType == typeid(ESM::Armor).name())||(mObjectType == typeid(ESM::Clothing).name())) - { - int soulConstAmount = MWBase::Environment::get().getWorld()->getStore().get().find ("iSoulAmountForConstantEffect")->getInt(); + + const bool powerfulSoul = getGemCharge() >= \ + MWBase::Environment::get().getWorld()->getStore().get().find ("iSoulAmountForConstantEffect")->getInt(); + if ((mObjectType == typeid(ESM::Armor).name()) || (mObjectType == typeid(ESM::Clothing).name())) + { // Armor or Clothing switch(mCastStyle) { - case 1: - mCastStyle = 2; - case 3: - if(getGemCharge() Date: Mon, 27 May 2013 18:08:12 +0200 Subject: [PATCH 6/9] Correct cast cost for enchantments. --- apps/openmw/mwgui/enchantingdialog.cpp | 2 +- apps/openmw/mwmechanics/enchanting.cpp | 18 ++++++++++++++++++ apps/openmw/mwmechanics/enchanting.hpp | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 86bdc25fc..8353cf99e 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -66,7 +66,7 @@ namespace MWGui mCharge->setCaption(boost::lexical_cast(mEnchanting.getGemCharge())); - mCastCost->setCaption(boost::lexical_cast(mEnchanting.getEnchantCost())); + mCastCost->setCaption(boost::lexical_cast(mEnchanting.getCastCost())); mPrice->setCaption(boost::lexical_cast(mEnchanting.getEnchantPrice())); diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 25aa0ea64..95d7694dc 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -206,6 +206,24 @@ namespace MWMechanics return enchantmentCost; } + + float Enchanting::getCastCost() const + { + const float enchantCost = getEnchantCost(); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::NpcStats &stats = MWWorld::Class::get(player).getNpcStats(player); + int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); + + /* + * Each point of enchant skill above/under 10 subtracts/adds + * one percent of enchantment cost while minimum is 1. + */ + const float castCost = enchantCost - (enchantCost / 100) * (eSkill - 10); + + return (castCost < 1) ? 1 : castCost; + } + + int Enchanting::getEnchantPrice() const { if(mEnchanter.isEmpty()) diff --git a/apps/openmw/mwmechanics/enchanting.hpp b/apps/openmw/mwmechanics/enchanting.hpp index a04bd86e9..fefabd308 100644 --- a/apps/openmw/mwmechanics/enchanting.hpp +++ b/apps/openmw/mwmechanics/enchanting.hpp @@ -37,6 +37,7 @@ namespace MWMechanics void nextCastStyle(); //Set enchant type to next possible type (for mOldItemPtr object) int getCastStyle() const; float getEnchantCost() const; + float getCastCost() const; int getEnchantPrice() const; float getMaxEnchantValue() const; int getGemCharge() const; From 4e17bc1499e64fd9aee851b9dc91a3a606b261a2 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 20:16:57 +0200 Subject: [PATCH 7/9] Fix for display of cast cost decimal value --- apps/openmw/mwgui/enchantingdialog.cpp | 4 +++- apps/openmw/mwmechanics/enchanting.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 8353cf99e..7f71716ed 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -66,7 +66,9 @@ namespace MWGui mCharge->setCaption(boost::lexical_cast(mEnchanting.getGemCharge())); - mCastCost->setCaption(boost::lexical_cast(mEnchanting.getCastCost())); + std::stringstream castCost; + castCost << std::setprecision(1) << std::fixed << mEnchanting.getCastCost(); + mCastCost->setCaption(boost::lexical_cast(castCost.str())); mPrice->setCaption(boost::lexical_cast(mEnchanting.getEnchantPrice())); diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 95d7694dc..821df8fba 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -209,6 +209,9 @@ namespace MWMechanics float Enchanting::getCastCost() const { + if (mCastStyle == ESM::CS_ConstantEffect) + return 0; + const float enchantCost = getEnchantCost(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::NpcStats &stats = MWWorld::Class::get(player).getNpcStats(player); From b40e24c50c5461892911d30ed997b49fc1d07ba0 Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 20:23:04 +0200 Subject: [PATCH 8/9] Refactorization --- apps/openmw/mwgui/enchantingdialog.cpp | 12 +++---- apps/openmw/mwmechanics/enchanting.cpp | 44 +++++++++++++------------- apps/openmw/mwmechanics/enchanting.hpp | 2 +- components/esm/defs.hpp | 8 ++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 7f71716ed..0db577de2 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -61,7 +61,7 @@ namespace MWGui void EnchantingDialog::updateLabels() { std::stringstream enchantCost; - enchantCost << std::setprecision(1) << std::fixed << mEnchanting.getEnchantCost(); + enchantCost << std::setprecision(1) << std::fixed << mEnchanting.getEnchantPoints(); mEnchantmentPoints->setCaption(enchantCost.str() + " / " + boost::lexical_cast(mEnchanting.getMaxEnchantValue())); mCharge->setCaption(boost::lexical_cast(mEnchanting.getGemCharge())); @@ -74,19 +74,19 @@ namespace MWGui switch(mEnchanting.getCastStyle()) { - case ESM::CS_CastOnce: + case ESM::CastingStyle_CastOnce: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastOnce","Cast Once")); mAddEffectDialog.constantEffect=false; break; - case ESM::CS_WhenStrikes: + case ESM::CastingStyle_WhenStrikes: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenStrikes", "When Strikes")); mAddEffectDialog.constantEffect=false; break; - case ESM::CS_WhenUsed: + case ESM::CastingStyle_WhenUsed: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenUsed", "When Used")); mAddEffectDialog.constantEffect=false; break; - case ESM::CS_ConstantEffect: + case ESM::CastingStyle_ConstantEffect: mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastConstant", "Cast Constant")); mAddEffectDialog.constantEffect=true; break; @@ -280,7 +280,7 @@ namespace MWGui return; } - if (mEnchanting.getEnchantCost() > mEnchanting.getMaxEnchantValue()) + if (mEnchanting.getEnchantPoints() > mEnchanting.getMaxEnchantValue()) { MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage29}"); return; diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 821df8fba..5be0d83e7 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -12,7 +12,7 @@ namespace MWMechanics { Enchanting::Enchanting(): - mCastStyle(ESM::CS_CastOnce) + mCastStyle(ESM::CastingStyle_CastOnce) {} void Enchanting::setOldItem(MWWorld::Ptr oldItem) @@ -74,12 +74,12 @@ namespace MWMechanics MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 1); } - if(mCastStyle==ESM::CS_ConstantEffect) + if(mCastStyle==ESM::CastingStyle_ConstantEffect) { enchantment.mData.mCharge=0; } enchantment.mData.mType = mCastStyle; - enchantment.mData.mCost = getEnchantCost(); + enchantment.mData.mCost = getEnchantPoints(); enchantment.mEffects = mEffectList; const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment); @@ -102,7 +102,7 @@ namespace MWMechanics { if (itemEmpty()) { - mCastStyle = ESM::CS_WhenUsed; + mCastStyle = ESM::CastingStyle_WhenUsed; return; } @@ -112,12 +112,12 @@ namespace MWMechanics { // Armor or Clothing switch(mCastStyle) { - case ESM::CS_WhenUsed: + case ESM::CastingStyle_WhenUsed: if (powerfulSoul) - mCastStyle = ESM::CS_ConstantEffect; + mCastStyle = ESM::CastingStyle_ConstantEffect; return; default: // takes care of Constant effect too - mCastStyle = ESM::CS_WhenUsed; + mCastStyle = ESM::CastingStyle_WhenUsed; return; } } @@ -125,28 +125,28 @@ namespace MWMechanics { // Weapon switch(mCastStyle) { - case ESM::CS_WhenStrikes: - mCastStyle = ESM::CS_WhenUsed; + case ESM::CastingStyle_WhenStrikes: + mCastStyle = ESM::CastingStyle_WhenUsed; return; - case ESM::CS_WhenUsed: + case ESM::CastingStyle_WhenUsed: if (powerfulSoul) - mCastStyle = ESM::CS_ConstantEffect; + mCastStyle = ESM::CastingStyle_ConstantEffect; else - mCastStyle = ESM::CS_WhenStrikes; + mCastStyle = ESM::CastingStyle_WhenStrikes; return; default: // takes care of Constant effect too - mCastStyle = ESM::CS_WhenStrikes; + mCastStyle = ESM::CastingStyle_WhenStrikes; return; } } else if(mObjectType == typeid(ESM::Book).name()) { // Scroll or Book - mCastStyle = ESM::CS_CastOnce; + mCastStyle = ESM::CastingStyle_CastOnce; return; } // Fail case - mCastStyle = ESM::CS_CastOnce; + mCastStyle = ESM::CastingStyle_CastOnce; } /* @@ -163,7 +163,7 @@ namespace MWMechanics * * Formula on UESPWiki is not entirely correct. */ - float Enchanting::getEnchantCost() const + float Enchanting::getEnchantPoints() const { if (mEffectList.mList.empty()) // No effects added, cost = 0 @@ -184,7 +184,7 @@ namespace MWMechanics magMax = (it->mMagnMax == 0) ? 1 : it->mMagnMax; area = (it->mArea == 0) ? 1 : it->mArea; - if (mCastStyle == ESM::CS_ConstantEffect) + if (mCastStyle == ESM::CastingStyle_ConstantEffect) { magnitudeCost = (magMin + magMax) * baseCost * 2.5; } @@ -209,10 +209,10 @@ namespace MWMechanics float Enchanting::getCastCost() const { - if (mCastStyle == ESM::CS_ConstantEffect) + if (mCastStyle == ESM::CastingStyle_ConstantEffect) return 0; - const float enchantCost = getEnchantCost(); + const float enchantCost = getEnchantPoints(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::NpcStats &stats = MWWorld::Class::get(player).getNpcStats(player); int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); @@ -233,7 +233,7 @@ namespace MWMechanics return 0; float priceMultipler = MWBase::Environment::get().getWorld()->getStore().get().find ("fEnchantmentValueMult")->getFloat(); - int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mEnchanter, (getEnchantCost() * priceMultipler), true); + int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mEnchanter, (getEnchantPoints() * priceMultipler), true); return price; } @@ -290,8 +290,8 @@ namespace MWMechanics (0.25 * creatureStats.getAttribute (ESM::Attribute::Intelligence).getModified()) + (0.125 * creatureStats.getAttribute (ESM::Attribute::Luck).getModified())); - float chance2 = 2.5 * getEnchantCost(); - if(mCastStyle==ESM::CS_ConstantEffect) + float chance2 = 2.5 * getEnchantPoints(); + if(mCastStyle==ESM::CastingStyle_ConstantEffect) { float constantChance = MWBase::Environment::get().getWorld()->getStore().get().find ("fEnchantmentConstantChanceMult")->getFloat(); chance2 /= constantChance; diff --git a/apps/openmw/mwmechanics/enchanting.hpp b/apps/openmw/mwmechanics/enchanting.hpp index fefabd308..4321e5bd6 100644 --- a/apps/openmw/mwmechanics/enchanting.hpp +++ b/apps/openmw/mwmechanics/enchanting.hpp @@ -36,7 +36,7 @@ namespace MWMechanics bool create(); //Return true if created, false if failed. void nextCastStyle(); //Set enchant type to next possible type (for mOldItemPtr object) int getCastStyle() const; - float getEnchantCost() const; + float getEnchantPoints() const; float getCastCost() const; int getEnchantPrice() const; float getMaxEnchantValue() const; diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index 7586413a6..cf7b586fc 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -26,10 +26,10 @@ enum RangeType // Casting style (in enchanting) enum CastingStyle { - CS_CastOnce = 0, - CS_WhenStrikes = 1, - CS_WhenUsed = 2, - CS_ConstantEffect = 3 + CastingStyle_CastOnce = 0, + CastingStyle_WhenStrikes = 1, + CastingStyle_WhenUsed = 2, + CastingStyle_ConstantEffect = 3 }; #pragma pack(push) From 7a4a386cbe069c5e127efc97241dc9aa38ecd4ce Mon Sep 17 00:00:00 2001 From: Miroslav Puda Date: Mon, 27 May 2013 20:47:53 +0200 Subject: [PATCH 9/9] Removal of tab characters. --- apps/openmw/mwmechanics/enchanting.cpp | 88 +++++++++++++------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 5be0d83e7..05d4c635f 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -107,7 +107,7 @@ namespace MWMechanics } const bool powerfulSoul = getGemCharge() >= \ - MWBase::Environment::get().getWorld()->getStore().get().find ("iSoulAmountForConstantEffect")->getInt(); + MWBase::Environment::get().getWorld()->getStore().get().find ("iSoulAmountForConstantEffect")->getInt(); if ((mObjectType == typeid(ESM::Armor).name()) || (mObjectType == typeid(ESM::Clothing).name())) { // Armor or Clothing switch(mCastStyle) @@ -126,17 +126,17 @@ namespace MWMechanics switch(mCastStyle) { case ESM::CastingStyle_WhenStrikes: - mCastStyle = ESM::CastingStyle_WhenUsed; - return; + mCastStyle = ESM::CastingStyle_WhenUsed; + return; case ESM::CastingStyle_WhenUsed: - if (powerfulSoul) - mCastStyle = ESM::CastingStyle_ConstantEffect; - else - mCastStyle = ESM::CastingStyle_WhenStrikes; - return; + if (powerfulSoul) + mCastStyle = ESM::CastingStyle_ConstantEffect; + else + mCastStyle = ESM::CastingStyle_WhenStrikes; + return; default: // takes care of Constant effect too - mCastStyle = ESM::CastingStyle_WhenStrikes; - return; + mCastStyle = ESM::CastingStyle_WhenStrikes; + return; } } else if(mObjectType == typeid(ESM::Book).name()) @@ -149,25 +149,25 @@ namespace MWMechanics mCastStyle = ESM::CastingStyle_CastOnce; } - /* - * Vanilla enchant cost formula: - * - * Touch/Self: (min + max) * baseCost * 0.025 * duration + area * baseCost * 0.025 - * Target: 1.5 * ((min + max) * baseCost * 0.025 * duration + area * baseCost * 0.025) - * Constant eff: (min + max) * baseCost * 2.5 + area * baseCost * 0.025 - * - * For multiple effects - cost of each effect is multiplied by number of effects that follows +1. - * - * Note: Minimal value inside formula for 'min' and 'max' is 1. So in vanilla: - * (0 + 0) == (1 + 0) == (1 + 1) => 2 or (2 + 0) == (1 + 2) => 3 - * - * Formula on UESPWiki is not entirely correct. - */ + /* + * Vanilla enchant cost formula: + * + * Touch/Self: (min + max) * baseCost * 0.025 * duration + area * baseCost * 0.025 + * Target: 1.5 * ((min + max) * baseCost * 0.025 * duration + area * baseCost * 0.025) + * Constant eff: (min + max) * baseCost * 2.5 + area * baseCost * 0.025 + * + * For multiple effects - cost of each effect is multiplied by number of effects that follows +1. + * + * Note: Minimal value inside formula for 'min' and 'max' is 1. So in vanilla: + * (0 + 0) == (1 + 0) == (1 + 1) => 2 or (2 + 0) == (1 + 2) => 3 + * + * Formula on UESPWiki is not entirely correct. + */ float Enchanting::getEnchantPoints() const { - if (mEffectList.mList.empty()) - // No effects added, cost = 0 - return 0; + if (mEffectList.mList.empty()) + // No effects added, cost = 0 + return 0; const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); std::vector mEffects = mEffectList.mList; @@ -186,18 +186,18 @@ namespace MWMechanics if (mCastStyle == ESM::CastingStyle_ConstantEffect) { - magnitudeCost = (magMin + magMax) * baseCost * 2.5; + magnitudeCost = (magMin + magMax) * baseCost * 2.5; } else { - magnitudeCost = (magMin + magMax) * it->mDuration * baseCost * 0.025; - if(it->mRange == ESM::RT_Target) - magnitudeCost *= 1.5; + magnitudeCost = (magMin + magMax) * it->mDuration * baseCost * 0.025; + if(it->mRange == ESM::RT_Target) + magnitudeCost *= 1.5; } areaCost = area * 0.025 * baseCost; if (it->mRange == ESM::RT_Target) - areaCost *= 1.5; + areaCost *= 1.5; enchantmentCost += (magnitudeCost + areaCost) * effectsLeftCnt; --effectsLeftCnt; @@ -209,21 +209,21 @@ namespace MWMechanics float Enchanting::getCastCost() const { - if (mCastStyle == ESM::CastingStyle_ConstantEffect) - return 0; + if (mCastStyle == ESM::CastingStyle_ConstantEffect) + return 0; - const float enchantCost = getEnchantPoints(); - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - MWMechanics::NpcStats &stats = MWWorld::Class::get(player).getNpcStats(player); - int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); + const float enchantCost = getEnchantPoints(); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::NpcStats &stats = MWWorld::Class::get(player).getNpcStats(player); + int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); - /* - * Each point of enchant skill above/under 10 subtracts/adds - * one percent of enchantment cost while minimum is 1. - */ - const float castCost = enchantCost - (enchantCost / 100) * (eSkill - 10); + /* + * Each point of enchant skill above/under 10 subtracts/adds + * one percent of enchantment cost while minimum is 1. + */ + const float castCost = enchantCost - (enchantCost / 100) * (eSkill - 10); - return (castCost < 1) ? 1 : castCost; + return (castCost < 1) ? 1 : castCost; }