From 33b57d9134f30f9e25b8a6acb1251d96cf3705e0 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 27 Sep 2023 21:23:07 +0200 Subject: [PATCH] Use moveToCell and init mwscript --- apps/openmw/mwclass/misc.cpp | 3 +-- apps/openmw/mwlua/objectbindings.cpp | 12 +++++++++--- apps/openmw/mwworld/class.cpp | 3 +-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index c5f9de23b1..6c517e3dde 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -205,8 +205,7 @@ namespace MWClass newPtr = MWWorld::Ptr(cell.insert(ref), &cell); newPtr.getRefData().setCount(count); } - if (ptr.getCell() != &MWBase::Environment::get().getWorldModel()->getDraftCell()) - newPtr.getCellRef().unsetRefNum(); + newPtr.getCellRef().unsetRefNum(); newPtr.getRefData().setLuaScripts(nullptr); MWBase::Environment::get().getWorldModel()->registerPtr(newPtr); return newPtr; diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index c607dc9d14..b2d5824629 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -11,6 +11,7 @@ #include "../mwworld/cellstore.hpp" #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/localscripts.hpp" #include "../mwworld/player.hpp" #include "../mwworld/scene.hpp" #include "../mwworld/worldmodel.hpp" @@ -112,17 +113,22 @@ namespace MWLua const MWWorld::Class& cls = ptr.getClass(); if (cls.isActor()) { - auto& stats = ptr.getClass().getCreatureStats(ptr); + auto& stats = cls.getCreatureStats(ptr); stats.land(false); stats.setTeleported(true); } + const MWWorld::CellStore* srcCell = ptr.getCell(); MWWorld::Ptr newPtr; - if (ptr.getCell() == &wm->getDraftCell()) + if (srcCell == &wm->getDraftCell()) { - newPtr = world->placeObject(ptr, destCell, toPos(pos, rot)); + newPtr = cls.moveToCell(ptr, *destCell, toPos(pos, rot)); ptr.getCellRef().unsetRefNum(); ptr.getRefData().setLuaScripts(nullptr); ptr.getRefData().setCount(0); + ESM::RefId script = cls.getScript(newPtr); + if (!script.empty()) + world->getLocalScripts().add(script, newPtr); + world->addContainerScripts(newPtr, newPtr.getCell()); } else { diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index c5e30fc5c3..de3c2b011d 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -372,8 +372,7 @@ namespace MWWorld MWWorld::Ptr Class::copyToCell(const ConstPtr& ptr, CellStore& cell, int count) const { 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().setLuaScripts(nullptr); MWBase::Environment::get().getWorldModel()->registerPtr(newPtr);