mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 20:15:35 +00:00
Bound items detection refactoring
This commit is contained in:
parent
a02124f884
commit
99517d83ea
4 changed files with 44 additions and 32 deletions
|
@ -238,6 +238,7 @@ namespace MWBase
|
|||
/// Has the player stolen this item from the given owner?
|
||||
virtual bool isItemStolenFrom(const std::string& itemid, const std::string& ownerid) = 0;
|
||||
|
||||
virtual bool isBoundItem(const MWWorld::Ptr& item) = 0;
|
||||
virtual bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim) = 0;
|
||||
|
||||
/// Turn actor into werewolf or normal form.
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
@ -23,38 +24,7 @@ namespace MWGui
|
|||
if (base.getClass().getEnchantment(base) != "")
|
||||
mFlags |= Flag_Enchanted;
|
||||
|
||||
static std::set<std::string> boundItemIDCache;
|
||||
|
||||
// If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's for some reason
|
||||
if (boundItemIDCache.empty())
|
||||
{
|
||||
// Build a list of known bound item ID's
|
||||
const MWWorld::Store<ESM::GameSetting> &gameSettings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
||||
|
||||
for (MWWorld::Store<ESM::GameSetting>::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration)
|
||||
{
|
||||
const ESM::GameSetting ¤tSetting = *currentIteration;
|
||||
std::string currentGMSTID = currentSetting.mId;
|
||||
Misc::StringUtils::lowerCaseInPlace(currentGMSTID);
|
||||
|
||||
// Don't bother checking this GMST if it's not a sMagicBound* one.
|
||||
const std::string& toFind = "smagicbound";
|
||||
if (currentGMSTID.compare(0, toFind.length(), toFind) != 0)
|
||||
continue;
|
||||
|
||||
// All sMagicBound* GMST's should be of type string
|
||||
std::string currentGMSTValue = currentSetting.getString();
|
||||
Misc::StringUtils::lowerCaseInPlace(currentGMSTValue);
|
||||
|
||||
boundItemIDCache.insert(currentGMSTValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Perform bound item check and assign the Flag_Bound bit if it passes
|
||||
std::string tempItemID = base.getCellRef().getRefId();
|
||||
Misc::StringUtils::lowerCaseInPlace(tempItemID);
|
||||
|
||||
if (boundItemIDCache.count(tempItemID) != 0)
|
||||
if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(base))
|
||||
mFlags |= Flag_Bound;
|
||||
}
|
||||
|
||||
|
|
|
@ -840,6 +840,45 @@ namespace MWMechanics
|
|||
mAI = true;
|
||||
}
|
||||
|
||||
bool MechanicsManager::isBoundItem(const MWWorld::Ptr& item)
|
||||
{
|
||||
static std::set<std::string> boundItemIDCache;
|
||||
|
||||
// If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's for some reason
|
||||
if (boundItemIDCache.empty())
|
||||
{
|
||||
// Build a list of known bound item ID's
|
||||
const MWWorld::Store<ESM::GameSetting> &gameSettings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
||||
|
||||
for (MWWorld::Store<ESM::GameSetting>::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration)
|
||||
{
|
||||
const ESM::GameSetting ¤tSetting = *currentIteration;
|
||||
std::string currentGMSTID = currentSetting.mId;
|
||||
Misc::StringUtils::lowerCaseInPlace(currentGMSTID);
|
||||
|
||||
// Don't bother checking this GMST if it's not a sMagicBound* one.
|
||||
const std::string& toFind = "smagicbound";
|
||||
if (currentGMSTID.compare(0, toFind.length(), toFind) != 0)
|
||||
continue;
|
||||
|
||||
// All sMagicBound* GMST's should be of type string
|
||||
std::string currentGMSTValue = currentSetting.getString();
|
||||
Misc::StringUtils::lowerCaseInPlace(currentGMSTValue);
|
||||
|
||||
boundItemIDCache.insert(currentGMSTValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Perform bound item check and assign the Flag_Bound bit if it passes
|
||||
std::string tempItemID = item.getCellRef().getRefId();
|
||||
Misc::StringUtils::lowerCaseInPlace(tempItemID);
|
||||
|
||||
if (boundItemIDCache.count(tempItemID) != 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MechanicsManager::isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim)
|
||||
{
|
||||
if (target.isEmpty())
|
||||
|
|
|
@ -204,6 +204,8 @@ namespace MWMechanics
|
|||
/// Has the player stolen this item from the given owner?
|
||||
virtual bool isItemStolenFrom(const std::string& itemid, const std::string& ownerid);
|
||||
|
||||
virtual bool isBoundItem(const MWWorld::Ptr& item);
|
||||
|
||||
/// @return is \a ptr allowed to take/use \a target or is it a crime?
|
||||
virtual bool isAllowedToUse (const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim);
|
||||
|
||||
|
|
Loading…
Reference in a new issue