mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 16:06:44 +00:00
Handle activation scripts in AiActivate (Fixes #1478)
This commit is contained in:
parent
a54ac579a5
commit
797134aa51
8 changed files with 33 additions and 26 deletions
|
@ -489,24 +489,7 @@ void OMW::Engine::activate()
|
||||||
if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
|
if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);
|
MWBase::Environment::get().getWorld()->activate(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OMW::Engine::screenshot()
|
void OMW::Engine::screenshot()
|
||||||
|
|
|
@ -517,6 +517,8 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void explodeSpell (const Ogre::Vector3& origin, const ESM::EffectList& effects,
|
virtual void explodeSpell (const Ogre::Vector3& origin, const ESM::EffectList& effects,
|
||||||
const MWWorld::Ptr& caster, const std::string& id, const std::string& sourceName) = 0;
|
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 "../mwbase/environment.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/action.hpp"
|
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
|
||||||
#include "steering.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
|
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;
|
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
|
||||||
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(mObjectId,false);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -419,11 +419,10 @@ namespace MWScript
|
||||||
mActivationHandled = false;
|
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, actor));
|
||||||
boost::shared_ptr<MWWorld::Action> action = (ptr.getClass().activate(ptr, player));
|
action->execute (actor);
|
||||||
action->execute (player);
|
|
||||||
if (mActivated == ptr)
|
if (mActivated == ptr)
|
||||||
mActivationHandled = true;
|
mActivationHandled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace MWScript
|
||||||
///< Store reference acted upon. The actual execution of the action does not
|
///< Store reference acted upon. The actual execution of the action does not
|
||||||
/// take place here.
|
/// 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.
|
///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled.
|
||||||
|
|
||||||
void clearActivation();
|
void clearActivation();
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace MWScript
|
||||||
|
|
||||||
MWWorld::Ptr ptr = R()(runtime);
|
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/sky.hpp"
|
||||||
#include "../mwrender/animation.hpp"
|
#include "../mwrender/animation.hpp"
|
||||||
|
|
||||||
|
#include "../mwscript/interpretercontext.hpp"
|
||||||
|
|
||||||
#include "../mwclass/door.hpp"
|
#include "../mwclass/door.hpp"
|
||||||
|
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
|
@ -2759,4 +2761,22 @@ namespace MWWorld
|
||||||
cast.inflict(apply->first, caster, effects, ESM::RT_Target, false, true);
|
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,
|
virtual void explodeSpell (const Ogre::Vector3& origin, const ESM::EffectList& effects,
|
||||||
const MWWorld::Ptr& caster, const std::string& id, const std::string& sourceName);
|
const MWWorld::Ptr& caster, const std::string& id, const std::string& sourceName);
|
||||||
|
|
||||||
|
virtual void activate (const MWWorld::Ptr& object, const MWWorld::Ptr& actor);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue