2011-11-21 13:08:44 +00:00
|
|
|
#include "animationextensions.hpp"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
2015-01-31 22:27:34 +00:00
|
|
|
#include <limits>
|
2011-11-21 13:08:44 +00:00
|
|
|
|
2017-04-24 16:46:12 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Include additional headers for multiplayer purposes
|
|
|
|
*/
|
2016-10-27 13:46:47 +00:00
|
|
|
#include "../mwmp/Main.hpp"
|
2016-12-16 08:59:15 +00:00
|
|
|
#include "../mwmp/Networking.hpp"
|
2018-05-12 21:42:24 +00:00
|
|
|
#include "../mwmp/ObjectList.hpp"
|
2018-07-22 22:39:43 +00:00
|
|
|
#include "../mwmp/ScriptController.hpp"
|
2017-04-24 16:46:12 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2016-12-16 08:59:15 +00:00
|
|
|
|
2016-10-27 13:46:47 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2016-10-27 14:41:48 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2016-10-27 13:46:47 +00:00
|
|
|
|
2013-08-07 00:38:41 +00:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2011-11-21 13:08:44 +00:00
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
|
2015-02-09 16:45:48 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2013-01-17 01:53:18 +00:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2011-11-21 13:08:44 +00:00
|
|
|
|
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
#include "ref.hpp"
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Animation
|
|
|
|
{
|
|
|
|
template<class R>
|
|
|
|
class OpSkipAnim : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2011-11-21 13:08:44 +00:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2013-01-17 01:53:18 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->skipAnimation (ptr);
|
2011-11-21 13:08:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class OpPlayAnim : public Interpreter::Opcode1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime, unsigned int arg0) override
|
2011-11-21 13:08:44 +00:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2017-04-21 14:22:55 +00:00
|
|
|
if (!ptr.getRefData().isEnabled())
|
|
|
|
return;
|
|
|
|
|
2011-11-21 13:08:44 +00:00
|
|
|
std::string group = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer mode = 0;
|
|
|
|
|
|
|
|
if (arg0==1)
|
|
|
|
{
|
|
|
|
mode = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
if (mode<0 || mode>2)
|
|
|
|
throw std::runtime_error ("animation mode out of range");
|
|
|
|
}
|
|
|
|
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
Start of tes3mp addition
|
|
|
|
|
|
|
|
Send an ID_OBJECT_ANIM_PLAY every time an animation is played for an object
|
|
|
|
through an approved script
|
|
|
|
*/
|
2016-10-27 14:41:48 +00:00
|
|
|
if (mwmp::Main::isValidPacketScript(ptr.getClass().getScript(ptr)))
|
|
|
|
{
|
2018-05-12 21:42:24 +00:00
|
|
|
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
|
|
|
objectList->reset();
|
2019-08-21 16:04:04 +00:00
|
|
|
|
2018-07-22 22:39:43 +00:00
|
|
|
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType());
|
2020-07-27 07:17:22 +00:00
|
|
|
objectList->originClientScript = runtime.getContext().getCurrentScriptName();
|
2018-05-12 21:42:24 +00:00
|
|
|
objectList->addObjectAnimPlay(ptr, group, mode);
|
|
|
|
objectList->sendObjectAnimPlay();
|
2016-10-27 14:41:48 +00:00
|
|
|
}
|
2017-02-26 14:59:53 +00:00
|
|
|
/*
|
|
|
|
End of tes3mp addition
|
|
|
|
*/
|
2016-10-27 13:46:47 +00:00
|
|
|
|
2016-07-30 17:24:03 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup (ptr, group, mode, std::numeric_limits<int>::max(), true);
|
2011-11-21 13:08:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class R>
|
|
|
|
class OpLoopAnim : public Interpreter::Opcode1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime, unsigned int arg0) override
|
2011-11-21 13:08:44 +00:00
|
|
|
{
|
|
|
|
MWWorld::Ptr ptr = R()(runtime);
|
|
|
|
|
2017-04-21 14:22:55 +00:00
|
|
|
if (!ptr.getRefData().isEnabled())
|
|
|
|
return;
|
|
|
|
|
2011-11-21 13:08:44 +00:00
|
|
|
std::string group = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer loops = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
if (loops<0)
|
|
|
|
throw std::runtime_error ("number of animation loops must be non-negative");
|
|
|
|
|
|
|
|
Interpreter::Type_Integer mode = 0;
|
|
|
|
|
|
|
|
if (arg0==1)
|
|
|
|
{
|
|
|
|
mode = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
if (mode<0 || mode>2)
|
|
|
|
throw std::runtime_error ("animation mode out of range");
|
|
|
|
}
|
|
|
|
|
2016-08-14 12:52:48 +00:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup (ptr, group, mode, loops + 1, true);
|
2011-11-21 13:08:44 +00:00
|
|
|
}
|
|
|
|
};
|
2013-08-07 00:38:41 +00:00
|
|
|
|
2011-11-21 13:08:44 +00:00
|
|
|
|
|
|
|
void installOpcodes (Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2013-08-07 00:38:41 +00:00
|
|
|
interpreter.installSegment5 (Compiler::Animation::opcodeSkipAnim, new OpSkipAnim<ImplicitRef>);
|
|
|
|
interpreter.installSegment5 (Compiler::Animation::opcodeSkipAnimExplicit, new OpSkipAnim<ExplicitRef>);
|
|
|
|
interpreter.installSegment3 (Compiler::Animation::opcodePlayAnim, new OpPlayAnim<ImplicitRef>);
|
|
|
|
interpreter.installSegment3 (Compiler::Animation::opcodePlayAnimExplicit, new OpPlayAnim<ExplicitRef>);
|
|
|
|
interpreter.installSegment3 (Compiler::Animation::opcodeLoopAnim, new OpLoopAnim<ImplicitRef>);
|
|
|
|
interpreter.installSegment3 (Compiler::Animation::opcodeLoopAnimExplicit, new OpLoopAnim<ExplicitRef>);
|
2011-11-21 13:08:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|