1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

container related script instruction are using the new container interface now

This commit is contained in:
Marc Zinnschlag 2012-02-23 12:34:51 +01:00
parent e13e858c7a
commit 1d551030d1

View file

@ -11,7 +11,7 @@
#include "../mwworld/manualref.hpp" #include "../mwworld/manualref.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/containerutil.hpp" #include "../mwworld/containerstore.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
@ -45,8 +45,7 @@ namespace MWScript
ref.getPtr().getRefData().setCount (count); ref.getPtr().getRefData().setCount (count);
MWWorld::Class::get (ref.getPtr()).insertIntoContainer (ref.getPtr(), MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr());
MWWorld::Class::get (ptr).getContainerStore (ptr));
} }
}; };
@ -59,25 +58,16 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::vector<MWWorld::Ptr> list; MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr);
MWWorld::listItemsInContainer (item,
MWWorld::Class::get (ptr).getContainerStore (ptr),
context.getWorld().getStore(), list);
Interpreter::Type_Integer sum = 0; Interpreter::Type_Integer sum = 0;
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin()); iter!=list.end(); for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter)
++iter) if (iter->getCellRef().refID==item)
{ sum += iter->getRefData().getCount();
sum += iter->getRefData().getCount();
}
runtime.push (sum); runtime.push (sum);
} }
@ -92,9 +82,6 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -104,25 +91,23 @@ namespace MWScript
if (count<0) if (count<0)
throw std::runtime_error ("second argument for RemoveItem must be non-negative"); throw std::runtime_error ("second argument for RemoveItem must be non-negative");
std::vector<MWWorld::Ptr> list; MWWorld::ContainerStore& store = MWWorld::Class::get (ptr).getContainerStore (ptr);
MWWorld::listItemsInContainer (item, for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end() && count;
MWWorld::Class::get (ptr).getContainerStore (ptr),
context.getWorld().getStore(), list);
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin());
iter!=list.end() && count;
++iter) ++iter)
{ {
if (iter->getRefData().getCount()<=count) if (iter->getCellRef().refID==item)
{ {
count -= iter->getRefData().getCount(); if (iter->getRefData().getCount()<=count)
iter->getRefData().setCount (0); {
} count -= iter->getRefData().getCount();
else iter->getRefData().setCount (0);
{ }
iter->getRefData().setCount (iter->getRefData().getCount()-count); else
count = 0; {
iter->getRefData().setCount (iter->getRefData().getCount()-count);
count = 0;
}
} }
} }