Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Lock picking with Activate: a locked door or chest with no key, a go at picking it with a carried lockpick

Alan Saunders35f35b159b41
diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp
index ff643ff..e3012c0 100644
--- a/apps/openmw/mwclass/container.cpp
+++ b/apps/openmw/mwclass/container.cpp
@@ -34,6 +34,7 @@
#include "../mwmechanics/inventory.hpp"
#include "../mwmechanics/npcstats.hpp"
+#include "../mwmechanics/security.hpp"
#include "classmodel.hpp"
#include "nameorid.hpp"
@@ -223,6 +224,10 @@ namespace MWClass
}
else
{
+ // Isowind: the player has a go at picking it instead, with a lockpick they carry (in top-down there is no
+ // crosshair to attack the lock under)
+ if (std::unique_ptr<MWWorld::Action> action = MWMechanics::pickLockOnActivation(ptr, actor))
+ return action;
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(ESM::RefId::stringRefId("LockedChest"));
return action;
diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp
index a037b52..e045204 100644
--- a/apps/openmw/mwclass/door.cpp
+++ b/apps/openmw/mwclass/door.cpp
@@ -37,6 +37,7 @@
#include "../mwrender/vismask.hpp"
#include "../mwmechanics/actorutil.hpp"
+#include "../mwmechanics/security.hpp"
#include "classmodel.hpp"
#include "nameorid.hpp"
@@ -254,6 +255,10 @@ namespace MWClass
}
else
{
+ // Isowind: the player has a go at picking it instead, with a lockpick they carry (in top-down there is no
+ // crosshair to attack the lock under)
+ if (std::unique_ptr<MWWorld::Action> action = MWMechanics::pickLockOnActivation(ptr, actor))
+ return action;
// locked, and we can't open.
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp
index 233856d..c3f0c62 100644
--- a/apps/openmw/mwmechanics/security.cpp
+++ b/apps/openmw/mwmechanics/security.cpp
@@ -5,12 +5,18 @@
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/esmstore.hpp"
+#include "../mwworld/failedaction.hpp"
+#include "../mwworld/inventorystore.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/world.hpp"
+#include "../mwmp/Hooks.hpp"
+
+#include "actorutil.hpp"
#include "creaturestats.hpp"
+#include "npcstats.hpp"
#include "spellutil.hpp"
namespace MWMechanics
@@ -29,6 +35,11 @@ namespace MWMechanics
void Security::pickLock(const MWWorld::Ptr& lock, const MWWorld::Ptr& lockpick, std::string_view& resultMessage,
std::string_view& resultSound)
{
+ // Isowind multiplayer: another player's (or a remote actor's) attempt is their own client's to make; here their
+ // swing would otherwise pick what this player is looking at
+ if (mwmp::hooks::isRemotelyControlled(mActor))
+ return;
+
// If it's unlocked or can not be unlocked back out immediately. Note that we're not strictly speaking checking
// if the ref is locked, lock levels <= 0 can exist but they cannot be picked
if (lock.getCellRef().getLockLevel() <= 0 || !lock.getClass().hasToolTip(lock))
@@ -62,7 +73,11 @@ namespace MWMechanics
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
if (Misc::Rng::roll0to99(prng) <= x)
{
- lock.getCellRef().unlock();
+ // Isowind multiplayer: the server unlocks it, for everyone
+ if (mwmp::hooks::isMultiplayer())
+ mwmp::hooks::sendObjectLock(lock, 0);
+ else
+ lock.getCellRef().unlock();
resultMessage = "#{sLockSuccess}";
resultSound = "Open Lock";
mActor.getClass().skillUsageSucceeded(mActor, ESM::Skill::Security, ESM::Skill::Security_PickLock);
@@ -79,6 +94,10 @@ namespace MWMechanics
void Security::probeTrap(const MWWorld::Ptr& trap, const MWWorld::Ptr& probe, std::string_view& resultMessage,
std::string_view& resultSound)
{
+ // Isowind multiplayer: as for lockpicks, another player's attempt is their own client's
+ if (mwmp::hooks::isRemotelyControlled(mActor))
+ return;
+
if (trap.getCellRef().getTrap().empty())
return;
@@ -127,4 +146,61 @@ namespace MWMechanics
probe.getContainerStore()->remove(probe, 1);
}
+ MWWorld::Ptr chooseLockpick(const MWWorld::Ptr& actor)
+ {
+ MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
+ MWWorld::ContainerStoreIterator held = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
+ if (held != store.end() && held->getType() == ESM::Lockpick::sRecordId
+ && held->getClass().getItemHealth(*held) > 0)
+ return *held;
+
+ // The best; of equally good ones the most worn, so that a whole stack isn't split for the one that is used
+ MWWorld::Ptr best;
+ float bestQuality = 0.f;
+ int bestUses = 0;
+ for (auto it = store.begin(MWWorld::ContainerStore::Type_Lockpick); it != store.end(); ++it)
+ {
+ const int uses = it->getClass().getItemHealth(*it);
+ if (uses <= 0)
+ continue;
+ const float quality = it->get<ESM::Lockpick>()->mBase->mData.mQuality;
+ if (best.isEmpty() || quality > bestQuality || (quality == bestQuality && uses < bestUses))
+ {
+ best = *it;
+ bestQuality = quality;
+ bestUses = uses;
+ }
+ }
+ return best;
+ }
+
+ std::unique_ptr<MWWorld::Action> pickLockOnActivation(const MWWorld::Ptr& lock, const MWWorld::Ptr& actor)
+ {
+ // NPCs don't pick locks, and a werewolf can't hold a lockpick
+ if (actor != getPlayer() || actor.getClass().getNpcStats(actor).isWerewolf())
+ return nullptr;
+ // What Security::pickLock backs out of, checked first so that no stack of lockpicks is split for nothing
+ if (lock.getCellRef().getLockLevel() <= 0 || !lock.getClass().hasToolTip(lock))
+ return nullptr;
+ MWWorld::Ptr lockpick = chooseLockpick(actor);
+ if (lockpick.isEmpty())
+ return nullptr;
+
+ // Isowind multiplayer: the inventory goes to the server once afterwards, with the pick's wear (or without
+ // the pick, used up), instead of item by item as the stack is split
+ mwmp::hooks::beginBatchedItemRemovals();
+ // Only the one pick wears (one that is held is on its own already)
+ actor.getClass().getContainerStore(actor).unstack(lockpick);
+ std::string_view resultMessage, resultSound;
+ Security(actor).pickLock(lock, lockpick, resultMessage, resultSound);
+ mwmp::hooks::endBatchedItemRemovals();
+
+ if (resultMessage.empty())
+ return nullptr;
+ // The result shown and heard as after a swing of the lockpick: the message, and the sound at the lock
+ std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(resultMessage, lock);
+ if (!resultSound.empty())
+ action->setSound(ESM::RefId::stringRefId(resultSound));
+ return action;
+ }
}
diff --git a/apps/openmw/mwmechanics/security.hpp b/apps/openmw/mwmechanics/security.hpp
index 7765bcb..6465082 100644
--- a/apps/openmw/mwmechanics/security.hpp
+++ b/apps/openmw/mwmechanics/security.hpp
@@ -1,8 +1,15 @@
#ifndef MWMECHANICS_SECURITY_H
#define MWMECHANICS_SECURITY_H
+#include <memory>
+
#include "../mwworld/ptr.hpp"
+namespace MWWorld
+{
+ class Action;
+}
+
namespace MWMechanics
{
@@ -22,6 +29,15 @@ namespace MWMechanics
MWWorld::Ptr mActor;
};
+ /// Isowind: the lockpick the player picks a lock with when they activate it: the one they hold, else the best
+ /// one they carry (of equally good ones the most worn). Empty if they carry none with uses left.
+ MWWorld::Ptr chooseLockpick(const MWWorld::Ptr& actor);
+
+ /// Isowind: the player activating a locked door or container they have no key to, while carrying a lockpick,
+ /// makes one attempt at picking it with chooseLockpick's (Security::pickLock, as attacking the lock with the
+ /// lockpick ready does): returns the action that shows the result. nullptr when there is no attempt to make,
+ /// and the object is just locked.
+ std::unique_ptr<MWWorld::Action> pickLockOnActivation(const MWWorld::Ptr& lock, const MWWorld::Ptr& actor);
}
#endif
diff --git a/isowind/README.txt b/isowind/README.txt
index 7f21ed4..a8f38cc 100644
--- a/isowind/README.txt
+++ b/isowind/README.txt
@@ -104,6 +104,8 @@ Left click Attack / cast when ready, otherwise use whatever is under the
(doors, people, chests, items).
Right click Power attack: your weapon's strongest attack type.
E Use what is under the cursor, or the nearest thing in front of you.
+ A locked door or chest you have no key to: E (X on a controller) has a go at picking
+ the lock if you carry a lockpick - the one in your hand, else your best one.
Space Jump
F / R Ready weapon / ready magic
Tab Inventory