From 1ee5dcff775995f783478204954786ece270b677 Mon Sep 17 00:00:00 2001 From: rexelion Date: Sat, 28 Oct 2017 20:56:08 +0100 Subject: [PATCH 1/6] added a function to determine if a script contains OnActivate --- apps/openmw/mwbase/scriptmanager.hpp | 4 ++++ apps/openmw/mwscript/scriptmanagerimp.cpp | 6 ++++++ apps/openmw/mwscript/scriptmanagerimp.hpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/apps/openmw/mwbase/scriptmanager.hpp b/apps/openmw/mwbase/scriptmanager.hpp index 7bdeba132c..44d3501154 100644 --- a/apps/openmw/mwbase/scriptmanager.hpp +++ b/apps/openmw/mwbase/scriptmanager.hpp @@ -42,6 +42,10 @@ namespace MWBase ///< Compile script with the given namen /// \return Success? + virtual bool hasOnActivate (const std::string& name) = 0; + ///< Determine if a script with the given name contains OnActivate + /// \return Contains OnActivate? + virtual std::pair compileAll() = 0; ///< Compile all scripts /// \return count, success diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index 7c1f9bf4df..01ff97be27 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -88,6 +88,12 @@ namespace MWScript return false; } + bool ScriptManager::hasOnActivate(const std::string& name) + { + const ESM::Script *script = mStore.get().find(name); + return script->mScriptText.find("OnActivate"); + } + void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext) { // compile script diff --git a/apps/openmw/mwscript/scriptmanagerimp.hpp b/apps/openmw/mwscript/scriptmanagerimp.hpp index c22a5da81f..3835be26e4 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.hpp +++ b/apps/openmw/mwscript/scriptmanagerimp.hpp @@ -62,6 +62,10 @@ namespace MWScript ///< Compile script with the given namen /// \return Success? + virtual bool hasOnActivate(const std::string& name); + ///< Determine if a script with the given name contains OnActivate + /// \return Contains OnActivate? + virtual std::pair compileAll(); ///< Compile all scripts /// \return count, success From 4e6f53d6f16572086ad1c0d5455e16ed3ce359af Mon Sep 17 00:00:00 2001 From: rexelion Date: Sun, 29 Oct 2017 11:45:17 +0000 Subject: [PATCH 2/6] item added to the player and OnActivate is triggered when the inventory is closed --- apps/openmw/mwgui/inventorywindow.cpp | 20 ++++++++++++++++++++ apps/openmw/mwgui/inventorywindow.hpp | 4 ++++ apps/openmw/mwgui/windowmanagerimp.cpp | 2 ++ 3 files changed, 26 insertions(+) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index b3697008c8..8586cfb5bb 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,6 +1,7 @@ #include "inventorywindow.hpp" #include +#include #include #include @@ -149,6 +150,15 @@ namespace MWGui mItemView->setModel(NULL); } + void InventoryWindow::activateItems() + { + for (std::vector::iterator it = mItemsToActivate.begin(); it != mItemsToActivate.end(); it++) + { + it->getRefData().activate(); + } + mItemsToActivate.clear(); + } + void InventoryWindow::setGuiMode(GuiMode mode) { std::string setting = "inventory"; @@ -653,6 +663,16 @@ namespace MWGui if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; + std::string scriptName = object.getClass().getScript(object); // Objects that have OnActivte in their script cannot be picked up through inventory + if (!scriptName.empty() && MWBase::Environment::get().getScriptManager()->hasOnActivate(scriptName)) + { + if (std::find(mItemsToActivate.begin(), mItemsToActivate.end(), object) == mItemsToActivate.end()) + { + mItemsToActivate.push_back(object); + } + return; + } + int count = object.getRefData().getCount(); MWWorld::Ptr player = MWMechanics::getPlayer(); diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 5576b52ed0..3f88d88226 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -58,6 +58,8 @@ namespace MWGui void clear(); + void activateItems(); + void useItem(const MWWorld::Ptr& ptr); void setGuiMode(GuiMode mode); @@ -70,6 +72,8 @@ namespace MWGui int mSelectedItem; + std::vector mItemsToActivate; + MWWorld::Ptr mPtr; MWGui::ItemView* mItemView; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index ccdd6916c0..e2a10ccc3d 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1171,6 +1171,8 @@ namespace MWGui mGuiModeStates[mode].update(false); if (!noSound) playSound(mGuiModeStates[mode].mCloseSound); + if (mode == GM_Inventory) + mInventoryWindow->activateItems(); // Activate cursed items when inventory is closed } if (!mGuiModes.empty()) From e8743f3f795ff8b4b7c3bfe103ca930587872258 Mon Sep 17 00:00:00 2001 From: rexelion Date: Mon, 30 Oct 2017 20:59:36 +0000 Subject: [PATCH 3/6] check the presence of OnActivate using the SuppressActivate flag instead of looking for keywords --- apps/openmw/mwbase/scriptmanager.hpp | 4 ---- apps/openmw/mwgui/inventorywindow.cpp | 3 +-- apps/openmw/mwscript/scriptmanagerimp.cpp | 6 ------ apps/openmw/mwscript/scriptmanagerimp.hpp | 4 ---- apps/openmw/mwworld/refdata.cpp | 5 +++++ apps/openmw/mwworld/refdata.hpp | 2 ++ 6 files changed, 8 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwbase/scriptmanager.hpp b/apps/openmw/mwbase/scriptmanager.hpp index 44d3501154..7bdeba132c 100644 --- a/apps/openmw/mwbase/scriptmanager.hpp +++ b/apps/openmw/mwbase/scriptmanager.hpp @@ -42,10 +42,6 @@ namespace MWBase ///< Compile script with the given namen /// \return Success? - virtual bool hasOnActivate (const std::string& name) = 0; - ///< Determine if a script with the given name contains OnActivate - /// \return Contains OnActivate? - virtual std::pair compileAll() = 0; ///< Compile all scripts /// \return count, success diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 8586cfb5bb..5fe644d45d 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -663,8 +663,7 @@ namespace MWGui if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; - std::string scriptName = object.getClass().getScript(object); // Objects that have OnActivte in their script cannot be picked up through inventory - if (!scriptName.empty() && MWBase::Environment::get().getScriptManager()->hasOnActivate(scriptName)) + if (object.getRefData().hasSuppressActivate()) // if Flag_SuppressActivate is set, script that contains OnActivate is attached to the item { if (std::find(mItemsToActivate.begin(), mItemsToActivate.end(), object) == mItemsToActivate.end()) { diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index 01ff97be27..7c1f9bf4df 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -88,12 +88,6 @@ namespace MWScript return false; } - bool ScriptManager::hasOnActivate(const std::string& name) - { - const ESM::Script *script = mStore.get().find(name); - return script->mScriptText.find("OnActivate"); - } - void ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext) { // compile script diff --git a/apps/openmw/mwscript/scriptmanagerimp.hpp b/apps/openmw/mwscript/scriptmanagerimp.hpp index 3835be26e4..c22a5da81f 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.hpp +++ b/apps/openmw/mwscript/scriptmanagerimp.hpp @@ -62,10 +62,6 @@ namespace MWScript ///< Compile script with the given namen /// \return Success? - virtual bool hasOnActivate(const std::string& name); - ///< Determine if a script with the given name contains OnActivate - /// \return Contains OnActivate? - virtual std::pair compileAll(); ///< Compile all scripts /// \return count, success diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index f6fa3556fa..95b0fb3e0b 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -192,6 +192,11 @@ namespace MWWorld return mEnabled; } + bool RefData::hasSuppressActivate() + { + return mFlags & Flag_SuppressActivate; + } + void RefData::enable() { if (!mEnabled) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 75eec6742d..4dfa9e91c4 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -111,6 +111,8 @@ namespace MWWorld bool isEnabled() const; + bool hasSuppressActivate(); + void enable(); void disable(); From a9e5e1948270945bbb16be1219cb61a10ce8ddd8 Mon Sep 17 00:00:00 2001 From: rexelion Date: Tue, 31 Oct 2017 18:16:40 +0000 Subject: [PATCH 4/6] OnActivate is triggered when the item is picked up --- apps/openmw/mwgui/inventorywindow.cpp | 26 +++++++------------------- apps/openmw/mwgui/inventorywindow.hpp | 4 ---- apps/openmw/mwgui/windowmanagerimp.cpp | 2 -- apps/openmw/mwworld/actiontake.cpp | 3 +++ 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 5fe644d45d..1e9f534d6a 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,7 +1,6 @@ #include "inventorywindow.hpp" #include -#include #include #include @@ -150,15 +149,6 @@ namespace MWGui mItemView->setModel(NULL); } - void InventoryWindow::activateItems() - { - for (std::vector::iterator it = mItemsToActivate.begin(); it != mItemsToActivate.end(); it++) - { - it->getRefData().activate(); - } - mItemsToActivate.clear(); - } - void InventoryWindow::setGuiMode(GuiMode mode) { std::string setting = "inventory"; @@ -663,15 +653,6 @@ namespace MWGui if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; - if (object.getRefData().hasSuppressActivate()) // if Flag_SuppressActivate is set, script that contains OnActivate is attached to the item - { - if (std::find(mItemsToActivate.begin(), mItemsToActivate.end(), object) == mItemsToActivate.end()) - { - mItemsToActivate.push_back(object); - } - return; - } - int count = object.getRefData().getCount(); MWWorld::Ptr player = MWMechanics::getPlayer(); @@ -682,6 +663,13 @@ namespace MWGui // add to player inventory // can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object MWWorld::Ptr newObject = *player.getClass().getContainerStore (player).add (object, object.getRefData().getCount(), player); + + if (object.getRefData().hasSuppressActivate()) // if Flag_SuppressActivate is set, script that contains OnActivate is attached to the item + { + newObject.getRefData().onActivate(); // set the flag_SuppressActivate flag for the new item + newObject.getRefData().activate(); + } + // remove from world MWBase::Environment::get().getWorld()->deleteObject (object); diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 3f88d88226..5576b52ed0 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -58,8 +58,6 @@ namespace MWGui void clear(); - void activateItems(); - void useItem(const MWWorld::Ptr& ptr); void setGuiMode(GuiMode mode); @@ -72,8 +70,6 @@ namespace MWGui int mSelectedItem; - std::vector mItemsToActivate; - MWWorld::Ptr mPtr; MWGui::ItemView* mItemView; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index e2a10ccc3d..ccdd6916c0 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1171,8 +1171,6 @@ namespace MWGui mGuiModeStates[mode].update(false); if (!noSound) playSound(mGuiModeStates[mode].mCloseSound); - if (mode == GM_Inventory) - mInventoryWindow->activateItems(); // Activate cursed items when inventory is closed } if (!mGuiModes.empty()) diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index d858859a69..52e30c8ac7 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -14,6 +14,9 @@ namespace MWWorld void ActionTake::executeImp (const Ptr& actor) { + //No need to do anything if moving items from the player's inventory back into player's inventory + if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr() && getTarget().getCell() == 0) + return; MWBase::Environment::get().getMechanicsManager()->itemTaken( actor, getTarget(), MWWorld::Ptr(), getTarget().getRefData().getCount()); MWWorld::Ptr newitem = *actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor); From bcbfa5fe1e97696a96794b0b55d3ec8b427a1212 Mon Sep 17 00:00:00 2001 From: rexelion Date: Sat, 4 Nov 2017 00:38:33 +0000 Subject: [PATCH 5/6] prevent activation, leave the rest to the script --- apps/openmw/mwgui/inventorywindow.cpp | 9 +++------ apps/openmw/mwworld/actiontake.cpp | 3 --- apps/openmw/mwworld/refdata.cpp | 5 ----- apps/openmw/mwworld/refdata.hpp | 2 -- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 1e9f534d6a..063bc5c016 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -653,6 +653,9 @@ namespace MWGui if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; + if (!object.getRefData().activate()) + return; + int count = object.getRefData().getCount(); MWWorld::Ptr player = MWMechanics::getPlayer(); @@ -663,12 +666,6 @@ namespace MWGui // add to player inventory // can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object MWWorld::Ptr newObject = *player.getClass().getContainerStore (player).add (object, object.getRefData().getCount(), player); - - if (object.getRefData().hasSuppressActivate()) // if Flag_SuppressActivate is set, script that contains OnActivate is attached to the item - { - newObject.getRefData().onActivate(); // set the flag_SuppressActivate flag for the new item - newObject.getRefData().activate(); - } // remove from world MWBase::Environment::get().getWorld()->deleteObject (object); diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 52e30c8ac7..d858859a69 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -14,9 +14,6 @@ namespace MWWorld void ActionTake::executeImp (const Ptr& actor) { - //No need to do anything if moving items from the player's inventory back into player's inventory - if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr() && getTarget().getCell() == 0) - return; MWBase::Environment::get().getMechanicsManager()->itemTaken( actor, getTarget(), MWWorld::Ptr(), getTarget().getRefData().getCount()); MWWorld::Ptr newitem = *actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor); diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index 95b0fb3e0b..f6fa3556fa 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -192,11 +192,6 @@ namespace MWWorld return mEnabled; } - bool RefData::hasSuppressActivate() - { - return mFlags & Flag_SuppressActivate; - } - void RefData::enable() { if (!mEnabled) diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 4dfa9e91c4..75eec6742d 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -111,8 +111,6 @@ namespace MWWorld bool isEnabled() const; - bool hasSuppressActivate(); - void enable(); void disable(); From 8c2cc0f42fa6b6e7717962a87a1d2c584460ca0b Mon Sep 17 00:00:00 2001 From: rexelion Date: Sat, 4 Nov 2017 00:44:16 +0000 Subject: [PATCH 6/6] break invisibility first --- apps/openmw/mwgui/inventorywindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 063bc5c016..e1301edd43 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -653,13 +653,13 @@ namespace MWGui if (object.getClass().getName(object) == "") // objects without name presented to user can never be picked up return; - if (!object.getRefData().activate()) - return; - int count = object.getRefData().getCount(); MWWorld::Ptr player = MWMechanics::getPlayer(); MWBase::Environment::get().getWorld()->breakInvisibility(player); + + if (!object.getRefData().activate()) + return; MWBase::Environment::get().getMechanicsManager()->itemTaken(player, object, MWWorld::Ptr(), count);