fixes based on comments by ptmikheev

revert-6246b479
Mads Buvik Sandvei 1 year ago
parent e22eec0585
commit b8a9fcad68

@ -53,15 +53,6 @@ namespace MWGui
return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, allowAutoEquip); return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, allowAutoEquip);
} }
MWWorld::Ptr InventoryItemModel::unstackItem(const ItemStack& item, size_t count)
{
MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor);
auto it = store.unstack(item.mBase, count);
if (it != store.end())
return *it;
return MWWorld::Ptr();
}
void InventoryItemModel::removeItem(const ItemStack& item, size_t count) void InventoryItemModel::removeItem(const ItemStack& item, size_t count)
{ {
int removed = 0; int removed = 0;

@ -18,7 +18,6 @@ namespace MWGui
bool onTakeItem(const MWWorld::Ptr& item, int count) override; bool onTakeItem(const MWWorld::Ptr& item, int count) override;
MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override;
MWWorld::Ptr unstackItem(const ItemStack& item, size_t count) override;
void removeItem(const ItemStack& item, size_t count) override; void removeItem(const ItemStack& item, size_t count) override;
/// Move items from this model to \a otherModel. /// Move items from this model to \a otherModel.

@ -67,16 +67,11 @@ namespace MWGui
ret.getCellRef().unsetRefNum(); ret.getCellRef().unsetRefNum();
ret.getRefData().setLuaScripts(nullptr); ret.getRefData().setLuaScripts(nullptr);
MWBase::Environment::get().getWorldModel()->registerPtr(ret); MWBase::Environment::get().getWorldModel()->registerPtr(ret);
MWBase::Environment::get().getWorldModel()->registerPtr(item.mBase);
} }
return ret; return ret;
} }
MWWorld::Ptr ItemModel::unstackItem(const ItemStack& item, size_t count)
{
// By default does nothing
return MWWorld::Ptr();
}
bool ItemModel::allowedToUseItems() const bool ItemModel::allowedToUseItems() const
{ {
return true; return true;
@ -151,11 +146,6 @@ namespace MWGui
return mSourceModel->onTakeItem(item, count); return mSourceModel->onTakeItem(item, count);
} }
MWWorld::Ptr ProxyItemModel::unstackItem(const ItemStack& item, size_t count)
{
return mSourceModel->unstackItem(item, count);
}
MWWorld::Ptr ProxyItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip) MWWorld::Ptr ProxyItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip)
{ {
return mSourceModel->addItem(item, count, allowAutoEquip); return mSourceModel->addItem(item, count, allowAutoEquip);

@ -66,10 +66,6 @@ namespace MWGui
virtual MWWorld::Ptr moveItem( virtual MWWorld::Ptr moveItem(
const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip = true); const ItemStack& item, size_t count, ItemModel* otherModel, bool allowAutoEquip = true);
/// Unstacks items from this model and returns a ptr to the new remainder stack.
/// @note Returns en empty ptr if there is no remainder or the item model does not support unstacking.
virtual MWWorld::Ptr unstackItem(const ItemStack& item, size_t count);
virtual MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) = 0; virtual MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) = 0;
virtual void removeItem(const ItemStack& item, size_t count) = 0; virtual void removeItem(const ItemStack& item, size_t count) = 0;
@ -100,7 +96,6 @@ namespace MWGui
bool onDropItem(const MWWorld::Ptr& item, int count) override; bool onDropItem(const MWWorld::Ptr& item, int count) override;
bool onTakeItem(const MWWorld::Ptr& item, int count) override; bool onTakeItem(const MWWorld::Ptr& item, int count) override;
MWWorld::Ptr unstackItem(const ItemStack& item, size_t count) override;
MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override; MWWorld::Ptr addItem(const ItemStack& item, size_t count, bool allowAutoEquip = true) override;
void removeItem(const ItemStack& item, size_t count) override; void removeItem(const ItemStack& item, size_t count) override;
ModelIndex getIndex(const ItemStack& item) override; ModelIndex getIndex(const ItemStack& item) override;

