2018-08-14 23:05:43 +04:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2015-06-03 23:04:35 +02:00
|
|
|
|
2015-11-20 21:57:04 +01:00
|
|
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
2012-09-18 10:49:51 +02:00
|
|
|
|
|
|
|
#include <components/esm/loadcell.hpp>
|
2012-07-09 18:47:59 +02:00
|
|
|
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2012-07-09 18:47:59 +02:00
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
2015-02-09 17:45:48 +01:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-07-09 18:47:59 +02:00
|
|
|
|
2015-02-09 15:01:49 +01:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2012-07-09 18:47:59 +02:00
|
|
|
#include "../mwworld/class.hpp"
|
2012-09-18 10:49:51 +02:00
|
|
|
#include "../mwworld/manualref.hpp"
|
2014-01-08 18:39:44 +01:00
|
|
|
#include "../mwworld/player.hpp"
|
2012-07-09 18:47:59 +02:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2012-07-09 18:47:59 +02:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
#include "ref.hpp"
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Transformation
|
|
|
|
{
|
2018-08-25 10:34:33 +04:00
|
|
|
void moveStandingActors(const MWWorld::Ptr &ptr, const osg::Vec3f& diff)
|
|
|
|
{
|
|
|
|
std::vector<MWWorld::Ptr> actors;
|
|
|
|
MWBase::Environment::get().getWorld()->getActorsStandingOn (ptr, actors);
|
|
|
|
for (auto& actor : actors)
|
2021-05-01 14:13:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->moveObjectBy(actor, diff, false, false);
|
2018-08-25 10:34:33 +04:00
|
|
|
}
|
|
|
|
|
2020-05-13 21:17:08 +02:00
|
|
|
template<class R>
|
|
|
|
class OpGetDistance : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2020-05-13 21:17:08 +02:00
|
|
|
{
|
2021-03-11 20:37:38 +01:00
|
|
|
MWWorld::Ptr from = R()(runtime, !R::implicit);
|
2020-05-13 21:17:08 +02:00
|
|
|
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2021-03-11 20:37:38 +01:00
|
|
|
if (from.isEmpty())
|
|
|
|
{
|
|
|
|
std::string error = "Missing implicit ref";
|
|
|
|
runtime.getContext().report(error);
|
|
|
|
Log(Debug::Error) << error;
|
|
|
|
runtime.push(0.f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-13 21:17:08 +02:00
|
|
|
if (from.getContainerStore()) // is the object contained?
|
|
|
|
{
|
|
|
|
MWWorld::Ptr container = MWBase::Environment::get().getWorld()->findContainer(from);
|
|
|
|
|
|
|
|
if (!container.isEmpty())
|
|
|
|
from = container;
|
|
|
|
else
|
2020-05-22 14:04:26 +03:00
|
|
|
{
|
|
|
|
std::string error = "Failed to find the container of object '" + from.getCellRef().getRefId() + "'";
|
|
|
|
runtime.getContext().report(error);
|
|
|
|
Log(Debug::Error) << error;
|
|
|
|
runtime.push(0.f);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-13 21:17:08 +02:00
|
|
|
}
|
|
|
|
|
2020-05-22 14:04:26 +03:00
|
|
|
const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false);
|
|
|
|
if (to.isEmpty())
|
|
|
|
{
|
|
|
|
std::string error = "Failed to find an instance of object '" + name + "'";
|
|
|
|
runtime.getContext().report(error);
|
|
|
|
Log(Debug::Error) << error;
|
|
|
|
runtime.push(0.f);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-13 21:17:08 +02:00
|
|
|
|
|
|
|
float distance;
|
|
|
|
// If the objects are in different worldspaces, return a large value (just like vanilla)
|
|
|
|
if (!to.isInCell() || !from.isInCell() || to.getCell()->getCell()->getCellId().mWorldspace != from.getCell()->getCell()->getCellId().mWorldspace)
|
|
|
|
distance = std::numeric_limits<float>::max();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double diff[3];
|
|
|
|
|
|
|
|
const float* const pos1 = to.getRefData().getPosition().pos;
|
|
|
|
const float* const pos2 = from.getRefData().getPosition().pos;
|
|
|
|
for (int i=0; i<3; ++i)
|
|
|
|
diff[i] = pos1[i] - pos2[i];
|
|
|
|
|
|
|
|
distance = static_cast<float>(std::sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]));
|
|
|
|
}
|
|
|
|
|
|
|
|
runtime.push(distance);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-09 18:47:59 +02:00
|
|
|
template<class R>
|
|
|
|
class OpSetScale : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-07-09 18:47:59 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2012-07-09 19:28:44 +02:00
|
|
|
Interpreter::Type_Float scale = runtime[0].mFloat;
|
2012-07-09 18:47:59 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->scaleObject(ptr,scale);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-09 19:28:44 +02:00
|
|
|
template<class R>
|
|
|
|
class OpGetScale : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-07-09 19:28:44 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2014-05-25 14:13:07 +02:00
|
|
|
runtime.push(ptr.getCellRef().getScale());
|
2012-07-09 19:28:44 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-27 06:54:13 +01:00
|
|
|
template<class R>
|
|
|
|
class OpModScale : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-11-27 06:54:13 +01:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
Interpreter::Type_Float scale = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
// add the parameter to the object's scale.
|
2014-05-25 14:13:07 +02:00
|
|
|
MWBase::Environment::get().getWorld()->scaleObject(ptr,ptr.getCellRef().getScale() + scale);
|
2012-11-27 06:54:13 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-09 18:47:59 +02:00
|
|
|
template<class R>
|
|
|
|
class OpSetAngle : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-07-09 18:47:59 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
2015-11-12 01:08:31 +01:00
|
|
|
Interpreter::Type_Float angle = osg::DegreesToRadians(runtime[0].mFloat);
|
2012-07-09 18:47:59 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2015-11-12 01:08:31 +01:00
|
|
|
float ax = ptr.getRefData().getPosition().rot[0];
|
|
|
|
float ay = ptr.getRefData().getPosition().rot[1];
|
|
|
|
float az = ptr.getRefData().getPosition().rot[2];
|
2012-07-10 11:15:46 +02:00
|
|
|
|
2020-09-08 22:49:02 +03:00
|
|
|
// XYZ axis use the inverse (XYZ) rotation order like vanilla SetAngle.
|
|
|
|
// UWV axis use the standard (ZYX) rotation order like TESCS/OpenMW-CS and the rest of the game.
|
2012-08-04 09:18:20 +02:00
|
|
|
if (axis == "x")
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(angle,ay,az),MWBase::RotationFlag_inverseOrder);
|
2012-08-04 09:18:20 +02:00
|
|
|
else if (axis == "y")
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,angle,az),MWBase::RotationFlag_inverseOrder);
|
2012-08-04 09:18:20 +02:00
|
|
|
else if (axis == "z")
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,ay,angle),MWBase::RotationFlag_inverseOrder);
|
2020-09-08 22:49:02 +03:00
|
|
|
else if (axis == "u")
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(angle,ay,az),MWBase::RotationFlag_none);
|
2020-09-08 22:49:02 +03:00
|
|
|
else if (axis == "w")
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,angle,az),MWBase::RotationFlag_none);
|
2020-09-08 22:49:02 +03:00
|
|
|
else if (axis == "v")
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,osg::Vec3f(ax,ay,angle),MWBase::RotationFlag_none);
|
2012-07-09 18:47:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-09 19:28:44 +02:00
|
|
|
template<class R>
|
2012-08-01 12:21:42 +02:00
|
|
|
class OpGetStartingAngle : public Interpreter::Opcode0
|
2012-07-09 19:28:44 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-07-09 19:28:44 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2012-08-04 09:18:20 +02:00
|
|
|
if (axis == "x")
|
2012-07-09 19:28:44 +02:00
|
|
|
{
|
2015-06-03 21:37:21 +02:00
|
|
|
runtime.push(osg::RadiansToDegrees(ptr.getCellRef().getPosition().rot[0]));
|
2012-07-09 19:28:44 +02:00
|
|
|
}
|
2012-08-04 09:18:20 +02:00
|
|
|
else if (axis == "y")
|
2012-07-09 19:28:44 +02:00
|
|
|
{
|
2015-06-03 21:37:21 +02:00
|
|
|
runtime.push(osg::RadiansToDegrees(ptr.getCellRef().getPosition().rot[1]));
|
2012-07-09 19:28:44 +02:00
|
|
|
}
|
2012-08-04 09:18:20 +02:00
|
|
|
else if (axis == "z")
|
2012-07-09 19:28:44 +02:00
|
|
|
{
|
2015-06-03 21:37:21 +02:00
|
|
|
runtime.push(osg::RadiansToDegrees(ptr.getCellRef().getPosition().rot[2]));
|
2012-07-09 19:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-01 12:21:42 +02:00
|
|
|
template<class R>
|
|
|
|
class OpGetAngle : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-08-01 12:21:42 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
2012-08-02 14:57:35 +02:00
|
|
|
|
2012-08-04 09:18:20 +02:00
|
|
|
if (axis=="x")
|
2012-08-01 12:21:42 +02:00
|
|
|
{
|
2015-06-03 21:37:21 +02:00
|
|
|
runtime.push(osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[0]));
|
2012-08-01 12:21:42 +02:00
|
|
|
}
|
2012-08-04 09:18:20 +02:00
|
|
|
else if (axis=="y")
|
2012-08-01 12:21:42 +02:00
|
|
|
{
|
2015-06-03 21:37:21 +02:00
|
|
|
runtime.push(osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[1]));
|
2012-08-01 12:21:42 +02:00
|
|
|
}
|
2012-08-04 09:18:20 +02:00
|
|
|
else if (axis=="z")
|
2012-08-01 12:21:42 +02:00
|
|
|
{
|
2015-06-03 21:37:21 +02:00
|
|
|
runtime.push(osg::RadiansToDegrees(ptr.getRefData().getPosition().rot[2]));
|
2012-08-01 12:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-03 18:14:05 +02:00
|
|
|
template<class R>
|
|
|
|
class OpGetPos : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2012-08-05 16:21:53 +02:00
|
|
|
if(axis == "x")
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
|
|
|
runtime.push(ptr.getRefData().getPosition().pos[0]);
|
|
|
|
}
|
2012-08-09 23:50:44 +02:00
|
|
|
else if(axis == "y")
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
|
|
|
runtime.push(ptr.getRefData().getPosition().pos[1]);
|
|
|
|
}
|
2012-08-09 23:50:44 +02:00
|
|
|
else if(axis == "z")
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
|
|
|
runtime.push(ptr.getRefData().getPosition().pos[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class OpSetPos : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2014-01-02 03:06:48 +01:00
|
|
|
|
|
|
|
if (!ptr.isInCell())
|
|
|
|
return;
|
|
|
|
|
2012-08-03 18:14:05 +02:00
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float pos = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
|
2017-12-13 10:53:23 +04:00
|
|
|
// Note: SetPos does not skip weather transitions in vanilla engine, so we do not call setTeleported(true) here.
|
|
|
|
|
2021-03-13 09:53:21 +01:00
|
|
|
const auto curPos = ptr.getRefData().getPosition().asVec3();
|
|
|
|
auto newPos = curPos;
|
2012-08-05 16:21:53 +02:00
|
|
|
if(axis == "x")
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
2021-03-13 09:53:21 +01:00
|
|
|
newPos[0] = pos;
|
2012-08-03 18:14:05 +02:00
|
|
|
}
|
2012-08-09 23:50:44 +02:00
|
|
|
else if(axis == "y")
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
2021-03-13 09:53:21 +01:00
|
|
|
newPos[1] = pos;
|
2012-08-03 18:14:05 +02:00
|
|
|
}
|
2012-08-09 23:50:44 +02:00
|
|
|
else if(axis == "z")
|
2012-08-03 18:14:05 +02:00
|
|
|
{
|
2021-04-09 23:06:36 +02:00
|
|
|
// We should not place actors under ground
|
|
|
|
if (ptr.getClass().isActor())
|
|
|
|
{
|
|
|
|
float terrainHeight = -std::numeric_limits<float>::max();
|
|
|
|
if (ptr.getCell()->isExterior())
|
|
|
|
terrainHeight = MWBase::Environment::get().getWorld()->getTerrainHeightAt(curPos);
|
|
|
|
|
|
|
|
if (pos < terrainHeight)
|
|
|
|
pos = terrainHeight;
|
|
|
|
}
|
|
|
|
|
2021-03-13 09:53:21 +01:00
|
|
|
newPos[2] = pos;
|
2012-08-03 18:14:05 +02:00
|
|
|
}
|
2012-09-18 10:49:51 +02:00
|
|
|
else
|
2019-05-02 20:49:40 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-12-11 19:27:13 +01:00
|
|
|
|
2021-03-13 09:53:21 +01:00
|
|
|
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr,
|
2021-05-01 14:13:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->moveObjectBy(ptr, newPos - curPos, true, true));
|
2012-08-03 18:14:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-03 18:20:51 +02:00
|
|
|
template<class R>
|
|
|
|
class OpGetStartingPos : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-08-03 18:20:51 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2012-08-05 16:21:53 +02:00
|
|
|
if(axis == "x")
|
2012-08-03 18:20:51 +02:00
|
|
|
{
|
2014-05-25 14:13:07 +02:00
|
|
|
runtime.push(ptr.getCellRef().getPosition().pos[0]);
|
2012-08-03 18:20:51 +02:00
|
|
|
}
|
2012-08-09 23:50:44 +02:00
|
|
|
else if(axis == "y")
|
2012-08-03 18:20:51 +02:00
|
|
|
{
|
2014-05-25 14:13:07 +02:00
|
|
|
runtime.push(ptr.getCellRef().getPosition().pos[1]);
|
2012-08-03 18:20:51 +02:00
|
|
|
}
|
2012-08-09 23:50:44 +02:00
|
|
|
else if(axis == "z")
|
2012-08-03 18:20:51 +02:00
|
|
|
{
|
2014-05-25 14:13:07 +02:00
|
|
|
runtime.push(ptr.getCellRef().getPosition().pos[2]);
|
2012-08-03 18:20:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-09 23:45:06 +02:00
|
|
|
template<class R>
|
|
|
|
class OpPositionCell : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-08-09 23:45:06 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2014-01-02 03:06:48 +01:00
|
|
|
|
2014-05-19 14:09:16 +02:00
|
|
|
if (ptr.getContainerStore())
|
2014-01-02 03:06:48 +01:00
|
|
|
return;
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
if (ptr == MWMechanics::getPlayer())
|
2013-12-31 20:40:23 +01:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true);
|
|
|
|
}
|
2012-08-09 23:45:06 +02:00
|
|
|
|
|
|
|
Interpreter::Type_Float x = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float y = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float z = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float zRot = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
std::string cellID = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2020-11-13 11:39:47 +04:00
|
|
|
MWWorld::CellStore* store = nullptr;
|
2012-08-11 19:16:00 +02:00
|
|
|
try
|
|
|
|
{
|
2012-08-18 10:50:58 +02:00
|
|
|
store = MWBase::Environment::get().getWorld()->getInterior(cellID);
|
2012-08-11 19:16:00 +02:00
|
|
|
}
|
2014-05-14 20:12:52 -05:00
|
|
|
catch(std::exception&)
|
2012-08-11 09:52:49 +02:00
|
|
|
{
|
2015-12-06 22:37:04 +01:00
|
|
|
// cell not found, move to exterior instead (vanilla PositionCell compatibility)
|
2015-09-30 10:30:50 +02:00
|
|
|
const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID);
|
2015-03-02 11:53:59 -05:00
|
|
|
int cx,cy;
|
|
|
|
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
|
|
|
store = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
|
|
|
if(!cell)
|
2012-08-11 09:52:49 +02:00
|
|
|
{
|
2017-03-02 22:07:43 +01:00
|
|
|
std::string error = "Warning: PositionCell: unknown interior cell (" + cellID + "), moving to exterior instead";
|
2015-12-06 22:37:04 +01:00
|
|
|
runtime.getContext().report (error);
|
2018-08-14 23:05:43 +04:00
|
|
|
Log(Debug::Warning) << error;
|
2012-09-02 17:57:03 +02:00
|
|
|
}
|
2012-08-11 09:52:49 +02:00
|
|
|
}
|
|
|
|
if(store)
|
2012-08-09 23:45:06 +02:00
|
|
|
{
|
2015-09-30 10:30:50 +02:00
|
|
|
MWWorld::Ptr base = ptr;
|
2021-04-11 18:18:10 +02:00
|
|
|
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr,store,osg::Vec3f(x,y,z));
|
2015-09-30 10:30:50 +02:00
|
|
|
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base,ptr);
|
2014-12-11 19:27:13 +01:00
|
|
|
|
2021-04-11 19:17:17 +02:00
|
|
|
auto rot = ptr.getRefData().getPosition().asRotationVec3();
|
2014-12-01 16:43:55 +01:00
|
|
|
// 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 "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
|
2015-08-21 21:12:39 +12:00
|
|
|
if(ptr != MWMechanics::getPlayer())
|
2015-03-08 13:07:29 +13:00
|
|
|
zRot = zRot/60.0f;
|
2021-04-11 19:17:17 +02:00
|
|
|
rot.z() = osg::DegreesToRadians(zRot);
|
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,rot);
|
2013-04-03 23:55:57 +02:00
|
|
|
|
2014-07-31 04:24:45 +02:00
|
|
|
ptr.getClass().adjustPosition(ptr, false);
|
2012-08-18 10:50:58 +02:00
|
|
|
}
|
2012-08-09 23:45:06 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-05 16:44:56 +02:00
|
|
|
template<class R>
|
|
|
|
class OpPosition : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-08-05 16:44:56 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2014-01-02 03:06:48 +01:00
|
|
|
|
|
|
|
if (!ptr.isInCell())
|
|
|
|
return;
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
if (ptr == MWMechanics::getPlayer())
|
2013-12-31 20:40:23 +01:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true);
|
|
|
|
}
|
2012-08-05 16:44:56 +02:00
|
|
|
|
|
|
|
Interpreter::Type_Float x = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float y = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float z = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float zRot = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
2012-08-11 18:07:20 +02:00
|
|
|
int cx,cy;
|
|
|
|
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
2014-08-11 02:01:20 +02:00
|
|
|
|
|
|
|
// 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.
|
2015-09-30 10:30:50 +02:00
|
|
|
MWWorld::Ptr base = ptr;
|
2015-08-21 21:12:39 +12:00
|
|
|
if (ptr == MWMechanics::getPlayer())
|
2014-08-11 02:01:20 +02:00
|
|
|
{
|
2014-12-11 19:27:13 +01:00
|
|
|
MWWorld::CellStore* cell = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
2021-04-11 18:18:10 +02:00
|
|
|
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, cell, osg::Vec3(x, y, z));
|
2014-08-11 02:01:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-11 18:18:10 +02:00
|
|
|
ptr = MWBase::Environment::get().getWorld()->moveObject(ptr, osg::Vec3f(x, y, z), true, true);
|
2014-08-11 02:01:20 +02:00
|
|
|
}
|
2015-09-30 10:30:50 +02:00
|
|
|
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(base,ptr);
|
2014-08-11 02:01:20 +02:00
|
|
|
|
2021-04-11 19:17:17 +02:00
|
|
|
auto rot = ptr.getRefData().getPosition().asRotationVec3();
|
2014-12-01 16:43:55 +01:00
|
|
|
// 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 "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference.
|
2015-08-21 21:12:39 +12:00
|
|
|
if(ptr != MWMechanics::getPlayer())
|
2015-03-08 13:07:29 +13:00
|
|
|
zRot = zRot/60.0f;
|
2021-04-11 19:17:17 +02:00
|
|
|
rot.z() = osg::DegreesToRadians(zRot);
|
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,rot);
|
2014-07-31 04:24:45 +02:00
|
|
|
ptr.getClass().adjustPosition(ptr, false);
|
2012-08-05 16:44:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-02 17:57:03 +02:00
|
|
|
class OpPlaceItemCell : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
|
|
|
std::string itemID = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
std::string cellID = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Float x = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float y = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float z = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
2015-11-11 21:19:50 +01:00
|
|
|
Interpreter::Type_Float zRotDegrees = runtime[0].mFloat;
|
2012-09-02 17:57:03 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2020-11-13 11:39:47 +04:00
|
|
|
MWWorld::CellStore* store = nullptr;
|
2012-09-02 17:57:03 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
store = MWBase::Environment::get().getWorld()->getInterior(cellID);
|
|
|
|
}
|
2014-05-14 20:12:52 -05:00
|
|
|
catch(std::exception&)
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
|
|
|
const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID);
|
2015-03-02 11:53:59 -05:00
|
|
|
int cx,cy;
|
|
|
|
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
|
|
|
store = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
|
|
|
if(!cell)
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
2015-03-03 17:36:22 -05:00
|
|
|
runtime.getContext().report ("unknown cell (" + cellID + ")");
|
2018-08-14 23:05:43 +04:00
|
|
|
Log(Debug::Error) << "Error: unknown cell (" << cellID << ")";
|
2012-09-02 17:57:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(store)
|
|
|
|
{
|
|
|
|
ESM::Position pos;
|
|
|
|
pos.pos[0] = x;
|
|
|
|
pos.pos[1] = y;
|
|
|
|
pos.pos[2] = z;
|
|
|
|
pos.rot[0] = pos.rot[1] = 0;
|
2015-11-11 21:19:50 +01:00
|
|
|
pos.rot[2] = osg::DegreesToRadians(zRotDegrees);
|
2012-09-17 14:12:27 +02:00
|
|
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(),itemID);
|
2021-03-05 22:21:53 +01:00
|
|
|
ref.getPtr().mRef->mData.mPhysicsPostponed = !ref.getPtr().getClass().isActor();
|
2014-05-25 14:13:07 +02:00
|
|
|
ref.getPtr().getCellRef().setPosition(pos);
|
2016-02-29 17:05:18 +01:00
|
|
|
MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(ref.getPtr(),store,pos);
|
2014-12-11 22:25:53 +01:00
|
|
|
placed.getClass().adjustPosition(placed, true);
|
2012-09-02 17:57:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpPlaceItem : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
|
|
|
std::string itemID = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Float x = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float y = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float z = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
2015-11-11 21:19:50 +01:00
|
|
|
Interpreter::Type_Float zRotDegrees = runtime[0].mFloat;
|
2012-09-02 17:57:03 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
2015-12-09 00:48:51 +01:00
|
|
|
|
|
|
|
if (!player.isInCell())
|
|
|
|
throw std::runtime_error("player not in a cell");
|
|
|
|
|
2018-10-09 10:21:12 +04:00
|
|
|
MWWorld::CellStore* store = nullptr;
|
2014-09-08 23:57:16 +02:00
|
|
|
if (player.getCell()->isExterior())
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
2014-09-08 23:57:16 +02:00
|
|
|
int cx,cy;
|
|
|
|
MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy);
|
|
|
|
store = MWBase::Environment::get().getWorld()->getExterior(cx,cy);
|
2012-09-02 17:57:03 +02:00
|
|
|
}
|
|
|
|
else
|
2014-09-08 23:57:16 +02:00
|
|
|
store = player.getCell();
|
|
|
|
|
|
|
|
ESM::Position pos;
|
|
|
|
pos.pos[0] = x;
|
|
|
|
pos.pos[1] = y;
|
|
|
|
pos.pos[2] = z;
|
|
|
|
pos.rot[0] = pos.rot[1] = 0;
|
2015-11-11 21:19:50 +01:00
|
|
|
pos.rot[2] = osg::DegreesToRadians(zRotDegrees);
|
2014-09-08 23:57:16 +02:00
|
|
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(),itemID);
|
2021-03-05 22:21:53 +01:00
|
|
|
ref.getPtr().mRef->mData.mPhysicsPostponed = !ref.getPtr().getClass().isActor();
|
2014-09-08 23:57:16 +02:00
|
|
|
ref.getPtr().getCellRef().setPosition(pos);
|
2016-02-29 17:05:18 +01:00
|
|
|
MWWorld::Ptr placed = MWBase::Environment::get().getWorld()->placeObject(ref.getPtr(),store,pos);
|
2014-12-11 22:25:53 +01:00
|
|
|
placed.getClass().adjustPosition(placed, true);
|
2012-09-02 17:57:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-14 21:49:21 +02:00
|
|
|
template<class R, bool pc>
|
|
|
|
class OpPlaceAt : public Interpreter::Opcode0
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-09-02 17:57:03 +02:00
|
|
|
{
|
2013-10-14 21:49:21 +02:00
|
|
|
MWWorld::Ptr actor = pc
|
2015-08-21 21:12:39 +12:00
|
|
|
? MWMechanics::getPlayer()
|
2013-10-14 21:49:21 +02:00
|
|
|
: R()(runtime);
|
2012-09-02 17:57:03 +02:00
|
|
|
|
|
|
|
std::string itemID = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer count = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float distance = runtime[0].mFloat;
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Integer direction = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
2016-06-02 21:19:02 +02:00
|
|
|
if (direction < 0 || direction > 3)
|
|
|
|
throw std::runtime_error ("invalid direction");
|
|
|
|
|
2013-04-06 19:25:29 +02:00
|
|
|
if (count<0)
|
|
|
|
throw std::runtime_error ("count must be non-negative");
|
|
|
|
|
2015-12-09 00:48:51 +01:00
|
|
|
if (!actor.isInCell())
|
|
|
|
throw std::runtime_error ("actor is not in a cell");
|
|
|
|
|
2016-02-29 16:54:00 +01:00
|
|
|
for (int i=0; i<count; ++i)
|
|
|
|
{
|
2015-01-31 17:58:10 +01:00
|
|
|
// create item
|
|
|
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), itemID, 1);
|
2021-03-05 22:21:53 +01:00
|
|
|
ref.getPtr().mRef->mData.mPhysicsPostponed = !ref.getPtr().getClass().isActor();
|
2012-09-17 13:36:48 +02:00
|
|
|
|
2018-04-19 23:43:13 +03:00
|
|
|
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(), actor, actor.getCell(), direction, distance);
|
|
|
|
MWBase::Environment::get().getWorld()->scaleObject(ptr, actor.getCellRef().getScale());
|
2013-11-30 08:29:22 +01:00
|
|
|
}
|
2012-09-02 17:57:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-10 22:53:03 +02:00
|
|
|
template<class R>
|
|
|
|
class OpRotate : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2013-04-10 22:53:03 +02:00
|
|
|
{
|
2013-04-15 16:45:53 +02:00
|
|
|
const MWWorld::Ptr& ptr = R()(runtime);
|
2013-04-10 22:53:03 +02:00
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
2015-11-12 01:16:37 +01:00
|
|
|
Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
|
2013-04-10 22:53:03 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2021-04-11 19:17:17 +02:00
|
|
|
auto rot = ptr.getRefData().getPosition().asRotationVec3();
|
2013-04-14 21:42:37 +02:00
|
|
|
if (axis == "x")
|
2021-04-11 19:17:17 +02:00
|
|
|
rot.x() += rotation;
|
2013-04-14 21:42:37 +02:00
|
|
|
else if (axis == "y")
|
2021-04-11 19:17:17 +02:00
|
|
|
rot.y() += rotation;
|
2013-04-10 22:53:03 +02:00
|
|
|
else if (axis == "z")
|
2021-04-11 19:17:17 +02:00
|
|
|
rot.z() += rotation;
|
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr,rot);
|
2013-04-10 22:53:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-15 16:45:53 +02:00
|
|
|
template<class R>
|
|
|
|
class OpRotateWorld : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2013-04-15 16:45:53 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
2015-11-12 01:08:31 +01:00
|
|
|
Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
|
2013-04-15 16:45:53 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2018-05-30 14:43:07 +04:00
|
|
|
if (!ptr.getRefData().getBaseNode())
|
|
|
|
return;
|
2013-04-15 16:45:53 +02:00
|
|
|
|
2018-05-30 14:43:07 +04:00
|
|
|
// We can rotate actors only around Z axis
|
|
|
|
if (ptr.getClass().isActor() && (axis == "x" || axis == "y"))
|
|
|
|
return;
|
2013-04-15 16:45:53 +02:00
|
|
|
|
2018-05-30 14:43:07 +04:00
|
|
|
osg::Quat rot;
|
2013-04-15 16:45:53 +02:00
|
|
|
if (axis == "x")
|
2018-05-30 14:43:07 +04:00
|
|
|
rot = osg::Quat(rotation, -osg::X_AXIS);
|
2013-04-15 16:45:53 +02:00
|
|
|
else if (axis == "y")
|
2018-05-30 14:43:07 +04:00
|
|
|
rot = osg::Quat(rotation, -osg::Y_AXIS);
|
2013-04-15 16:45:53 +02:00
|
|
|
else if (axis == "z")
|
2018-05-30 14:43:07 +04:00
|
|
|
rot = osg::Quat(rotation, -osg::Z_AXIS);
|
2013-04-15 16:45:53 +02:00
|
|
|
else
|
2019-05-02 20:49:40 +03:00
|
|
|
return;
|
2018-05-30 14:43:07 +04:00
|
|
|
|
|
|
|
osg::Quat attitude = ptr.getRefData().getBaseNode()->getAttitude();
|
|
|
|
MWBase::Environment::get().getWorld()->rotateWorldObject(ptr, attitude * rot);
|
2013-04-15 16:45:53 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-26 02:02:51 +02:00
|
|
|
template<class R>
|
|
|
|
class OpSetAtStart : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2013-04-26 02:02:51 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
2014-01-02 03:06:48 +01:00
|
|
|
|
|
|
|
if (!ptr.isInCell())
|
|
|
|
return;
|
|
|
|
|
2021-04-11 19:17:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->rotateObject(ptr, ptr.getCellRef().getPosition().asRotationVec3());
|
2014-12-11 19:27:13 +01:00
|
|
|
|
2015-09-30 10:30:50 +02:00
|
|
|
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr,
|
2021-04-11 18:18:10 +02:00
|
|
|
MWBase::Environment::get().getWorld()->moveObject(ptr, ptr.getCellRef().getPosition().asVec3()));
|
2013-04-26 02:02:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-26 17:28:19 +02:00
|
|
|
template<class R>
|
|
|
|
class OpMove : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2013-04-26 17:28:19 +02:00
|
|
|
{
|
|
|
|
const MWWorld::Ptr& ptr = R()(runtime);
|
|
|
|
|
2014-01-02 03:06:48 +01:00
|
|
|
if (!ptr.isInCell())
|
|
|
|
return;
|
|
|
|
|
2013-04-26 17:28:19 +02:00
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
|
|
|
|
runtime.pop();
|
|
|
|
|
2015-05-12 19:02:56 +02:00
|
|
|
osg::Vec3f posChange;
|
2013-04-26 17:28:19 +02:00
|
|
|
if (axis == "x")
|
|
|
|
{
|
2015-05-12 19:02:56 +02:00
|
|
|
posChange=osg::Vec3f(movement, 0, 0);
|
2013-04-26 17:28:19 +02:00
|
|
|
}
|
|
|
|
else if (axis == "y")
|
|
|
|
{
|
2015-05-12 19:02:56 +02:00
|
|
|
posChange=osg::Vec3f(0, movement, 0);
|
2013-04-26 17:28:19 +02:00
|
|
|
}
|
|
|
|
else if (axis == "z")
|
|
|
|
{
|
2015-05-12 19:02:56 +02:00
|
|
|
posChange=osg::Vec3f(0, 0, movement);
|
2013-04-26 17:28:19 +02:00
|
|
|
}
|
|
|
|
else
|
2019-05-02 20:49:40 +03:00
|
|
|
return;
|
2013-04-26 17:28:19 +02:00
|
|
|
|
2015-05-12 19:02:56 +02:00
|
|
|
// is it correct that disabled objects can't be Move-d?
|
|
|
|
if (!ptr.getRefData().getBaseNode())
|
2014-12-27 17:20:37 +01:00
|
|
|
return;
|
|
|
|
|
2015-05-12 19:02:56 +02:00
|
|
|
osg::Vec3f diff = ptr.getRefData().getBaseNode()->getAttitude() * posChange;
|
2018-08-25 10:34:33 +04:00
|
|
|
|
|
|
|
// We should move actors, standing on moving object, too.
|
|
|
|
// This approach can be used to create elevators.
|
|
|
|
moveStandingActors(ptr, diff);
|
2020-07-11 17:24:20 +04:00
|
|
|
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr,
|
2021-05-01 14:13:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->moveObjectBy(ptr, diff, false, true));
|
2013-04-26 17:28:19 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class OpMoveWorld : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2013-04-26 17:28:19 +02:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2014-01-02 03:06:48 +01:00
|
|
|
if (!ptr.isInCell())
|
|
|
|
return;
|
|
|
|
|
2013-04-26 17:28:19 +02:00
|
|
|
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
|
|
|
|
runtime.pop();
|
|
|
|
|
2018-08-25 10:34:33 +04:00
|
|
|
osg::Vec3f diff;
|
2013-04-26 17:28:19 +02:00
|
|
|
|
|
|
|
if (axis == "x")
|
2020-12-18 08:18:07 +01:00
|
|
|
diff.x() = movement;
|
2013-04-26 17:28:19 +02:00
|
|
|
else if (axis == "y")
|
2020-12-18 08:18:07 +01:00
|
|
|
diff.y() = movement;
|
2013-04-26 17:28:19 +02:00
|
|
|
else if (axis == "z")
|
2020-12-18 08:18:07 +01:00
|
|
|
diff.z() = movement;
|
2013-04-26 17:28:19 +02:00
|
|
|
else
|
2019-05-02 20:49:40 +03:00
|
|
|
return;
|
2018-08-25 10:34:33 +04:00
|
|
|
|
|
|
|
// We should move actors, standing on moving object, too.
|
|
|
|
// This approach can be used to create elevators.
|
|
|
|
moveStandingActors(ptr, diff);
|
2020-07-11 17:24:20 +04:00
|
|
|
dynamic_cast<MWScript::InterpreterContext&>(runtime.getContext()).updatePtr(ptr,
|
2021-05-01 14:13:17 +02:00
|
|
|
MWBase::Environment::get().getWorld()->moveObjectBy(ptr, diff, false, true));
|
2013-04-26 17:28:19 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-30 17:55:35 +02:00
|
|
|
class OpResetActors : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2014-08-30 17:55:35 +02:00
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld()->resetActors();
|
|
|
|
}
|
|
|
|
};
|
2013-04-26 17:28:19 +02:00
|
|
|
|
2016-01-20 04:07:07 +01:00
|
|
|
class OpFixme : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2016-01-20 04:07:07 +01:00
|
|
|
{
|
2018-10-24 01:40:57 +03:00
|
|
|
MWBase::Environment::get().getWorld()->fixPosition();
|
2016-01-20 04:07:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-09 18:47:59 +02:00
|
|
|
void installOpcodes (Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2020-05-13 21:17:08 +02:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetDistance, new OpGetDistance<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetDistanceExplicit, new OpGetDistance<ExplicitRef>);
|
2013-08-06 20:38:41 -04:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetScale,new OpSetScale<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetScaleExplicit,new OpSetScale<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetAngle,new OpSetAngle<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetAngleExplicit,new OpSetAngle<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetScale,new OpGetScale<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetScaleExplicit,new OpGetScale<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetAngle,new OpGetAngle<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetAngleExplicit,new OpGetAngle<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetPos,new OpGetPos<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetPosExplicit,new OpGetPos<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetPos,new OpSetPos<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetPosExplicit,new OpSetPos<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetStartingPos,new OpGetStartingPos<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetStartingPosExplicit,new OpGetStartingPos<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePosition,new OpPosition<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePositionExplicit,new OpPosition<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePositionCell,new OpPositionCell<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePositionCellExplicit,new OpPositionCell<ExplicitRef>);
|
2020-05-05 19:18:23 +02:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePlaceItemCell,new OpPlaceItemCell);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePlaceItem,new OpPlaceItem);
|
2013-10-14 21:49:21 +02:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePlaceAtPc,new OpPlaceAt<ImplicitRef, true>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePlaceAtMe,new OpPlaceAt<ImplicitRef, false>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodePlaceAtMeExplicit,new OpPlaceAt<ExplicitRef, false>);
|
2013-08-06 20:38:41 -04:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeModScale,new OpModScale<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeModScaleExplicit,new OpModScale<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeRotate,new OpRotate<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeRotateExplicit,new OpRotate<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeRotateWorld,new OpRotateWorld<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeRotateWorldExplicit,new OpRotateWorld<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetAtStart,new OpSetAtStart<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeSetAtStartExplicit,new OpSetAtStart<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeMove,new OpMove<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeMoveExplicit,new OpMove<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeMoveWorld,new OpMoveWorld<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeMoveWorldExplicit,new OpMoveWorld<ExplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetStartingAngle, new OpGetStartingAngle<ImplicitRef>);
|
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeGetStartingAngleExplicit, new OpGetStartingAngle<ExplicitRef>);
|
2014-08-30 17:55:35 +02:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeResetActors, new OpResetActors);
|
2018-09-13 13:21:38 +04:00
|
|
|
interpreter.installSegment5(Compiler::Transformation::opcodeFixme, new OpFixme);
|
2012-07-09 18:47:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|