Page 1 of 2

[PATCH] Show stolen items in inventory

Posted: 04 Mar 2019, 21:50
by CyberShadow
Makes stolen items in inventory/containers show up like owned items (before they are stolen), if highlighting owned items is enabled.

It didn't make sense to me that the player character doesn't know which items they pilfered, yet the guards did.
But, I don't think the original game had this either, so I don't know about submitting this for inclusion.

Screenshot:
Image

Code:

Code: Select all

diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp
index 1bdd8f8b5..b9026c139 100644
--- a/apps/openmw/mwbase/mechanicsmanager.hpp
+++ b/apps/openmw/mwbase/mechanicsmanager.hpp
@@ -250,6 +250,7 @@ namespace MWBase
             /// <Owner, item count>
             virtual std::vector<std::pair<std::string, int> > getStolenItemOwners(const std::string& itemid) = 0;
 
+            virtual bool isItemStolen(const std::string& itemid) = 0;
             /// Has the player stolen this item from the given owner?
             virtual bool isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) = 0;
 
diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp
index f9775253a..77a4a5ea6 100644
--- a/apps/openmw/mwgui/tooltips.cpp
+++ b/apps/openmw/mwgui/tooltips.cpp
@@ -124,7 +124,7 @@ namespace MWGui
                     tooltipSize = createToolTip(info, checkOwned());
                 }
                 else
-                    tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), true);
+                    tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), true, checkStolen());
 
                 MyGUI::IntPoint tooltipPosition = MyGUI::InputManager::getInstance().getMousePosition();
                 position(tooltipPosition, tooltipSize, viewSize);
@@ -202,7 +202,7 @@ namespace MWGui
                     std::pair<ItemModel::ModelIndex, ItemModel*> pair = *focus->getUserData<std::pair<ItemModel::ModelIndex, ItemModel*> >();
                     mFocusObject = pair.second->getItem(pair.first).mBase;
                     bool isAllowedToUse = pair.second->allowedToUseItems();
-                    tooltipSize = getToolTipViaPtr(pair.second->getItem(pair.first).mCount, false, !isAllowedToUse);
+                    tooltipSize = getToolTipViaPtr(pair.second->getItem(pair.first).mCount, false, !isAllowedToUse || checkStolen());
                 }
                 else if (type == "ToolTipInfo")
                 {
@@ -216,7 +216,7 @@ namespace MWGui
 
                     mFocusObject = item;
                     if (!mFocusObject.isEmpty ())
-                        tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), false);
+                        tooltipSize = getToolTipViaPtr(mFocusObject.getRefData().getCount(), checkStolen());
                 }
                 else if (type == "Spell")
                 {
@@ -387,6 +387,12 @@ namespace MWGui
         return !mm->isAllowedToUse(ptr, mFocusObject, victim);
     }
 
+    bool ToolTips::checkStolen()
+    {
+        MWBase::MechanicsManager* mm = MWBase::Environment::get().getMechanicsManager();
+        return mm->isItemStolen(mFocusObject.getCellRef().getRefId());
+    }
+
     MyGUI::IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info, bool isOwned)
     {
         mDynamicToolTipBox->setVisible(true);
diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp
index 3b8e8b2cc..4f78f75ea 100644
--- a/apps/openmw/mwgui/tooltips.hpp
+++ b/apps/openmw/mwgui/tooltips.hpp
@@ -94,6 +94,8 @@ namespace MWGui
         
         bool checkOwned();
         /// Returns True if taking mFocusObject would be crime
+
+        bool checkStolen();
  
     private:
         MyGUI::Widget* mDynamicToolTipBox;
diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp
index eead40537..68e64beba 100644
--- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp
+++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp
@@ -1043,6 +1043,12 @@ namespace MWMechanics
         }
     }
 
