forked from mirror/openmw-tes3mp
Call ContainerStore::remove() to remove items from inventory
Make placeObject() and dropObjectOnGround() in MWWorld to copy objects (and indicate it clearly). Enchanting an item now unequips it.
This commit is contained in:
parent
23b8206bdc
commit
10abb9d297
17 changed files with 101 additions and 163 deletions
|
@ -309,14 +309,19 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void update (float duration, bool paused) = 0;
|
virtual void update (float duration, bool paused) = 0;
|
||||||
|
|
||||||
virtual bool placeObject(const MWWorld::Ptr& object, float cursorX, float cursorY) = 0;
|
virtual bool placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount) = 0;
|
||||||
///< place an object into the gameworld at the specified cursor position
|
///< copy and place an object into the gameworld at the specified cursor position
|
||||||
/// @param object
|
/// @param object
|
||||||
/// @param cursor X (relative 0-1)
|
/// @param cursor X (relative 0-1)
|
||||||
/// @param cursor Y (relative 0-1)
|
/// @param cursor Y (relative 0-1)
|
||||||
|
/// @param number of objects to place
|
||||||
/// @return true if the object was placed, or false if it was rejected because the position is too far away
|
/// @return true if the object was placed, or false if it was rejected because the position is too far away
|
||||||
|
|
||||||
virtual void dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object) = 0;
|
virtual void dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount) = 0;
|
||||||
|
///< copy and place an object into the gameworld at the given actor's position
|
||||||
|
/// @param actor giving the dropped object position
|
||||||
|
/// @param object
|
||||||
|
/// @param number of objects to place
|
||||||
|
|
||||||
virtual bool canPlaceObject (float cursorX, float cursorY) = 0;
|
virtual bool canPlaceObject (float cursorX, float cursorY) = 0;
|
||||||
///< @return true if it is possible to place on object at specified cursor location
|
///< @return true if it is possible to place on object at specified cursor location
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "../mwworld/actiontake.hpp"
|
#include "../mwworld/actiontake.hpp"
|
||||||
#include "../mwworld/actionapply.hpp"
|
#include "../mwworld/actionapply.hpp"
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
#include "../mwworld/containerstore.hpp"
|
||||||
#include "../mwworld/physicssystem.hpp"
|
#include "../mwworld/physicssystem.hpp"
|
||||||
#include "../mwworld/player.hpp"
|
#include "../mwworld/player.hpp"
|
||||||
#include "../mwworld/nullaction.hpp"
|
#include "../mwworld/nullaction.hpp"
|
||||||
|
@ -164,10 +165,11 @@ namespace MWClass
|
||||||
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
||||||
ptr.get<ESM::Potion>();
|
ptr.get<ESM::Potion>();
|
||||||
|
|
||||||
ptr.getRefData().setCount (ptr.getRefData().getCount()-1);
|
|
||||||
|
|
||||||
MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
|
||||||
|
// remove used potion (assume it is present in inventory)
|
||||||
|
ptr.getContainerStore()->remove(ptr, 1, actor);
|
||||||
|
|
||||||
boost::shared_ptr<MWWorld::Action> action (
|
boost::shared_ptr<MWWorld::Action> action (
|
||||||
new MWWorld::ActionApply (actor, ref->mBase->mId));
|
new MWWorld::ActionApply (actor, ref->mBase->mId));
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,7 @@ void ContainerItemModel::removeItem (const ItemStack& item, size_t count)
|
||||||
{
|
{
|
||||||
if (stacks(*it, item.mBase))
|
if (stacks(*it, item.mBase))
|
||||||
{
|
{
|
||||||
int refCount = it->getRefData().getCount();
|
toRemove -= store.remove(*it, toRemove, *source);
|
||||||
it->getRefData().setCount(std::max(0, refCount - toRemove));
|
|
||||||
toRemove -= refCount;
|
|
||||||
if (toRemove <= 0)
|
if (toRemove <= 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,21 +243,16 @@ namespace MWGui
|
||||||
float mouseX = cursorPosition.left / float(viewSize.width);
|
float mouseX = cursorPosition.left / float(viewSize.width);
|
||||||
float mouseY = cursorPosition.top / float(viewSize.height);
|
float mouseY = cursorPosition.top / float(viewSize.height);
|
||||||
|
|
||||||
int origCount = object.getRefData().getCount();
|
|
||||||
object.getRefData().setCount(mDragAndDrop->mDraggedCount);
|
|
||||||
|
|
||||||
if (world->canPlaceObject(mouseX, mouseY))
|
if (world->canPlaceObject(mouseX, mouseY))
|
||||||
world->placeObject(object, mouseX, mouseY);
|
world->placeObject(object, mouseX, mouseY, mDragAndDrop->mDraggedCount);
|
||||||
else
|
else
|
||||||
world->dropObjectOnGround(world->getPlayer().getPlayer(), object);
|
world->dropObjectOnGround(world->getPlayer().getPlayer(), object, mDragAndDrop->mDraggedCount);
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
|
MWBase::Environment::get().getWindowManager()->changePointer("arrow");
|
||||||
|
|
||||||
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
|
std::string sound = MWWorld::Class::get(object).getDownSoundId(object);
|
||||||
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
|
||||||
|
|
||||||
object.getRefData().setCount(origCount);
|
|
||||||
|
|
||||||
// remove object from the container it was coming from
|
// remove object from the container it was coming from
|
||||||
mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
|
mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
|
||||||
mDragAndDrop->finish();
|
mDragAndDrop->finish();
|
||||||
|
|
|
@ -52,18 +52,12 @@ void InventoryItemModel::copyItem (const ItemStack& item, size_t count)
|
||||||
void InventoryItemModel::removeItem (const ItemStack& item, size_t count)
|
void InventoryItemModel::removeItem (const ItemStack& item, size_t count)
|
||||||
{
|
{
|
||||||
MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor);
|
MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor);
|
||||||
|
int removed = store.remove(item.mBase, count, mActor);
|
||||||
|
|
||||||
for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it)
|
if (removed == 0)
|
||||||
{
|
|
||||||
if (*it == item.mBase)
|
|
||||||
{
|
|
||||||
if (it->getRefData().getCount() < static_cast<int>(count))
|
|
||||||
throw std::runtime_error("Not enough items in the stack to remove");
|
|
||||||
it->getRefData().setCount(it->getRefData().getCount() - count);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw std::runtime_error("Item to remove not found in container store");
|
throw std::runtime_error("Item to remove not found in container store");
|
||||||
|
else if (removed < count)
|
||||||
|
throw std::runtime_error("Not enough items in the stack to remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryItemModel::update()
|
void InventoryItemModel::update()
|
||||||
|
|
|
@ -202,31 +202,19 @@ namespace MWGui
|
||||||
|
|
||||||
void TradeWindow::addOrRemoveGold(int amount)
|
void TradeWindow::addOrRemoveGold(int amount)
|
||||||
{
|
{
|
||||||
bool goldFound = false;
|
|
||||||
MWWorld::Ptr gold;
|
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
MWWorld::ContainerStore& playerStore = MWWorld::Class::get(player).getContainerStore(player);
|
MWWorld::ContainerStore& playerStore = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
|
||||||
for (MWWorld::ContainerStoreIterator it = playerStore.begin();
|
if (amount > 0)
|
||||||
it != playerStore.end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (Misc::StringUtils::ciEqual(it->getCellRef().mRefID, "gold_001"))
|
|
||||||
{
|
|
||||||
goldFound = true;
|
|
||||||
gold = *it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (goldFound)
|
|
||||||
{
|
|
||||||
gold.getRefData().setCount(gold.getRefData().getCount() + amount);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(amount > 0);
|
|
||||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001");
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001");
|
||||||
ref.getPtr().getRefData().setCount(amount);
|
ref.getPtr().getRefData().setCount(amount);
|
||||||
playerStore.add(ref.getPtr(), player);
|
playerStore.add(ref.getPtr(), player);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerStore.remove("gold_001", - amount, player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TradeWindow::onFrame(float frameDuration)
|
void TradeWindow::onFrame(float frameDuration)
|
||||||
|
|
|
@ -244,7 +244,7 @@ namespace MWMechanics
|
||||||
heldIter->getClass().setRemainingUsageTime(*heldIter, timeRemaining);
|
heldIter->getClass().setRemainingUsageTime(*heldIter, timeRemaining);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
heldIter->getRefData().setCount(0); // remove it
|
inventoryStore.remove(*heldIter, 1, ptr); // remove it
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ namespace MWMechanics
|
||||||
// Both NPC and player lights extinguish in water.
|
// Both NPC and player lights extinguish in water.
|
||||||
if(MWBase::Environment::get().getWorld()->isSwimming(ptr))
|
if(MWBase::Environment::get().getWorld()->isSwimming(ptr))
|
||||||
{
|
{
|
||||||
heldIter->getRefData().setCount(0); // remove it
|
inventoryStore.remove(*heldIter, 1, ptr); // remove it
|
||||||
|
|
||||||
// ...But, only the player makes a sound.
|
// ...But, only the player makes a sound.
|
||||||
if(isPlayer)
|
if(isPlayer)
|
||||||
|
|
|
@ -240,7 +240,8 @@ void MWMechanics::Alchemy::removeIngredients()
|
||||||
for (TIngredientsContainer::iterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter)
|
for (TIngredientsContainer::iterator iter (mIngredients.begin()); iter!=mIngredients.end(); ++iter)
|
||||||
if (!iter->isEmpty())
|
if (!iter->isEmpty())
|
||||||
{
|
{
|
||||||
iter->getRefData().setCount (iter->getRefData().getCount()-1);
|
iter->getContainerStore()->remove(*iter, 1, mAlchemist);
|
||||||
|
|
||||||
if (iter->getRefData().getCount()<1)
|
if (iter->getRefData().getCount()<1)
|
||||||
{
|
{
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
|
|
|
@ -14,7 +14,6 @@ namespace MWMechanics
|
||||||
Enchanting::Enchanting()
|
Enchanting::Enchanting()
|
||||||
: mCastStyle(ESM::Enchantment::CastOnce)
|
: mCastStyle(ESM::Enchantment::CastOnce)
|
||||||
, mSelfEnchanting(false)
|
, mSelfEnchanting(false)
|
||||||
, mOldItemCount(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void Enchanting::setOldItem(MWWorld::Ptr oldItem)
|
void Enchanting::setOldItem(MWWorld::Ptr oldItem)
|
||||||
|
@ -24,7 +23,6 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
mObjectType = mOldItemPtr.getTypeName();
|
mObjectType = mOldItemPtr.getTypeName();
|
||||||
mOldItemId = mOldItemPtr.getCellRef().mRefID;
|
mOldItemId = mOldItemPtr.getCellRef().mRefID;
|
||||||
mOldItemCount = mOldItemPtr.getRefData().getCount();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -55,17 +53,18 @@ namespace MWMechanics
|
||||||
|
|
||||||
bool Enchanting::create()
|
bool Enchanting::create()
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
ESM::Enchantment enchantment;
|
ESM::Enchantment enchantment;
|
||||||
enchantment.mData.mCharge = getGemCharge();
|
enchantment.mData.mCharge = getGemCharge();
|
||||||
|
|
||||||
mSoulGemPtr.getRefData().setCount (mSoulGemPtr.getRefData().getCount()-1);
|
store.remove(mSoulGemPtr, 1, player);
|
||||||
|
|
||||||
//Exception for Azura Star, new one will be added after enchanting
|
//Exception for Azura Star, new one will be added after enchanting
|
||||||
if(boost::iequals(mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura"))
|
if(boost::iequals(mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura"))
|
||||||
{
|
{
|
||||||
MWWorld::ManualRef azura (MWBase::Environment::get().getWorld()->getStore(), "Misc_SoulGem_Azura");
|
MWWorld::ManualRef azura (MWBase::Environment::get().getWorld()->getStore(), "Misc_SoulGem_Azura");
|
||||||
MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr(), player);
|
store.add(azura.getPtr(), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mSelfEnchanting)
|
if(mSelfEnchanting)
|
||||||
|
@ -84,16 +83,19 @@ namespace MWMechanics
|
||||||
enchantment.mData.mCost = getEnchantPoints();
|
enchantment.mData.mCost = getEnchantPoints();
|
||||||
enchantment.mEffects = mEffectList;
|
enchantment.mEffects = mEffectList;
|
||||||
|
|
||||||
const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
|
// Create a new item
|
||||||
|
|
||||||
MWWorld::Class::get(mOldItemPtr).applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
|
||||||
|
|
||||||
mOldItemPtr.getRefData().setCount(1);
|
|
||||||
|
|
||||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
|
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
|
||||||
ref.getPtr().getRefData().setCount (mOldItemCount-1);
|
const MWWorld::Ptr& newItemPtr = ref.getPtr();
|
||||||
|
newItemPtr.getRefData().setCount(1);
|
||||||
|
|
||||||
|
// Apply the enchantment
|
||||||
|
const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
|
||||||
|
MWWorld::Class::get(newItemPtr).applyEnchantment(newItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
||||||
|
|
||||||
|
// Add the new item to player inventory and remove the old one
|
||||||
|
store.add(newItemPtr, player);
|
||||||
|
store.remove(mOldItemPtr, 1, player);
|
||||||
|
|
||||||
MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr(), player);
|
|
||||||
if(!mSelfEnchanting)
|
if(!mSelfEnchanting)
|
||||||
payForEnchantment();
|
payForEnchantment();
|
||||||
|
|
||||||
|
@ -299,20 +301,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
void Enchanting::payForEnchantment() const
|
void Enchanting::payForEnchantment() const
|
||||||
{
|
{
|
||||||
MWWorld::Ptr gold;
|
const MWWorld::Ptr& player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
|
||||||
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
|
||||||
for (MWWorld::ContainerStoreIterator it = store.begin();
|
store.remove("gold_001", getEnchantPrice(), player);
|
||||||
it != store.end(); ++it)
|
|
||||||
{
|
|
||||||
if (Misc::StringUtils::ciEqual(it->getCellRef().mRefID, "gold_001"))
|
|
||||||
{
|
|
||||||
gold = *it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gold.getRefData().setCount(gold.getRefData().getCount() - getEnchantPrice());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ namespace MWMechanics
|
||||||
std::string mNewItemName;
|
std::string mNewItemName;
|
||||||
std::string mObjectType;
|
std::string mObjectType;
|
||||||
std::string mOldItemId;
|
std::string mOldItemId;
|
||||||
int mOldItemCount;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Enchanting();
|
Enchanting();
|
||||||
|
|
|
@ -85,7 +85,10 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair)
|
||||||
// tool used up?
|
// tool used up?
|
||||||
if (mTool.getCellRef().mCharge == 0)
|
if (mTool.getCellRef().mCharge == 0)
|
||||||
{
|
{
|
||||||
mTool.getRefData().setCount(0);
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
|
||||||
|
store.remove(mTool, 1, player);
|
||||||
|
|
||||||
std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
std::string message = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||||
.find("sNotifyMessage51")->getString();
|
.find("sNotifyMessage51")->getString();
|
||||||
|
@ -93,8 +96,6 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair)
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox((boost::format(message) % MWWorld::Class::get(mTool).getName(mTool)).str());
|
MWBase::Environment::get().getWindowManager()->messageBox((boost::format(message) % MWWorld::Class::get(mTool).getName(mTool)).str());
|
||||||
|
|
||||||
// try to find a new tool of the same ID
|
// try to find a new tool of the same ID
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
|
||||||
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
|
||||||
for (MWWorld::ContainerStoreIterator iter (store.begin());
|
for (MWWorld::ContainerStoreIterator iter (store.begin());
|
||||||
iter!=store.end(); ++iter)
|
iter!=store.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/player.hpp"
|
#include "../mwworld/player.hpp"
|
||||||
|
#include "../mwworld/containerstore.hpp"
|
||||||
|
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
@ -61,7 +62,7 @@ namespace MWMechanics
|
||||||
lockpick.getCellRef().mCharge = lockpick.get<ESM::Lockpick>()->mBase->mData.mUses;
|
lockpick.getCellRef().mCharge = lockpick.get<ESM::Lockpick>()->mBase->mData.mUses;
|
||||||
--lockpick.getCellRef().mCharge;
|
--lockpick.getCellRef().mCharge;
|
||||||
if (!lockpick.getCellRef().mCharge)
|
if (!lockpick.getCellRef().mCharge)
|
||||||
lockpick.getRefData().setCount(0);
|
lockpick.getContainerStore()->remove(lockpick, 1, mActor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Security::probeTrap(const MWWorld::Ptr &trap, const MWWorld::Ptr &probe,
|
void Security::probeTrap(const MWWorld::Ptr &trap, const MWWorld::Ptr &probe,
|
||||||
|
@ -103,7 +104,7 @@ namespace MWMechanics
|
||||||
probe.getCellRef().mCharge = probe.get<ESM::Probe>()->mBase->mData.mUses;
|
probe.getCellRef().mCharge = probe.get<ESM::Probe>()->mBase->mData.mUses;
|
||||||
--probe.getCellRef().mCharge;
|
--probe.getCellRef().mCharge;
|
||||||
if (!probe.getCellRef().mCharge)
|
if (!probe.getCellRef().mCharge)
|
||||||
probe.getRefData().setCount(0);
|
probe.getContainerStore()->remove(probe, 1, mActor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,37 +139,14 @@ namespace MWScript
|
||||||
|
|
||||||
std::string itemName = "";
|
std::string itemName = "";
|
||||||
|
|
||||||
// originalCount holds the total number of items to remove, count holds the remaining number of items to remove
|
int numRemoved = store.remove(item, count, ptr);
|
||||||
Interpreter::Type_Integer originalCount = count;
|
|
||||||
|
|
||||||
for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end() && count;
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
if (Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, item))
|
|
||||||
{
|
|
||||||
itemName = MWWorld::Class::get(*iter).getName(*iter);
|
|
||||||
|
|
||||||
if (iter->getRefData().getCount()<=count)
|
|
||||||
{
|
|
||||||
count -= iter->getRefData().getCount();
|
|
||||||
iter->getRefData().setCount (0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iter->getRefData().setCount (iter->getRefData().getCount()-count);
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn a messagebox (only for items removed from player's inventory)
|
// Spawn a messagebox (only for items removed from player's inventory)
|
||||||
if (ptr == MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer())
|
if ((numRemoved > 0)
|
||||||
|
&& (ptr == MWBase::Environment::get().getWorld()->getPlayer().getPlayer()))
|
||||||
{
|
{
|
||||||
// The two GMST entries below expand to strings informing the player of what, and how many of it has been removed from their inventory
|
// The two GMST entries below expand to strings informing the player of what, and how many of it has been removed from their inventory
|
||||||
std::string msgBox;
|
std::string msgBox;
|
||||||
int numRemoved = (originalCount - count);
|
|
||||||
if (numRemoved == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(numRemoved > 1)
|
if(numRemoved > 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -374,18 +374,7 @@ namespace MWScript
|
||||||
|
|
||||||
MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr);
|
MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr);
|
||||||
|
|
||||||
|
store.remove(soul, 1, ptr);
|
||||||
for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter)
|
|
||||||
{
|
|
||||||
if (::Misc::StringUtils::ciEqual(iter->getCellRef().mSoul, soul))
|
|
||||||
{
|
|
||||||
if (iter->getRefData().getCount() <= 1)
|
|
||||||
iter->getRefData().setCount (0);
|
|
||||||
else
|
|
||||||
iter->getRefData().setCount (iter->getRefData().getCount() - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -415,23 +404,17 @@ namespace MWScript
|
||||||
MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr);
|
MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr);
|
||||||
|
|
||||||
|
|
||||||
|
int toRemove = amount;
|
||||||
for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter)
|
for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (::Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, item))
|
if (::Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, item))
|
||||||
{
|
{
|
||||||
if(iter->getRefData().getCount() <= amount)
|
int removed = store.remove(*iter, toRemove, ptr);
|
||||||
{
|
MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, removed);
|
||||||
MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter);
|
|
||||||
iter->getRefData().setCount(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int original = iter->getRefData().getCount();
|
|
||||||
iter->getRefData().setCount(amount);
|
|
||||||
MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter);
|
|
||||||
iter->getRefData().setCount(original - amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
toRemove -= removed;
|
||||||
|
|
||||||
|
if (toRemove <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,20 +441,8 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
if (::Misc::StringUtils::ciEqual(iter->getCellRef().mSoul, soul))
|
if (::Misc::StringUtils::ciEqual(iter->getCellRef().mSoul, soul))
|
||||||
{
|
{
|
||||||
|
MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, 1);
|
||||||
if(iter->getRefData().getCount() <= 1)
|
store.remove(*iter, 1, ptr);
|
||||||
{
|
|
||||||
MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter);
|
|
||||||
iter->getRefData().setCount(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int original = iter->getRefData().getCount();
|
|
||||||
iter->getRefData().setCount(1);
|
|
||||||
MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter);
|
|
||||||
iter->getRefData().setCount(original - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,10 +515,16 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
if (ptr.isInCell())
|
if (ptr.isInCell())
|
||||||
MWBase::Environment::get().getWorld()->deleteObject (ptr);
|
MWBase::Environment::get().getWorld()->deleteObject (ptr);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MWWorld::ContainerStore* store = ptr.getContainerStore();
|
||||||
|
if (store != NULL)
|
||||||
|
store->remove(ptr, ptr.getRefData().getCount(), ptr);
|
||||||
else
|
else
|
||||||
ptr.getRefData().setCount(0);
|
ptr.getRefData().setCount(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class OpGetSquareRoot : public Interpreter::Opcode0
|
class OpGetSquareRoot : public Interpreter::Opcode0
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "../mwmechanics/creaturestats.hpp"
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
#include "../mwmechanics/npcstats.hpp"
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/containerstore.hpp"
|
||||||
|
|
||||||
#include "esmstore.hpp"
|
#include "esmstore.hpp"
|
||||||
#include "class.hpp"
|
#include "class.hpp"
|
||||||
|
|
||||||
|
@ -18,8 +20,8 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
void ActionEat::executeImp (const Ptr& actor)
|
void ActionEat::executeImp (const Ptr& actor)
|
||||||
{
|
{
|
||||||
// remove used item
|
// remove used item (assume the item is present in inventory)
|
||||||
getTarget().getRefData().setCount (getTarget().getRefData().getCount()-1);
|
getTarget().getContainerStore()->remove(getTarget(), 1, actor);
|
||||||
|
|
||||||
// check for success
|
// check for success
|
||||||
const MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (actor).getCreatureStats (actor);
|
const MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (actor).getCreatureStats (actor);
|
||||||
|
|
|
@ -1477,7 +1477,7 @@ namespace MWWorld
|
||||||
item.getRefData().getLocals().setVarByInt(script, "onpcdrop", 1);
|
item.getRefData().getLocals().setVarByInt(script, "onpcdrop", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::placeObject (const Ptr& object, float cursorX, float cursorY)
|
bool World::placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount)
|
||||||
{
|
{
|
||||||
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
|
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
|
||||||
|
|
||||||
|
@ -1502,9 +1502,14 @@ namespace MWWorld
|
||||||
pos.rot[0] = 0;
|
pos.rot[0] = 0;
|
||||||
pos.rot[1] = 0;
|
pos.rot[1] = 0;
|
||||||
|
|
||||||
|
// copy the object and set its count
|
||||||
|
int origCount = object.getRefData().getCount();
|
||||||
|
object.getRefData().setCount(amount);
|
||||||
Ptr dropped = copyObjectToCell(object, *cell, pos);
|
Ptr dropped = copyObjectToCell(object, *cell, pos);
|
||||||
|
object.getRefData().setCount(origCount);
|
||||||
|
|
||||||
|
// only the player place items in the world, so no need to check actor
|
||||||
PCDropped(dropped);
|
PCDropped(dropped);
|
||||||
object.getRefData().setCount(0);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1549,7 +1554,7 @@ namespace MWWorld
|
||||||
return dropped;
|
return dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::dropObjectOnGround (const Ptr& actor, const Ptr& object)
|
void World::dropObjectOnGround (const Ptr& actor, const Ptr& object, int amount)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr::CellStore* cell = actor.getCell();
|
MWWorld::Ptr::CellStore* cell = actor.getCell();
|
||||||
|
|
||||||
|
@ -1570,10 +1575,14 @@ namespace MWWorld
|
||||||
mPhysics->castRay(orig, dir, len);
|
mPhysics->castRay(orig, dir, len);
|
||||||
pos.pos[2] = hit.second.z;
|
pos.pos[2] = hit.second.z;
|
||||||
|
|
||||||
|
// copy the object and set its count
|
||||||
|
int origCount = object.getRefData().getCount();
|
||||||
|
object.getRefData().setCount(amount);
|
||||||
Ptr dropped = copyObjectToCell(object, *cell, pos);
|
Ptr dropped = copyObjectToCell(object, *cell, pos);
|
||||||
|
object.getRefData().setCount(origCount);
|
||||||
|
|
||||||
if(actor == mPlayer->getPlayer()) // Only call if dropped by player
|
if(actor == mPlayer->getPlayer()) // Only call if dropped by player
|
||||||
PCDropped(dropped);
|
PCDropped(dropped);
|
||||||
object.getRefData().setCount(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::processChangedSettings(const Settings::CategorySettingVector& settings)
|
void World::processChangedSettings(const Settings::CategorySettingVector& settings)
|
||||||
|
@ -1955,14 +1964,7 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ContainerStore &store = Class::get(actor).getContainerStore(actor);
|
Class::get(actor).getContainerStore(actor).remove("WerewolfRobe", 1, actor);
|
||||||
|
|
||||||
const std::string item = "WerewolfRobe";
|
|
||||||
for(ContainerStoreIterator iter(store.begin());iter != store.end();++iter)
|
|
||||||
{
|
|
||||||
if(Misc::StringUtils::ciEqual(iter->getCellRef().mRefID, item))
|
|
||||||
iter->getRefData().setCount(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(actor.getRefData().getHandle() == "player")
|
if(actor.getRefData().getHandle() == "player")
|
||||||
|
|
|
@ -354,14 +354,19 @@ namespace MWWorld
|
||||||
|
|
||||||
virtual void update (float duration, bool paused);
|
virtual void update (float duration, bool paused);
|
||||||
|
|
||||||
virtual bool placeObject (const Ptr& object, float cursorX, float cursorY);
|
virtual bool placeObject (const MWWorld::Ptr& object, float cursorX, float cursorY, int amount);
|
||||||
///< place an object into the gameworld at the specified cursor position
|
///< copy and place an object into the gameworld at the specified cursor position
|
||||||
/// @param object
|
/// @param object
|
||||||
/// @param cursor X (relative 0-1)
|
/// @param cursor X (relative 0-1)
|
||||||
/// @param cursor Y (relative 0-1)
|
/// @param cursor Y (relative 0-1)
|
||||||
|
/// @param number of objects to place
|
||||||
/// @return true if the object was placed, or false if it was rejected because the position is too far away
|
/// @return true if the object was placed, or false if it was rejected because the position is too far away
|
||||||
|
|
||||||
virtual void dropObjectOnGround (const Ptr& actor, const Ptr& object);
|
virtual void dropObjectOnGround (const MWWorld::Ptr& actor, const MWWorld::Ptr& object, int amount);
|
||||||
|
///< copy and place an object into the gameworld at the given actor's position
|
||||||
|
/// @param actor giving the dropped object position
|
||||||
|
/// @param object
|
||||||
|
/// @param number of objects to place
|
||||||
|
|
||||||
virtual bool canPlaceObject(float cursorX, float cursorY);
|
virtual bool canPlaceObject(float cursorX, float cursorY);
|
||||||
///< @return true if it is possible to place on object at specified cursor location
|
///< @return true if it is possible to place on object at specified cursor location
|
||||||
|
|
Loading…
Reference in a new issue