diff --git a/CHANGELOG.md b/CHANGELOG.md index b307e630d..9d9104199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,7 @@ Bug #5134: Doors rotation by "Lock" console command is inconsistent Bug #5137: Textures with Clamp Mode set to Clamp instead of Wrap are too dark outside the boundaries Bug #5149: Failing lock pick attempts isn't always a crime + Bug #5155: Lock/unlock behavior differs from vanilla Bug #5158: Objects without a name don't fallback to their ID Bug #5159: NiMaterialColorController can only control the diffuse color Bug #5161: Creature companions can't be activated when they are knocked down diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 243b6ce11..369077d6c 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -181,7 +181,7 @@ namespace MWClass { MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}"); if(isLocked) - unlock(ptr); + ptr.getCellRef().unlock(); // using a key disarms the trap if(isTrapped) { @@ -300,23 +300,10 @@ namespace MWClass return getContainerStore (ptr).getWeight(); } - void Container::lock (const MWWorld::Ptr& ptr, int lockLevel) const - { - if(lockLevel != 0) - ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, if positive - else - ptr.getCellRef().setLockLevel(ESM::UnbreakableLock); // If zero, set to max lock level - } - - void Container::unlock (const MWWorld::Ptr& ptr) const - { - int lockLevel = ptr.getCellRef().getLockLevel(); - ptr.getCellRef().setLockLevel(-abs(lockLevel)); //Makes lockLevel negative - } - bool Container::canLock(const MWWorld::ConstPtr &ptr) const { - return true; + const MWWorld::LiveCellRef *ref = ptr.get(); + return !(ref->mBase->mFlags & ESM::Container::Organic); } MWWorld::Ptr Container::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 87826da88..b84c5787b 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -46,12 +46,6 @@ namespace MWClass ///< Returns total weight of objects inside this object (including modifications from magic /// effects). Throws an exception, if the object can't hold other objects. - virtual void lock (const MWWorld::Ptr& ptr, int lockLevel = 0) const; - ///< Lock object - - virtual void unlock (const MWWorld::Ptr& ptr) const; - ///< Unlock object - virtual bool canLock(const MWWorld::ConstPtr &ptr) const; virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 3a0e13e62..f2d79a0a3 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -163,7 +163,7 @@ namespace MWClass if(actor == MWMechanics::getPlayer()) MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}"); if(isLocked) - unlock(ptr); //Call the function here. because that makes sense. + ptr.getCellRef().unlock(); //Call the function here. because that makes sense. // using a key disarms the trap if(isTrapped) { @@ -241,20 +241,6 @@ namespace MWClass } } - void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const - { - if(lockLevel != 0) - ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, if positive - else - ptr.getCellRef().setLockLevel(ESM::UnbreakableLock); // If zero, set to max lock level - } - - void Door::unlock (const MWWorld::Ptr& ptr) const - { - int lockLevel = ptr.getCellRef().getLockLevel(); - ptr.getCellRef().setLockLevel(-abs(lockLevel)); //Makes lockLevel negative - } - bool Door::canLock(const MWWorld::ConstPtr &ptr) const { return true; diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index fa566b98e..84761900c 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -37,12 +37,6 @@ namespace MWClass static std::string getDestination (const MWWorld::LiveCellRef& door); ///< @return destination cell name or token - virtual void lock (const MWWorld::Ptr& ptr, int lockLevel = 0) const; - ///< Lock object - - virtual void unlock (const MWWorld::Ptr& ptr) const; - ///< Unlock object - virtual bool canLock(const MWWorld::ConstPtr &ptr) const; virtual bool allowTelekinesis(const MWWorld::ConstPtr &ptr) const; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index de1780ce7..137775481 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1154,7 +1154,7 @@ namespace MWMechanics store.remove(*it, toMove, player); } // TODO: unhardcode the locklevel - targetContainer.getClass().lock(targetContainer,50); + targetContainer.getCellRef().lock(50); } void MechanicsManager::itemTaken(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item, const MWWorld::Ptr& container, diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index d09355cca..cafc65b99 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -30,7 +30,7 @@ namespace MWMechanics { if (lock.getCellRef().getLockLevel() <= 0 || lock.getCellRef().getLockLevel() == ESM::UnbreakableLock || - !lock.getClass().canLock(lock)) //If it's unlocked or can not be unlocked back out immediately + !lock.getClass().hasToolTip(lock)) //If it's unlocked or can not be unlocked back out immediately return; int lockStrength = lock.getCellRef().getLockLevel(); @@ -50,7 +50,7 @@ namespace MWMechanics { if (Misc::Rng::roll0to99() <= x) { - lock.getClass().unlock(lock); + lock.getCellRef().unlock(); resultMessage = "#{sLockSuccess}"; resultSound = "Open Lock"; mActor.getClass().skillUsageSucceeded(mActor, ESM::Skill::Security, 1); diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 359e74fc6..2d979e034 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -696,7 +696,7 @@ namespace MWMechanics { if (caster == getPlayer()) MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}"); - target.getClass().lock(target, static_cast(magnitude)); + target.getCellRef().lock(static_cast(magnitude)); } return true; } @@ -716,7 +716,7 @@ namespace MWMechanics if (caster == getPlayer()) MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicOpenSuccess}"); } - target.getClass().unlock(target); + target.getCellRef().unlock(); } else MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock Fail", 1.f, 1.f); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 29a25c997..e2506edb8 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -182,7 +182,7 @@ namespace MWScript runtime.pop(); } - ptr.getClass().lock (ptr, lockLevel); + ptr.getCellRef().lock (lockLevel); // Instantly reset door to closed state // This is done when using Lock in scripts, but not when using Lock spells. @@ -202,7 +202,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - ptr.getClass().unlock (ptr); + ptr.getCellRef().unlock (); } }; diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index 094669bdd..fb9fd592a 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -225,6 +225,19 @@ namespace MWWorld } } + void CellRef::lock(int lockLevel) + { + if(lockLevel != 0) + setLockLevel(abs(lockLevel)); //Changes lock to locklevel, if positive + else + setLockLevel(ESM::UnbreakableLock); // If zero, set to max lock level + } + + void CellRef::unlock() + { + setLockLevel(-abs(mCellRef.mLockLevel)); //Makes lockLevel negative + } + std::string CellRef::getKey() const { return mCellRef.mKey; diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index 5646bafb0..04e807ce5 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -99,6 +99,8 @@ namespace MWWorld // For an unlocked door, it is set to -(previous locklevel) int getLockLevel() const; void setLockLevel(int lockLevel); + void lock(int lockLevel); + void unlock(); // Key and trap ID names, if any std::string getKey() const; std::string getTrap() const; diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 637a8d3da..0287db56f 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -139,16 +139,6 @@ namespace MWWorld return false; } - void Class::lock (const Ptr& ptr, int lockLevel) const - { - throw std::runtime_error ("class does not support locking"); - } - - void Class::unlock (const Ptr& ptr) const - { - throw std::runtime_error ("class does not support unlocking"); - } - bool Class::canLock(const ConstPtr &ptr) const { return false; diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 1e3eefe33..8c3740edd 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -158,12 +158,6 @@ namespace MWWorld virtual bool hasInventoryStore (const Ptr& ptr) const; ///< Does this object have an inventory store, i.e. equipment slots? (default implementation: false) - virtual void lock (const Ptr& ptr, int lockLevel) const; - ///< Lock object (default implementation: throw an exception) - - virtual void unlock (const Ptr& ptr) const; - ///< Unlock object (default implementation: throw an exception) - virtual bool canLock (const ConstPtr& ptr) const; virtual void setRemainingUsageTime (const Ptr& ptr, float duration) const;