Fixes #1143: Make getCurrentAiPackage return the package that was run last, not the package that will be run in the next frame.

This makes the Mehra Milo script work properly.
actorid
scrawl 11 years ago
parent 434fd21584
commit 23ffb8a4dc

@ -23,7 +23,7 @@ void MWMechanics::AiSequence::copy (const AiSequence& sequence)
mPackages.push_back ((*iter)->clone());
}
MWMechanics::AiSequence::AiSequence() : mDone (false) {}
MWMechanics::AiSequence::AiSequence() : mDone (false), mLastAiPackage(-1) {}
MWMechanics::AiSequence::AiSequence (const AiSequence& sequence) : mDone (false)
{
@ -84,6 +84,7 @@ void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor,float duration)
{
if (!mPackages.empty())
{
mLastAiPackage = mPackages.front()->getTypeId();
if (mPackages.front()->execute (actor,duration))
{
delete *mPackages.begin();
@ -91,7 +92,9 @@ void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor,float duration)
mDone = true;
}
else
{
mDone = false;
}
}
}
}

@ -23,6 +23,9 @@ namespace MWMechanics
void copy (const AiSequence& sequence);
// The type of AI package that ran last
int mLastAiPackage;
public:
AiSequence();
@ -36,6 +39,10 @@ namespace MWMechanics
int getTypeId() const;
///< @see enum AiPackage::TypeId
int getLastRunTypeId() const { return mLastAiPackage; }
///< Get the typeid of the Ai package that ran last, NOT the currently "active" Ai package that will be run in the next frame.
/// This difference is important when an Ai package has just finished and been removed.
bool getCombatTarget (std::string &targetActorId) const;
///< Return true and assign target if combat package is currently
/// active, return false otherwise

@ -352,7 +352,7 @@ namespace MWScript
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Integer value = MWWorld::Class::get (ptr).getCreatureStats (ptr).getAiSequence().getTypeId ();
Interpreter::Type_Integer value = MWWorld::Class::get (ptr).getCreatureStats (ptr).getAiSequence().getLastRunTypeId();
runtime.push (value);
}

Loading…
Cancel
Save