diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 608fc6122..4f11e1c0e 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -87,7 +87,6 @@ namespace MWClass const std::string lockedSound = "LockedChest"; const std::string trapActivationSound = "Disarm Trap Fail"; - if (ptr.getCellRef().lockLevel>0) { // TODO check for key @@ -98,12 +97,11 @@ namespace MWClass } else { - std::cout << "Unlocked container" << std::endl; if(ptr.getCellRef().trap.empty()) { - // Not trapped, Inventory GUI goes here - //return boost::shared_ptr (new MWWorld::NullAction); - return boost::shared_ptr (new MWWorld::ActionOpen(ptr)); + boost::shared_ptr action (new MWWorld::ActionOpen(ptr)); + action->setSound ("chest open"); + return action; } else { diff --git a/apps/openmw/mwworld/action.cpp b/apps/openmw/mwworld/action.cpp index 748f6aff7..a5199fb3e 100644 --- a/apps/openmw/mwworld/action.cpp +++ b/apps/openmw/mwworld/action.cpp @@ -6,7 +6,12 @@ #include "../mwbase/soundmanager.hpp" -MWWorld::Action::Action (bool teleport) : mTeleport (teleport) +const MWWorld::Ptr& MWWorld::Action::getTarget() const +{ + return mTarget; +} + +MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSound), mTarget (target) {} MWWorld::Action::~Action() {} @@ -15,16 +20,19 @@ void MWWorld::Action::execute (const Ptr& actor) { if (!mSoundId.empty()) { - if (mTeleport == true) + if (mKeepSound && actor.getRefData().getHandle()=="player") { - //this is a teleport action, so we need to call playSound + // sound moves with player when teleporting MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_NoTrack); } else { - MWBase::Environment::get().getSoundManager()->playSound3D (actor, mSoundId, 1.0, 1.0, - MWBase::SoundManager::Play_NoTrack); + bool local = mTarget.isEmpty() || !mTarget.isInCell(); // no usable target + + MWBase::Environment::get().getSoundManager()->playSound3D (local ? actor : mTarget, + mSoundId, 1.0, 1.0, + mKeepSound ? MWBase::SoundManager::Play_NoTrack : MWBase::SoundManager::Play_Normal); } } diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp index 511a7002d..d8e5d93bb 100644 --- a/apps/openmw/mwworld/action.hpp +++ b/apps/openmw/mwworld/action.hpp @@ -3,15 +3,16 @@ #include +#include "ptr.hpp" + namespace MWWorld { - class Ptr; - /// \brief Abstract base for actions class Action { std::string mSoundId; - bool mTeleport; + bool mKeepSound; + Ptr mTarget; // not implemented Action (const Action& action); @@ -19,10 +20,14 @@ namespace MWWorld virtual void executeImp (const Ptr& actor) = 0; - public: + protected: + + const Ptr& getTarget() const; + + public: - Action (bool teleport = false); - ///< \param teleport action will teleport the actor + Action (bool keepSound = false, const Ptr& target = Ptr()); + ///< \param keepSound Keep playing the sound even if the object the sound is played on is removed. virtual ~Action(); diff --git a/apps/openmw/mwworld/actionapply.cpp b/apps/openmw/mwworld/actionapply.cpp index 595ee6cb3..f78b8f798 100644 --- a/apps/openmw/mwworld/actionapply.cpp +++ b/apps/openmw/mwworld/actionapply.cpp @@ -6,23 +6,23 @@ namespace MWWorld { ActionApply::ActionApply (const Ptr& target, const std::string& id) - : mTarget (target), mId (id) + : Action (false, target), mId (id) {} void ActionApply::executeImp (const Ptr& actor) { - MWWorld::Class::get (mTarget).apply (mTarget, mId, actor); + MWWorld::Class::get (getTarget()).apply (getTarget(), mId, actor); } ActionApplyWithSkill::ActionApplyWithSkill (const Ptr& target, const std::string& id, int skillIndex, int usageType) - : mTarget (target), mId (id), mSkillIndex (skillIndex), mUsageType (usageType) + : Action (false, target), mId (id), mSkillIndex (skillIndex), mUsageType (usageType) {} void ActionApplyWithSkill::executeImp (const Ptr& actor) { - if (MWWorld::Class::get (mTarget).apply (mTarget, mId, actor) && mUsageType!=-1) - MWWorld::Class::get (mTarget).skillUsageSucceeded (actor, mSkillIndex, mUsageType); + if (MWWorld::Class::get (getTarget()).apply (getTarget(), mId, actor) && mUsageType!=-1) + MWWorld::Class::get (getTarget()).skillUsageSucceeded (actor, mSkillIndex, mUsageType); } } diff --git a/apps/openmw/mwworld/actionapply.hpp b/apps/openmw/mwworld/actionapply.hpp index 523bf9373..3353ae0ee 100644 --- a/apps/openmw/mwworld/actionapply.hpp +++ b/apps/openmw/mwworld/actionapply.hpp @@ -11,7 +11,6 @@ namespace MWWorld { class ActionApply : public Action { - Ptr mTarget; std::string mId; virtual void executeImp (const Ptr& actor); @@ -23,7 +22,6 @@ namespace MWWorld class ActionApplyWithSkill : public Action { - Ptr mTarget; std::string mId; int mSkillIndex; int mUsageType; diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index 20e0afb68..d8c019644 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -9,7 +9,7 @@ namespace MWWorld { - ActionEquip::ActionEquip (const MWWorld::Ptr& object) : mObject (object) + ActionEquip::ActionEquip (const MWWorld::Ptr& object) : Action (false, object) { } @@ -19,13 +19,13 @@ namespace MWWorld MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player); // slots that this item can be equipped in - std::pair, bool> slots = MWWorld::Class::get(mObject).getEquipmentSlots(mObject); + std::pair, bool> slots = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget()); // retrieve ContainerStoreIterator to the item MWWorld::ContainerStoreIterator it = invStore.begin(); for (; it != invStore.end(); ++it) { - if (*it == mObject) + if (*it == getTarget()) { break; } diff --git a/apps/openmw/mwworld/actionequip.hpp b/apps/openmw/mwworld/actionequip.hpp index 5685a294a..3b56c7402 100644 --- a/apps/openmw/mwworld/actionequip.hpp +++ b/apps/openmw/mwworld/actionequip.hpp @@ -8,8 +8,6 @@ namespace MWWorld { class ActionEquip : public Action { - Ptr mObject; - virtual void executeImp (const Ptr& actor); public: diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp index 15a9f510d..040a3856e 100644 --- a/apps/openmw/mwworld/actionopen.cpp +++ b/apps/openmw/mwworld/actionopen.cpp @@ -10,8 +10,8 @@ namespace MWWorld { - ActionOpen::ActionOpen (const MWWorld::Ptr& container) : mContainer (container) { - mContainer = container; + ActionOpen::ActionOpen (const MWWorld::Ptr& container) : Action (false, container) + { } void ActionOpen::executeImp (const MWWorld::Ptr& actor) @@ -20,6 +20,6 @@ namespace MWWorld return; MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Container); - MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(mContainer); + MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(getTarget()); } } diff --git a/apps/openmw/mwworld/actionopen.hpp b/apps/openmw/mwworld/actionopen.hpp index 5666ff293..c49ebefa5 100644 --- a/apps/openmw/mwworld/actionopen.hpp +++ b/apps/openmw/mwworld/actionopen.hpp @@ -10,8 +10,6 @@ namespace MWWorld { class ActionOpen : public Action { - Ptr mContainer; - virtual void executeImp (const MWWorld::Ptr& actor); public: diff --git a/apps/openmw/mwworld/actionread.cpp b/apps/openmw/mwworld/actionread.cpp index 5c6ab93c1..7fb2b23e7 100644 --- a/apps/openmw/mwworld/actionread.cpp +++ b/apps/openmw/mwworld/actionread.cpp @@ -8,23 +8,23 @@ namespace MWWorld { - ActionRead::ActionRead (const MWWorld::Ptr& object) : mObject (object) + ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object) { } void ActionRead::executeImp (const MWWorld::Ptr& actor) { - LiveCellRef *ref = mObject.get(); + LiveCellRef *ref = getTarget().get(); if (ref->base->data.isScroll) { MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Scroll); - MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(mObject); + MWBase::Environment::get().getWindowManager()->getScrollWindow()->open(getTarget()); } else { MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book); - MWBase::Environment::get().getWindowManager()->getBookWindow()->open(mObject); + MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget()); } } } diff --git a/apps/openmw/mwworld/actionread.hpp b/apps/openmw/mwworld/actionread.hpp index 9bb74fb88..00a4756dd 100644 --- a/apps/openmw/mwworld/actionread.hpp +++ b/apps/openmw/mwworld/actionread.hpp @@ -8,8 +8,6 @@ namespace MWWorld { class ActionRead : public Action { - Ptr mObject; // book or scroll to read - virtual void executeImp (const MWWorld::Ptr& actor); public: diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 90f3c000e..fd28dd52e 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -10,7 +10,7 @@ namespace MWWorld { - ActionTake::ActionTake (const MWWorld::Ptr& object) : mObject (object) {} + ActionTake::ActionTake (const MWWorld::Ptr& object) : Action (true, object) {} void ActionTake::executeImp (const Ptr& actor) { @@ -20,10 +20,8 @@ namespace MWWorld // insert into player's inventory MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPtr ("player", true); - MWWorld::Class::get (player).getContainerStore (player).add (mObject); + MWWorld::Class::get (player).getContainerStore (player).add (getTarget()); - // remove from world, if the item is currently in the world (it could also be in a container) - if (mObject.isInCell()) - MWBase::Environment::get().getWorld()->deleteObject (mObject); + MWBase::Environment::get().getWorld()->deleteObject (getTarget()); } } diff --git a/apps/openmw/mwworld/actiontake.hpp b/apps/openmw/mwworld/actiontake.hpp index 52a114acf..b0a9b8247 100644 --- a/apps/openmw/mwworld/actiontake.hpp +++ b/apps/openmw/mwworld/actiontake.hpp @@ -8,8 +8,6 @@ namespace MWWorld { class ActionTake : public Action { - MWWorld::Ptr mObject; - virtual void executeImp (const Ptr& actor); public: diff --git a/apps/openmw/mwworld/actiontalk.cpp b/apps/openmw/mwworld/actiontalk.cpp index d94cb67f4..905497f85 100644 --- a/apps/openmw/mwworld/actiontalk.cpp +++ b/apps/openmw/mwworld/actiontalk.cpp @@ -6,10 +6,10 @@ namespace MWWorld { - ActionTalk::ActionTalk (const Ptr& actor) : mActor (actor) {} + ActionTalk::ActionTalk (const Ptr& actor) : Action (false, actor) {} void ActionTalk::executeImp (const Ptr& actor) { - MWBase::Environment::get().getDialogueManager()->startDialogue (mActor); + MWBase::Environment::get().getDialogueManager()->startDialogue (getTarget()); } } diff --git a/apps/openmw/mwworld/actiontalk.hpp b/apps/openmw/mwworld/actiontalk.hpp index 53adf9e53..b88b168d8 100644 --- a/apps/openmw/mwworld/actiontalk.hpp +++ b/apps/openmw/mwworld/actiontalk.hpp @@ -8,8 +8,6 @@ namespace MWWorld { class ActionTalk : public Action { - Ptr mActor; - virtual void executeImp (const Ptr& actor); public: diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index 14ddd3ec5..41794c2ad 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -75,6 +75,9 @@ namespace MWWorld std::string RefData::getHandle() { + if (!mBaseNode) + return ""; + return mBaseNode->getName(); }