#include "door.hpp" #include #include #include "../mwworld/player.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/nullaction.hpp" #include "../mwworld/actionteleport.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" #include "../mwrender/cellimp.hpp" #include namespace MWClass { void Door::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, MWWorld::Environment& environment) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); const std::string &model = ref->base->model; if (!model.empty()) { MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); cellRender.insertObjectPhysics(); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } std::string Door::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = ptr.get(); if (ref->ref.teleport && !ref->ref.destCell.empty()) // TODO doors that lead to exteriors return ref->ref.destCell; return ref->base->name; } boost::shared_ptr Door::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const { ESMS::LiveCellRef *ref = ptr.get(); 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; return boost::shared_ptr (new MWWorld::NullAction); } // TODO check trap if (ref->ref.teleport) { // teleport door if (environment.mWorld->getPlayer().getPlayer()==actor) { // the player is using the door return boost::shared_ptr ( new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest)); } else { // another NPC or a create is using the door // TODO return action for teleporting other NPC/creature return boost::shared_ptr (new MWWorld::NullAction); } } else { // animated door // TODO return action for rotating the door return boost::shared_ptr (new MWWorld::NullAction); } } 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 { ESMS::LiveCellRef *ref = ptr.get(); return ref->base->script; } void Door::registerSelf() { boost::shared_ptr instance (new Door); registerClass (typeid (ESM::Door).name(), instance); } }