2010-08-03 13:24:44 +00:00
|
|
|
#include "container.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loadcont.hpp>
|
2014-01-31 12:25:32 +00:00
|
|
|
#include <components/esm/containerstate.hpp>
|
2010-08-03 13:24:44 +00:00
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-12 16:11:09 +00:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2016-07-10 12:42:03 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2012-11-17 17:17:08 +00:00
|
|
|
#include "../mwworld/failedaction.hpp"
|
2013-02-17 14:56:22 +00:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
2012-01-27 13:55:58 +00:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
#include "../mwworld/customdata.hpp"
|
2012-06-29 14:48:50 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2014-12-19 10:26:54 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2018-12-03 16:21:40 +00:00
|
|
|
#include "../mwworld/actionharvest.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwworld/actionopen.hpp"
|
2013-11-13 13:02:15 +00:00
|
|
|
#include "../mwworld/actiontrap.hpp"
|
2015-05-09 23:09:00 +00:00
|
|
|
#include "../mwphysics/physicssystem.hpp"
|
2012-09-10 15:44:59 +00:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
#include "../mwgui/tooltips.hpp"
|
2012-01-27 13:55:58 +00:00
|
|
|
|
2018-12-03 16:21:40 +00:00
|
|
|
#include "../mwrender/animation.hpp"
|
2015-04-12 13:34:50 +00:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-01-27 14:11:02 +00:00
|
|
|
|
2013-08-09 05:34:53 +00:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
2015-11-29 13:13:14 +00:00
|
|
|
namespace MWClass
|
2012-01-27 13:55:58 +00:00
|
|
|
{
|
2015-11-29 13:13:14 +00:00
|
|
|
class ContainerCustomData : public MWWorld::CustomData
|
2012-01-27 13:55:58 +00:00
|
|
|
{
|
2015-11-29 13:13:14 +00:00
|
|
|
public:
|
2012-01-28 10:45:55 +00:00
|
|
|
MWWorld::ContainerStore mContainerStore;
|
2012-01-27 13:55:58 +00:00
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const;
|
2015-11-29 13:13:14 +00:00
|
|
|
|
|
|
|
virtual ContainerCustomData& asContainerCustomData()
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2018-12-03 16:21:40 +00:00
|
|
|
virtual const ContainerCustomData& asContainerCustomData() const
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2012-01-27 13:55:58 +00:00
|
|
|
};
|
|
|
|
|
2014-03-16 22:38:51 +00:00
|
|
|
MWWorld::CustomData *ContainerCustomData::clone() const
|
2012-01-27 13:55:58 +00:00
|
|
|
{
|
2014-03-16 22:38:51 +00:00
|
|
|
return new ContainerCustomData (*this);
|
2012-01-27 13:55:58 +00:00
|
|
|
}
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2012-01-27 13:55:58 +00:00
|
|
|
void Container::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
2017-04-28 15:30:26 +00:00
|
|
|
std::unique_ptr<ContainerCustomData> data (new ContainerCustomData);
|
2012-01-27 13:55:58 +00:00
|
|
|
|
2013-07-30 22:02:24 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Container> *ref =
|
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
2015-02-04 20:18:43 +00:00
|
|
|
// setting ownership not needed, since taking items from a container inherits the
|
|
|
|
// container's owner automatically
|
2013-07-30 22:02:24 +00:00
|
|
|
data->mContainerStore.fill(
|
2015-02-04 20:18:43 +00:00
|
|
|
ref->mBase->mInventory, "");
|
2012-01-27 13:55:58 +00:00
|
|
|
|
|
|
|
// store
|
|
|
|
ptr.getRefData().setCustomData (data.release());
|
2018-12-03 16:21:40 +00:00
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->addContainerScripts(ptr, ptr.getCell());
|
2012-01-27 13:55:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-03 16:21:40 +00:00
|
|
|
bool canBeHarvested(const MWWorld::ConstPtr& ptr)
|
|
|
|
{
|
|
|
|
const MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
|
|
|
if (animation == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return animation->canBeHarvested();
|
|
|
|
}
|
|
|
|
|
2014-05-17 07:05:41 +00:00
|
|
|
void Container::respawn(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Container> *ref =
|
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
if (ref->mBase->mFlags & ESM::Container::Respawn)
|
|
|
|
{
|
2019-05-04 10:09:09 +00:00
|
|
|
// Container was not touched, there is no need to modify its content.
|
|
|
|
if (ptr.getRefData().getCustomData() == nullptr)
|
|
|
|
return;
|
|
|
|
|
2015-12-14 01:57:55 +00:00
|
|
|
MWBase::Environment::get().getWorld()->removeContainerScripts(ptr);
|
2018-10-09 06:21:12 +00:00
|
|
|
ptr.getRefData().setCustomData(nullptr);
|
2014-05-17 07:05:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-17 12:30:31 +00:00
|
|
|
void Container::restock(const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
|
|
|
const ESM::InventoryList& list = ref->mBase->mInventory;
|
2014-05-18 10:53:21 +00:00
|
|
|
MWWorld::ContainerStore& store = getContainerStore(ptr);
|
2015-02-04 20:18:43 +00:00
|
|
|
|
|
|
|
// setting ownership not needed, since taking items from a container inherits the
|
|
|
|
// container's owner automatically
|
|
|
|
store.restock(list, ptr, "");
|
2014-05-17 12:30:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 10:29:56 +00:00
|
|
|
void Container::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
2012-07-24 16:22:11 +00:00
|
|
|
if (!model.empty()) {
|
2015-04-12 13:34:50 +00:00
|
|
|
renderingInterface.getObjects().insertModel(ptr, model, true);
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-09 23:09:00 +00:00
|
|
|
void Container::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const
|
2012-07-24 16:22:11 +00:00
|
|
|
{
|
2012-11-05 18:40:02 +00:00
|
|
|
if(!model.empty())
|
2015-01-12 10:29:56 +00:00
|
|
|
physics.addObject(ptr, model);
|
2012-07-24 16:22:11 +00:00
|
|
|
}
|
2012-08-09 12:33:21 +00:00
|
|
|
|
2015-12-18 14:51:05 +00:00
|
|
|
std::string Container::getModel(const MWWorld::ConstPtr &ptr) const
|
2011-11-12 04:01:12 +00:00
|
|
|
{
|
2015-12-18 14:51:05 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2011-11-12 04:01:12 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
const std::string &model = ref->mBase->mModel;
|
2012-07-24 16:22:11 +00:00
|
|
|
if (!model.empty()) {
|
|
|
|
return "meshes\\" + model;
|
2011-11-12 04:01:12 +00:00
|
|
|
}
|
2012-07-24 16:22:11 +00:00
|
|
|
return "";
|
2011-11-12 04:01:12 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 18:04:02 +00:00
|
|
|
bool Container::useAnim() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> Container::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 13:27:03 +00:00
|
|
|
const MWWorld::Ptr& actor) const
|
2012-02-27 14:37:05 +00:00
|
|
|
{
|
2013-02-17 14:56:22 +00:00
|
|
|
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
|
2017-05-05 19:21:11 +00:00
|
|
|
return std::shared_ptr<MWWorld::Action> (new MWWorld::NullAction ());
|
2013-02-17 14:56:22 +00:00
|
|
|
|
2014-05-22 18:37:22 +00:00
|
|
|
if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
|
2013-08-09 05:34:53 +00:00
|
|
|
{
|
2013-08-11 07:35:19 +00:00
|
|
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfContainer");
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction("#{sWerewolfRefusal}"));
|
2013-08-11 07:35:19 +00:00
|
|
|
if(sound) action->setSound(sound->mId);
|
|
|
|
|
2013-08-09 05:34:53 +00:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2012-02-27 14:37:05 +00:00
|
|
|
const std::string lockedSound = "LockedChest";
|
|
|
|
const std::string trapActivationSound = "Disarm Trap Fail";
|
|
|
|
|
2014-01-08 17:39:44 +00:00
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
2017-12-01 06:07:02 +00:00
|
|
|
MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player);
|
2012-09-10 15:44:59 +00:00
|
|
|
|
2016-07-10 13:29:21 +00:00
|
|
|
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
|
|
|
|
bool isTrapped = !ptr.getCellRef().getTrap().empty();
|
2012-09-10 15:44:59 +00:00
|
|
|
bool hasKey = false;
|
|
|
|
std::string keyName;
|
2012-11-02 21:21:32 +00:00
|
|
|
|
2017-12-01 06:07:02 +00:00
|
|
|
const std::string keyId = ptr.getCellRef().getKey();
|
|
|
|
if (!keyId.empty())
|
2012-02-27 14:37:05 +00:00
|
|
|
{
|
2017-12-01 06:07:02 +00:00
|
|
|
MWWorld::Ptr keyPtr = invStore.search(keyId);
|
|
|
|
if (!keyPtr.isEmpty())
|
2012-09-10 15:44:59 +00:00
|
|
|
{
|
|
|
|
hasKey = true;
|
2017-12-01 06:07:02 +00:00
|
|
|
keyName = keyPtr.getClass().getName(keyPtr);
|
2012-09-10 15:44:59 +00:00
|
|
|
}
|
2012-02-27 14:37:05 +00:00
|
|
|
}
|
2012-09-10 15:44:59 +00:00
|
|
|
|
2020-04-12 11:40:06 +00:00
|
|
|
if (isLocked && hasKey)
|
2012-09-10 15:44:59 +00:00
|
|
|
{
|
2013-03-30 11:56:37 +00:00
|
|
|
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}");
|
2020-04-12 11:40:06 +00:00
|
|
|
ptr.getCellRef().unlock();
|
2012-09-10 15:44:59 +00:00
|
|
|
// using a key disarms the trap
|
2016-07-10 13:29:21 +00:00
|
|
|
if(isTrapped)
|
2016-07-10 12:42:03 +00:00
|
|
|
{
|
|
|
|
ptr.getCellRef().setTrap("");
|
2017-09-15 08:03:41 +00:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f);
|
2016-07-10 13:29:21 +00:00
|
|
|
isTrapped = false;
|
2016-07-10 12:42:03 +00:00
|
|
|
}
|
2012-09-10 15:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-10 13:29:21 +00:00
|
|
|
if (!isLocked || hasKey)
|
2012-02-27 14:37:05 +00:00
|
|
|
{
|
2016-07-10 13:29:21 +00:00
|
|
|
if(!isTrapped)
|
2012-02-27 14:37:05 +00:00
|
|
|
{
|
2018-12-03 16:21:40 +00:00
|
|
|
if (canBeHarvested(ptr))
|
|
|
|
{
|
|
|
|
std::shared_ptr<MWWorld::Action> action (new MWWorld::ActionHarvest(ptr));
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action (new MWWorld::ActionOpen(ptr));
|
2012-09-04 13:42:41 +00:00
|
|
|
return action;
|
2012-02-27 14:37:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-13 13:02:15 +00:00
|
|
|
// Activate trap
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTrap(ptr.getCellRef().getTrap(), ptr));
|
2012-08-19 23:11:50 +00:00
|
|
|
action->setSound(trapActivationSound);
|
|
|
|
return action;
|
2012-02-27 14:37:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-10 15:44:59 +00:00
|
|
|
else
|
|
|
|
{
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction(std::string(), ptr));
|
2012-09-10 15:44:59 +00:00
|
|
|
action->setSound(lockedSound);
|
|
|
|
return action;
|
|
|
|
}
|
2012-02-27 14:37:05 +00:00
|
|
|
}
|
|
|
|
|
2015-12-18 14:27:06 +00:00
|
|
|
std::string Container::getName (const MWWorld::ConstPtr& ptr) const
|
2010-08-03 15:11:41 +00:00
|
|
|
{
|
2015-12-18 14:27:06 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2019-09-10 21:06:50 +00:00
|
|
|
const std::string& name = ref->mBase->mName;
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2019-09-10 21:06:50 +00:00
|
|
|
return !name.empty() ? name : ref->mBase->mId;
|
2010-08-03 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 10:45:55 +00:00
|
|
|
MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr)
|
2010-08-04 12:37:23 +00:00
|
|
|
const
|
|
|
|
{
|
2012-01-27 13:55:58 +00:00
|
|
|
ensureCustomData (ptr);
|
2010-08-04 12:37:23 +00:00
|
|
|
|
2015-11-29 13:13:14 +00:00
|
|
|
return ptr.getRefData().getCustomData()->asContainerCustomData().mContainerStore;
|
2010-08-04 12:37:23 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 23:12:03 +00:00
|
|
|
std::string Container::getScript (const MWWorld::ConstPtr& ptr) const
|
2010-08-05 13:40:03 +00:00
|
|
|
{
|
2015-12-17 23:12:03 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 13:40:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
void Container::registerSelf()
|
|
|
|
{
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<Class> instance (new Container);
|
2010-08-03 13:24:44 +00:00
|
|
|
|
|
|
|
registerClass (typeid (ESM::Container).name(), instance);
|
|
|
|
}
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2015-12-19 15:13:00 +00:00
|
|
|
bool Container::hasToolTip (const MWWorld::ConstPtr& ptr) const
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2018-12-03 16:21:40 +00:00
|
|
|
if (const MWWorld::CustomData* data = ptr.getRefData().getCustomData())
|
|
|
|
return !canBeHarvested(ptr) || data->asContainerCustomData().mContainerStore.hasVisibleItems();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-19 15:29:07 +00:00
|
|
|
MWGui::ToolTipInfo Container::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2015-12-18 14:27:06 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2019-09-10 18:56:10 +00:00
|
|
|
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
std::string text;
|
2018-06-19 10:17:33 +00:00
|
|
|
int lockLevel = ptr.getCellRef().getLockLevel();
|
|
|
|
if (lockLevel > 0 && lockLevel != ESM::UnbreakableLock)
|
2019-03-04 16:23:57 +00:00
|
|
|
text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(lockLevel);
|
|
|
|
else if (lockLevel < 0)
|
2014-04-23 17:02:51 +00:00
|
|
|
text += "\n#{sUnlocked}";
|
2014-05-25 12:13:07 +00:00
|
|
|
if (ptr.getCellRef().getTrap() != "")
|
2012-09-22 19:35:57 +00:00
|
|
|
text += "\n#{sTrapped}";
|
2012-04-15 15:52:39 +00:00
|
|
|
|
2019-09-16 10:18:41 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
|
|
|
{ text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
|
2012-11-05 12:07:59 +00:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2019-09-16 10:18:41 +00:00
|
|
|
if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "stolen_goods"))
|
|
|
|
text += "\nYou can not use evidence chests";
|
2012-04-16 20:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-05-15 19:17:00 +00:00
|
|
|
|
2012-05-15 20:31:52 +00:00
|
|
|
float Container::getCapacity (const MWWorld::Ptr& ptr) const
|
2012-05-15 19:17:00 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Container> *ref =
|
2012-05-15 19:17:00 +00:00
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mWeight;
|
2012-05-15 19:17:00 +00:00
|
|
|
}
|
2012-05-15 19:34:00 +00:00
|
|
|
|
|
|
|
float Container::getEncumbrance (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
return getContainerStore (ptr).getWeight();
|
|
|
|
}
|
2012-06-17 22:21:55 +00:00
|
|
|
|
2015-12-18 15:50:32 +00:00
|
|
|
bool Container::canLock(const MWWorld::ConstPtr &ptr) const
|
2015-08-04 15:33:34 +00:00
|
|
|
{
|
2019-09-09 20:29:59 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
|
|
|
return !(ref->mBase->mFlags & ESM::Container::Organic);
|
2015-08-04 15:33:34 +00:00
|
|
|
}
|
2012-07-25 13:18:17 +00:00
|
|
|
|
2015-12-18 15:24:24 +00:00
|
|
|
MWWorld::Ptr Container::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 13:18:17 +00:00
|
|
|
{
|
2015-12-18 15:24:24 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2012-07-25 13:18:17 +00:00
|
|
|
|
2015-11-14 16:12:05 +00:00
|
|
|
return MWWorld::Ptr(cell.insert(ref), &cell);
|
2012-07-25 13:18:17 +00:00
|
|
|
}
|
2014-01-31 12:25:32 +00:00
|
|
|
|
2015-08-04 15:33:34 +00:00
|
|
|
void Container::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const
|
2014-01-31 12:25:32 +00:00
|
|
|
{
|
2015-12-17 23:07:13 +00:00
|
|
|
if (!state.mHasCustomState)
|
|
|
|
return;
|
2014-01-31 12:25:32 +00:00
|
|
|
|
2014-06-18 20:59:18 +00:00
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
// Create a CustomData, but don't fill it from ESM records (not needed)
|
2017-04-28 15:30:26 +00:00
|
|
|
std::unique_ptr<ContainerCustomData> data (new ContainerCustomData);
|
2014-06-18 20:59:18 +00:00
|
|
|
ptr.getRefData().setCustomData (data.release());
|
|
|
|
}
|
2014-01-31 12:25:32 +00:00
|
|
|
|
2020-03-17 10:15:19 +00:00
|
|
|
ContainerCustomData& customData = ptr.getRefData().getCustomData()->asContainerCustomData();
|
|
|
|
const ESM::ContainerState& containerState = state.asContainerState();
|
|
|
|
customData.mContainerStore.readState (containerState.mInventory);
|
2014-01-31 12:25:32 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 23:18:06 +00:00
|
|
|
void Container::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const
|
2014-01-31 12:25:32 +00:00
|
|
|
{
|
2015-12-17 23:07:13 +00:00
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
state.mHasCustomState = false;
|
|
|
|
return;
|
|
|
|
}
|
2014-01-31 12:25:32 +00:00
|
|
|
|
2020-03-17 10:15:19 +00:00
|
|
|
const ContainerCustomData& customData = ptr.getRefData().getCustomData()->asContainerCustomData();
|
|
|
|
ESM::ContainerState& containerState = state.asContainerState();
|
|
|
|
customData.mContainerStore.writeState (containerState.mInventory);
|
2014-01-31 12:25:32 +00:00
|
|
|
}
|
2010-08-03 13:24:44 +00:00
|
|
|
}
|