1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-17 02:42:45 +00:00
OpenMW/apps/openmw/mwgui/pickpocketitemmodel.cpp
dteviot 4b0aeb4066 consolidate random number logic
Note, I suspect Rng::rollClosedProbability() is not needed.  The only difference between it and rollProbability() is that one time in 37k (on Windows), it will give an output of 1.0.
On some versions of Linux, the value of 1.0 will occur about 1 time in 4 billion.

(cherry picked from commit 3f28634d1f617691c672e41a3ee950e6daec8c77)

# Conflicts:
#	apps/openmw/mwclass/creature.cpp
#	apps/openmw/mwclass/npc.cpp
#	apps/openmw/mwgui/pickpocketitemmodel.cpp
#	apps/openmw/mwgui/waitdialog.cpp
#	apps/openmw/mwmechanics/combat.cpp
#	apps/openmw/mwmechanics/mechanicsmanagerimp.cpp
#	components/CMakeLists.txt
#	libs/openengine/misc/rng.cpp
2018-10-05 18:45:57 +10:00

68 lines
1.9 KiB
C++

#include "pickpocketitemmodel.hpp"
#include <openengine/misc/rng.hpp>
#include "../mwmechanics/npcstats.hpp"
#include "../mwworld/class.hpp"
namespace MWGui
{
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& thief, ItemModel *sourceModel, bool hideItems)
{
mSourceModel = sourceModel;
int chance = thief.getClass().getSkill(thief, ESM::Skill::Sneak);
mSourceModel->update();
// build list of items that player is unable to find when attempts to pickpocket.
if (hideItems)
{
for (size_t i = 0; i<mSourceModel->getItemCount(); ++i)
{
if (chance <= OEngine::Misc::Rng::roll0to99())
mHiddenItems.push_back(mSourceModel->getItem(i));
}
}
}
ItemStack PickpocketItemModel::getItem (ModelIndex index)
{
if (index < 0)
throw std::runtime_error("Invalid index supplied");
if (mItems.size() <= static_cast<size_t>(index))
throw std::runtime_error("Item index out of range");
return mItems[index];
}
size_t PickpocketItemModel::getItemCount()
{
return mItems.size();
}
void PickpocketItemModel::update()
{
mSourceModel->update();
mItems.clear();
for (size_t i = 0; i<mSourceModel->getItemCount(); ++i)
{
const ItemStack& item = mSourceModel->getItem(i);
// Bound items may not be stolen
if (item.mFlags & ItemStack::Flag_Bound)
continue;
if (std::find(mHiddenItems.begin(), mHiddenItems.end(), item) == mHiddenItems.end()
&& item.mType != ItemStack::Type_Equipped)
mItems.push_back(item);
}
}
void PickpocketItemModel::removeItem (const ItemStack &item, size_t count)
{
ProxyItemModel::removeItem(item, count);
/// \todo check if player is detected
}
}