Handle activation scripts in AiActivate (Fixes #1478)

deque
scrawl 11 years ago
parent a54ac579a5
commit 797134aa51

@ -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()

@ -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;
};
}

@ -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 {

@ -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<MWWorld::Action> action = (ptr.getClass().activate(ptr, player));
action->execute (player);
boost::shared_ptr<MWWorld::Action> action = (ptr.getClass().activate(ptr, actor));
action->execute (actor);
if (mActivated == ptr)
mActivationHandled = true;
}

@ -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();

@ -121,7 +121,7 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime);
context.executeActivation(ptr);
context.executeActivation(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
}
};

@ -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);
}
}

@ -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);
};
}

Loading…
Cancel
Save