+    bool MechanicsManager::isItemStolen(const std::string &itemid)
+    {
+        StolenItemsMap::const_iterator it = mStolenItems.find(Misc::StringUtils::lowerCase(itemid));
+        return it != mStolenItems.end();
+    }
+
     bool MechanicsManager::isItemStolenFrom(const std::string &itemid, const MWWorld::Ptr& ptr)
     {
         StolenItemsMap::const_iterator it = mStolenItems.find(Misc::StringUtils::lowerCase(itemid));
diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp
index 2dda376f5..93c3993a8 100644
--- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp
+++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp
@@ -221,6 +221,8 @@ namespace MWMechanics
             /// <Owner, item count>
             virtual std::vector<std::pair<std::string, int> > getStolenItemOwners(const std::string& itemid) override;
 
+            virtual bool isItemStolen(const std::string& itemid) override;
+
             /// Has the player stolen this item from the given owner?
             virtual bool isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) override;
 
There might be a performance issue (due to an O(n) lookup) in saves where many items have been stolen.

Re: [PATCH] Show stolen items in inventory

Posted: 04 Mar 2019, 22:50
by silentthief
Likewise, this is a pretty cool idea as well.

ST

Re: [PATCH] Show stolen items in inventory

Posted: 05 Mar 2019, 04:59
by akortunov
It does not make much sense since there is no "Stolen" flag for item references.
I did a patch a long time ago which adds a "stolen" flag to the CellRef, but it is unclear how to handle merchant confiscation:
viewtopic.php?f=6&t=5206&p=55103
May be a good idea for Lua mod instead of patch.

Re: [PATCH] Show stolen items in inventory

Posted: 05 Mar 2019, 19:50
by CyberShadow
akortunov wrote:
05 Mar 2019, 04:59
It does not make much sense since there is no "Stolen" flag for item references.
I think it makes sense insofar as previewing which items the guards would confiscate. But, I agree that, as is, such a feature would probably cause a lot of bug reports due to users being confused by the unintuitive way the game keeps track of what is considered "stolen".
akortunov wrote:
05 Mar 2019, 04:59
I did a patch a long time ago which adds a "stolen" flag to the CellRef, but it is unclear how to handle merchant confiscation:
viewtopic.php?f=6&t=5206&p=55103
That's great! But I didn't want to change any game mechanics, just provide some info to the player.

Re: [PATCH] Show stolen items in inventory

Posted: 30 Mar 2019, 15:10
by Strela99
Awesome, thanks for thinking about this and realising it! Does it need a specific version of the game to work?

Re: [PATCH] Show stolen items in inventory

Posted: 01 Apr 2019, 08:47
by darkbasic
Is there any reason why this shouldn't be merged?

Re: [PATCH] Show stolen items in inventory

Posted: 01 Apr 2019, 09:29
by akortunov
Are there reasons why it should be merged?

Re: [PATCH] Show stolen items in inventory

Posted: 01 Apr 2019, 14:09
by darkbasic
Not being able to know which items you stole is a bug in the vanilla engine in my opinion, because it doesn't make sense that guards knows while you don't have any clue about it. I hoped that OpenMW could one day fix it, but since not everybody seems to share the same enthusiasm I would like to know why they don't think this should be implemented.

Re: [PATCH] Show stolen items in inventory

Posted: 01 Apr 2019, 14:36
by akortunov
The whole Morrowind's owners system is a huge mess and this patch does not solve any issues with this system.
A more proper solution would be to track stolen items on a per-instance basis, but it requires a savegame format change and I doubt that it can be implemented as a togglable option, so more likely we will have either use or not to use it.
Since almost every time when we try to fix a some kind of vanilla bug some people complain and demand to leave this bug, I see no reason to change the current system right now.
darkbasic wrote:
01 Apr 2019, 14:09
Not being able to know which items you stole is a bug in the vanilla engine in my opinion.
At least the half of Morrowind's game mechanics can be considered as bugs, but generally we do not change them since the main goal is to recreate the Morrowind with its game mechanics. We can not have an option just for every case to please everyone.

Re: [PATCH] Show stolen items in inventory

Posted: 01 Apr 2019, 16:16
by CyberShadow
It is not the intention of the patch posted here to change any game mechanics.

If you believe that the only way to address this topic is a change in game mechanics, respectfully, that is your opinion. I only wanted to improve the UI while preserving the original mechanics.