@ -81,7 +81,7 @@ namespace MWMechanics
// NOTE: MIN_DIST_TO_DOOR_SQUARED is defined in obstacle.hpp
AiCombat : : AiCombat ( const MWWorld : : Ptr & actor ) :
mTarget ( actor ) ,
mTarget ActorId ( actor . getClass ( ) . getCreatureStats ( actor ) . getActorId ( ) ) ,
mTimerAttack ( 0 ) ,
mTimerReact ( 0 ) ,
mTimerCombatMove ( 0 ) ,
@ -153,7 +153,9 @@ namespace MWMechanics
| | actor . getClass ( ) . getCreatureStats ( actor ) . getHealth ( ) . getCurrent ( ) < = 0 )
return true ;
if ( mTarget . getClass ( ) . getCreatureStats ( mTarget ) . isDead ( ) )
MWWorld : : Ptr target = MWBase : : Environment : : get ( ) . getWorld ( ) - > searchPtrViaActorId ( mTargetActorId ) ;
if ( target . getClass ( ) . getCreatureStats ( target ) . isDead ( ) )
return true ;
//Update every frame
@ -325,7 +327,7 @@ namespace MWMechanics
ESM : : Position pos = actor . getRefData ( ) . getPosition ( ) ;
Ogre : : Vector3 vActorPos ( pos . pos ) ;
Ogre : : Vector3 vTargetPos ( mT arget. getRefData ( ) . getPosition ( ) . pos ) ;
Ogre : : Vector3 vTargetPos ( t arget. getRefData ( ) . getPosition ( ) . pos ) ;
Ogre : : Vector3 vDirToTarget = vTargetPos - vActorPos ;
bool isStuck = false ;
@ -396,7 +398,7 @@ namespace MWMechanics
else // remote pathfinding
{
bool preferShortcut = false ;
bool inLOS = MWBase : : Environment : : get ( ) . getWorld ( ) - > getLOS ( actor , mT arget) ;
bool inLOS = MWBase : : Environment : : get ( ) . getWorld ( ) - > getLOS ( actor , t arget) ;
if ( mReadyToAttack ) isStuck = false ;
@ -432,7 +434,7 @@ namespace MWMechanics
mFollowTarget = false ;
buildNewPath ( actor ); //may fail to build a path, check before use
buildNewPath ( actor , target ); //may fail to build a path, check before use
//delete visited path node
mPathFinder . checkWaypoint ( pos . pos [ 0 ] , pos . pos [ 1 ] , pos . pos [ 2 ] ) ;
@ -476,9 +478,9 @@ namespace MWMechanics
//less than in time of playing weapon anim from 'start' to 'hit' tags (t_swing)
//then start attacking
float speed1 = actorCls . getSpeed ( actor ) ;
float speed2 = mTarget. getClass ( ) . getSpeed ( mT arget) ;
if ( mT arget. getClass ( ) . getMovementSettings ( mT arget) . mPosition [ 0 ] = = 0
& & mT arget. getClass ( ) . getMovementSettings ( mT arget) . mPosition [ 1 ] = = 0 )
float speed2 = target. getClass ( ) . getSpeed ( t arget) ;
if ( t arget. getClass ( ) . getMovementSettings ( t arget) . mPosition [ 0 ] = = 0
& & t arget. getClass ( ) . getMovementSettings ( t arget) . mPosition [ 1 ] = = 0 )
speed2 = 0 ;
float s1 = distToTarget - weapRange ;
@ -570,9 +572,9 @@ namespace MWMechanics
return false ;
}
void AiCombat : : buildNewPath ( const MWWorld : : Ptr & actor )
void AiCombat : : buildNewPath ( const MWWorld : : Ptr & actor , const MWWorld : : Ptr & target )
{
Ogre : : Vector3 newPathTarget = Ogre : : Vector3 ( mT arget. getRefData ( ) . getPosition ( ) . pos ) ;
Ogre : : Vector3 newPathTarget = Ogre : : Vector3 ( t arget. getRefData ( ) . getPosition ( ) . pos ) ;
float dist ;
@ -627,9 +629,12 @@ namespace MWMechanics
return 1 ;
}
const std : : string & AiCombat : : getTargetId ( ) const
std : : string AiCombat : : getTargetId ( ) const
{
return mTarget . getRefData ( ) . getHandle ( ) ;
MWWorld : : Ptr target = MWBase : : Environment : : get ( ) . getWorld ( ) - > searchPtrViaActorId ( mTargetActorId ) ;
if ( target . isEmpty ( ) )
return " " ;
return target . getRefData ( ) . getHandle ( ) ;
}