You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw/mwscript/transformationextensions.cpp

244 lines
9.2 KiB
C++

13 years ago
#include <boost/algorithm/string.hpp>
#include <components/esm_store/store.hpp>
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/class.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
#include "OgreSceneNode.h"
13 years ago
namespace MWScript
{
namespace Transformation
{
template<class R>
class OpSetScale : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Float scale = runtime[0].mFloat;
13 years ago
runtime.pop();
MWBase::Environment::get().getWorld()->scaleObject(ptr,scale);
}
};
template<class R>
class OpGetScale : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
runtime.push(ptr.getCellRef().scale);
}
};
13 years ago
template<class R>
class OpSetAngle : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Float angle = runtime[0].mFloat;
13 years ago
runtime.pop();
float ax = Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees();
float ay = Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees();
float az = Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees();
13 years ago
if(axis == "x")
13 years ago
{
MWBase::Environment::get().getWorld()->rotateObject(ptr,angle,ay,az);
13 years ago
}
13 years ago
if(axis == "y")
13 years ago
{
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,angle,az);
13 years ago
}
13 years ago
if(axis == "z")
13 years ago
{
MWBase::Environment::get().getWorld()->rotateObject(ptr,ax,ay,angle);
13 years ago
}
}
};
template<class R>
class OpGetAngle : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
13 years ago
if(axis == "x")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[0]).valueDegrees());
}
13 years ago
if(axis == "y")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[1]).valueDegrees());
}
13 years ago
if(axis == "z")
{
runtime.push(Ogre::Radian(ptr.getRefData().getPosition().rot[2]).valueDegrees());
}
}
};
template<class R>
class OpGetPos : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
13 years ago
if(axis == "x")
{
runtime.push(ptr.getRefData().getPosition().pos[0]);
}
13 years ago
if(axis == "y")
{
runtime.push(ptr.getRefData().getPosition().pos[1]);
}
13 years ago
if(axis == "z")
{
runtime.push(ptr.getRefData().getPosition().pos[2]);
}
}
};
template<class R>
class OpSetPos : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Float pos = runtime[0].mFloat;
runtime.pop();
float ax = ptr.getRefData().getPosition().pos[0];
float ay = ptr.getRefData().getPosition().pos[1];
float az = ptr.getRefData().getPosition().pos[2];
std::cout << "setPos";
13 years ago
if(axis == "x")
{
MWBase::Environment::get().getWorld()->moveObject(ptr,pos,ay,az);
}
13 years ago
if(axis == "y")
{
MWBase::Environment::get().getWorld()->moveObject(ptr,ax,pos,az);
}
13 years ago
if(axis == "z")
{
MWBase::Environment::get().getWorld()->moveObject(ptr,ax,ay,pos);
}
}
};
13 years ago
template<class R>
class OpGetStartingPos : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
13 years ago
if(axis == "x")
13 years ago
{
runtime.push(ptr.getCellRef().pos.pos[0]);
}
13 years ago
if(axis == "y")
13 years ago
{
runtime.push(ptr.getCellRef().pos.pos[1]);
}
13 years ago
if(axis == "z")
13 years ago
{
runtime.push(ptr.getCellRef().pos.pos[2]);
}
}
};
13 years ago
const int opcodeSetScale = 0x2000164;
const int opcodeSetScaleExplicit = 0x2000165;
const int opcodeSetAngle = 0x2000166;
const int opcodeSetAngleExplicit = 0x2000167;
const int opcodeGetScale = 0x2000168;
const int opcodeGetScaleExplicit = 0x2000169;
const int opcodeGetAngle = 0x200016a;
const int opcodeGetAngleExplicit = 0x200016b;
const int opcodeGetPos = 0x200016c;
const int opcodeGetPosExplicit = 0x200016d;
const int opcodeSetPos = 0x200016e;
const int opcodeSetPosExplicit = 0x200016f;
13 years ago
const int opcodeGetStartingPos = 0x2000170;
const int opcodeGetStartingPosExplicit = 0x2000171;
13 years ago
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerInstruction("setscale","f",opcodeSetScale,opcodeSetScaleExplicit);
extensions.registerFunction("getscale",'f',"",opcodeGetScale,opcodeGetScaleExplicit);
extensions.registerInstruction("setangle","Sf",opcodeSetAngle,opcodeSetAngleExplicit);
extensions.registerFunction("getangle",'f',"S",opcodeGetAngle,opcodeGetAngleExplicit);
13 years ago
extensions.registerInstruction("setpos","cf",opcodeSetPos,opcodeSetPosExplicit);
extensions.registerFunction("getpos",'f',"c",opcodeGetPos,opcodeGetPosExplicit);
extensions.registerFunction("getstartingpos",'f',"c",opcodeGetStartingPos,opcodeGetStartingPosExplicit);
13 years ago
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5(opcodeSetScale,new OpSetScale<ImplicitRef>);
interpreter.installSegment5(opcodeSetScaleExplicit,new OpSetScale<ExplicitRef>);
interpreter.installSegment5(opcodeSetAngle,new OpSetAngle<ImplicitRef>);
interpreter.installSegment5(opcodeSetAngleExplicit,new OpSetAngle<ExplicitRef>);
interpreter.installSegment5(opcodeGetScale,new OpGetScale<ImplicitRef>);
interpreter.installSegment5(opcodeGetScaleExplicit,new OpGetScale<ExplicitRef>);
interpreter.installSegment5(opcodeGetAngle,new OpGetAngle<ImplicitRef>);
interpreter.installSegment5(opcodeGetAngleExplicit,new OpGetAngle<ExplicitRef>);
interpreter.installSegment5(opcodeGetPos,new OpGetPos<ImplicitRef>);
interpreter.installSegment5(opcodeGetPosExplicit,new OpGetPos<ExplicitRef>);
interpreter.installSegment5(opcodeSetPos,new OpSetPos<ImplicitRef>);
interpreter.installSegment5(opcodeSetPosExplicit,new OpSetPos<ExplicitRef>);
13 years ago
interpreter.installSegment5(opcodeGetStartingPos,new OpGetStartingPos<ImplicitRef>);
interpreter.installSegment5(opcodeGetStartingPosExplicit,new OpGetStartingPos<ExplicitRef>);
13 years ago
}
}
}