forked from teamnwah/openmw-tes3coop
Throw an exception when trying to get an empty Ptr's type
This commit is contained in:
parent
0f2b2ff1ce
commit
2853b56ed5
3 changed files with 29 additions and 32 deletions
|
@ -146,27 +146,30 @@ namespace MWGui
|
|||
for (size_t i=0; i<mSourceModel->getItemCount(); ++i)
|
||||
{
|
||||
ItemStack item = mSourceModel->getItem(i);
|
||||
MWWorld::Ptr base = item.mBase;
|
||||
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())
|
||||
if(!mMerchant.isEmpty())
|
||||
{
|
||||
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)
|
||||
MWWorld::Ptr base = item.mBase;
|
||||
if(Misc::StringUtils::ciEqual(base.getCellRef().mRefID, "gold_001"))
|
||||
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
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "containerstore.hpp"
|
||||
|
||||
const std::string MWWorld::Ptr::sEmptyString;
|
||||
|
||||
ESM::CellRef& MWWorld::Ptr::getCellRef() const
|
||||
{
|
||||
|
|
|
@ -12,8 +12,6 @@ namespace MWWorld
|
|||
|
||||
class Ptr
|
||||
{
|
||||
static const std::string sEmptyString;
|
||||
|
||||
public:
|
||||
|
||||
typedef MWWorld::CellStore CellStore;
|
||||
|
@ -24,8 +22,10 @@ namespace MWWorld
|
|||
ContainerStore *mContainerStore;
|
||||
|
||||
public:
|
||||
|
||||
Ptr() : mRef(0), mCell(0), mContainerStore(0) { }
|
||||
Ptr(MWWorld::LiveCellRefBase *liveCellRef=0, CellStore *cell=0)
|
||||
: mRef(liveCellRef), mCell(cell), mContainerStore(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
|
@ -34,14 +34,9 @@ namespace MWWorld
|
|||
|
||||
const std::string& getTypeName() const
|
||||
{
|
||||
return mRef ? mRef->mTypeName : sEmptyString;
|
||||
}
|
||||
|
||||
Ptr (MWWorld::LiveCellRefBase *liveCellRef, CellStore *cell)
|
||||
: mContainerStore (0)
|
||||
{
|
||||
mRef = liveCellRef;
|
||||
mCell = cell;
|
||||
if(mRef != 0)
|
||||
return mRef->mTypeName;
|
||||
throw std::runtime_error("Can't get type name from an empty object.");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Reference in a new issue