@ -391,10 +391,20 @@ namespace MWWorld
return newPtr; return newPtr;
} }
Ptr Class::moveToCell(const Ptr& ptr, CellStore& cell, const ESM::Position& pos, int count) const
{
Ptr newPtr = moveToCell(ptr, cell);
newPtr.getRefData().setPosition(pos);
newPtr.getCellRef().setPosition(pos);
newPtr.getRefData().setCount(count);
return newPtr;
}
MWWorld::Ptr Class::copyToCell(const ConstPtr& ptr, CellStore& cell, const ESM::Position& pos, int count) const MWWorld::Ptr Class::copyToCell(const ConstPtr& ptr, CellStore& cell, const ESM::Position& pos, int count) const
{ {
Ptr newPtr = copyToCell(ptr, cell, count); Ptr newPtr = copyToCell(ptr, cell, count);
newPtr.getRefData().setPosition(pos); newPtr.getRefData().setPosition(pos);
newPtr.getCellRef().setPosition(pos);
return newPtr; return newPtr;
} }

@ -317,6 +317,7 @@ namespace MWWorld
// The original is expected to be removed after calling this function, // The original is expected to be removed after calling this function,
// but this function itself doesn't remove the original. // but this function itself doesn't remove the original.
virtual Ptr moveToCell(const Ptr& ptr, CellStore& cell) const; virtual Ptr moveToCell(const Ptr& ptr, CellStore& cell) const;
Ptr moveToCell(const Ptr& ptr, CellStore& cell, const ESM::Position& pos, int count) const;
Ptr copyToCell(const ConstPtr& ptr, CellStore& cell, const ESM::Position& pos, int count) const; Ptr copyToCell(const ConstPtr& ptr, CellStore& cell, const ESM::Position& pos, int count) const;

@ -2063,7 +2063,7 @@ namespace MWWorld
MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count); MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count);
addObjectToCell(dropped, cell, pos, adjustPos); initObjectInCell(dropped, *cell, adjustPos);
return dropped; return dropped;
} }
@ -2079,30 +2079,16 @@ namespace MWWorld
cell = &mWorldModel.getExterior(index); cell = &mWorldModel.getExterior(index);
} }
MWWorld::Ptr dropped = object.getClass().moveToCell(object, *cell); MWWorld::Ptr dropped = object.getClass().moveToCell(object, *cell, pos, count);
dropped.getRefData().setCount(count);
dropped.getRefData().setPosition(pos);
addObjectToCell(dropped, cell, pos, adjustPos); initObjectInCell(dropped, *cell, adjustPos);
return dropped; return dropped;
} }
void World::addObjectToCell(const Ptr& object, CellStore* cell, ESM::Position pos, bool adjustPos) void World::initObjectInCell(const Ptr& object, CellStore& cell, bool adjustPos)
{ {
if (!cell) if (mWorldScene->isCellActive(cell))
throw std::runtime_error("addObjectToCell(): cannot add object to null cell");
if (cell->isExterior())
{
const ESM::ExteriorCellLocation index
= ESM::positionToExteriorCellLocation(pos.pos[0], pos.pos[1], cell->getCell()->getWorldSpace());
cell = &mWorldModel.getExterior(index);
}
// Reset some position values that could be uninitialized if this item came from a container
object.getCellRef().setPosition(pos);
if (mWorldScene->isCellActive(*cell))
{ {
if (object.getRefData().isEnabled()) if (object.getRefData().isEnabled())
{ {
@ -2113,7 +2099,7 @@ namespace MWWorld
{ {
mLocalScripts.add(script, object); mLocalScripts.add(script, object);
} }
addContainerScripts(object, cell); addContainerScripts(object, &cell);
} }
if (!object.getClass().isActor() && adjustPos && object.getRefData().getBaseNode()) if (!object.getClass().isActor() && adjustPos && object.getRefData().getBaseNode())
@ -2125,6 +2111,7 @@ namespace MWWorld
osg::BoundingBox bounds = computeBounds.getBoundingBox(); osg::BoundingBox bounds = computeBounds.getBoundingBox();
if (bounds.valid()) if (bounds.valid())
{ {
ESM::Position pos = object.getRefData().getPosition();
bounds.set(bounds._min - pos.asVec3(), bounds._max - pos.asVec3()); bounds.set(bounds._min - pos.asVec3(), bounds._max - pos.asVec3());
osg::Vec3f adjust( osg::Vec3f adjust(

@ -143,7 +143,7 @@ namespace MWWorld
void updateWeather(float duration, bool paused = false); void updateWeather(float duration, bool paused = false);
void addObjectToCell(const Ptr& ptr, CellStore* cell, ESM::Position pos, bool adjustPos); void initObjectInCell(const Ptr& ptr, CellStore& cell, bool adjustPos);
Ptr moveObjectToCell(const Ptr& ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos); Ptr moveObjectToCell(const Ptr& ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos);
Ptr copyObjectToCell(const ConstPtr& ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos); Ptr copyObjectToCell(const ConstPtr& ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos);

Loading…
Cancel
Save