From ad333e88fe04d7ebbd1d3f7378cba1af6690c0e9 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sat, 11 Apr 2020 00:02:12 +0300 Subject: [PATCH] Handle enchantment autocalc flag as a flag (bug #5363) --- CHANGELOG.md | 1 + apps/esmtool/labels.cpp | 11 +++++++++++ apps/esmtool/labels.hpp | 1 + apps/esmtool/record.cpp | 2 +- apps/opencs/model/world/data.cpp | 2 +- apps/openmw/mwmechanics/enchanting.cpp | 4 ++-- components/esm/loadench.cpp | 2 +- components/esm/loadench.hpp | 8 ++++++-- 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31a5271db..cd4b75630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.47.0 ------ + Bug #5363: Enchantment autocalc not always 0/1 0.46.0 ------ diff --git a/apps/esmtool/labels.cpp b/apps/esmtool/labels.cpp index 6793e770c..5e1437a6d 100644 --- a/apps/esmtool/labels.cpp +++ b/apps/esmtool/labels.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -726,6 +727,16 @@ std::string creatureFlags(int flags) return properties; } +std::string enchantmentFlags(int flags) +{ + std::string properties; + if (flags == 0) properties += "[None] "; + if (flags & ESM::Enchantment::Autocalc) properties += "Autocalc "; + if (flags & (0xFFFFFFFF ^ ESM::Enchantment::Autocalc)) properties += "Invalid "; + properties += Misc::StringUtils::format("(0x%08X)", flags); + return properties; +} + std::string landFlags(int flags) { std::string properties; diff --git a/apps/esmtool/labels.hpp b/apps/esmtool/labels.hpp index 007f93316..b06480a97 100644 --- a/apps/esmtool/labels.hpp +++ b/apps/esmtool/labels.hpp @@ -49,6 +49,7 @@ std::string bodyPartFlags(int flags); std::string cellFlags(int flags); std::string containerFlags(int flags); std::string creatureFlags(int flags); +std::string enchantmentFlags(int flags); std::string landFlags(int flags); std::string creatureListFlags(int flags); std::string itemListFlags(int flags); diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index a3f98792c..bd081249a 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -714,7 +714,7 @@ void Record::print() << " (" << mData.mData.mType << ")" << std::endl; std::cout << " Cost: " << mData.mData.mCost << std::endl; std::cout << " Charge: " << mData.mData.mCharge << std::endl; - std::cout << " AutoCalc: " << mData.mData.mAutocalc << std::endl; + std::cout << " Flags: " << enchantmentFlags(mData.mData.mFlags) << std::endl; printEffectList(mData.mEffects); std::cout << " Deleted: " << mIsDeleted << std::endl; } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index b45df35b1..23720a99a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -373,7 +373,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::Pat mEnchantments.addColumn (new EnchantmentTypeColumn); mEnchantments.addColumn (new CostColumn); mEnchantments.addColumn (new ChargesColumn2); - mEnchantments.addColumn (new AutoCalcColumn); + mEnchantments.addColumn (new FlagColumn (Columns::ColumnId_AutoCalc, ESM::Enchantment::Autocalc)); // Enchantment effects mEnchantments.addColumn (new NestedParentColumn (Columns::ColumnId_EffectList)); index = mEnchantments.getColumns()-1; diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 9c4290820..fdf25b7c6 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -63,7 +63,7 @@ namespace MWMechanics const MWWorld::Ptr& player = getPlayer(); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); ESM::Enchantment enchantment; - enchantment.mData.mAutocalc = 0; + enchantment.mData.mFlags = 0; enchantment.mData.mType = mCastStyle; enchantment.mData.mCost = getBaseCastCost(); @@ -219,7 +219,7 @@ namespace MWMechanics if (iter->mEffects.mList.size() != toFind.mEffects.mList.size()) continue; - if (iter->mData.mAutocalc != toFind.mData.mAutocalc + if (iter->mData.mFlags != toFind.mData.mFlags || iter->mData.mType != toFind.mData.mType || iter->mData.mCost != toFind.mData.mCost || iter->mData.mCharge != toFind.mData.mCharge) diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 78e2fb5aa..8c4dd8c64 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -66,7 +66,7 @@ namespace ESM mData.mType = 0; mData.mCost = 0; mData.mCharge = 0; - mData.mAutocalc = 0; + mData.mFlags = 0; mEffects.mList.clear(); } diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 7b93b519c..b98549ef3 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -29,13 +29,17 @@ struct Enchantment ConstantEffect = 3 }; + enum Flags + { + Autocalc = 0x01 + }; + struct ENDTstruct { int mType; int mCost; int mCharge; - int mAutocalc; // Guessing this is 1 if we are supposed to auto - // calculate + int mFlags; }; std::string mId;