mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 07:06:45 +00:00
Merge branch 'locked_and_loaded' into 'master'
Change the legalities of opening unlocked objects Closes #6493 See merge request OpenMW/openmw!1479
This commit is contained in:
commit
92c9ae3eb7
2 changed files with 41 additions and 30 deletions
|
@ -89,6 +89,7 @@
|
||||||
Bug #6433: Items bound to Quick Keys sometimes do not appear until the Quick Key menu is opened
|
Bug #6433: Items bound to Quick Keys sometimes do not appear until the Quick Key menu is opened
|
||||||
Bug #6451: Weapon summoned from Cast When Used item will have the name "None"
|
Bug #6451: Weapon summoned from Cast When Used item will have the name "None"
|
||||||
Bug #6473: Strings from NIF should be parsed only to first null terminator
|
Bug #6473: Strings from NIF should be parsed only to first null terminator
|
||||||
|
Bug #6493: Unlocking owned but not locked or unlocked containers is considered a crime
|
||||||
Feature #890: OpenMW-CS: Column filtering
|
Feature #890: OpenMW-CS: Column filtering
|
||||||
Feature #1465: "Reset" argument for AI functions
|
Feature #1465: "Reset" argument for AI functions
|
||||||
Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record
|
Feature #2554: Modifying an object triggers the instances table to scroll to the corresponding record
|
||||||
|
|
|
@ -66,6 +66,35 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isOwned(const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim)
|
||||||
|
{
|
||||||
|
const MWWorld::CellRef& cellref = target.getCellRef();
|
||||||
|
|
||||||
|
const std::string& owner = cellref.getOwner();
|
||||||
|
bool isOwned = !owner.empty() && owner != "player";
|
||||||
|
|
||||||
|
const std::string& faction = cellref.getFaction();
|
||||||
|
bool isFactionOwned = false;
|
||||||
|
if (!faction.empty() && ptr.getClass().isNpc())
|
||||||
|
{
|
||||||
|
const std::map<std::string, int>& factions = ptr.getClass().getNpcStats(ptr).getFactionRanks();
|
||||||
|
auto found = factions.find(Misc::StringUtils::lowerCase(faction));
|
||||||
|
if (found == factions.end() || found->second < cellref.getFactionRank())
|
||||||
|
isFactionOwned = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& globalVariable = cellref.getGlobalVariable();
|
||||||
|
if (!globalVariable.empty() && MWBase::Environment::get().getWorld()->getGlobalInt(globalVariable))
|
||||||
|
{
|
||||||
|
isOwned = false;
|
||||||
|
isFactionOwned = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cellref.getOwner().empty())
|
||||||
|
victim = MWBase::Environment::get().getWorld()->searchPtr(cellref.getOwner(), true, false);
|
||||||
|
|
||||||
|
return isOwned || isFactionOwned;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
|
@ -881,35 +910,11 @@ namespace MWMechanics
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& owner = cellref.getOwner();
|
if (isOwned(ptr, target, victim))
|
||||||
bool isOwned = !owner.empty() && owner != "player";
|
|
||||||
|
|
||||||
const std::string& faction = cellref.getFaction();
|
|
||||||
bool isFactionOwned = false;
|
|
||||||
if (!faction.empty() && ptr.getClass().isNpc())
|
|
||||||
{
|
|
||||||
const std::map<std::string, int>& factions = ptr.getClass().getNpcStats(ptr).getFactionRanks();
|
|
||||||
std::map<std::string, int>::const_iterator found = factions.find(Misc::StringUtils::lowerCase(faction));
|
|
||||||
if (found == factions.end()
|
|
||||||
|| found->second < cellref.getFactionRank())
|
|
||||||
isFactionOwned = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& globalVariable = cellref.getGlobalVariable();
|
|
||||||
if (!globalVariable.empty() && MWBase::Environment::get().getWorld()->getGlobalInt(Misc::StringUtils::lowerCase(globalVariable)) == 1)
|
|
||||||
{
|
|
||||||
isOwned = false;
|
|
||||||
isFactionOwned = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cellref.getOwner().empty())
|
|
||||||
victim = MWBase::Environment::get().getWorld()->searchPtr(cellref.getOwner(), true, false);
|
|
||||||
|
|
||||||
// A special case for evidence chest - we should not allow to take items even if it is technically permitted
|
|
||||||
if (Misc::StringUtils::ciEqual(cellref.getRefId(), "stolen_goods"))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (!isOwned && !isFactionOwned);
|
// A special case for evidence chest - we should not allow to take items even if it is technically permitted
|
||||||
|
return !Misc::StringUtils::ciEqual(cellref.getRefId(), "stolen_goods");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MechanicsManager::sleepInBed(const MWWorld::Ptr &ptr, const MWWorld::Ptr &bed)
|
bool MechanicsManager::sleepInBed(const MWWorld::Ptr &ptr, const MWWorld::Ptr &bed)
|
||||||
|
@ -941,10 +946,15 @@ namespace MWMechanics
|
||||||
void MechanicsManager::unlockAttempted(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item)
|
void MechanicsManager::unlockAttempted(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr victim;
|
MWWorld::Ptr victim;
|
||||||
if (isAllowedToUse(ptr, item, victim))
|
if (isOwned(ptr, item, victim))
|
||||||
return;
|
{
|
||||||
|
// Note that attempting to unlock something that has ever been locked (even ESM::UnbreakableLock) is a crime even if it's already unlocked.
|
||||||
|
// Likewise, it's illegal to unlock something that has a trap but isn't otherwise locked.
|
||||||
|
const auto& cellref = item.getCellRef();
|
||||||
|
if(cellref.getLockLevel() || !cellref.getTrap().empty())
|
||||||
commitCrime(ptr, victim, OT_Trespassing, item.getCellRef().getFaction());
|
commitCrime(ptr, victim, OT_Trespassing, item.getCellRef().getFaction());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<std::string, int> > MechanicsManager::getStolenItemOwners(const std::string& itemid)
|
std::vector<std::pair<std::string, int> > MechanicsManager::getStolenItemOwners(const std::string& itemid)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue