Implement unlockable locks with 'lock 0' console command

pull/456/head
Andrei Kortunov 7 years ago
parent a8ad530db9
commit 5fd3ec1035

@ -34,6 +34,7 @@
Bug #4419: MRK NiStringExtraData is handled incorrectly Bug #4419: MRK NiStringExtraData is handled incorrectly
Bug #4426: RotateWorld behavior is incorrect Bug #4426: RotateWorld behavior is incorrect
Bug #4429: [Windows] Error on build INSTALL.vcxproj project (debug) with cmake 3.7.2 Bug #4429: [Windows] Error on build INSTALL.vcxproj project (debug) with cmake 3.7.2
Bug #4431: "Lock 0" console command is a no-op
Bug #4432: Guards behaviour is incorrect if they do not have AI packages Bug #4432: Guards behaviour is incorrect if they do not have AI packages
Bug #4433: Guard behaviour is incorrect with Alarm = 0 Bug #4433: Guard behaviour is incorrect with Alarm = 0
Bug #4451: Script fails to compile when using "Begin, [ScriptName]" syntax Bug #4451: Script fails to compile when using "Begin, [ScriptName]" syntax

@ -239,7 +239,8 @@ namespace MWClass
info.caption = ref->mBase->mName; info.caption = ref->mBase->mName;
std::string text; std::string text;
if (ptr.getCellRef().getLockLevel() > 0) int lockLevel = ptr.getCellRef().getLockLevel();
if (lockLevel > 0 && lockLevel != ESM::UnbreakableLock)
text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel()); text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel());
else if (ptr.getCellRef().getLockLevel() < 0) else if (ptr.getCellRef().getLockLevel() < 0)
text += "\n#{sUnlocked}"; text += "\n#{sUnlocked}";
@ -271,15 +272,16 @@ namespace MWClass
void Container::lock (const MWWorld::Ptr& ptr, int lockLevel) const void Container::lock (const MWWorld::Ptr& ptr, int lockLevel) const
{ {
if(lockLevel!=0) if(lockLevel != 0)
ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, in positive ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, if positive
else else
ptr.getCellRef().setLockLevel(abs(ptr.getCellRef().getLockLevel())); //No locklevel given, just flip the original one ptr.getCellRef().setLockLevel(ESM::UnbreakableLock); // If zero, set to max lock level
} }
void Container::unlock (const MWWorld::Ptr& ptr) const void Container::unlock (const MWWorld::Ptr& ptr) const
{ {
ptr.getCellRef().setLockLevel(-abs(ptr.getCellRef().getLockLevel())); //Makes lockLevel negative int lockLevel = ptr.getCellRef().getLockLevel();
ptr.getCellRef().setLockLevel(-abs(lockLevel)); //Makes lockLevel negative
} }
bool Container::canLock(const MWWorld::ConstPtr &ptr) const bool Container::canLock(const MWWorld::ConstPtr &ptr) const

@ -193,7 +193,7 @@ namespace MWClass
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport (ptr.getCellRef().getDestCell(), ptr.getCellRef().getDoorDest(), true)); std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport (ptr.getCellRef().getDestCell(), ptr.getCellRef().getDoorDest(), true));
action->setSound(openSound); action->setSound(openSound);
return action; return action;
} }
} }
else else
{ {
@ -240,15 +240,16 @@ namespace MWClass
void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const
{ {
if(lockLevel!=0) if(lockLevel != 0)
ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, in positive ptr.getCellRef().setLockLevel(abs(lockLevel)); //Changes lock to locklevel, if positive
else else
ptr.getCellRef().setLockLevel(abs(ptr.getCellRef().getLockLevel())); //No locklevel given, just flip the original one ptr.getCellRef().setLockLevel(ESM::UnbreakableLock); // If zero, set to max lock level
} }
void Door::unlock (const MWWorld::Ptr& ptr) const void Door::unlock (const MWWorld::Ptr& ptr) const
{ {
ptr.getCellRef().setLockLevel(-abs(ptr.getCellRef().getLockLevel())); //Makes lockLevel negative int lockLevel = ptr.getCellRef().getLockLevel();
ptr.getCellRef().setLockLevel(-abs(lockLevel)); //Makes lockLevel negative
} }
bool Door::canLock(const MWWorld::ConstPtr &ptr) const bool Door::canLock(const MWWorld::ConstPtr &ptr) const
@ -300,7 +301,8 @@ namespace MWClass
text += "\n" + getDestination(*ref); text += "\n" + getDestination(*ref);
} }
if (ptr.getCellRef().getLockLevel() > 0) int lockLevel = ptr.getCellRef().getLockLevel();
if (lockLevel > 0 && lockLevel != ESM::UnbreakableLock)
text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel()); text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel());
else if (ptr.getCellRef().getLockLevel() < 0) else if (ptr.getCellRef().getLockLevel() < 0)
text += "\n#{sUnlocked}"; text += "\n#{sUnlocked}";

@ -884,8 +884,13 @@ namespace MWMechanics
const MWWorld::CellRef& cellref = target.getCellRef(); const MWWorld::CellRef& cellref = target.getCellRef();
// there is no harm to use unlocked doors // there is no harm to use unlocked doors
if (target.getClass().isDoor() && cellref.getLockLevel() <= 0 && ptr.getCellRef().getTrap().empty()) int lockLevel = cellref.getLockLevel();
if (target.getClass().isDoor() &&
(lockLevel <= 0 || lockLevel == ESM::UnbreakableLock) &&
ptr.getCellRef().getTrap().empty())
{
return true; return true;
}
// TODO: implement a better check to check if target is owned bed // TODO: implement a better check to check if target is owned bed
if (target.getClass().isActivator() && target.getClass().getScript(target).compare(0, 3, "Bed") != 0) if (target.getClass().isActivator() && target.getClass().getScript(target).compare(0, 3, "Bed") != 0)

@ -31,7 +31,9 @@ namespace MWMechanics
void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick, void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick,
std::string& resultMessage, std::string& resultSound) std::string& resultMessage, std::string& resultSound)
{ {
if (!(lock.getCellRef().getLockLevel() > 0) || !lock.getClass().canLock(lock)) //If it's unlocked back out immediately 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
return; return;
int lockStrength = lock.getCellRef().getLockLevel(); int lockStrength = lock.getCellRef().getLockLevel();

@ -126,6 +126,9 @@ void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted)
break; break;
} }
} }
if (mLockLevel == 0 && !mKey.empty())
mLockLevel = UnbreakableLock;
} }
void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool isDeleted) const void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool isDeleted) const

@ -1,6 +1,7 @@
#ifndef OPENMW_ESM_CELLREF_H #ifndef OPENMW_ESM_CELLREF_H
#define OPENMW_ESM_CELLREF_H #define OPENMW_ESM_CELLREF_H
#include <limits>
#include <string> #include <string>
#include "defs.hpp" #include "defs.hpp"
@ -10,6 +11,7 @@ namespace ESM
class ESMWriter; class ESMWriter;
class ESMReader; class ESMReader;
const int UnbreakableLock = std::numeric_limits<int>::max();
struct RefNum struct RefNum
{ {

Loading…
Cancel
Save