Implement ToggleScripts

celladd
scrawl 10 years ago
parent ee574e08ef
commit 3ccf4642b4

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

@ -489,6 +489,9 @@ namespace MWBase
virtual bool toggleGodMode() = 0; 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. * @brief startSpellCast attempt to start casting a spell. Might fail immediately if conditions are not met.
* @param actor * @param actor

@ -420,7 +420,7 @@ namespace MWGui
// Give the script a chance to run once before we do anything else // 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) // 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); MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);
MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);

@ -444,5 +444,6 @@ op 0x20002fd: AddToLevItem
op 0x20002fe: RemoveFromLevItem op 0x20002fe: RemoveFromLevItem
op 0x20002ff: SetFactionReaction op 0x20002ff: SetFactionReaction
op 0x2000300: EnableLevelupMenu 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 class OpToggleGodMode : public Interpreter::Opcode0
{ {
public: public:
@ -1220,6 +1233,7 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVars<ImplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeShowVars, new OpShowVars<ImplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeShowVarsExplicit, new OpShowVars<ExplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeShowVarsExplicit, new OpShowVars<ExplicitRef>);
interpreter.installSegment5 (Compiler::Misc::opcodeToggleGodMode, new OpToggleGodMode); 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::opcodeDisableLevitation, new OpEnableLevitation<false>);
interpreter.installSegment5 (Compiler::Misc::opcodeEnableLevitation, new OpEnableLevitation<true>); interpreter.installSegment5 (Compiler::Misc::opcodeEnableLevitation, new OpEnableLevitation<true>);
interpreter.installSegment5 (Compiler::Misc::opcodeCast, new OpCast<ImplicitRef>); interpreter.installSegment5 (Compiler::Misc::opcodeCast, new OpCast<ImplicitRef>);

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

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

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

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

Loading…
Cancel
Save