2010-08-03 13:24:44 +00:00
|
|
|
|
|
|
|
#include "door.hpp"
|
|
|
|
|
|
|
|
#include <components/esm/loaddoor.hpp>
|
|
|
|
|
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"
|
2012-04-23 13:27:03 +00:00
|
|
|
|
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"
|
2012-06-29 14:48:50 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwworld/physicssystem.hpp"
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2012-04-16 20:58:16 +00:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
|
|
|
|
2011-11-12 20:58:22 +00:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2010-08-14 08:02:54 +00:00
|
|
|
|
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
|
|
|
{
|
2012-07-24 16:22:11 +00:00
|
|
|
const std::string model = getModel(ptr);
|
|
|
|
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);
|
2012-07-24 16:22:11 +00:00
|
|
|
objects.insertMesh(ptr, model);
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-23 13:27:03 +00:00
|
|
|
void Door::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
|
2011-11-12 04:01:12 +00:00
|
|
|
{
|
2012-07-24 16:22:11 +00:00
|
|
|
const std::string model = getModel(ptr);
|
|
|
|
if(!model.empty()) {
|
|
|
|
physics.insertObjectPhysics(ptr, model);
|
|
|
|
}
|
|
|
|
}
|
2012-07-27 10:00:10 +00:00
|
|
|
|
2012-07-24 16:22:11 +00:00
|
|
|
std::string Door::getModel(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
2011-11-12 04:01:12 +00:00
|
|
|
ptr.get<ESM::Door>();
|
2012-07-24 16:22:11 +00:00
|
|
|
assert(ref->base != NULL);
|
2011-11-12 04:01:12 +00:00
|
|
|
|
|
|
|
const std::string &model = ref->base->model;
|
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
|
|
|
}
|
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
std::string Door::getName (const MWWorld::Ptr& ptr) const
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
2010-08-03 15:11:41 +00:00
|
|
|
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,
|
2012-04-23 13:27:03 +00:00
|
|
|
const MWWorld::Ptr& actor) const
|
2010-08-03 16:44:52 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
2010-08-03 16:44:52 +00:00
|
|
|
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-08-19 23:11:50 +00:00
|
|
|
|
|
|
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
|
|
|
|
|
|
|
|
action->setSound(lockedSound);
|
|
|
|
|
|
|
|
return action;
|
2010-08-30 10:02:47 +00:00
|
|
|
}
|
|
|
|
|
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-08-19 23:11:50 +00:00
|
|
|
|
|
|
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
|
|
|
|
|
|
|
|
action->setSound(trapActivationSound);
|
2012-02-27 14:59:45 +00:00
|
|
|
ptr.getCellRef().trap = "";
|
2012-08-19 23:11:50 +00:00
|
|
|
|
|
|
|
return action;
|
2012-02-27 14:59:45 +00:00
|
|
|
}
|
2010-08-30 09:56:55 +00:00
|
|
|
|
2010-08-03 16:44:52 +00:00
|
|
|
if (ref->ref.teleport)
|
|
|
|
{
|
|
|
|
// teleport door
|
2012-07-27 10:00:10 +00:00
|
|
|
/// \todo remove this if clause once ActionTeleport can also support other actors
|
2012-04-23 13:27:03 +00:00
|
|
|
if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor)
|
2010-08-03 16:44:52 +00:00
|
|
|
{
|
2012-08-19 23:11:50 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest));
|
|
|
|
|
2012-08-26 14:47:45 +00:00
|
|
|
action->setSound(openSound);
|
2012-08-19 23:11:50 +00:00
|
|
|
|
|
|
|
return action;
|
2010-08-03 16:44:52 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
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-08-19 23:11:50 +00:00
|
|
|
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
|
|
|
|
|
|
|
|
action->setSound(openSound);
|
|
|
|
|
|
|
|
return action;
|
2010-08-03 16:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
2010-08-05 13:40:03 +00:00
|
|
|
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
|
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
2012-04-16 20:58:16 +00:00
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
return (ref->base->name != "");
|
|
|
|
}
|
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
MWGui::ToolTipInfo Door::getToolTipInfo (const MWWorld::Ptr& ptr) const
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
2012-04-16 20:58:16 +00:00
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
|
|
|
info.caption = ref->base->name;
|
|
|
|
|
|
|
|
std::string text;
|
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2012-04-17 16:47:51 +00:00
|
|
|
if (ref->ref.teleport)
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2012-04-17 16:47:51 +00:00
|
|
|
std::string dest;
|
|
|
|
if (ref->ref.destCell != "")
|
|
|
|
{
|
|
|
|
// door leads to an interior, use interior name as tooltip
|
|
|
|
dest = ref->ref.destCell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// door leads to exterior, use cell name (if any), otherwise translated region name
|
|
|
|
int x,y;
|
2012-04-24 00:02:03 +00:00
|
|
|
MWBase::Environment::get().getWorld()->positionToIndex (ref->ref.doorDest.pos[0], ref->ref.doorDest.pos[1], x, y);
|
|
|
|
const ESM::Cell* cell = store.cells.findExt(x,y);
|
2012-04-17 16:47:51 +00:00
|
|
|
if (cell->name != "")
|
|
|
|
dest = cell->name;
|
|
|
|
else
|
|
|
|
{
|
2012-04-24 00:02:03 +00:00
|
|
|
const ESM::Region* region = store.regions.search(cell->region);
|
2012-04-17 16:47:51 +00:00
|
|
|
dest = region->name;
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 00:02:03 +00:00
|
|
|
text += "\n" + store.gameSettings.search("sTo")->str;
|
2012-04-17 16:47:51 +00:00
|
|
|
text += "\n"+dest;
|
2012-04-16 20:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ref->ref.lockLevel > 0)
|
2012-04-24 00:02:03 +00:00
|
|
|
text += "\n" + store.gameSettings.search("sLockLevel")->str + ": " + MWGui::ToolTips::toString(ref->ref.lockLevel);
|
2012-04-16 20:58:16 +00:00
|
|
|
if (ref->ref.trap != "")
|
2012-04-24 00:02:03 +00:00
|
|
|
text += "\n" + store.gameSettings.search("sTrapped")->str;
|
2012-04-16 20:58:16 +00:00
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
2012-04-16 20:58:16 +00:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
|
|
|
|
|
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-07-25 13:18:17 +00:00
|
|
|
|
|
|
|
MWWorld::Ptr
|
2012-07-26 12:14:11 +00:00
|
|
|
Door::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 13:18:17 +00:00
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref =
|
|
|
|
ptr.get<ESM::Door>();
|
|
|
|
|
|
|
|
return MWWorld::Ptr(&cell.doors.insert(*ref), &cell);
|
|
|
|
}
|
2010-08-03 13:24:44 +00:00
|
|
|
}
|