diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 675287af9..09891652a 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -7,6 +7,7 @@ #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" +#include "../mwbase/soundmanager.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/failedaction.hpp" @@ -136,7 +137,8 @@ namespace MWClass MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); - bool needKey = ptr.getCellRef().getLockLevel() > 0; + bool isLocked = ptr.getCellRef().getLockLevel() > 0; + bool isTrapped = !ptr.getCellRef().getTrap().empty(); bool hasKey = false; std::string keyName; @@ -154,18 +156,26 @@ namespace MWClass } } - if (needKey && hasKey) + if ((isLocked || isTrapped) && hasKey) { MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}"); - unlock(ptr); + if(isLocked) + unlock(ptr); // using a key disarms the trap - ptr.getCellRef().setTrap(""); + if(isTrapped) + { + ptr.getCellRef().setTrap(""); + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, + "Disarm Trap", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, + MWBase::SoundManager::Play_Normal); + isTrapped = false; + } } - if (!needKey || hasKey) + if (!isLocked || hasKey) { - if(ptr.getCellRef().getTrap().empty()) + if(!isTrapped) { boost::shared_ptr action (new MWWorld::ActionOpen(ptr)); return action; @@ -173,7 +183,7 @@ namespace MWClass else { // Activate trap - boost::shared_ptr action(new MWWorld::ActionTrap(actor, ptr.getCellRef().getTrap(), ptr)); + boost::shared_ptr action(new MWWorld::ActionTrap(ptr.getCellRef().getTrap(), ptr)); action->setSound(trapActivationSound); return action; } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index d8a9efba5..a54b64897 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -107,7 +107,8 @@ namespace MWClass MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); - bool needKey = ptr.getCellRef().getLockLevel() > 0; + bool isLocked = ptr.getCellRef().getLockLevel() > 0; + bool isTrapped = !ptr.getCellRef().getTrap().empty(); bool hasKey = false; std::string keyName; @@ -125,21 +126,29 @@ namespace MWClass } } - if (needKey && hasKey) + if ((isLocked || isTrapped) && hasKey) { if(actor == MWMechanics::getPlayer()) MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}"); - unlock(ptr); //Call the function here. because that makes sense. + if(isLocked) + unlock(ptr); //Call the function here. because that makes sense. // using a key disarms the trap - ptr.getCellRef().setTrap(""); + if(isTrapped) + { + ptr.getCellRef().setTrap(""); + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, + "Disarm Trap", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, + MWBase::SoundManager::Play_Normal); + isTrapped = false; + } } - if (!needKey || hasKey) + if (!isLocked || hasKey) { - if(!ptr.getCellRef().getTrap().empty()) + if(isTrapped) { // Trap activation - boost::shared_ptr action(new MWWorld::ActionTrap(actor, ptr.getCellRef().getTrap(), ptr)); + boost::shared_ptr action(new MWWorld::ActionTrap(ptr.getCellRef().getTrap(), ptr)); action->setSound(trapActivationSound); return action; } diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 24f004588..081f288d5 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1305,7 +1305,9 @@ bool CharacterController::updateWeaponState() if(!resultMessage.empty()) MWBase::Environment::get().getWindowManager()->messageBox(resultMessage); if(!resultSound.empty()) - MWBase::Environment::get().getSoundManager()->playSound(resultSound, 1.0f, 1.0f); + MWBase::Environment::get().getSoundManager()->playSound3D(target, + resultSound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, + MWBase::SoundManager::Play_Normal); } else if (ammunition) { diff --git a/apps/openmw/mwworld/actiontrap.hpp b/apps/openmw/mwworld/actiontrap.hpp index 4c2f4139f..5ff91613f 100644 --- a/apps/openmw/mwworld/actiontrap.hpp +++ b/apps/openmw/mwworld/actiontrap.hpp @@ -18,10 +18,9 @@ namespace MWWorld public: /// @param spellId - /// @param actor Actor that activated the trap /// @param trapSource - ActionTrap (const Ptr& actor, const std::string& spellId, const Ptr& trapSource) - : Action(false, actor), mSpellId(spellId), mTrapSource(trapSource) {} + ActionTrap (const std::string& spellId, const Ptr& trapSource) + : Action(false, trapSource), mSpellId(spellId), mTrapSource(trapSource) {} }; }