2010-08-03 13:24:44 +00:00
|
|
|
|
|
|
|
#include "container.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loadcont.hpp>
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
#include <components/esm_store/cell_store.hpp>
|
|
|
|
|
|
|
|
#include "../mwworld/ptr.hpp"
|
2012-02-27 14:37:05 +00:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
2012-01-27 13:55:58 +00:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
#include "../mwworld/customdata.hpp"
|
2012-02-27 14:37:05 +00:00
|
|
|
#include "../mwworld/environment.hpp"
|
2012-01-27 13:55:58 +00:00
|
|
|
|
2012-01-27 14:11:02 +00:00
|
|
|
#include "../mwrender/objects.hpp"
|
|
|
|
|
2012-02-27 14:37:05 +00:00
|
|
|
#include "../mwsound/soundmanager.hpp"
|
|
|
|
|
2012-01-27 13:55:58 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct CustomData : public MWWorld::CustomData
|
|
|
|
{
|
2012-01-28 10:45:55 +00:00
|
|
|
MWWorld::ContainerStore mContainerStore;
|
2012-01-27 13:55:58 +00:00
|
|
|
|
|
|
|
virtual MWWorld::CustomData *clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
MWWorld::CustomData *CustomData::clone() const
|
|
|
|
{
|
|
|
|
return new CustomData (*this);
|
|
|
|
}
|
|
|
|
}
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
namespace MWClass
|
|
|
|
{
|
2012-01-27 13:55:58 +00:00
|
|
|
void Container::ensureCustomData (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
std::auto_ptr<CustomData> data (new CustomData);
|
|
|
|
|
|
|
|
// \todo add initial container content
|
|
|
|
|
|
|
|
// store
|
|
|
|
ptr.getRefData().setCustomData (data.release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
void Container::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
|
|
|
assert (ref->base != NULL);
|
|
|
|
const std::string &model = ref->base->model;
|
2012-01-27 13:55:58 +00:00
|
|
|
|
2010-08-14 08:02:54 +00:00
|
|
|
if (!model.empty())
|
|
|
|
{
|
2011-11-19 06:01:19 +00:00
|
|
|
MWRender::Objects& objects = renderingInterface.getObjects();
|
2011-11-12 04:01:12 +00:00
|
|
|
objects.insertBegin(ptr, ptr.getRefData().isEnabled(), false);
|
|
|
|
objects.insertMesh(ptr, "meshes\\" + model);
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-12 04:01:12 +00:00
|
|
|
void Container::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
|
|
|
|
|
|
|
const std::string &model = ref->base->model;
|
|
|
|
assert (ref->base != NULL);
|
|
|
|
if(!model.empty()){
|
2011-11-18 00:38:52 +00:00
|
|
|
physics.insertObjectPhysics(ptr, "meshes\\" + model);
|
2011-11-12 04:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-27 14:37:05 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> Container::activate (const MWWorld::Ptr& ptr,
|
|
|
|
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
const std::string lockedSound = "LockedChest";
|
|
|
|
const std::string trapActivationSound = "Disarm Trap Fail";
|
|
|
|
|
|
|
|
if (ptr.getCellRef().lockLevel>0)
|
|
|
|
{
|
|
|
|
// TODO check for key
|
|
|
|
std::cout << "Locked container" << std::endl;
|
2012-03-31 14:31:55 +00:00
|
|
|
environment.mSoundManager->playSound3D (ptr, lockedSound, 1.0, 1.0);
|
2012-02-27 14:37:05 +00:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Unlocked container" << std::endl;
|
|
|
|
if(ptr.getCellRef().trap.empty())
|
|
|
|
{
|
|
|
|
// Not trapped, Inventory GUI goes here
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Trap activation goes here
|
2012-02-27 14:59:45 +00:00
|
|
|
std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl;
|
2012-03-31 14:31:55 +00:00
|
|
|
environment.mSoundManager->playSound3D (ptr, trapActivationSound, 1.0, 1.0);
|
2012-02-27 14:59:45 +00:00
|
|
|
ptr.getCellRef().trap = "";
|
2012-02-27 14:37:05 +00:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Container::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
|
|
|
return ref->base->name;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-01-27 13:55:58 +00:00
|
|
|
return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mContainerStore;
|
2010-08-04 12:37:23 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
std::string Container::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Container>();
|
|
|
|
|
|
|
|
return ref->base->script;
|
|
|
|
}
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
void Container::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Container);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::Container).name(), instance);
|
|
|
|
}
|
|
|
|
}
|