summaryrefslogtreecommitdiffstats
path: root/src/Entities/Compoments/AIAgresssiveComponent.cpp
blob: ae89ef5b9885eb4dd1fbc64b630618fbf0583adf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "AIAgressiveComponent.h"

void cAIAggressiveComponent::Attack(float a_Dt)
{
	float attack_interval = m_Self->GetAttackInterval();
	attack_interval += a_Dt * m_Self->GetAttackRate();

	if ((m_Target != NULL) && (attack_interval > 3.0))
	{
		// Setting this higher gives us more wiggle room for attackrate
		attack_interval = 0.0f;
		m_Target->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
	}

	m_Self->SetAttackInterval(attack_interval)
}

bool cAIAggressiveComponent::IsMovingToTargetPosition()
{
	// Difference between destination x and target x is negligible (to 10^-12 precision)
	if (fabsf((float)m_Self->m_FinalDestination.x - (float)m_Target->GetPosX()) < std::numeric_limits<float>::epsilon())
	{
		return false;
	}
	// Difference between destination z and target z is negligible (to 10^-12 precision)
	else if (fabsf((float)m_Self->m_FinalDestination.z - (float)m_Target->GetPosZ()) > std::numeric_limits<float>::epsilon())
	{
		return false;
	}
	return true;
}