summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Entities/Compoments/AIAgressiveComponent.h (renamed from src/Entities/Compoments/AIAggressiveComponent.h)13
-rw-r--r--src/Entities/Compoments/AIAgresssiveComponent.cpp (renamed from src/Entities/Compoments/AIAggresssiveComponent.cpp)48
-rw-r--r--src/Entities/Compoments/AIComponent.h2
3 files changed, 16 insertions, 47 deletions
diff --git a/src/Entities/Compoments/AIAggressiveComponent.h b/src/Entities/Compoments/AIAgressiveComponent.h
index a99fa2693..2cd3f2304 100644
--- a/src/Entities/Compoments/AIAggressiveComponent.h
+++ b/src/Entities/Compoments/AIAgressiveComponent.h
@@ -1,25 +1,22 @@
#pragma once
#include "AIComponent.h"
-class cAIAggressiveComponent : public cAIComponent {
- typedef cAIComponent super;
+class cAIAgressiveComponent : public cAIComponent {
protected:
enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
cEntity * m_Target;
public:
- cAIAggressiveComponent(cMonster * a_Monster) : cAIComponent(a_Monster), m_Target(NULL){}
+ cAIAgressiveComponent(cMonster * a_Monster) : cAIComponent(a_Monster), m_Target(null){}
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void InStateChasing(float a_Dt);
+ virtual void EventSeePlayer(cEntity *);
virtual void Attack(float a_Dt);
protected:
- virtual void CheckEventLostPlayer(void);
- virtual void CheckEventSeePlayer(void);
virtual void EventLosePlayer(void);
- virtual void EventSeePlayer(cEntity *);
+ virtual void CheckEventLostPlayer(void);
bool IsMovingToTargetPosition();
- bool ReachedFinalDestination();
-};
+} \ No newline at end of file
diff --git a/src/Entities/Compoments/AIAggresssiveComponent.cpp b/src/Entities/Compoments/AIAgresssiveComponent.cpp
index de8c8d2a9..4dcd3e618 100644
--- a/src/Entities/Compoments/AIAggresssiveComponent.cpp
+++ b/src/Entities/Compoments/AIAgresssiveComponent.cpp
@@ -1,8 +1,4 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-#include "AIAggressiveComponent.h"
-#include "../Entities/Player.h"
-#include "../Tracer.h"
+#include "AIAgressiveComponent.h"
@@ -22,10 +18,10 @@ void cAIAggressiveComponent::Tick(float a_Dt, cChunk & a_Chunk)
if (m_Target == NULL)
return;
- cTracer LineOfSight(m_Self->GetWorld());
- Vector3d AttackDirection(m_Target->GetPosition() - m_Self->GetPosition());
+ cTracer LineOfSight(GetWorld());
+ Vector3d AttackDirection(m_Target->GetPosition() - GetPosition());
- if (ReachedFinalDestination() && !LineOfSight.Trace(m_Self->GetPosition(), AttackDirection, (int)AttackDirection.Length()))
+ if (ReachedFinalDestination() && !LineOfSight.Trace(GetPosition(), AttackDirection, (int)AttackDirection.Length()))
{
// Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
Attack(a_Dt / 1000);
@@ -42,10 +38,10 @@ void cAIAggressiveComponent::Attack(float a_Dt)
{
// Setting this higher gives us more wiggle room for attackrate
attack_interval = 0.0f;
- m_Target->TakeDamage(dtMobAttack, m_Self, m_Self->GetAttackDamage(), 0);
+ m_Target->TakeDamage(dtMobAttack, m_Self, m_AttackDamage, 0);
}
- m_Self->SetAttackInterval(attack_interval);
+ m_Self->SetAttackInterval(attack_interval)
}
@@ -65,37 +61,12 @@ bool cAIAggressiveComponent::IsMovingToTargetPosition()
}
-bool cAIAggressiveComponent::ReachedFinalDestination()
-{
- if ((m_Self->GetPosition() - m_Self->m_FinalDestination).Length() <= m_Self->GetAttackRange())
- {
- return true;
- }
-
- return false;
-}
-
-
/// Event Checkers
-//Checks to see if EventSeePlayer should be fired
-//monster sez: Do I see the player
-void cAIAggressiveComponent::CheckEventSeePlayer(void)
-{
- // TODO: Rewrite this to use cWorld's DoWithPlayers()
- cPlayer * Closest = m_Self->GetWorld()->FindClosestPlayer(m_Self->GetPosition(), (float)m_Self->GetSightDistance(), false);
-
- if (Closest != NULL)
- {
- EventSeePlayer(Closest);
- }
-}
-
-
void cAIAggressiveComponent::CheckEventLostPlayer(void)
{
if (m_Target != NULL)
{
- if ((m_Target->GetPosition() - m_Self->GetPosition()).Length() > m_Self->GetSightDistance())
+ if ((m_Target->GetPosition() - GetPosition()).Length() > m_Self->GetSightDistance())
{
EventLosePlayer();
}
@@ -108,7 +79,7 @@ void cAIAggressiveComponent::CheckEventLostPlayer(void)
/// Event Handlers
-void cAIAggressiveComponent::EventSeePlayer(cEntity * a_Entity)
+void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
{
if (!((cPlayer *)a_Entity)->IsGameModeCreative())
{
@@ -126,8 +97,9 @@ void cAIAggressiveComponent::EventLosePlayer(void)
/// State Logic
-void cAIAggressiveComponent::InStateChasing(float a_Dt)
+void cAggressiveMonster::InStateChasing(float a_Dt)
{
+ super::InStateChasing(a_Dt);
if (m_Target != NULL)
{
diff --git a/src/Entities/Compoments/AIComponent.h b/src/Entities/Compoments/AIComponent.h
index 502516b85..ac50a5a62 100644
--- a/src/Entities/Compoments/AIComponent.h
+++ b/src/Entities/Compoments/AIComponent.h
@@ -7,7 +7,7 @@ class cAIComponent
protected:
cMonster * m_Self;
public:
- cAIComponent(cMonster * a_Entity) : m_Self(a_Entity){}
+ cAIComponent(cEntity * a_Entity) : m_Self(a_Entity){}
virtual void Tick(float a_Dt, cChunk & a_Chunk){}
};