Moved huge conditional out of InStateChasing(), improving readability
Squashed a warning.
This commit is contained in:
parent
d64e46186f
commit
5ffdaa8142
@ -37,7 +37,7 @@ void cAggressiveMonster::InStateChasing(float a_Dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((float)m_FinalDestination.x != (float)m_Target->GetPosX()) || ((float)m_FinalDestination.z != (float)m_Target->GetPosZ()))
|
if (!IsMovingToTargetPosition())
|
||||||
{
|
{
|
||||||
MoveToPosition(m_Target->GetPosition());
|
MoveToPosition(m_Target->GetPosition());
|
||||||
}
|
}
|
||||||
@ -106,3 +106,18 @@ void cAggressiveMonster::Attack(float a_Dt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cAggressiveMonster::IsMovingToTargetPosition()
|
||||||
|
{
|
||||||
|
float epsilon = 0.000000000001;
|
||||||
|
//Difference between destination x and target x is negligable (to 10^-12 precision)
|
||||||
|
if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < epsilon)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Difference between destination z and target z is negligable (to 10^-12 precision)
|
||||||
|
else if (fabsf(m_FinalDestination.z - (float)m_Target->GetPosZ()) > epsilon)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -22,6 +22,10 @@ public:
|
|||||||
virtual void EventSeePlayer(cEntity *) override;
|
virtual void EventSeePlayer(cEntity *) override;
|
||||||
virtual void Attack(float a_Dt);
|
virtual void Attack(float a_Dt);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Whether this mob's destination is the same as its target's position. */
|
||||||
|
bool IsMovingToTargetPosition();
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user