diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 95e2deee9..9c950c8ff 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -492,6 +492,15 @@ namespace MWScript { public: + osg::Vec3f getSpawnPosition(const osg::Vec3f& origin, const osg::Quat& orientation, int direction, float distance) + { + if(direction == 0) return origin + (orientation * osg::Vec3f(0,1,0)) * distance; + else if(direction == 1) return origin - (orientation * osg::Vec3f(0,1,0)) * distance; + else if(direction == 2) return origin - (orientation * osg::Vec3f(1,0,0)) * distance; + else if(direction == 3) return origin + (orientation * osg::Vec3f(1,0,0)) * distance; + else return origin; + } + virtual void execute (Interpreter::Runtime& runtime) { MWWorld::Ptr actor = pc @@ -514,40 +523,52 @@ namespace MWScript if (!actor.isInCell()) throw std::runtime_error ("actor is not in a cell"); - for (int i=0; icastRay(spawnPoint.x(), spawnPoint.y(), spawnPoint.z(), + pos.x(), pos.y(), pos.z() + 20)) { - ipos.rot[0] = actor.getRefData().getPosition().rot[0]; - ipos.rot[1] = actor.getRefData().getPosition().rot[1]; - ipos.rot[2] = actor.getRefData().getPosition().rot[2]; + // safe + ipos.pos[0] = spawnPoint.x(); + ipos.pos[1] = spawnPoint.y(); + ipos.pos[2] = spawnPoint.z(); + break; } + direction = (direction+1) % 4; + } + + if (actor.getClass().isActor()) + { + // TODO: should this depend on the 'direction' parameter? + ipos.rot[0] = 0; + ipos.rot[1] = 0; + ipos.rot[2] = 0; + } + else + { + ipos.rot[0] = actor.getRefData().getPosition().rot[0]; + ipos.rot[1] = actor.getRefData().getPosition().rot[1]; + ipos.rot[2] = actor.getRefData().getPosition().rot[2]; + } + + + for (int i=0; igetStore(), itemID, 1); ref.getPtr().getCellRef().setPosition(ipos); - MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,ipos); + MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(),store,ipos); + placed.getClass().adjustPosition(placed, true); // snap to ground } } };