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

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

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

@ -419,9 +419,10 @@ namespace MWScript
std::string currentTargetId; std::string currentTargetId;
bool targetsAreEqual = false; 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; targetsAreEqual = true;
} }
runtime.push(int(targetsAreEqual)); runtime.push(int(targetsAreEqual));

Loading…
Cancel
Save