1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/apps/openmw/mwscript/miscextensions.cpp

435 lines
17 KiB
C++
Raw Normal View History

2010-07-05 13:15:49 +02:00
#include "miscextensions.hpp"
#include <libs/openengine/ogre/fader.hpp>
2010-07-05 13:15:49 +02:00
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include "../mwbase/environment.hpp"
2012-09-19 03:11:23 +02:00
#include "../mwbase/windowmanager.hpp"
2010-08-30 12:30:34 +02:00
#include "../mwworld/class.hpp"
#include "../mwworld/player.hpp"
#include "../mwmechanics/npcstats.hpp"
2010-08-30 12:30:34 +02:00
#include "interpretercontext.hpp"
#include "ref.hpp"
2010-07-05 13:15:49 +02:00
namespace MWScript
{
namespace Misc
{
2012-09-19 03:11:23 +02:00
class OpGetPcSleep : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push (MWBase::Environment::get().getWindowManager ()->getPlayerSleeping());
}
};
2012-09-29 09:41:34 +02:00
class OpWakeUpPc : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getWindowManager ()->wakeUpPlayer();
}
};
2010-07-05 13:15:49 +02:00
class OpXBox : public Interpreter::Opcode0
{
public:
2010-07-05 13:15:49 +02:00
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push (0);
}
2010-07-05 13:15:49 +02:00
};
2010-07-06 10:25:42 +02:00
class OpOnActivate : public Interpreter::Opcode0
{
public:
2010-07-06 10:25:42 +02:00
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
runtime.push (context.hasBeenActivated (ptr));
}
2010-07-06 10:25:42 +02:00
};
2010-08-05 15:52:07 +02:00
class OpActivate : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
context.executeActivation();
}
};
template<class R>
2010-08-30 12:30:34 +02:00
class OpLock : public Interpreter::Opcode1
{
public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{
MWWorld::Ptr ptr = R()(runtime);
2010-08-30 12:30:34 +02:00
Interpreter::Type_Integer lockLevel = 100;
if (arg0==1)
{
lockLevel = runtime[0].mInteger;
runtime.pop();
}
MWWorld::Class::get (ptr).lock (ptr, lockLevel);
}
};
template<class R>
2010-08-30 12:30:34 +02:00
class OpUnlock : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
2010-08-30 12:30:34 +02:00
MWWorld::Class::get (ptr).unlock (ptr);
}
};
class OpToggleCollisionDebug : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
bool enabled =
MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_CollisionDebug);
context.report (enabled ?
2012-02-18 16:06:03 +01:00
"Collision Mesh Rendering -> On" : "Collision Mesh Rendering -> Off");
}
};
class OpToggleCollisionBoxes : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
bool enabled =
MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_BoundingBoxes);
context.report (enabled ?
"Bounding Box Rendering -> On" : "Bounding Box Rendering -> Off");
}
};
2012-02-18 16:06:03 +01:00
class OpToggleWireframe : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
bool enabled =
MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_Wireframe);
2012-02-18 16:06:03 +01:00
context.report (enabled ?
"Wireframe Rendering -> On" : "Wireframe Rendering -> Off");
}
};
2012-03-08 01:09:06 +04:00
class OpTogglePathgrid : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
bool enabled =
MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_Pathgrid);
context.report (enabled ?
"Path Grid rendering -> On" : "Path Grid Rendering -> Off");
}
};
class OpFadeIn : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
Interpreter::Type_Float time = runtime[0].mFloat;
runtime.pop();
MWBase::Environment::get().getWorld()->getFader()->fadeIn(time);
}
};
class OpFadeOut : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
Interpreter::Type_Float time = runtime[0].mFloat;
runtime.pop();
MWBase::Environment::get().getWorld()->getFader()->fadeOut(time);
}
};
class OpFadeTo : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
Interpreter::Type_Float alpha = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float time = runtime[0].mFloat;
runtime.pop();
MWBase::Environment::get().getWorld()->getFader()->fadeTo(alpha, time);
}
};
2010-08-30 12:30:34 +02:00
class OpToggleWater : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getWorld()->toggleWater();
}
};
class OpDontSaveObject : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
// We are ignoring the DontSaveObject statement for now. Probably not worth
/// bothering with. The incompatibility we are creating should be marginal at most.
}
};
2012-08-18 18:05:10 +04:00
class OpToggleVanityMode : public Interpreter::Opcode0
{
2012-08-19 10:37:51 +04:00
static bool sActivate;
2012-08-18 18:05:10 +04:00
public:
virtual void execute(Interpreter::Runtime &runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWBase::World *world =
MWBase::Environment::get().getWorld();
2012-08-19 10:37:51 +04:00
if (world->toggleVanityMode(sActivate, true)) {
2012-08-18 18:05:10 +04:00
context.report(
2012-08-19 10:37:51 +04:00
(sActivate) ? "Vanity Mode -> On" : "Vanity Mode -> Off"
2012-08-18 18:05:10 +04:00
);
2012-08-19 10:37:51 +04:00
sActivate = !sActivate;
2012-08-18 18:05:10 +04:00
} else {
context.report("Vanity Mode -> No");
}
}
};
2012-08-19 10:37:51 +04:00
bool OpToggleVanityMode::sActivate = true;
2012-08-18 18:05:10 +04:00
2012-11-23 21:31:10 +01:00
template <class R>
class OpGetLocked : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
runtime.push (ptr.getCellRef ().mLockLevel > 0);
}
};
template <class R>
class OpGetForceRun : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(ptr).getNpcStats (ptr);
runtime.push (npcStats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceRun));
}
};
template <class R>
class OpGetForceSneak : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(ptr).getNpcStats (ptr);
runtime.push (npcStats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak));
}
};
class OpGetPcRunning : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer();
runtime.push (MWWorld::Class::get(ptr).getStance (ptr, MWWorld::Class::Run));
}
};
class OpGetPcSneaking : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer();
runtime.push (MWWorld::Class::get(ptr).getStance (ptr, MWWorld::Class::Sneak));
}
};
2010-07-05 13:15:49 +02:00
const int opcodeXBox = 0x200000c;
const int opcodeOnActivate = 0x200000d;
2010-08-05 15:52:07 +02:00
const int opcodeActivate = 0x2000075;
2010-08-30 12:30:34 +02:00
const int opcodeLock = 0x20004;
const int opcodeLockExplicit = 0x20005;
const int opcodeUnlock = 0x200008c;
const int opcodeUnlockExplicit = 0x200008d;
const int opcodeToggleCollisionDebug = 0x2000132;
const int opcodeToggleCollisionBoxes = 0x20001ac;
2012-02-18 16:06:03 +01:00
const int opcodeToggleWireframe = 0x200013b;
const int opcodeFadeIn = 0x200013c;
const int opcodeFadeOut = 0x200013d;
const int opcodeFadeTo = 0x200013e;
const int opcodeToggleWater = 0x2000144;
const int opcodeTogglePathgrid = 0x2000146;
const int opcodeDontSaveObject = 0x2000153;
2012-08-18 18:05:10 +04:00
const int opcodeToggleVanityMode = 0x2000174;
2012-09-19 03:11:23 +02:00
const int opcodeGetPcSleep = 0x200019f;
2012-09-29 09:41:34 +02:00
const int opcodeWakeUpPc = 0x20001a2;
2012-11-23 21:31:10 +01:00
const int opcodeGetLocked = 0x20001c7;
const int opcodeGetLockedExplicit = 0x20001c8;
const int opcodeGetPcRunning = 0x20001c9;
const int opcodeGetPcSneaking = 0x20001ca;
const int opcodeGetForceRun = 0x20001cb;
const int opcodeGetForceSneak = 0x20001cc;
const int opcodeGetForceRunExplicit = 0x20001cd;
const int opcodeGetForceSneakExplicit = 0x20001ce;
2010-07-05 13:15:49 +02:00
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerFunction ("xbox", 'l', "", opcodeXBox);
2010-07-06 10:25:42 +02:00
extensions.registerFunction ("onactivate", 'l', "", opcodeOnActivate);
2010-08-05 15:52:07 +02:00
extensions.registerInstruction ("activate", "", opcodeActivate);
2010-08-30 12:30:34 +02:00
extensions.registerInstruction ("lock", "/l", opcodeLock, opcodeLockExplicit);
extensions.registerInstruction ("unlock", "", opcodeUnlock, opcodeUnlockExplicit);
extensions.registerInstruction ("togglecollisionboxes", "", opcodeToggleCollisionBoxes);
extensions.registerInstruction ("togglecollisiongrid", "", opcodeToggleCollisionDebug);
extensions.registerInstruction ("tcb", "", opcodeToggleCollisionBoxes);
extensions.registerInstruction ("tcg", "", opcodeToggleCollisionDebug);
2012-02-18 16:06:03 +01:00
extensions.registerInstruction ("twf", "", opcodeToggleWireframe);
extensions.registerInstruction ("togglewireframe", "", opcodeToggleWireframe);
extensions.registerInstruction ("fadein", "f", opcodeFadeIn);
extensions.registerInstruction ("fadeout", "f", opcodeFadeOut);
extensions.registerInstruction ("fadeto", "ff", opcodeFadeTo);
extensions.registerInstruction ("togglewater", "", opcodeToggleWater);
extensions.registerInstruction ("twa", "", opcodeToggleWater);
extensions.registerInstruction ("togglepathgrid", "", opcodeTogglePathgrid);
extensions.registerInstruction ("tpg", "", opcodeTogglePathgrid);
extensions.registerInstruction ("dontsaveobject", "", opcodeDontSaveObject);
2012-08-18 18:05:10 +04:00
extensions.registerInstruction ("togglevanitymode", "", opcodeToggleVanityMode);
extensions.registerInstruction ("tvm", "", opcodeToggleVanityMode);
2012-09-19 03:11:23 +02:00
extensions.registerFunction ("getpcsleep", 'l', "", opcodeGetPcSleep);
2012-09-29 09:41:34 +02:00
extensions.registerInstruction ("wakeuppc", "", opcodeWakeUpPc);
2012-11-23 21:31:10 +01:00
extensions.registerFunction ("getlocked", 'l', "", opcodeGetLocked, opcodeGetLockedExplicit);
extensions.registerFunction ("getpcrunning", 'l', "", opcodeGetPcRunning);
extensions.registerFunction ("getpcsneaking", 'l', "", opcodeGetPcSneaking);
extensions.registerFunction ("getforcerun", 'l', "", opcodeGetForceRun, opcodeGetForceRunExplicit);
extensions.registerFunction ("getforcesneak", 'l', "", opcodeGetForceSneak, opcodeGetForceSneakExplicit);
2010-07-05 13:15:49 +02:00
}
2010-07-05 13:15:49 +02:00
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeXBox, new OpXBox);
2010-07-06 10:25:42 +02:00
interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate);
2010-08-05 15:52:07 +02:00
interpreter.installSegment5 (opcodeActivate, new OpActivate);
interpreter.installSegment3 (opcodeLock, new OpLock<ImplicitRef>);
interpreter.installSegment3 (opcodeLockExplicit, new OpLock<ExplicitRef>);
interpreter.installSegment5 (opcodeUnlock, new OpUnlock<ImplicitRef>);
interpreter.installSegment5 (opcodeUnlockExplicit, new OpUnlock<ExplicitRef>);
interpreter.installSegment5 (opcodeToggleCollisionDebug, new OpToggleCollisionDebug);
interpreter.installSegment5 (opcodeToggleCollisionBoxes, new OpToggleCollisionBoxes);
2012-02-18 16:06:03 +01:00
interpreter.installSegment5 (opcodeToggleWireframe, new OpToggleWireframe);
interpreter.installSegment5 (opcodeFadeIn, new OpFadeIn);
interpreter.installSegment5 (opcodeFadeOut, new OpFadeOut);
interpreter.installSegment5 (opcodeFadeTo, new OpFadeTo);
2012-03-08 01:09:06 +04:00
interpreter.installSegment5 (opcodeTogglePathgrid, new OpTogglePathgrid);
interpreter.installSegment5 (opcodeToggleWater, new OpToggleWater);
interpreter.installSegment5 (opcodeDontSaveObject, new OpDontSaveObject);
2012-08-18 18:05:10 +04:00
interpreter.installSegment5 (opcodeToggleVanityMode, new OpToggleVanityMode);
2012-09-19 03:11:23 +02:00
interpreter.installSegment5 (opcodeGetPcSleep, new OpGetPcSleep);
2012-09-29 09:41:34 +02:00
interpreter.installSegment5 (opcodeWakeUpPc, new OpWakeUpPc);
2012-11-23 21:31:10 +01:00
interpreter.installSegment5 (opcodeGetLocked, new OpGetLocked<ImplicitRef>);
interpreter.installSegment5 (opcodeGetLockedExplicit, new OpGetLocked<ExplicitRef>);
interpreter.installSegment5 (opcodeGetPcRunning, new OpGetPcRunning);
interpreter.installSegment5 (opcodeGetPcSneaking, new OpGetPcSneaking);
interpreter.installSegment5 (opcodeGetForceRun, new OpGetForceRun<ImplicitRef>);
interpreter.installSegment5 (opcodeGetForceRunExplicit, new OpGetForceRun<ExplicitRef>);
interpreter.installSegment5 (opcodeGetForceSneak, new OpGetForceSneak<ImplicitRef>);
interpreter.installSegment5 (opcodeGetForceSneakExplicit, new OpGetForceSneak<ExplicitRef>);
}
}
2010-07-05 13:15:49 +02:00
}