2010-08-03 13:24:44 +00:00
|
|
|
|
|
|
|
#include "door.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loaddoor.hpp>
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
#include <components/esm_store/cell_store.hpp>
|
|
|
|
|
2011-01-04 14:58:22 +00:00
|
|
|
#include "../mwworld/player.hpp"
|
2010-08-03 15:11:41 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2010-08-03 16:44:52 +00:00
|
|
|
#include "../mwworld/nullaction.hpp"
|
|
|
|
#include "../mwworld/actionteleport.hpp"
|
|
|
|
#include "../mwworld/environment.hpp"
|
|
|
|
#include "../mwworld/world.hpp"
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2012-04-16 20:58:16 +00:00
|
|
|
#include "../mwgui/window_manager.hpp"
|
|
|
|
#include "../mwgui/tooltips.hpp"
|
|
|
|
|
2011-11-12 20:58:22 +00:00
|
|
|
#include "../mwrender/objects.hpp"
|
2010-08-14 08:02:54 +00:00
|
|
|
|
2012-02-27 07:39:35 +00:00
|
|
|
#include "../mwsound/soundmanager.hpp"
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
namespace MWClass
|
|
|
|
{
|
2011-11-12 04:01:12 +00:00
|
|
|
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
2011-11-12 04:01:12 +00:00
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
2010-08-14 08:02:54 +00:00
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
assert (ref->base != NULL);
|
|
|
|
const std::string &model = ref->base->model;
|
2012-01-27 14:11:02 +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 Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Door::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
2010-08-19 11:19:23 +00:00
|
|
|
if (ref->ref.teleport && !ref->ref.destCell.empty()) // TODO doors that lead to exteriors
|
|
|
|
return ref->ref.destCell;
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
return ref->base->name;
|
|
|
|
}
|
|
|
|
|
2010-08-03 16:44:52 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> Door::activate (const MWWorld::Ptr& ptr,
|
|
|
|
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
2012-02-27 07:39:35 +00:00
|
|
|
const std::string &openSound = ref->base->openSound;
|
|
|
|
//const std::string &closeSound = ref->base->closeSound;
|
|
|
|
const std::string lockedSound = "LockedDoor";
|
2012-02-27 14:59:45 +00:00
|
|
|
const std::string trapActivationSound = "Disarm Trap Fail";
|
2012-02-27 07:39:35 +00:00
|
|
|
|
2010-08-30 10:02:47 +00:00
|
|
|
if (ptr.getCellRef().lockLevel>0)
|
|
|
|
{
|
|
|
|
// TODO check for key
|
|
|
|
// TODO report failure to player (message, sound?). Look up behaviour of original MW.
|
|
|
|
std::cout << "Locked!" << std::endl;
|
2012-03-31 14:31:55 +00:00
|
|
|
environment.mSoundManager->playSound3D (ptr, lockedSound, 1.0, 1.0);
|
2010-08-30 10:02:47 +00:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
|
|
|
|
2012-02-27 14:59:45 +00:00
|
|
|
if(!ptr.getCellRef().trap.empty())
|
|
|
|
{
|
|
|
|
// Trap activation
|
|
|
|
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 = "";
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
2010-08-30 09:56:55 +00:00
|
|
|
|
2010-08-03 16:44:52 +00:00
|
|
|
if (ref->ref.teleport)
|
|
|
|
{
|
|
|
|
// teleport door
|
2011-01-04 14:58:22 +00:00
|
|
|
if (environment.mWorld->getPlayer().getPlayer()==actor)
|
2010-08-03 16:44:52 +00:00
|
|
|
{
|
|
|
|
// the player is using the door
|
2012-03-13 12:17:49 +00:00
|
|
|
// The reason this is not 3D is that it would get interrupted when you teleport
|
2012-02-27 07:39:35 +00:00
|
|
|
environment.mSoundManager->playSound(openSound, 1.0, 1.0);
|
2010-08-03 16:44:52 +00:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (
|
|
|
|
new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-27 14:11:02 +00:00
|
|
|
// another NPC or a creature is using the door
|
2010-08-03 16:44:52 +00:00
|
|
|
// TODO return action for teleporting other NPC/creature
|
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// animated door
|
|
|
|
// TODO return action for rotating the door
|
2012-02-27 14:59:45 +00:00
|
|
|
|
|
|
|
// This is a little pointless, but helps with testing
|
2012-03-31 14:31:55 +00:00
|
|
|
environment.mSoundManager->playSound3D (ptr, openSound, 1.0, 1.0);
|
2010-08-03 16:44:52 +00:00
|
|
|
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 09:56:55 +00:00
|
|
|
void Door::lock (const MWWorld::Ptr& ptr, int lockLevel) const
|
|
|
|
{
|
|
|
|
if (lockLevel<0)
|
|
|
|
lockLevel = 0;
|
|
|
|
|
|
|
|
ptr.getCellRef().lockLevel = lockLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Door::unlock (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ptr.getCellRef().lockLevel = 0;
|
|
|
|
}
|
|
|
|
|
2010-08-05 13:40:03 +00:00
|
|
|
std::string Door::getScript (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
return ref->base->script;
|
|
|
|
}
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
void Door::registerSelf()
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Class> instance (new Door);
|
|
|
|
|
|
|
|
registerClass (typeid (ESM::Door).name(), instance);
|
|
|
|
}
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
bool Door::hasToolTip (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
return (ref->base->name != "");
|
|
|
|
}
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo Door::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const
|
|
|
|
{
|
|
|
|
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
|
|
|
info.caption = ref->base->name;
|
|
|
|
|
|
|
|
std::string text;
|
|
|
|
|
|
|
|
/// \todo If destCell is empty, the teleport target is an exterior cell. In that case we
|
|
|
|
/// need to fetch that cell (via target position) and retrieve the region name.
|
|
|
|
if (ref->ref.teleport && (ref->ref.destCell != ""))
|
|
|
|
{
|
|
|
|
text += "\n" + environment.mWorld->getStore().gameSettings.search("sTo")->str;
|
|
|
|
text += "\n"+ref->ref.destCell;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref->ref.lockLevel > 0)
|
|
|
|
text += "\n" + environment.mWorld->getStore().gameSettings.search("sLockLevel")->str + ": " + MWGui::ToolTips::toString(ref->ref.lockLevel);
|
|
|
|
if (ref->ref.trap != "")
|
|
|
|
text += "\n" + environment.mWorld->getStore().gameSettings.search("sTrapped")->str;
|
|
|
|
|
|
|
|
if (environment.mWindowManager->getFullHelp())
|
|
|
|
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2010-08-03 13:24:44 +00:00
|
|
|
}
|