1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 13:19:54 +00:00
openmw-tes3mp/apps/openmw/mwclass/door.cpp

231 lines
6.9 KiB
C++
Raw Normal View History

2010-08-03 13:24:44 +00:00
#include "door.hpp"
#include <components/esm/loaddoor.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwworld/player.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwworld/ptr.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwworld/actionteleport.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/physicssystem.hpp"
2010-08-03 15:11:41 +00:00
#include "../mwgui/tooltips.hpp"
2011-11-12 20:58:22 +00:00
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.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
{
2012-07-24 16:22:11 +00:00
const std::string model = getModel(ptr);
if (!model.empty()) {
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);
}
}
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
{
MWWorld::LiveCellRef<ESM::Door> *ref =
2010-08-03 15:11:41 +00:00
ptr.get<ESM::Door>();
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;
}
boost::shared_ptr<MWWorld::Action> Door::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor) const
{
MWWorld::LiveCellRef<ESM::Door> *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
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;
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(lockedSound);
return action;
}
2012-02-27 14:59:45 +00:00
if(!ptr.getCellRef().trap.empty())
{
// Trap activation
std::cout << "Activated trap: " << ptr.getCellRef().trap << std::endl;
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(trapActivationSound);
2012-02-27 14:59:45 +00:00
ptr.getCellRef().trap = "";
return action;
2012-02-27 14:59:45 +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
if (MWBase::Environment::get().getWorld()->getPlayer().getPlayer()==actor)
{
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport (ref->ref.destCell, ref->ref.doorDest));
action->setSound(openSound);
return action;
}
else
{
2012-01-27 14:11:02 +00:00
// another NPC or a creature is using the door
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
boost::shared_ptr<MWWorld::Action> action(new MWWorld::NullAction);
action->setSound(openSound);
return action;
}
}
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;
}
std::string Door::getScript (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Door> *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);
}
bool Door::hasToolTip (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Door> *ref =
ptr.get<ESM::Door>();
return (ref->base->name != "");
}
MWGui::ToolTipInfo Door::getToolTipInfo (const MWWorld::Ptr& ptr) const
{
MWWorld::LiveCellRef<ESM::Door> *ref =
ptr.get<ESM::Door>();
MWGui::ToolTipInfo info;
info.caption = ref->base->name;
std::string text;
const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
if (ref->ref.teleport)
{
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;
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);
if (cell->name != "")
dest = cell->name;
else
{
const ESM::Region* region = store.regions.search(cell->region);
dest = region->name;
}
}
text += "\n" + store.gameSettings.search("sTo")->str;
text += "\n"+dest;
}
if (ref->ref.lockLevel > 0)
text += "\n" + store.gameSettings.search("sLockLevel")->str + ": " + MWGui::ToolTips::toString(ref->ref.lockLevel);
if (ref->ref.trap != "")
text += "\n" + store.gameSettings.search("sTrapped")->str;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
text += MWGui::ToolTips::getMiscString(ref->base->script, "Script");
info.text = text;
return info;
}
MWWorld::Ptr
Door::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
{
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
}