2010-08-03 15:24:44 +02:00
|
|
|
#include "container.hpp"
|
|
|
|
|
2022-06-04 15:26:36 +02:00
|
|
|
#include <MyGUI_TextIterator.h>
|
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadcont.hpp>
|
|
|
|
#include <components/esm3/containerstate.hpp>
|
2020-12-07 19:04:32 +01:00
|
|
|
#include <components/settings/settings.hpp>
|
2010-08-03 15:24:44 +02:00
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2016-07-10 21:42:03 +09:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2012-11-17 18:17:08 +01:00
|
|
|
#include "../mwworld/failedaction.hpp"
|
2013-02-17 15:56:22 +01:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
2012-06-29 16:48:50 +02:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2014-12-19 11:26:54 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2018-12-03 20:21:40 +04:00
|
|
|
#include "../mwworld/actionharvest.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwworld/actionopen.hpp"
|
2013-11-13 14:02:15 +01:00
|
|
|
#include "../mwworld/actiontrap.hpp"
|
2015-05-10 01:09:00 +02:00
|
|
|
#include "../mwphysics/physicssystem.hpp"
|
2012-09-10 17:44:59 +02:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
#include "../mwgui/tooltips.hpp"
|
2012-01-27 14:55:58 +01:00
|
|
|
|
2018-12-03 20:21:40 +04:00
|
|
|
#include "../mwrender/animation.hpp"
|
2015-04-12 15:34:50 +02:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 13:15:20 +02:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2012-01-27 15:11:02 +01:00
|
|
|
|
2020-10-20 09:22:43 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2013-08-08 22:34:53 -07:00
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
2015-11-29 14:13:14 +01:00
|
|
|
namespace MWClass
|
2012-01-27 14:55:58 +01:00
|
|
|
{
|
2020-10-13 17:46:32 +02:00
|
|
|
ContainerCustomData::ContainerCustomData(const ESM::Container& container, MWWorld::CellStore* cell)
|
2012-01-27 14:55:58 +01:00
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
|
|
|
unsigned int seed = Misc::Rng::rollDice(std::numeric_limits<int>::max(), prng);
|
2020-10-13 17:46:32 +02:00
|
|
|
// setting ownership not needed, since taking items from a container inherits the
|
|
|
|
// container's owner automatically
|
|
|
|
mStore.fillNonRandom(container.mInventory, "", seed);
|
|
|
|
}
|
2015-11-29 14:13:14 +01:00
|
|
|
|
2020-10-13 17:46:32 +02:00
|
|
|
ContainerCustomData::ContainerCustomData(const ESM::InventoryState& inventory)
|
|
|
|
{
|
|
|
|
mStore.readState(inventory);
|
|
|
|
}
|
2012-01-27 14:55:58 +01:00
|
|
|
|
2020-10-13 17:46:32 +02:00
|
|
|
ContainerCustomData& ContainerCustomData::asContainerCustomData()
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
const ContainerCustomData& ContainerCustomData::asContainerCustomData() const
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-12-07 19:04:32 +01:00
|
|
|
Container::Container()
|
2022-04-04 02:44:53 +02:00
|
|
|
: MWWorld::RegisteredClass<Container>(ESM::Container::sRecordId)
|
|
|
|
, mHarvestEnabled(Settings::Manager::getBool("graphic herbalism", "Game"))
|
2020-12-07 19:04:32 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-27 14:55:58 +01:00
|
|
|
void Container::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
2020-10-13 17:46:32 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2012-01-27 14:55:58 +01:00
|
|
|
|
|
|
|
// store
|
2021-04-03 00:48:35 +02:00
|
|
|
ptr.getRefData().setCustomData (std::make_unique<ContainerCustomData>(*ref->mBase, ptr.getCell()));
|
2018-12-03 20:21:40 +04:00
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->addContainerScripts(ptr, ptr.getCell());
|
2012-01-27 14:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 19:04:32 +01:00
|
|
|
bool Container::canBeHarvested(const MWWorld::ConstPtr& ptr) const
|
2018-12-03 20:21:40 +04:00
|
|
|
{
|
2020-12-07 19:04:32 +01:00
|
|
|
if (!mHarvestEnabled)
|
|
|
|
return false;
|
2018-12-03 20:21:40 +04:00
|
|
|
const MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
|
|
|
if (animation == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return animation->canBeHarvested();
|
|
|
|
}
|
|
|
|
|
2014-05-17 09:05:41 +02: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 14:09:09 +04:00
|
|
|
// Container was not touched, there is no need to modify its content.
|
|
|
|
if (ptr.getRefData().getCustomData() == nullptr)
|
|
|
|
return;
|
|
|
|
|
2015-12-14 02:57:55 +01:00
|
|
|
MWBase::Environment::get().getWorld()->removeContainerScripts(ptr);
|
2018-10-09 10:21:12 +04:00
|
|
|
ptr.getRefData().setCustomData(nullptr);
|
2014-05-17 09:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-12 11:29:56 +01:00
|
|
|
void Container::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 10:02:54 +02:00
|
|
|
{
|
2012-07-24 20:22:11 +04:00
|
|
|
if (!model.empty()) {
|
2015-04-12 15:34:50 +02:00
|
|
|
renderingInterface.getObjects().insertModel(ptr, model, true);
|
2010-08-14 10:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 22:58:16 +02:00
|
|
|
void Container::insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const
|
2021-03-05 22:21:53 +01:00
|
|
|
{
|
2021-09-30 22:58:16 +02:00
|
|
|
insertObjectPhysics(ptr, model, rotation, physics);
|
2021-03-05 22:21:53 +01:00
|
|
|
}
|
|
|
|
|
2021-09-30 22:58:16 +02:00
|
|
|
void Container::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const
|
2012-07-24 20:22:11 +04:00
|
|
|
{
|
2022-04-03 17:38:33 +00:00
|
|
|
physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World);
|
2012-07-24 20:22:11 +04:00
|
|
|
}
|
2012-08-09 14:33:21 +02:00
|
|
|
|
2015-12-18 15:51:05 +01:00
|
|
|
std::string Container::getModel(const MWWorld::ConstPtr &ptr) const
|
2011-11-11 23:01:12 -05:00
|
|
|
{
|
2015-12-18 15:51:05 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2011-11-11 23:01:12 -05:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
const std::string &model = ref->mBase->mModel;
|
2012-07-24 20:22:11 +04:00
|
|
|
if (!model.empty()) {
|
2022-05-13 19:28:53 +02:00
|
|
|
return MWBase::Environment::get().getWindowManager()->correctMeshPath(model);
|
2011-11-11 23:01:12 -05:00
|
|
|
}
|
2012-07-24 20:22:11 +04:00
|
|
|
return "";
|
2011-11-11 23:01:12 -05:00
|
|
|
}
|
|
|
|
|
2017-02-20 19:04:02 +01:00
|
|
|
bool Container::useAnim() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:06:55 +02:00
|
|
|
std::unique_ptr<MWWorld::Action> Container::activate (const MWWorld::Ptr& ptr,
|
2012-04-23 15:27:03 +02:00
|
|
|
const MWWorld::Ptr& actor) const
|
2012-02-27 16:37:05 +02:00
|
|
|
{
|
2013-02-17 15:56:22 +01:00
|
|
|
if (!MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory))
|
2022-05-29 13:24:48 +02:00
|
|
|
return std::make_unique<MWWorld::NullAction>();
|
2013-02-17 15:56:22 +01:00
|
|
|
|
2014-05-22 20:37:22 +02:00
|
|
|
if(actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
|
2013-08-08 22:34:53 -07:00
|
|
|
{
|
2013-08-11 00:35:19 -07:00
|
|
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
2022-03-06 21:56:02 +02:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
|
|
|
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfContainer", prng);
|
2013-08-11 00:35:19 -07:00
|
|
|
|
2022-05-29 13:24:48 +02:00
|
|
|
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>("#{sWerewolfRefusal}");
|
2013-08-11 00:35:19 -07:00
|
|
|
if(sound) action->setSound(sound->mId);
|
|
|
|
|
2013-08-08 22:34:53 -07:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2012-02-27 16:37:05 +02:00
|
|
|
const std::string lockedSound = "LockedChest";
|
|
|
|
const std::string trapActivationSound = "Disarm Trap Fail";
|
|
|
|
|
2014-01-08 18:39:44 +01:00
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
2017-12-01 10:07:02 +04:00
|
|
|
MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player);
|
2012-09-10 17:44:59 +02:00
|
|
|
|
2016-07-10 22:29:21 +09:00
|
|
|
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
|
|
|
|
bool isTrapped = !ptr.getCellRef().getTrap().empty();
|
2012-09-10 17:44:59 +02:00
|
|
|
bool hasKey = false;
|
|
|
|
std::string keyName;
|
2012-11-02 21:21:32 +00:00
|
|
|
|
2017-12-01 10:07:02 +04:00
|
|
|
const std::string keyId = ptr.getCellRef().getKey();
|
|
|
|
if (!keyId.empty())
|
2012-02-27 16:37:05 +02:00
|
|
|
{
|
2017-12-01 10:07:02 +04:00
|
|
|
MWWorld::Ptr keyPtr = invStore.search(keyId);
|
|
|
|
if (!keyPtr.isEmpty())
|
2012-09-10 17:44:59 +02:00
|
|
|
{
|
|
|
|
hasKey = true;
|
2017-12-01 10:07:02 +04:00
|
|
|
keyName = keyPtr.getClass().getName(keyPtr);
|
2012-09-10 17:44:59 +02:00
|
|
|
}
|
2012-02-27 16:37:05 +02:00
|
|
|
}
|
2012-09-10 17:44:59 +02:00
|
|
|
|
2020-04-12 14:40:06 +03:00
|
|
|
if (isLocked && hasKey)
|
2012-09-10 17:44:59 +02:00
|
|
|
{
|
2013-03-30 12:56:37 +01:00
|
|
|
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}");
|
2020-04-12 14:40:06 +03:00
|
|
|
ptr.getCellRef().unlock();
|
2012-09-10 17:44:59 +02:00
|
|
|
// using a key disarms the trap
|
2016-07-10 22:29:21 +09:00
|
|
|
if(isTrapped)
|
2016-07-10 21:42:03 +09:00
|
|
|
{
|
|
|
|
ptr.getCellRef().setTrap("");
|
2017-09-15 01:03:41 -07:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f);
|
2016-07-10 22:29:21 +09:00
|
|
|
isTrapped = false;
|
2016-07-10 21:42:03 +09:00
|
|
|
}
|
2012-09-10 17:44:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-10 22:29:21 +09:00
|
|
|
if (!isLocked || hasKey)
|
2012-02-27 16:37:05 +02:00
|
|
|
{
|
2016-07-10 22:29:21 +09:00
|
|
|
if(!isTrapped)
|
2012-02-27 16:37:05 +02:00
|
|
|
{
|
2018-12-03 20:21:40 +04:00
|
|
|
if (canBeHarvested(ptr))
|
|
|
|
{
|
2022-05-29 13:24:48 +02:00
|
|
|
return std::make_unique<MWWorld::ActionHarvest>(ptr);
|
2018-12-03 20:21:40 +04:00
|
|
|
}
|
|
|
|
|
2022-05-29 13:24:48 +02:00
|
|
|
return std::make_unique<MWWorld::ActionOpen>(ptr);
|
2012-02-27 16:37:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-13 14:02:15 +01:00
|
|
|
// Activate trap
|
2022-05-29 13:24:48 +02:00
|
|
|
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::ActionTrap>(ptr.getCellRef().getTrap(), ptr);
|
2012-08-19 20:11:50 -03:00
|
|
|
action->setSound(trapActivationSound);
|
|
|
|
return action;
|
2012-02-27 16:37:05 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-10 17:44:59 +02:00
|
|
|
else
|
|
|
|
{
|
2022-05-29 13:24:48 +02:00
|
|
|
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
|
2012-09-10 17:44:59 +02:00
|
|
|
action->setSound(lockedSound);
|
|
|
|
return action;
|
|
|
|
}
|
2012-02-27 16:37:05 +02:00
|
|
|
}
|
|
|
|
|
2015-12-18 15:27:06 +01:00
|
|
|
std::string Container::getName (const MWWorld::ConstPtr& ptr) const
|
2010-08-03 17:11:41 +02:00
|
|
|
{
|
2015-12-18 15:27:06 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2019-09-11 00:06:50 +03:00
|
|
|
const std::string& name = ref->mBase->mName;
|
2010-08-03 17:11:41 +02:00
|
|
|
|
2019-09-11 00:06:50 +03:00
|
|
|
return !name.empty() ? name : ref->mBase->mId;
|
2010-08-03 17:11:41 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 17:46:32 +02:00
|
|
|
MWWorld::ContainerStore& Container::getContainerStore (const MWWorld::Ptr& ptr) const
|
2010-08-04 14:37:23 +02:00
|
|
|
{
|
2012-01-27 14:55:58 +01:00
|
|
|
ensureCustomData (ptr);
|
2020-10-13 17:46:32 +02:00
|
|
|
auto& data = ptr.getRefData().getCustomData()->asContainerCustomData();
|
|
|
|
data.mStore.mPtr = ptr;
|
|
|
|
return data.mStore;
|
2010-08-04 14:37:23 +02:00
|
|
|
}
|
|
|
|
|
2015-12-18 00:12:03 +01:00
|
|
|
std::string Container::getScript (const MWWorld::ConstPtr& ptr) const
|
2010-08-05 15:40:03 +02:00
|
|
|
{
|
2015-12-18 00:12:03 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2010-08-05 15:40:03 +02:00
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 15:40:03 +02:00
|
|
|
}
|
|
|
|
|
2015-12-19 16:13:00 +01:00
|
|
|
bool Container::hasToolTip (const MWWorld::ConstPtr& ptr) const
|
2012-04-16 22:58:16 +02:00
|
|
|
{
|
2018-12-03 20:21:40 +04:00
|
|
|
if (const MWWorld::CustomData* data = ptr.getRefData().getCustomData())
|
2020-10-13 17:46:32 +02:00
|
|
|
return !canBeHarvested(ptr) || data->asContainerCustomData().mStore.hasVisibleItems();
|
2018-12-03 20:21:40 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-19 16:29:07 +01:00
|
|
|
MWGui::ToolTipInfo Container::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
|
2012-04-16 22:58:16 +02:00
|
|
|
{
|
2015-12-18 15:27:06 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2019-09-10 21:56:10 +03:00
|
|
|
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
|
2012-04-16 22:58:16 +02:00
|
|
|
|
|
|
|
std::string text;
|
2018-06-19 14:17:33 +04: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 13:02:51 -04:00
|
|
|
text += "\n#{sUnlocked}";
|
2014-05-25 14:13:07 +02:00
|
|
|
if (ptr.getCellRef().getTrap() != "")
|
2012-09-22 21:35:57 +02:00
|
|
|
text += "\n#{sTrapped}";
|
2012-04-15 17:52:39 +02:00
|
|
|
|
2019-09-16 14:18:41 +04:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
|
|
|
{ text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
|
2012-11-05 16:07:59 +04:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2019-09-16 14:18:41 +04:00
|
|
|
if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "stolen_goods"))
|
|
|
|
text += "\nYou can not use evidence chests";
|
2012-04-16 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-05-15 21:17:00 +02:00
|
|
|
|
2012-05-15 22:31:52 +02:00
|
|
|
float Container::getCapacity (const MWWorld::Ptr& ptr) const
|
2012-05-15 21:17:00 +02:00
|
|
|
{
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<ESM::Container> *ref =
|
2012-05-15 21:17:00 +02:00
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
2012-11-05 16:07:59 +04:00
|
|
|
return ref->mBase->mWeight;
|
2012-05-15 21:17:00 +02:00
|
|
|
}
|
2012-05-15 21:34:00 +02:00
|
|
|
|
|
|
|
float Container::getEncumbrance (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
return getContainerStore (ptr).getWeight();
|
|
|
|
}
|
2012-06-18 00:21:55 +02:00
|
|
|
|
2015-12-18 16:50:32 +01:00
|
|
|
bool Container::canLock(const MWWorld::ConstPtr &ptr) const
|
2015-08-04 17:33:34 +02:00
|
|
|
{
|
2019-09-09 22:29:59 +02:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
|
|
|
return !(ref->mBase->mFlags & ESM::Container::Organic);
|
2015-08-04 17:33:34 +02:00
|
|
|
}
|
2012-07-25 17:18:17 +04:00
|
|
|
|
2020-10-20 09:22:43 +00:00
|
|
|
void Container::modifyBaseInventory(const std::string& containerId, const std::string& itemId, int amount) const
|
|
|
|
{
|
|
|
|
MWMechanics::modifyBaseInventory<ESM::Container>(containerId, itemId, amount);
|
|
|
|
}
|
|
|
|
|
2015-12-18 16:24:24 +01:00
|
|
|
MWWorld::Ptr Container::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 17:18:17 +04:00
|
|
|
{
|
2015-12-18 16:24:24 +01:00
|
|
|
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
|
2012-07-25 17:18:17 +04:00
|
|
|
|
2015-11-14 17:12:05 +01:00
|
|
|
return MWWorld::Ptr(cell.insert(ref), &cell);
|
2012-07-25 17:18:17 +04:00
|
|
|
}
|
2014-01-31 13:25:32 +01:00
|
|
|
|
2015-08-04 17:33:34 +02:00
|
|
|
void Container::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const
|
2014-01-31 13:25:32 +01:00
|
|
|
{
|
2015-12-18 00:07:13 +01:00
|
|
|
if (!state.mHasCustomState)
|
|
|
|
return;
|
2014-01-31 13:25:32 +01:00
|
|
|
|
2020-03-17 14:15:19 +04:00
|
|
|
const ESM::ContainerState& containerState = state.asContainerState();
|
2021-04-03 00:48:35 +02:00
|
|
|
ptr.getRefData().setCustomData(std::make_unique<ContainerCustomData>(containerState.mInventory));
|
2014-01-31 13:25:32 +01:00
|
|
|
}
|
|
|
|
|
2015-12-18 00:18:06 +01:00
|
|
|
void Container::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const
|
2014-01-31 13:25:32 +01:00
|
|
|
{
|
2020-10-14 09:16:01 +04:00
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
state.mHasCustomState = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-13 17:46:32 +02:00
|
|
|
const ContainerCustomData& customData = ptr.getRefData().getCustomData()->asContainerCustomData();
|
2020-10-14 09:16:01 +04:00
|
|
|
if (!customData.mStore.isResolved())
|
2015-12-18 00:07:13 +01:00
|
|
|
{
|
|
|
|
state.mHasCustomState = false;
|
|
|
|
return;
|
|
|
|
}
|
2014-01-31 13:25:32 +01:00
|
|
|
|
2020-03-17 14:15:19 +04:00
|
|
|
ESM::ContainerState& containerState = state.asContainerState();
|
2020-10-13 17:46:32 +02:00
|
|
|
customData.mStore.writeState (containerState.mInventory);
|
2014-01-31 13:25:32 +01:00
|
|
|
}
|
2010-08-03 15:24:44 +02:00
|
|
|
}
|