From 3a0e374dc6c0dab3eb24c1876817ab082299be35 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sun, 31 Mar 2019 14:02:24 +0300 Subject: [PATCH] Replicate vanilla Position/SetPos behavior more closely (bug #3109) --- CHANGELOG.md | 1 + apps/openmw/mwbase/world.hpp | 2 +- .../mwscript/transformationextensions.cpp | 8 ++++---- apps/openmw/mwworld/worldimp.cpp | 19 ++++++++++--------- apps/openmw/mwworld/worldimp.hpp | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index deb5c88d1c..ac6d6483c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Bug #2969: Scripted items can stack Bug #2987: Editor: some chance and AI data fields can overflow Bug #3006: 'else if' operator breaks script compilation + Bug #3109: SetPos/Position handles actors differently Bug #3282: Unintended behaviour when assigning F3 and Windows keys Bug #3623: Fix HiDPI on Windows Bug #3733: Normal maps are inverted on mirrored UVs diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index d3bdb419ed..f5ca91dc6a 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -278,7 +278,7 @@ namespace MWBase virtual void deleteObject (const MWWorld::Ptr& ptr) = 0; virtual void undeleteObject (const MWWorld::Ptr& ptr) = 0; - virtual MWWorld::Ptr moveObject (const MWWorld::Ptr& ptr, float x, float y, float z) = 0; + virtual MWWorld::Ptr moveObject (const MWWorld::Ptr& ptr, float x, float y, float z, bool moveToActive=false) = 0; ///< @return an updated Ptr in case the Ptr's cell changes virtual MWWorld::Ptr moveObject(const MWWorld::Ptr &ptr, MWWorld::CellStore* newCell, float x, float y, float z, bool movePhysics=true) = 0; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 0d0d6f29e3..93645d5fba 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -226,11 +226,11 @@ namespace MWScript MWWorld::Ptr updated = ptr; if(axis == "x") { - updated = MWBase::Environment::get().getWorld()->moveObject(ptr,pos,ay,az); + updated = MWBase::Environment::get().getWorld()->moveObject(ptr,pos,ay,az,true); } else if(axis == "y") { - updated = MWBase::Environment::get().getWorld()->moveObject(ptr,ax,pos,az); + updated = MWBase::Environment::get().getWorld()->moveObject(ptr,ax,pos,az,true); } else if(axis == "z") { @@ -245,7 +245,7 @@ namespace MWScript pos = terrainHeight; } - updated = MWBase::Environment::get().getWorld()->moveObject(ptr,ax,ay,pos); + updated = MWBase::Environment::get().getWorld()->moveObject(ptr,ax,ay,pos,true); } else throw std::runtime_error ("invalid axis: " + axis); @@ -388,7 +388,7 @@ namespace MWScript } else { - ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, x, y, z); + ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, x, y, z, true); } dynamic_cast(runtime.getContext()).updatePtr(base,ptr); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1d33d039eb..7455bd28ef 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1307,23 +1307,24 @@ namespace MWWorld return newPtr; } - MWWorld::Ptr World::moveObjectImp(const Ptr& ptr, float x, float y, float z, bool movePhysics) + MWWorld::Ptr World::moveObjectImp(const Ptr& ptr, float x, float y, float z, bool movePhysics, bool moveToActive) { - CellStore *cell = ptr.getCell(); + int cellX, cellY; + positionToIndex(x, y, cellX, cellY); - if (cell->isExterior()) { - int cellX, cellY; - positionToIndex(x, y, cellX, cellY); + CellStore* cell = ptr.getCell(); + CellStore* newCell = getExterior(cellX, cellY); + bool isCellActive = getPlayerPtr().getCell()->isExterior() && mWorldScene->isCellActive(*newCell); - cell = getExterior(cellX, cellY); - } + if (cell->isExterior() || (moveToActive && isCellActive && ptr.getClass().isActor())) + cell = newCell; return moveObject(ptr, cell, x, y, z, movePhysics); } - MWWorld::Ptr World::moveObject (const Ptr& ptr, float x, float y, float z) + MWWorld::Ptr World::moveObject (const Ptr& ptr, float x, float y, float z, bool moveToActive) { - return moveObjectImp(ptr, x, y, z); + return moveObjectImp(ptr, x, y, z, true, moveToActive); } void World::scaleObject (const Ptr& ptr, float scale) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index d3e445cff8..8eae2a0efa 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -130,7 +130,7 @@ namespace MWWorld void rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust); - Ptr moveObjectImp (const Ptr& ptr, float x, float y, float z, bool movePhysics=true); + Ptr moveObjectImp (const Ptr& ptr, float x, float y, float z, bool movePhysics=true, bool moveToActive=false); ///< @return an updated Ptr in case the Ptr's cell changes Ptr copyObjectToCell(const ConstPtr &ptr, CellStore* cell, ESM::Position pos, int count, bool adjustPos); @@ -382,7 +382,7 @@ namespace MWWorld void undeleteObject (const Ptr& ptr) override; - MWWorld::Ptr moveObject (const Ptr& ptr, float x, float y, float z) override; + MWWorld::Ptr moveObject (const Ptr& ptr, float x, float y, float z, bool moveToActive=false) override; ///< @return an updated Ptr in case the Ptr's cell changes MWWorld::Ptr moveObject (const Ptr& ptr, CellStore* newCell, float x, float y, float z, bool movePhysics=true) override;