mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-19 21:23:54 +00:00
Treat teleportation out of the draft cell as object creation
This commit is contained in:
parent
38f56cfcdd
commit
641f34a3c9
9 changed files with 40 additions and 17 deletions
|
@ -692,7 +692,7 @@ namespace MWClass
|
||||||
if (newPtr.getRefData().getCustomData())
|
if (newPtr.getRefData().getCustomData())
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
|
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
|
||||||
newPtr.getContainerStore()->setPtr(newPtr);
|
newPtr.getClass().getContainerStore(newPtr).setPtr(newPtr);
|
||||||
}
|
}
|
||||||
return newPtr;
|
return newPtr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,7 @@ namespace MWClass
|
||||||
newPtr = MWWorld::Ptr(cell.insert(ref), &cell);
|
newPtr = MWWorld::Ptr(cell.insert(ref), &cell);
|
||||||
newPtr.getRefData().setCount(count);
|
newPtr.getRefData().setCount(count);
|
||||||
}
|
}
|
||||||
|
if (ptr.getCell() != &MWBase::Environment::get().getWorldModel()->getDraftCell())
|
||||||
newPtr.getCellRef().unsetRefNum();
|
newPtr.getCellRef().unsetRefNum();
|
||||||
newPtr.getRefData().setLuaScripts(nullptr);
|
newPtr.getRefData().setLuaScripts(nullptr);
|
||||||
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
|
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
|
||||||
|
|
|
@ -1338,7 +1338,7 @@ namespace MWClass
|
||||||
if (newPtr.getRefData().getCustomData())
|
if (newPtr.getRefData().getCustomData())
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
|
MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);
|
||||||
newPtr.getContainerStore()->setPtr(newPtr);
|
newPtr.getClass().getContainerStore(newPtr).setPtr(newPtr);
|
||||||
}
|
}
|
||||||
return newPtr;
|
return newPtr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <components/esm3/loadcrea.hpp>
|
#include <components/esm3/loadcrea.hpp>
|
||||||
#include <components/esm3/loaddoor.hpp>
|
#include <components/esm3/loaddoor.hpp>
|
||||||
#include <components/esm3/loadingr.hpp>
|
#include <components/esm3/loadingr.hpp>
|
||||||
|
#include <components/esm3/loadlevlist.hpp>
|
||||||
#include <components/esm3/loadligh.hpp>
|
#include <components/esm3/loadligh.hpp>
|
||||||
#include <components/esm3/loadlock.hpp>
|
#include <components/esm3/loadlock.hpp>
|
||||||
#include <components/esm3/loadmisc.hpp>
|
#include <components/esm3/loadmisc.hpp>
|
||||||
|
@ -198,6 +199,9 @@ namespace MWLua
|
||||||
case ESM::REC_STAT:
|
case ESM::REC_STAT:
|
||||||
cell.mStore->template forEachType<ESM::Static>(visitor);
|
cell.mStore->template forEachType<ESM::Static>(visitor);
|
||||||
break;
|
break;
|
||||||
|
case ESM::REC_LEVC:
|
||||||
|
cell.mStore->template forEachType<ESM::CreatureLevList>(visitor);
|
||||||
|
break;
|
||||||
|
|
||||||
case ESM::REC_ACTI4:
|
case ESM::REC_ACTI4:
|
||||||
cell.mStore->template forEachType<ESM4::Activator>(visitor);
|
cell.mStore->template forEachType<ESM4::Activator>(visitor);
|
||||||
|
|
|
@ -77,20 +77,25 @@ namespace MWLua
|
||||||
return &wm->getExterior(ESM::positionToExteriorCellLocation(pos.x(), pos.y(), worldspace));
|
return &wm->getExterior(ESM::positionToExteriorCellLocation(pos.x(), pos.y(), worldspace));
|
||||||
}
|
}
|
||||||
|
|
||||||
void teleportPlayer(
|
ESM::Position toPos(const osg::Vec3f& pos, const osg::Vec3f& rot)
|
||||||
MWWorld::CellStore* destCell, const osg::Vec3f& pos, const osg::Vec3f& rot, bool placeOnGround)
|
|
||||||
{
|
{
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
|
||||||
ESM::Position esmPos;
|
ESM::Position esmPos;
|
||||||
static_assert(sizeof(esmPos) == sizeof(osg::Vec3f) * 2);
|
static_assert(sizeof(esmPos) == sizeof(osg::Vec3f) * 2);
|
||||||
std::memcpy(esmPos.pos, &pos, sizeof(osg::Vec3f));
|
std::memcpy(esmPos.pos, &pos, sizeof(osg::Vec3f));
|
||||||
std::memcpy(esmPos.rot, &rot, sizeof(osg::Vec3f));
|
std::memcpy(esmPos.rot, &rot, sizeof(osg::Vec3f));
|
||||||
|
return esmPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void teleportPlayer(
|
||||||
|
MWWorld::CellStore* destCell, const osg::Vec3f& pos, const osg::Vec3f& rot, bool placeOnGround)
|
||||||
|
{
|
||||||
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
MWWorld::Ptr ptr = world->getPlayerPtr();
|
MWWorld::Ptr ptr = world->getPlayerPtr();
|
||||||
auto& stats = ptr.getClass().getCreatureStats(ptr);
|
auto& stats = ptr.getClass().getCreatureStats(ptr);
|
||||||
stats.land(true);
|
stats.land(true);
|
||||||
stats.setTeleported(true);
|
stats.setTeleported(true);
|
||||||
world->getPlayer().setTeleported(true);
|
world->getPlayer().setTeleported(true);
|
||||||
world->changeToCell(destCell->getCell()->getId(), esmPos, false);
|
world->changeToCell(destCell->getCell()->getId(), toPos(pos, rot), false);
|
||||||
MWWorld::Ptr newPtr = world->getPlayerPtr();
|
MWWorld::Ptr newPtr = world->getPlayerPtr();
|
||||||
world->moveObject(newPtr, pos);
|
world->moveObject(newPtr, pos);
|
||||||
world->rotateObject(newPtr, rot);
|
world->rotateObject(newPtr, rot);
|
||||||
|
@ -103,6 +108,7 @@ namespace MWLua
|
||||||
const osg::Vec3f& rot, bool placeOnGround)
|
const osg::Vec3f& rot, bool placeOnGround)
|
||||||
{
|
{
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
|
MWWorld::WorldModel* wm = MWBase::Environment::get().getWorldModel();
|
||||||
const MWWorld::Class& cls = ptr.getClass();
|
const MWWorld::Class& cls = ptr.getClass();
|
||||||
if (cls.isActor())
|
if (cls.isActor())
|
||||||
{
|
{
|
||||||
|
@ -110,8 +116,19 @@ namespace MWLua
|
||||||
stats.land(false);
|
stats.land(false);
|
||||||
stats.setTeleported(true);
|
stats.setTeleported(true);
|
||||||
}
|
}
|
||||||
MWWorld::Ptr newPtr = world->moveObject(ptr, destCell, pos);
|
MWWorld::Ptr newPtr;
|
||||||
|
if (ptr.getCell() == &wm->getDraftCell())
|
||||||
|
{
|
||||||
|
newPtr = world->placeObject(ptr, destCell, toPos(pos, rot));
|
||||||
|
ptr.getCellRef().unsetRefNum();
|
||||||
|
ptr.getRefData().setLuaScripts(nullptr);
|
||||||
|
ptr.getRefData().setCount(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newPtr = world->moveObject(ptr, destCell, pos);
|
||||||
world->rotateObject(newPtr, rot, MWBase::RotationFlag_none);
|
world->rotateObject(newPtr, rot, MWBase::RotationFlag_none);
|
||||||
|
}
|
||||||
if (placeOnGround)
|
if (placeOnGround)
|
||||||
world->adjustPosition(newPtr, true);
|
world->adjustPosition(newPtr, true);
|
||||||
if (cls.isDoor())
|
if (cls.isDoor())
|
||||||
|
|
|
@ -1235,13 +1235,12 @@ namespace MWWorld
|
||||||
clearCorpse(ptr, mStore);
|
clearCorpse(ptr, mStore);
|
||||||
ptr.getClass().respawn(ptr);
|
ptr.getClass().respawn(ptr);
|
||||||
}
|
}
|
||||||
for (CellRefList<ESM::CreatureLevList>::List::iterator it(get<ESM::CreatureLevList>().mList.begin());
|
forEachType<ESM::CreatureLevList>([](Ptr ptr) {
|
||||||
it != get<ESM::CreatureLevList>().mList.end(); ++it)
|
|
||||||
{
|
|
||||||
Ptr ptr = getCurrentPtr(&*it);
|
|
||||||
// no need to clearCorpse, handled as part of get<ESM::Creature>()
|
// no need to clearCorpse, handled as part of get<ESM::Creature>()
|
||||||
|
if (!ptr.getRefData().isDeleted())
|
||||||
ptr.getClass().respawn(ptr);
|
ptr.getClass().respawn(ptr);
|
||||||
}
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,7 @@ namespace MWWorld
|
||||||
/// unintended behaviour. \attention This function also lists deleted (count 0) objects! \return Iteration
|
/// unintended behaviour. \attention This function also lists deleted (count 0) objects! \return Iteration
|
||||||
/// completed?
|
/// completed?
|
||||||
template <class T, class Visitor>
|
template <class T, class Visitor>
|
||||||
bool forEachType(Visitor& visitor)
|
bool forEachType(Visitor&& visitor)
|
||||||
{
|
{
|
||||||
if (mState != State_Loaded)
|
if (mState != State_Loaded)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -372,6 +372,7 @@ namespace MWWorld
|
||||||
MWWorld::Ptr Class::copyToCell(const ConstPtr& ptr, CellStore& cell, int count) const
|
MWWorld::Ptr Class::copyToCell(const ConstPtr& ptr, CellStore& cell, int count) const
|
||||||
{
|
{
|
||||||
Ptr newPtr = copyToCellImpl(ptr, cell);
|
Ptr newPtr = copyToCellImpl(ptr, cell);
|
||||||
|
if (ptr.getCell() != &MWBase::Environment::get().getWorldModel()->getDraftCell())
|
||||||
newPtr.getCellRef().unsetRefNum(); // This RefNum is only valid within the original cell of the reference
|
newPtr.getCellRef().unsetRefNum(); // This RefNum is only valid within the original cell of the reference
|
||||||
newPtr.getRefData().setCount(count);
|
newPtr.getRefData().setCount(count);
|
||||||
newPtr.getRefData().setLuaScripts(nullptr);
|
newPtr.getRefData().setLuaScripts(nullptr);
|
||||||
|
|
|
@ -134,6 +134,7 @@
|
||||||
---
|
---
|
||||||
-- Create a new instance of the given record.
|
-- Create a new instance of the given record.
|
||||||
-- After creation the object is in the disabled state. Use :teleport to place to the world or :moveInto to put it into a container or an inventory.
|
-- After creation the object is in the disabled state. Use :teleport to place to the world or :moveInto to put it into a container or an inventory.
|
||||||
|
-- Note that dynamically created creatures, NPCs, and container inventories will not respawn.
|
||||||
-- @function [parent=#world] createObject
|
-- @function [parent=#world] createObject
|
||||||
-- @param #string recordId Record ID in lowercase
|
-- @param #string recordId Record ID in lowercase
|
||||||
-- @param #number count (optional, 1 by default) The number of objects in stack
|
-- @param #number count (optional, 1 by default) The number of objects in stack
|
||||||
|
|
Loading…
Reference in a new issue