mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-27 15:11:36 -04:00
Throw an exception when trying to get an empty Ptr's type
This commit is contained in:
parent
0f2b2ff1ce
commit
2853b56ed5
@ -146,27 +146,30 @@ namespace MWGui
|
|||||||
for (size_t i=0; i<mSourceModel->getItemCount(); ++i)
|
for (size_t i=0; i<mSourceModel->getItemCount(); ++i)
|
||||||
{
|
{
|
||||||
ItemStack item = mSourceModel->getItem(i);
|
ItemStack item = mSourceModel->getItem(i);
|
||||||
MWWorld::Ptr base = item.mBase;
|
if(!mMerchant.isEmpty())
|
||||||
if (!mMerchant.isEmpty() && Misc::StringUtils::ciEqual(base.getCellRef().mRefID, "gold_001"))
|
|
||||||
continue;
|
|
||||||
if (!mMerchant.isEmpty() && !MWWorld::Class::get(base).canSell(base, services))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// don't show equipped items
|
|
||||||
if (mMerchant.getTypeName() == typeid(ESM::NPC).name())
|
|
||||||
{
|
{
|
||||||
bool isEquipped = false;
|
MWWorld::Ptr base = item.mBase;
|
||||||
MWWorld::InventoryStore& store = MWWorld::Class::get(mMerchant).getInventoryStore(mMerchant);
|
if(Misc::StringUtils::ciEqual(base.getCellRef().mRefID, "gold_001"))
|
||||||
for (int slot=0; slot<MWWorld::InventoryStore::Slots; ++slot)
|
|
||||||
{
|
|
||||||
MWWorld::ContainerStoreIterator equipped = store.getSlot(slot);
|
|
||||||
if (equipped == store.end())
|
|
||||||
continue;
|
|
||||||
if (*equipped == base)
|
|
||||||
isEquipped = true;
|
|
||||||
}
|
|
||||||
if (isEquipped)
|
|
||||||
continue;
|
continue;
|
||||||
|
if(!MWWorld::Class::get(base).canSell(base, services))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// don't show equipped items
|
||||||
|
if(mMerchant.getTypeName() == typeid(ESM::NPC).name())
|
||||||
|
{
|
||||||
|
bool isEquipped = false;
|
||||||
|
MWWorld::InventoryStore& store = MWWorld::Class::get(mMerchant).getInventoryStore(mMerchant);
|
||||||
|
for (int slot=0; slot<MWWorld::InventoryStore::Slots; ++slot)
|
||||||
|
{
|
||||||
|
MWWorld::ContainerStoreIterator equipped = store.getSlot(slot);
|
||||||
|
if (equipped == store.end())
|
||||||
|
continue;
|
||||||
|
if (*equipped == base)
|
||||||
|
isEquipped = true;
|
||||||
|
}
|
||||||
|
if (isEquipped)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't show items that we borrowed to someone else
|
// don't show items that we borrowed to someone else
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "containerstore.hpp"
|
#include "containerstore.hpp"
|
||||||
|
|
||||||
const std::string MWWorld::Ptr::sEmptyString;
|
|
||||||
|
|
||||||
ESM::CellRef& MWWorld::Ptr::getCellRef() const
|
ESM::CellRef& MWWorld::Ptr::getCellRef() const
|
||||||
{
|
{
|
||||||
|
@ -12,8 +12,6 @@ namespace MWWorld
|
|||||||
|
|
||||||
class Ptr
|
class Ptr
|
||||||
{
|
{
|
||||||
static const std::string sEmptyString;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef MWWorld::CellStore CellStore;
|
typedef MWWorld::CellStore CellStore;
|
||||||
@ -24,8 +22,10 @@ namespace MWWorld
|
|||||||
ContainerStore *mContainerStore;
|
ContainerStore *mContainerStore;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Ptr(MWWorld::LiveCellRefBase *liveCellRef=0, CellStore *cell=0)
|
||||||
Ptr() : mRef(0), mCell(0), mContainerStore(0) { }
|
: mRef(liveCellRef), mCell(cell), mContainerStore(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool isEmpty() const
|
bool isEmpty() const
|
||||||
{
|
{
|
||||||
@ -34,14 +34,9 @@ namespace MWWorld
|
|||||||
|
|
||||||
const std::string& getTypeName() const
|
const std::string& getTypeName() const
|
||||||
{
|
{
|
||||||
return mRef ? mRef->mTypeName : sEmptyString;
|
if(mRef != 0)
|
||||||
}
|
return mRef->mTypeName;
|
||||||
|
throw std::runtime_error("Can't get type name from an empty object.");
|
||||||
Ptr (MWWorld::LiveCellRefBase *liveCellRef, CellStore *cell)
|
|
||||||
: mContainerStore (0)
|
|
||||||
{
|
|
||||||
mRef = liveCellRef;
|
|
||||||
mCell = cell;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user