Merge branch 'flying_position' into 'master'

Only force adjust the player and NPCs teleported out of the active grid

See merge request OpenMW/openmw!2488
7098-improve-post-process-behavior-with-transparent-objects
psi29a 2 years ago
commit 45e673564f

@ -387,21 +387,22 @@ namespace MWScript
return; return;
bool isPlayer = ptr == MWMechanics::getPlayer(); bool isPlayer = ptr == MWMechanics::getPlayer();
auto world = MWBase::Environment::get().getWorld();
if (isPlayer) if (isPlayer)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true); world->getPlayer().setTeleported(true);
} }
MWWorld::CellStore* store = nullptr; MWWorld::CellStore* store = nullptr;
try try
{ {
store = MWBase::Environment::get().getWorld()->getInterior(cellID); store = world->getInterior(cellID);
} }
catch (std::exception&) catch (std::exception&)
{ {
// cell not found, move to exterior instead if moving the player (vanilla PositionCell // cell not found, move to exterior instead if moving the player (vanilla PositionCell
// compatibility) // compatibility)
const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID); const ESM::Cell* cell = world->getExterior(cellID);
if (!cell) if (!cell)
{ {
std::string error std::string error
@ -414,12 +415,12 @@ namespace MWScript
return; return;
} }
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
store = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y()); store = world->getExterior(cellIndex.x(), cellIndex.y());
} }
if (store) if (store)
{ {
MWWorld::Ptr base = ptr; MWWorld::Ptr base = ptr;
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, store, osg::Vec3f(x, y, z)); ptr = world->moveObject(ptr, store, osg::Vec3f(x, y, z));
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base, ptr); dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base, ptr);
auto rot = ptr.getRefData().getPosition().asRotationVec3(); auto rot = ptr.getRefData().getPosition().asRotationVec3();
@ -429,9 +430,9 @@ namespace MWScript
if (!isPlayer) if (!isPlayer)
zRot = zRot / 60.0f; zRot = zRot / 60.0f;
rot.z() = osg::DegreesToRadians(zRot); rot.z() = osg::DegreesToRadians(zRot);
MWBase::Environment::get().getWorld()->rotateObject(ptr, rot); world->rotateObject(ptr, rot);
ptr.getClass().adjustPosition(ptr, true); ptr.getClass().adjustPosition(ptr, isPlayer || !world->isCellActive(ptr.getCell()));
} }
} }
}; };
@ -456,24 +457,25 @@ namespace MWScript
if (!ptr.isInCell()) if (!ptr.isInCell())
return; return;
if (ptr == MWMechanics::getPlayer()) bool isPlayer = ptr == MWMechanics::getPlayer();
auto world = MWBase::Environment::get().getWorld();
if (isPlayer)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true); world->getPlayer().setTeleported(true);
} }
const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y);
// another morrowind oddity: player will be moved to the exterior cell at this location, // another morrowind oddity: player will be moved to the exterior cell at this location,
// non-player actors will move within the cell they are in. // non-player actors will move within the cell they are in.
MWWorld::Ptr base = ptr; MWWorld::Ptr base = ptr;
if (ptr == MWMechanics::getPlayer()) if (isPlayer)
{ {
MWWorld::CellStore* cell MWWorld::CellStore* cell = world->getExterior(cellIndex.x(), cellIndex.y());
= MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y()); ptr = world->moveObject(ptr, cell, osg::Vec3(x, y, z));
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, cell, osg::Vec3(x, y, z));
} }
else else
{ {
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, osg::Vec3f(x, y, z), true, true); ptr = world->moveObject(ptr, osg::Vec3f(x, y, z), true, true);
} }
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base, ptr); dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base, ptr);
@ -481,11 +483,11 @@ namespace MWScript
// Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = // Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south =
// 10800, west = 16200) except for when you position the player, then degrees must be used. See // 10800, west = 16200) except for when you position the player, then degrees must be used. See
// "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference. // "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
if (ptr != MWMechanics::getPlayer()) if (!isPlayer)
zRot = zRot / 60.0f; zRot = zRot / 60.0f;
rot.z() = osg::DegreesToRadians(zRot); rot.z() = osg::DegreesToRadians(zRot);
MWBase::Environment::get().getWorld()->rotateObject(ptr, rot); world->rotateObject(ptr, rot);
ptr.getClass().adjustPosition(ptr, true); ptr.getClass().adjustPosition(ptr, isPlayer || !world->isCellActive(ptr.getCell()));
} }
}; };

Loading…
Cancel
Save