diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index bda903d561..46f384f594 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -489,24 +489,7 @@ void OMW::Engine::activate() if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated return; - MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); - - interpreterContext.activate (ptr); - - std::string script = ptr.getClass().getScript (ptr); - - MWBase::Environment::get().getWorld()->breakInvisibility(MWBase::Environment::get().getWorld()->getPlayerPtr()); - - if (!script.empty()) - { - MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr); - MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); - } - - if (!interpreterContext.hasActivationBeenHandled()) - { - interpreterContext.executeActivation(ptr); - } + MWBase::Environment::get().getWorld()->activate(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr()); } void OMW::Engine::screenshot() diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 81bec6fe86..9fb91398da 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -517,6 +517,8 @@ namespace MWBase virtual void explodeSpell (const Ogre::Vector3& origin, const ESM::EffectList& effects, const MWWorld::Ptr& caster, const std::string& id, const std::string& sourceName) = 0; + + virtual void activate (const MWWorld::Ptr& object, const MWWorld::Ptr& actor) = 0; }; } diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index 1cdda24c00..9e01c3fe72 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -6,7 +6,6 @@ #include "../mwbase/environment.hpp" #include "../mwworld/class.hpp" -#include "../mwworld/action.hpp" #include "../mwworld/cellstore.hpp" #include "steering.hpp" @@ -34,7 +33,9 @@ bool MWMechanics::AiActivate::execute (const MWWorld::Ptr& actor,float duration) if(distance(dest, pos.pos[0], pos.pos[1], pos.pos[2]) < 200) { //Stop when you get close actor.getClass().getMovementSettings(actor).mPosition[1] = 0; MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mObjectId,false); - target.getClass().activate(target,actor).get()->execute(actor); //Arrest player + + MWBase::Environment::get().getWorld()->activate(target, actor); + return true; } else { diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 6bf50371b8..ebe88c3a42 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -419,11 +419,10 @@ namespace MWScript mActivationHandled = false; } - void InterpreterContext::executeActivation(MWWorld::Ptr ptr) + void InterpreterContext::executeActivation(MWWorld::Ptr ptr, MWWorld::Ptr actor) { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - boost::shared_ptr action = (ptr.getClass().activate(ptr, player)); - action->execute (player); + boost::shared_ptr action = (ptr.getClass().activate(ptr, actor)); + action->execute (actor); if (mActivated == ptr) mActivationHandled = true; } diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 1137efed31..fdf9d6424d 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -129,7 +129,7 @@ namespace MWScript ///< Store reference acted upon. The actual execution of the action does not /// take place here. - void executeActivation(MWWorld::Ptr ptr); + void executeActivation(MWWorld::Ptr ptr, MWWorld::Ptr actor); ///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled. void clearActivation(); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 9d6d5e50dc..cd76f3b9c2 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -121,7 +121,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - context.executeActivation(ptr); + context.executeActivation(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr()); } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index bf752734fb..371f9edfea 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -36,6 +36,8 @@ #include "../mwrender/sky.hpp" #include "../mwrender/animation.hpp" +#include "../mwscript/interpretercontext.hpp" + #include "../mwclass/door.hpp" #include "player.hpp" @@ -2759,4 +2761,22 @@ namespace MWWorld cast.inflict(apply->first, caster, effects, ESM::RT_Target, false, true); } } + + void World::activate(const Ptr &object, const Ptr &actor) + { + MWScript::InterpreterContext interpreterContext (&object.getRefData().getLocals(), object); + interpreterContext.activate (object); + + std::string script = object.getClass().getScript (object); + + breakInvisibility(actor); + + if (!script.empty()) + { + getLocalScripts().setIgnore (object); + MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); + } + if (!interpreterContext.hasActivationBeenHandled()) + interpreterContext.executeActivation(object, actor); + } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 0a396ef5c6..5b493efcc8 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -586,6 +586,8 @@ namespace MWWorld virtual void explodeSpell (const Ogre::Vector3& origin, const ESM::EffectList& effects, const MWWorld::Ptr& caster, const std::string& id, const std::string& sourceName); + + virtual void activate (const MWWorld::Ptr& object, const MWWorld::Ptr& actor); }; }