From a3b9274365921e53f731431f63c22917de840997 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 11 Aug 2018 16:02:09 +0300 Subject: [PATCH] [Client] Make it possible to check if an item ID belongs to a bound item --- apps/openmw/mwbase/mechanicsmanager.hpp | 11 +++++++ .../mwmechanics/mechanicsmanagerimp.cpp | 31 +++++++++++++++++-- .../mwmechanics/mechanicsmanagerimp.hpp | 10 ++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index ecf139d15..83c149fd1 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -255,6 +255,17 @@ namespace MWBase virtual bool isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) = 0; virtual bool isBoundItem(const MWWorld::Ptr& item) = 0; + + /* + Start of tes3mp addition + + Make it possible to check if an itemId corresponds to a bound item + */ + virtual bool isBoundItem(std::string itemId) = 0; + /* + End of tes3mp addition + */ + virtual bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim) = 0; /// Turn actor into werewolf or normal form. diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index c19c6560a..46555e1dd 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -879,10 +879,19 @@ namespace MWMechanics */ } + /* + Start of tes3mp change (major) + + Move boundItemIDCache outside of the original isBoundItem(const MWWorld::Ptr& item) + method so it can be reused in the new isBoundItem(std::string itemId) method + */ + std::set boundItemIDCache; + bool MechanicsManager::isBoundItem(const MWWorld::Ptr& item) { - static std::set boundItemIDCache; - + /* + End of tes3mp change (major) + */ // If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's for some reason if (boundItemIDCache.empty()) { @@ -918,6 +927,24 @@ namespace MWMechanics return false; } + /* + Start of tes3mp addition + + Make it possible to check if an itemId corresponds to a bound item + */ + bool MechanicsManager::isBoundItem(std::string itemId) + { + Misc::StringUtils::lowerCaseInPlace(itemId); + + if (boundItemIDCache.count(itemId) != 0) + return true; + + return false; + } + /* + End of tes3mp addition + */ + bool MechanicsManager::isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim) { if (target.isEmpty()) diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index 712a05a82..f2e3aa056 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -223,6 +223,16 @@ namespace MWMechanics virtual bool isBoundItem(const MWWorld::Ptr& item); + /* + Start of tes3mp addition + + Make it possible to check if an itemId corresponds to a bound item + */ + virtual bool isBoundItem(std::string itemId); + /* + End of tes3mp addition + */ + /// @return is \a ptr allowed to take/use \a target or is it a crime? virtual bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim);