From 89ad2af1d903bf34d12e5cba9b8f9d839b6805ef Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 10 Sep 2012 17:44:59 +0200 Subject: [PATCH] key usage to open doors or containers to test: player->additem, "key_arrile", 1 (door in arille's tradehouse) player->additem, "key_alvur", 1 (chest in the back of beshara) --- apps/openmw/mwclass/container.cpp | 38 +++++++++-- apps/openmw/mwclass/door.cpp | 103 ++++++++++++++++++------------ apps/openmw/mwgui/tradewindow.cpp | 3 +- 3 files changed, 95 insertions(+), 49 deletions(-) diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 6fa23a98ae..1164873a00 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -14,6 +14,8 @@ #include "../mwworld/cellstore.hpp" #include "../mwworld/actionopen.hpp" #include "../mwworld/physicssystem.hpp" +#include "../mwworld/player.hpp" +#include "../mwworld/inventorystore.hpp" #include "../mwgui/tooltips.hpp" @@ -87,15 +89,31 @@ namespace MWClass const std::string lockedSound = "LockedChest"; const std::string trapActivationSound = "Disarm Trap Fail"; - if (ptr.getCellRef().lockLevel>0) + MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer(); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player); + + bool needKey = ptr.getCellRef().lockLevel>0; + bool hasKey = false; + std::string keyName; + for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { - // TODO check for key - std::cout << "Locked container" << std::endl; - boost::shared_ptr action(new MWWorld::NullAction); - action->setSound(lockedSound); - return action; + if (it->getCellRef ().refID == ptr.getCellRef().key) + { + hasKey = true; + keyName = MWWorld::Class::get(*it).getName(*it); + } } - else + + if (needKey && hasKey) + { + MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}", std::vector()); + ptr.getCellRef().lockLevel = 0; + // using a key disarms the trap + ptr.getCellRef().trap = ""; + } + + + if (!needKey || hasKey) { if(ptr.getCellRef().trap.empty()) { @@ -112,6 +130,12 @@ namespace MWClass return action; } } + else + { + boost::shared_ptr action(new MWWorld::NullAction); + action->setSound(lockedSound); + return action; + } } std::string Container::getName (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index f483aa3a88..96c6eba5f9 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -13,6 +13,7 @@ #include "../mwworld/actionteleport.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/physicssystem.hpp" +#include "../mwworld/inventorystore.hpp" #include "../mwgui/tooltips.hpp" @@ -74,60 +75,80 @@ namespace MWClass const std::string lockedSound = "LockedDoor"; const std::string trapActivationSound = "Disarm Trap Fail"; - if (ptr.getCellRef().lockLevel>0) + MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer(); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player); + + bool needKey = ptr.getCellRef().lockLevel>0; + bool hasKey = false; + std::string keyName; + for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { - // TODO check for key - // TODO report failure to player (message, sound?). Look up behaviour of original MW. - std::cout << "Locked!" << std::endl; - - boost::shared_ptr action(new MWWorld::NullAction); - - action->setSound(lockedSound); - - return action; - } - - if(!ptr.getCellRef().trap.empty()) - { - // Trap activation - std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl; - - boost::shared_ptr action(new MWWorld::NullAction); - - action->setSound(trapActivationSound); - ptr.getCellRef().trap = ""; - - return action; - } - - if (ref->ref.teleport) - { - // teleport door - /// \todo remove this if clause once ActionTeleport can also support other actors - if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor) + if (it->getCellRef ().refID == ptr.getCellRef().key) { - boost::shared_ptr action(new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest)); + hasKey = true; + keyName = MWWorld::Class::get(*it).getName(*it); + } + } - action->setSound(openSound); + if (needKey && hasKey) + { + MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}", std::vector()); + ptr.getCellRef().lockLevel = 0; + // using a key disarms the trap + ptr.getCellRef().trap = ""; + } + + if (!needKey || hasKey) + { + if(!ptr.getCellRef().trap.empty()) + { + // Trap activation + std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl; + + boost::shared_ptr action(new MWWorld::NullAction); + + action->setSound(trapActivationSound); + ptr.getCellRef().trap = ""; return action; } + + if (ref->ref.teleport) + { + // teleport door + /// \todo remove this if clause once ActionTeleport can also support other actors + if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor) + { + boost::shared_ptr action(new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest)); + + action->setSound(openSound); + + return action; + } + else + { + // another NPC or a creature is using the door + return boost::shared_ptr (new MWWorld::NullAction); + } + } else { - // another NPC or a creature is using the door - return boost::shared_ptr (new MWWorld::NullAction); + // animated door + // TODO return action for rotating the door + + // This is a little pointless, but helps with testing + boost::shared_ptr action(new MWWorld::NullAction); + + action->setSound(openSound); + + return action; } } else { - // animated door - // TODO return action for rotating the door - - // This is a little pointless, but helps with testing + // locked, and we can't open. boost::shared_ptr action(new MWWorld::NullAction); - - action->setSound(openSound); - + action->setSound(lockedSound); return action; } } diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 6d7286dd0a..27a24c22cf 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -179,7 +179,8 @@ namespace MWGui mWindowManager.getInventoryWindow()->transferBoughtItems(); // add or remove gold from the player. - addOrRemoveGold(mCurrentBalance); + if (mCurrentBalance != 0) + addOrRemoveGold(mCurrentBalance); std::string sound = "Item Gold Up"; MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);