Implement ToggleScripts

celladd
scrawl 10 years ago
parent ee574e08ef
commit 3ccf4642b4

@ -108,12 +108,15 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
MWBase::StateManager::State_Running)
{
if (!paused)
{
if (MWBase::Environment::get().getWorld()->getScriptsEnabled())
{
// local scripts
executeLocalScripts();
// global scripts
MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
}
MWBase::Environment::get().getWorld()->markCellAsUnchanged();
}

@ -489,6 +489,9 @@ namespace MWBase
virtual bool toggleGodMode() = 0;
virtual bool toggleScripts() = 0;
virtual bool getScriptsEnabled() const = 0;
/**
* @brief startSpellCast attempt to start casting a spell. Might fail immediately if conditions are not met.
* @param actor

@ -420,7 +420,7 @@ namespace MWGui
// Give the script a chance to run once before we do anything else
// this is important when setting pcskipequip as a reaction to onpcequip being set (bk_treasuryreport does this)
if (!script.empty())
if (!script.empty() && MWBase::Environment::get().getWorld()->getScriptsEnabled())
{
MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);
MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);

@ -444,5 +444,6 @@ op 0x20002fd: AddToLevItem
op 0x20002fe: RemoveFromLevItem
op 0x20002ff: SetFactionReaction
op 0x2000300: EnableLevelupMenu
op 0x2000301: ToggleScripts
opcodes 0x2000301-0x3ffffff unused
opcodes 0x2000302-0x3ffffff unused

@ -915,6 +915,19 @@ namespace MWScript
}
};
class OpToggleScripts : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context = static_cast<InterpreterContext&> (runtime.getContext());
bool enabled = MWBase::Environment::get().getWorld()->toggleScripts();
context.report(enabled ? "Scripts -> On" : "Scripts -> Off");
}
};
class OpToggleGodMode : public Interpreter::Opcode0
{
public:
@ -1220,6 +1233,7 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVars<ImplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeShowVarsExplicit, new OpShowVars<ExplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeToggleGodMode, new OpToggleGodMode);
interpreter.installSegment5 (Compiler::Misc::opcodeToggleScripts, new OpToggleScripts);
interpreter.installSegment5 (Compiler::Misc::opcodeDisableLevitation, new OpEnableLevitation<false>);
interpreter.installSegment5 (Compiler::Misc::opcodeEnableLevitation, new OpEnableLevitation<true>);
interpreter.installSegment5 (Compiler::Misc::opcodeCast, new OpCast<ImplicitRef>);

@ -151,7 +151,8 @@ namespace MWWorld
mFallback(fallbackMap), mTeleportEnabled(true), mLevitationEnabled(true),
mGodMode(false), mContentFiles (contentFiles),
mGoToJail(false), mDaysInPrison(0),
mStartCell (startCell), mStartupScript(startupScript)
mStartCell (startCell), mStartupScript(startupScript),
mScriptsEnabled(true)
{
mPhysics = new PhysicsSystem(renderer);
mPhysEngine = mPhysics->getEngine();
@ -293,6 +294,7 @@ namespace MWWorld
mDoorStates.clear();
mGodMode = false;
mScriptsEnabled = true;
mSky = true;
mTeleportEnabled = true;
mLevitationEnabled = true;
@ -2587,6 +2589,17 @@ namespace MWWorld
return mGodMode;
}
bool World::toggleScripts()
{
mScriptsEnabled = !mScriptsEnabled;
return mScriptsEnabled;
}
bool World::getScriptsEnabled() const
{
return mScriptsEnabled;
}
void World::loadContentFiles(const Files::Collections& fileCollections,
const std::vector<std::string>& content, ContentLoader& contentLoader)
{
@ -3167,6 +3180,8 @@ namespace MWWorld
breakInvisibility(actor);
if (mScriptsEnabled)
{
if (!script.empty())
{
getLocalScripts().setIgnore (object);
@ -3175,6 +3190,9 @@ namespace MWWorld
if (!interpreterContext.hasActivationBeenHandled())
interpreterContext.executeActivation(object, actor);
}
else
interpreterContext.executeActivation(object, actor);
}
struct ResetActorsFunctor
{

@ -82,6 +82,7 @@ namespace MWWorld
boost::shared_ptr<ProjectileManager> mProjectileManager;
bool mGodMode;
bool mScriptsEnabled;
std::vector<std::string> mContentFiles;
// not implemented
@ -572,6 +573,9 @@ namespace MWWorld
virtual bool toggleGodMode();
virtual bool toggleScripts();
virtual bool getScriptsEnabled() const;
/**
* @brief startSpellCast attempt to start casting a spell. Might fail immediately if conditions are not met.
* @param actor

@ -303,6 +303,7 @@ namespace Compiler
extensions.registerInstruction ("sv", "", opcodeShowVars, opcodeShowVarsExplicit);
extensions.registerInstruction("tgm", "", opcodeToggleGodMode);
extensions.registerInstruction("togglegodmode", "", opcodeToggleGodMode);
extensions.registerInstruction("togglescripts", "", opcodeToggleScripts);
extensions.registerInstruction ("disablelevitation", "", opcodeDisableLevitation);
extensions.registerInstruction ("enablelevitation", "", opcodeEnableLevitation);
extensions.registerFunction ("getpcinjail", 'l', "", opcodeGetPcInJail);

@ -278,6 +278,7 @@ namespace Compiler
const int opcodeShowVars = 0x200021d;
const int opcodeShowVarsExplicit = 0x200021e;
const int opcodeToggleGodMode = 0x200021f;
const int opcodeToggleScripts = 0x2000301;
const int opcodeDisableLevitation = 0x2000220;
const int opcodeEnableLevitation = 0x2000221;
const int opcodeCast = 0x2000227;

Loading…
Cancel
Save