actor handle and id confusing fix

deque
mrcheko 11 years ago
parent 66307dd889
commit e1249f6a31

@ -59,14 +59,13 @@ int AiSequence::getTypeId() const
return mPackages.front()->getTypeId();
}
bool AiSequence::getCombatTarget(std::string &targetActorId) const
bool AiSequence::getCombatTarget(MWWorld::Ptr &targetActor) const
{
if (getTypeId() != AiPackage::TypeIdCombat)
return false;
const AiCombat *combat = static_cast<const AiCombat *>(mPackages.front());
MWWorld::Ptr target = combat->getTarget();
targetActorId = target.getClass().getCreatureStats(target).getActorId();
targetActor = combat->getTarget();
return true;
}
@ -138,15 +137,11 @@ void AiSequence::execute (const MWWorld::Ptr& actor,float duration)
float nearestDist = std::numeric_limits<float>::max();
Ogre::Vector3 vActorPos = Ogre::Vector3(actor.getRefData().getPosition().pos);
const AiCombat *package;
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
{
package = static_cast<const AiCombat *>(*it);
if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break;
ESM::Position &targetPos = package->getTarget().getRefData().getPosition();
ESM::Position &targetPos = static_cast<const AiCombat *>(*it)->getTarget().getRefData().getPosition();
float distTo = (Ogre::Vector3(targetPos.pos) - vActorPos).length();
if (distTo < nearestDist)

@ -53,7 +53,7 @@ namespace MWMechanics
int getLastRunTypeId() const { return mLastAiPackage; }
/// Return true and assign target if combat package is currently active, return false otherwise
bool getCombatTarget (std::string &targetActorId) const;
bool getCombatTarget (MWWorld::Ptr &targetActor) const;
bool canAddTarget(const ESM::Position& actorPos, float distToTarget) const;
///< Function assumes that actor can have only 1 target apart player

@ -322,11 +322,9 @@ namespace MWMechanics
bool CreatureStats::getCreatureTargetted() const
{
std::string target;
if (mAiSequence.getCombatTarget(target))
MWWorld::Ptr targetPtr;
if (mAiSequence.getCombatTarget(targetPtr))
{
MWWorld::Ptr targetPtr;
targetPtr = MWBase::Environment::get().getWorld()->getPtr(target, true);
return targetPtr.getTypeName() == typeid(ESM::Creature).name();
}
return false;

@ -419,9 +419,10 @@ namespace MWScript
std::string currentTargetId;
bool targetsAreEqual = false;
if (creatureStats.getAiSequence().getCombatTarget (currentTargetId))
MWWorld::Ptr targetPtr;
if (creatureStats.getAiSequence().getCombatTarget (targetPtr))
{
if (currentTargetId == testedTargetId)
if (targetPtr.getRefData().getHandle() == testedTargetId)
targetsAreEqual = true;
}
runtime.push(int(targetsAreEqual));

Loading…
Cancel
Save