2010-08-03 13:24:44 +00:00
|
|
|
#include "door.hpp"
|
|
|
|
|
2017-05-24 13:25:44 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Include additional headers for multiplayer purposes
|
|
|
|
*/
|
|
|
|
#include "../mwmp/Main.hpp"
|
|
|
|
#include "../mwmp/Networking.hpp"
|
2018-05-12 21:42:24 +00:00
|
|
|
#include "../mwmp/ObjectList.hpp"
|
2017-05-24 13:25:44 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
#include <components/esm/loaddoor.hpp>
|
2014-05-14 23:58:44 +00:00
|
|
|
#include <components/esm/doorstate.hpp>
|
2019-02-21 16:14:18 +00:00
|
|
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
2010-08-03 13:24:44 +00:00
|
|
|
|
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"
|
2013-07-26 16:43:06 +00:00
|
|
|
#include "../mwbase/soundmanager.hpp"
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-08-03 15:11:41 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2012-11-17 17:17:08 +00:00
|
|
|
#include "../mwworld/failedaction.hpp"
|
2010-08-03 16:44:52 +00:00
|
|
|
#include "../mwworld/actionteleport.hpp"
|
2013-04-28 12:59:15 +00:00
|
|
|
#include "../mwworld/actiondoor.hpp"
|
2012-06-29 14:48:50 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2014-12-19 10:26:54 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2015-05-09 23:09:00 +00:00
|
|
|
#include "../mwphysics/physicssystem.hpp"
|
2012-09-10 15:44:59 +00:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2013-11-13 13:02:15 +00:00
|
|
|
#include "../mwworld/actiontrap.hpp"
|
2014-05-14 23:58:44 +00:00
|
|
|
#include "../mwworld/customdata.hpp"
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2012-04-16 20:58:16 +00:00
|
|
|
#include "../mwgui/tooltips.hpp"
|
|
|
|
|
2015-04-12 13:34:50 +00:00
|
|
|
#include "../mwrender/objects.hpp"
|
2012-07-03 11:15:20 +00:00
|
|
|
#include "../mwrender/renderinginterface.hpp"
|
2016-08-02 17:45:42 +00:00
|
|
|
#include "../mwrender/animation.hpp"
|
2020-04-20 16:47:14 +00:00
|
|
|
#include "../mwrender/vismask.hpp"
|
2010-08-14 08:02:54 +00:00
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2015-11-29 13:13:14 +00:00
|
|
|
namespace MWClass
|
2014-05-14 23:58:44 +00:00
|
|
|
{
|
2021-04-03 10:59:44 +00:00
|
|
|
class DoorCustomData : public MWWorld::TypedCustomData<DoorCustomData>
|
2014-05-14 23:58:44 +00:00
|
|
|
{
|
2015-11-29 13:13:14 +00:00
|
|
|
public:
|
2019-12-21 10:35:08 +00:00
|
|
|
MWWorld::DoorState mDoorState = MWWorld::DoorState::Idle;
|
2014-05-14 23:58:44 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
DoorCustomData& asDoorCustomData() override
|
2015-11-29 13:13:14 +00:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2020-10-16 18:18:54 +00:00
|
|
|
const DoorCustomData& asDoorCustomData() const override
|
2015-12-19 14:57:37 +00:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2014-05-14 23:58:44 +00:00
|
|
|
};
|
|
|
|
|
2015-01-12 10:29:56 +00:00
|
|
|
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
|
2010-08-14 08:02:54 +00:00
|
|
|
{
|
2019-02-21 16:14:18 +00:00
|
|
|
if (!model.empty())
|
|
|
|
{
|
2015-04-12 13:34:50 +00:00
|
|
|
renderingInterface.getObjects().insertModel(ptr, model, true);
|
2020-04-20 16:47:14 +00:00
|
|
|
ptr.getRefData().getBaseNode()->setNodeMask(MWRender::Mask_Static);
|
2010-08-14 08:02:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-09 23:09:00 +00:00
|
|
|
void Door::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWPhysics::PhysicsSystem& physics) const
|
2011-11-12 04:01:12 +00:00
|
|
|
{
|
2012-11-05 18:40:02 +00:00
|
|
|
if(!model.empty())
|
2015-12-18 17:32:42 +00:00
|
|
|
physics.addObject(ptr, model, MWPhysics::CollisionType_Door);
|
2014-05-14 23:58:44 +00:00
|
|
|
|
|
|
|
// Resume the door's opening/closing animation if it wasn't finished
|
2014-06-14 17:12:49 +00:00
|
|
|
if (ptr.getRefData().getCustomData())
|
2014-05-14 23:58:44 +00:00
|
|
|
{
|
2015-11-29 13:13:14 +00:00
|
|
|
const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData();
|
2019-08-25 13:20:14 +00:00
|
|
|
if (customData.mDoorState != MWWorld::DoorState::Idle)
|
2014-06-14 17:12:49 +00:00
|
|
|
{
|
2014-07-22 15:55:54 +00:00
|
|
|
MWBase::Environment::get().getWorld()->activateDoor(ptr, customData.mDoorState);
|
2014-06-14 17:12:49 +00:00
|
|
|
}
|
2014-05-14 23:58:44 +00:00
|
|
|
}
|
2017-02-20 18:04:02 +00:00
|
|
|
}
|
2014-12-22 17:50:24 +00:00
|
|
|
|
2017-08-18 13:06:47 +00:00
|
|
|
bool Door::isDoor() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-20 18:04:02 +00:00
|
|
|
bool Door::useAnim() const
|
|
|
|
{
|
|
|
|
return true;
|
2012-07-24 16:22:11 +00:00
|
|
|
}
|
2012-07-27 10:00:10 +00:00
|
|
|
|
2015-12-18 14:51:05 +00:00
|
|
|
std::string Door::getModel(const MWWorld::ConstPtr &ptr) const
|
2012-07-24 16:22:11 +00:00
|
|
|
{
|
2015-12-18 14:51:05 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
|
2011-11-12 04:01:12 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
const std::string &model = ref->mBase->mModel;
|
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
|
|
|
}
|
|
|
|
|
2015-12-18 14:27:06 +00:00
|
|
|
std::string Door::getName (const MWWorld::ConstPtr& ptr) const
|
2010-08-03 15:11:41 +00:00
|
|
|
{
|
2015-12-18 14:27:06 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
|
2019-09-10 21:06:50 +00:00
|
|
|
const std::string& name = ref->mBase->mName;
|
2010-08-03 15:11:41 +00:00
|
|
|
|
2019-09-10 21:06:50 +00:00
|
|
|
return !name.empty() ? name : ref->mBase->mId;
|
2010-08-03 15:11:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:21:11 +00:00
|
|
|
std::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
|
|
|
{
|
2013-08-09 08:35:29 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
|
2010-08-03 16:44:52 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
const std::string &openSound = ref->mBase->mOpenSound;
|
2013-04-28 12:59:15 +00:00
|
|
|
const std::string &closeSound = ref->mBase->mCloseSound;
|
2012-02-27 07:39:35 +00:00
|
|
|
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
|
|
|
|
2017-12-01 06:07:02 +00:00
|
|
|
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
|
2012-08-19 23:11:50 +00:00
|
|
|
|
2016-07-10 13:29:21 +00:00
|
|
|
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
|
|
|
|
bool isTrapped = !ptr.getCellRef().getTrap().empty();
|
2012-09-10 15:44:59 +00:00
|
|
|
bool hasKey = false;
|
|
|
|
std::string keyName;
|
2012-11-02 20:43:07 +00:00
|
|
|
|
2018-06-16 10:21:28 +00:00
|
|
|
// FIXME: If NPC activate teleporting door, it can lead to crash due to iterator invalidation in the Actors update.
|
2018-06-17 08:13:03 +00:00
|
|
|
// Make such activation a no-op for now, like how it is in the vanilla game.
|
2018-06-16 10:21:28 +00:00
|
|
|
if (actor != MWMechanics::getPlayer() && ptr.getCellRef().getTeleport())
|
|
|
|
{
|
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction(std::string(), ptr));
|
|
|
|
action->setSound(lockedSound);
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2016-08-06 18:08:46 +00:00
|
|
|
// make door glow if player activates it with telekinesis
|
2018-06-16 10:21:28 +00:00
|
|
|
if (actor == MWMechanics::getPlayer() &&
|
|
|
|
MWBase::Environment::get().getWorld()->getDistanceToFacedObject() >
|
2016-08-02 17:45:42 +00:00
|
|
|
MWBase::Environment::get().getWorld()->getMaxActivationDistance())
|
|
|
|
{
|
|
|
|
MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(ptr);
|
2021-06-25 09:20:25 +00:00
|
|
|
if(animation)
|
|
|
|
{
|
|
|
|
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
int index = ESM::MagicEffect::effectStringToId("sEffectTelekinesis");
|
|
|
|
const ESM::MagicEffect *effect = store.get<ESM::MagicEffect>().find(index);
|
2016-08-02 17:45:42 +00:00
|
|
|
|
2021-06-25 09:20:25 +00:00
|
|
|
animation->addSpellCastGlow(effect, 1); // 1 second glow to match the time taken for a door opening or closing
|
|
|
|
}
|
2016-08-02 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 06:07:02 +00:00
|
|
|
const std::string keyId = ptr.getCellRef().getKey();
|
2017-06-10 18:33:14 +00:00
|
|
|
if (!keyId.empty())
|
2012-09-10 15:44:59 +00:00
|
|
|
{
|
2017-12-01 06:07:02 +00:00
|
|
|
MWWorld::Ptr keyPtr = invStore.search(keyId);
|
|
|
|
if (!keyPtr.isEmpty())
|
2012-09-10 15:44:59 +00:00
|
|
|
{
|
2017-12-01 06:07:02 +00:00
|
|
|
hasKey = true;
|
|
|
|
keyName = keyPtr.getClass().getName(keyPtr);
|
2012-09-10 15:44:59 +00:00
|
|
|
}
|
2010-08-30 10:02:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 11:40:06 +00:00
|
|
|
if (isLocked && hasKey)
|
2012-02-27 14:59:45 +00:00
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
if(actor == MWMechanics::getPlayer())
|
2013-08-09 08:35:29 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}");
|
2018-07-07 21:06:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp change (major)
|
|
|
|
|
|
|
|
Disable unilateral unlocking on this client and expect the server's reply to our
|
|
|
|
packet to do it instead
|
|
|
|
*/
|
2020-04-25 06:52:58 +00:00
|
|
|
//ptr.getCellRef().unlock(); //Call the function here. because that makes sense.
|
2018-07-07 21:06:01 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp change (major)
|
|
|
|
*/
|
|
|
|
|
2012-09-10 15:44:59 +00:00
|
|
|
// using a key disarms the trap
|
2016-07-10 13:29:21 +00:00
|
|
|
if(isTrapped)
|
2016-07-10 12:42:03 +00:00
|
|
|
{
|
2018-07-07 23:38:10 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp change (major)
|
|
|
|
|
|
|
|
Disable unilateral trap disarming on this client and expect the server's reply to our
|
|
|
|
packet to do it instead
|
|
|
|
*/
|
|
|
|
//ptr.getCellRef().setTrap("");
|
2020-02-26 20:24:58 +00:00
|
|
|
//MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f);
|
2018-07-07 23:38:10 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp change (major)
|
|
|
|
*/
|
|
|
|
|
2016-07-10 13:29:21 +00:00
|
|
|
isTrapped = false;
|
2017-05-25 22:47:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_OBJECT_TRAP packet every time a trap is disarmed
|
|
|
|
*/
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addObjectTrap(ptr, ptr.getRefData().getPosition(), true);
|
|
|
|
objectList->sendObjectTrap();
|
2017-05-25 22:47:59 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2016-07-10 12:42:03 +00:00
|
|
|
}
|
2017-05-24 13:25:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_OBJECT_LOCK packet every time a door is unlocked here
|
|
|
|
*/
|
|
|
|
if (isLocked)
|
|
|
|
{
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addObjectLock(ptr, 0);
|
|
|
|
objectList->sendObjectLock();
|
2017-05-24 13:25:44 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2012-02-27 14:59:45 +00:00
|
|
|
}
|
2010-08-30 09:56:55 +00:00
|
|
|
|
2016-07-10 13:29:21 +00:00
|
|
|
if (!isLocked || hasKey)
|
2010-08-03 16:44:52 +00:00
|
|
|
{
|
2016-07-10 13:29:21 +00:00
|
|
|
if(isTrapped)
|
2010-08-03 16:44:52 +00:00
|
|
|
{
|
2012-09-10 15:44:59 +00:00
|
|
|
// Trap activation
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTrap(ptr.getCellRef().getTrap(), ptr));
|
2012-09-10 15:44:59 +00:00
|
|
|
action->setSound(trapActivationSound);
|
2012-08-19 23:11:50 +00:00
|
|
|
return action;
|
2010-08-03 16:44:52 +00:00
|
|
|
}
|
2012-09-10 15:44:59 +00:00
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
if (ptr.getCellRef().getTeleport())
|
2012-09-10 15:44:59 +00:00
|
|
|
{
|
2016-07-08 15:31:39 +00:00
|
|
|
if (actor == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getDistanceToFacedObject() > MWBase::Environment::get().getWorld()->getMaxActivationDistance())
|
|
|
|
{
|
|
|
|
// player activated teleport door with telekinesis
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction);
|
2016-07-08 15:31:39 +00:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-04 14:43:56 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp change (major)
|
|
|
|
|
|
|
|
If there is a destination override in the mwmp::Worldstate for this door's original
|
|
|
|
destination, use it
|
|
|
|
*/
|
|
|
|
std::string destinationCell = ptr.getCellRef().getDestCell();
|
|
|
|
|
|
|
|
if (mwmp::Main::get().getNetworking()->getWorldstate()->destinationOverrides.count(destinationCell) != 0)
|
|
|
|
destinationCell = mwmp::Main::get().getNetworking()->getWorldstate()->destinationOverrides[destinationCell];
|
|
|
|
|
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTeleport(destinationCell, ptr.getCellRef().getDoorDest(), true));
|
|
|
|
/*
|
|
|
|
End of tes3mp change (major)
|
|
|
|
*/
|
|
|
|
|
2016-07-08 15:31:39 +00:00
|
|
|
action->setSound(openSound);
|
|
|
|
return action;
|
2018-06-19 10:17:33 +00:00
|
|
|
}
|
2012-09-10 15:44:59 +00:00
|
|
|
}
|
2010-08-03 16:44:52 +00:00
|
|
|
else
|
|
|
|
{
|
2012-09-10 15:44:59 +00:00
|
|
|
// animated door
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::ActionDoor(ptr));
|
2019-08-25 13:20:14 +00:00
|
|
|
const auto doorState = getDoorState(ptr);
|
2014-05-14 23:58:44 +00:00
|
|
|
bool opening = true;
|
2015-11-11 23:58:29 +00:00
|
|
|
float doorRot = ptr.getRefData().getPosition().rot[2] - ptr.getCellRef().getPosition().rot[2];
|
2019-08-25 13:20:14 +00:00
|
|
|
if (doorState == MWWorld::DoorState::Opening)
|
2014-05-14 23:58:44 +00:00
|
|
|
opening = false;
|
2019-08-25 13:20:14 +00:00
|
|
|
if (doorState == MWWorld::DoorState::Idle && doorRot != 0)
|
2014-05-14 23:58:44 +00:00
|
|
|
opening = false;
|
|
|
|
|
|
|
|
if (opening)
|
2013-07-26 16:43:06 +00:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
2015-03-08 00:07:29 +00:00
|
|
|
closeSound, 0.5f);
|
2015-11-27 07:40:02 +00:00
|
|
|
// Doors rotate at 90 degrees per second, so start the sound at
|
|
|
|
// where it would be at the current rotation.
|
2018-09-17 10:52:43 +00:00
|
|
|
float offset = doorRot/(osg::PI * 0.5f);
|
2013-07-26 16:43:06 +00:00
|
|
|
action->setSoundOffset(offset);
|
2013-04-28 12:59:15 +00:00
|
|
|
action->setSound(openSound);
|
2013-07-26 16:43:06 +00:00
|
|
|
}
|
2013-04-28 12:59:15 +00:00
|
|
|
else
|
2013-07-26 16:43:06 +00:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
2015-03-08 00:07:29 +00:00
|
|
|
openSound, 0.5f);
|
2018-09-17 10:52:43 +00:00
|
|
|
float offset = 1.0f - doorRot/(osg::PI * 0.5f);
|
2015-11-27 07:40:02 +00:00
|
|
|
action->setSoundOffset(std::max(offset, 0.0f));
|
2013-04-28 12:59:15 +00:00
|
|
|
action->setSound(closeSound);
|
2013-07-26 16:43:06 +00:00
|
|
|
}
|
2012-09-10 15:44:59 +00:00
|
|
|
|
|
|
|
return action;
|
2010-08-03 16:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-10 15:44:59 +00:00
|
|
|
// locked, and we can't open.
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<MWWorld::Action> action(new MWWorld::FailedAction(std::string(), ptr));
|
2012-09-10 15:44:59 +00:00
|
|
|
action->setSound(lockedSound);
|
2012-08-19 23:11:50 +00:00
|
|
|
return action;
|
2010-08-03 16:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:50:32 +00:00
|
|
|
bool Door::canLock(const MWWorld::ConstPtr &ptr) const
|
2015-08-04 15:33:34 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-06 15:03:14 +00:00
|
|
|
bool Door::allowTelekinesis(const MWWorld::ConstPtr &ptr) const
|
|
|
|
{
|
2016-07-08 15:31:39 +00:00
|
|
|
if (ptr.getCellRef().getTeleport() && ptr.getCellRef().getLockLevel() <= 0 && ptr.getCellRef().getTrap().empty())
|
2016-07-06 15:03:14 +00:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-17 23:12:03 +00:00
|
|
|
std::string Door::getScript (const MWWorld::ConstPtr& ptr) const
|
2010-08-05 13:40:03 +00:00
|
|
|
{
|
2015-12-17 23:12:03 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
|
2010-08-05 13:40:03 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
return ref->mBase->mScript;
|
2010-08-05 13:40:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
void Door::registerSelf()
|
|
|
|
{
|
2017-05-05 19:21:11 +00:00
|
|
|
std::shared_ptr<Class> instance (new Door);
|
2010-08-03 13:24:44 +00:00
|
|
|
|
|
|
|
registerClass (typeid (ESM::Door).name(), instance);
|
|
|
|
}
|
2012-04-16 20:58:16 +00:00
|
|
|
|
2015-12-19 15:29:07 +00:00
|
|
|
MWGui::ToolTipInfo Door::getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2015-12-18 14:27:06 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
MWGui::ToolTipInfo info;
|
2019-09-10 18:56:10 +00:00
|
|
|
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
|
2012-04-16 20:58:16 +00:00
|
|
|
|
|
|
|
std::string text;
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
if (ptr.getCellRef().getTeleport())
|
2012-04-16 20:58:16 +00:00
|
|
|
{
|
2012-09-22 19:35:57 +00:00
|
|
|
text += "\n#{sTo}";
|
2012-12-23 19:23:24 +00:00
|
|
|
text += "\n" + getDestination(*ref);
|
2012-04-16 20:58:16 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 10:17:33 +00:00
|
|
|
int lockLevel = ptr.getCellRef().getLockLevel();
|
|
|
|
if (lockLevel > 0 && lockLevel != ESM::UnbreakableLock)
|
2014-05-25 12:13:07 +00:00
|
|
|
text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel());
|
|
|
|
else if (ptr.getCellRef().getLockLevel() < 0)
|
2014-04-23 17:02:51 +00:00
|
|
|
text += "\n#{sUnlocked}";
|
2014-05-25 12:13:07 +00:00
|
|
|
if (ptr.getCellRef().getTrap() != "")
|
2012-09-22 19:35:57 +00:00
|
|
|
text += "\n#{sTrapped}";
|
2012-04-16 20:58:16 +00:00
|
|
|
|
2012-04-24 00:02:03 +00:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
|
2014-07-11 09:57:21 +00:00
|
|
|
{
|
2014-07-22 18:03:35 +00:00
|
|
|
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
|
2012-11-05 12:07:59 +00:00
|
|
|
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
|
2014-07-11 09:57:21 +00:00
|
|
|
}
|
2012-04-16 20:58:16 +00:00
|
|
|
info.text = text;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2012-07-25 13:18:17 +00:00
|
|
|
|
2021-02-14 17:49:22 +00:00
|
|
|
std::string Door::getDestination(const MWWorld::LiveCellRef<ESM::Door>& door)
|
2012-12-23 19:23:24 +00:00
|
|
|
{
|
|
|
|
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
2021-02-10 21:13:04 +00:00
|
|
|
std::string dest = door.mRef.getDestCell();
|
|
|
|
if (dest.empty())
|
2012-12-23 19:23:24 +00:00
|
|
|
{
|
|
|
|
// door leads to exterior, use cell name (if any), otherwise translated region name
|
2021-02-14 17:49:22 +00:00
|
|
|
int x, y;
|
2021-02-10 21:13:04 +00:00
|
|
|
auto world = MWBase::Environment::get().getWorld();
|
2021-02-14 17:49:22 +00:00
|
|
|
world->positionToIndex(door.mRef.getDoorDest().pos[0], door.mRef.getDoorDest().pos[1], x, y);
|
|
|
|
const ESM::Cell* cell = world->getStore().get<ESM::Cell>().search(x, y);
|
2021-02-10 21:13:04 +00:00
|
|
|
dest = world->getCellName(cell);
|
2012-12-23 19:23:24 +00:00
|
|
|
}
|
2021-02-14 17:49:22 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
If there is a destination override in the mwmp::Worldstate for this door's original
|
|
|
|
destination, use it
|
|
|
|
*/
|
|
|
|
else if (mwmp::Main::get().getNetworking()->getWorldstate()->destinationOverrides.count(dest) != 0)
|
|
|
|
dest = mwmp::Main::get().getNetworking()->getWorldstate()->destinationOverrides[dest];
|
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2012-12-23 19:23:24 +00:00
|
|
|
|
|
|
|
return "#{sCell=" + dest + "}";
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:24:24 +00:00
|
|
|
MWWorld::Ptr Door::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const
|
2012-07-25 13:18:17 +00:00
|
|
|
{
|
2015-12-18 15:24:24 +00:00
|
|
|
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
|
2012-07-25 13:18:17 +00:00
|
|
|
|
2015-11-14 16:12:05 +00:00
|
|
|
return MWWorld::Ptr(cell.insert(ref), &cell);
|
2012-07-25 13:18:17 +00:00
|
|
|
}
|
2014-05-14 23:58:44 +00:00
|
|
|
|
|
|
|
void Door::ensureCustomData(const MWWorld::Ptr &ptr) const
|
|
|
|
{
|
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
2021-04-02 22:48:35 +00:00
|
|
|
ptr.getRefData().setCustomData(std::make_unique<DoorCustomData>());
|
2014-05-14 23:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 13:20:14 +00:00
|
|
|
MWWorld::DoorState Door::getDoorState (const MWWorld::ConstPtr &ptr) const
|
2014-05-14 23:58:44 +00:00
|
|
|
{
|
2015-12-19 14:57:37 +00:00
|
|
|
if (!ptr.getRefData().getCustomData())
|
2019-08-25 13:20:14 +00:00
|
|
|
return MWWorld::DoorState::Idle;
|
2015-11-29 13:13:14 +00:00
|
|
|
const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData();
|
2014-05-14 23:58:44 +00:00
|
|
|
return customData.mDoorState;
|
|
|
|
}
|
|
|
|
|
2019-08-25 13:20:14 +00:00
|
|
|
void Door::setDoorState (const MWWorld::Ptr &ptr, MWWorld::DoorState state) const
|
2014-05-14 23:58:44 +00:00
|
|
|
{
|
2014-09-11 03:48:46 +00:00
|
|
|
if (ptr.getCellRef().getTeleport())
|
|
|
|
throw std::runtime_error("load doors can't be moved");
|
|
|
|
|
2014-05-14 23:58:44 +00:00
|
|
|
ensureCustomData(ptr);
|
2015-11-29 13:13:14 +00:00
|
|
|
DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData();
|
2014-05-14 23:58:44 +00:00
|
|
|
customData.mDoorState = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Door::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const
|
|
|
|
{
|
2015-12-17 23:07:13 +00:00
|
|
|
if (!state.mHasCustomState)
|
|
|
|
return;
|
2020-03-17 10:15:19 +00:00
|
|
|
|
2014-05-14 23:58:44 +00:00
|
|
|
ensureCustomData(ptr);
|
2015-11-29 13:13:14 +00:00
|
|
|
DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData();
|
2020-03-17 10:15:19 +00:00
|
|
|
const ESM::DoorState& doorState = state.asDoorState();
|
|
|
|
customData.mDoorState = MWWorld::DoorState(doorState.mDoorState);
|
2014-05-14 23:58:44 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 23:18:06 +00:00
|
|
|
void Door::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const
|
2014-05-14 23:58:44 +00:00
|
|
|
{
|
2015-12-17 23:07:13 +00:00
|
|
|
if (!ptr.getRefData().getCustomData())
|
|
|
|
{
|
|
|
|
state.mHasCustomState = false;
|
|
|
|
return;
|
|
|
|
}
|
2014-05-14 23:58:44 +00:00
|
|
|
|
2020-03-17 10:15:19 +00:00
|
|
|
const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData();
|
|
|
|
ESM::DoorState& doorState = state.asDoorState();
|
|
|
|
doorState.mDoorState = int(customData.mDoorState);
|
2014-05-14 23:58:44 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 13:24:44 +00:00
|
|
|
}
|