From 4600f24e27dfa77dffdc966374af976a909086e4 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 9 Jun 2017 22:52:40 +0400 Subject: [PATCH 1/4] Playing sound when AI is opening a door --- apps/openmw/mwmechanics/aipackage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index abdc57042..08fe0b28c 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -182,7 +182,7 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float dur if (getTypeId() != TypeIdWander && !door.getCellRef().getTeleport() && door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 && door.getClass().getDoorState(door) == 0) { - MWBase::Environment::get().getWorld()->activateDoor(door, 1); + MWBase::Environment::get().getWorld()->activate(door, actor); } } else // any other obstacle (NPC, crate, etc.) From 188424d5d336151d7363aca49c8b996eec9773e5 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 10 Jun 2017 22:31:17 +0400 Subject: [PATCH 2/4] Allow AI to use keys to open doors --- apps/openmw/mwmechanics/aipackage.cpp | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 08fe0b28c..62fd56bec 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -12,6 +12,7 @@ #include "../mwworld/action.hpp" #include "../mwworld/class.hpp" #include "../mwworld/cellstore.hpp" +#include "../mwworld/inventorystore.hpp" #include "creaturestats.hpp" #include "movement.hpp" @@ -179,10 +180,33 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float dur if (door != MWWorld::Ptr()) { // note: AiWander currently does not open doors - if (getTypeId() != TypeIdWander && !door.getCellRef().getTeleport() && door.getCellRef().getTrap().empty() - && door.getCellRef().getLockLevel() <= 0 && door.getClass().getDoorState(door) == 0) + if (getTypeId() != TypeIdWander && !door.getCellRef().getTeleport() && door.getClass().getDoorState(door) == 0) { - MWBase::Environment::get().getWorld()->activate(door, actor); + if ((door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 )) + MWBase::Environment::get().getWorld()->activate(door, actor); + + std::string keyId = door.getCellRef().getKey(); + if (keyId.empty()) + return; + + bool hasKey = false; + const MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); + + // make key id lowercase + Misc::StringUtils::lowerCaseInPlace(keyId); + for (MWWorld::ConstContainerStoreIterator it = invStore.cbegin(); it != invStore.cend(); ++it) + { + std::string refId = it->getCellRef().getRefId(); + Misc::StringUtils::lowerCaseInPlace(refId); + if (refId == keyId) + { + hasKey = true; + break; + } + } + + if (hasKey) + MWBase::Environment::get().getWorld()->activate(door, actor); } } else // any other obstacle (NPC, crate, etc.) From cab51d26cc4f106ee5cb516f9655ede6e48357ce Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 10 Jun 2017 22:33:14 +0400 Subject: [PATCH 3/4] Doors: small key search optimizations --- apps/openmw/mwclass/door.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 5f977174f..bbaff6338 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -132,15 +132,19 @@ namespace MWClass // make key id lowercase std::string keyId = ptr.getCellRef().getKey(); - Misc::StringUtils::lowerCaseInPlace(keyId); - for (MWWorld::ConstContainerStoreIterator it = invStore.cbegin(); it != invStore.cend(); ++it) + if (!keyId.empty()) { - std::string refId = it->getCellRef().getRefId(); - Misc::StringUtils::lowerCaseInPlace(refId); - if (refId == keyId) + Misc::StringUtils::lowerCaseInPlace(keyId); + for (MWWorld::ConstContainerStoreIterator it = invStore.cbegin(); it != invStore.cend(); ++it) { - hasKey = true; - keyName = it->getClass().getName(*it); + std::string refId = it->getCellRef().getRefId(); + Misc::StringUtils::lowerCaseInPlace(refId); + if (refId == keyId) + { + hasKey = true; + keyName = it->getClass().getName(*it); + break; + } } } From e9d0bf7c1270652394ac17081a306007d521fbc7 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 11 Jun 2017 15:06:44 +0400 Subject: [PATCH 4/4] Added missed return statement --- apps/openmw/mwmechanics/aipackage.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 62fd56bec..529e7ca41 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -183,7 +183,10 @@ void MWMechanics::AiPackage::evadeObstacles(const MWWorld::Ptr& actor, float dur if (getTypeId() != TypeIdWander && !door.getCellRef().getTeleport() && door.getClass().getDoorState(door) == 0) { if ((door.getCellRef().getTrap().empty() && door.getCellRef().getLockLevel() <= 0 )) + { MWBase::Environment::get().getWorld()->activate(door, actor); + return; + } std::string keyId = door.getCellRef().getKey(); if (keyId.empty())