prepared InterpreterContext for activation implementation

actorid
Marc Zinnschlag 15 years ago
parent 052d049a6c
commit 7ba6bdb56c

@ -50,7 +50,8 @@ namespace MWScript
InterpreterContext::InterpreterContext (MWWorld::Environment& environment,
MWScript::Locals *locals, MWWorld::Ptr reference)
: mEnvironment (environment), mLocals (locals), mReference (reference)
: mEnvironment (environment), mLocals (locals), mReference (reference),
mActivationHandled (false)
{}
int InterpreterContext::getLocalShort (int index) const
@ -197,11 +198,46 @@ namespace MWScript
return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]);
}
bool InterpreterContext::hasBeenActivated() const
bool InterpreterContext::hasBeenActivated (const MWWorld::Ptr& ptr)
{
if (!mActivated.isEmpty() && mActivated==ptr)
{
mActivationHandled = true;
return true;
}
return false;
}
bool InterpreterContext::hasActivationBeenHandled() const
{
return mActivationHandled;
}
void InterpreterContext::activate (const MWWorld::Ptr& ptr,
boost::shared_ptr<MWWorld::Action> action)
{
mActivated = ptr;
mActivationHandled = false;
mAction = action;
}
void InterpreterContext::executeActivation()
{
if (!mAction.get())
throw std::runtime_error ("activation failed, because no action to perform");
mAction->execute (mEnvironment);
mActivationHandled = true;
}
void InterpreterContext::clearActivation()
{
mActivated = MWWorld::Ptr();
mActivationHandled = false;
mAction.reset();
}
float InterpreterContext::getSecondsPassed() const
{
return mEnvironment.mFrameDuration;
@ -245,4 +281,3 @@ namespace MWScript
return getReference ("", true);
}
}

@ -1,11 +1,14 @@
#ifndef GAME_SCRIPT_INTERPRETERCONTEXT_H
#define GAME_SCRIPT_INTERPRETERCONTEXT_H
#include <boost/shared_ptr.hpp>
#include <components/interpreter/context.hpp>
#include "../mwworld/ptr.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp"
#include "../mwworld/action.hpp"
namespace MWSound
{
@ -22,6 +25,9 @@ namespace MWScript
Locals *mLocals;
MWWorld::Ptr mReference;
MWWorld::Ptr mActivated;
bool mActivationHandled;
boost::shared_ptr<MWWorld::Action> mAction;
MWWorld::Ptr getReference (const std::string& id, bool activeOnly);
@ -70,7 +76,21 @@ namespace MWScript
virtual float getDistance (const std::string& name, const std::string& id = "") const;
virtual bool hasBeenActivated() const;
bool hasBeenActivated (const MWWorld::Ptr& ptr);
///< \attention Calling this function for the right reference will mark the action as
/// been handled.
bool hasActivationBeenHandled() const;
void activate (const MWWorld::Ptr& ptr, boost::shared_ptr<MWWorld::Action> action);
///< Store reference acted upon and action. The actual execution of the action does not
/// take place here.
void executeActivation();
///< Execute the action defined by the last activate call.
void clearActivation();
///< Discard the action defined by the last activate call.
virtual float getSecondsPassed() const;
@ -92,5 +112,3 @@ namespace MWScript
}
#endif

@ -29,8 +29,12 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push (static_cast<InterpreterContext&> (
runtime.getContext()).hasBeenActivated());
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
runtime.push (context.hasBeenActivated (ptr));
}
};

Loading…
Cancel
Save