summaryrefslogtreecommitdiffstats
path: root/src/Entities/Compoments
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2014-07-10 23:54:10 +0200
committerSamuel Barney <samjbarney@gmail.com>2014-07-10 23:54:10 +0200
commit62a8403e4c61bd50680e9d8712506b951ac61b48 (patch)
treee2478dcd7396f5f569cef4a8c29aea0df922de2c /src/Entities/Compoments
parentMoved m_FinalDestination out where I could get to it. (diff)
downloadcuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.tar
cuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.tar.gz
cuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.tar.bz2
cuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.tar.lz
cuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.tar.xz
cuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.tar.zst
cuberite-62a8403e4c61bd50680e9d8712506b951ac61b48.zip
Diffstat (limited to 'src/Entities/Compoments')
-rw-r--r--src/Entities/Compoments/AIAggressiveComponent.h (renamed from src/Entities/Compoments/AIAgressiveComponent.h)13
-rw-r--r--src/Entities/Compoments/AIAggresssiveComponent.cpp (renamed from src/Entities/Compoments/AIAgresssiveComponent.cpp)48
-rw-r--r--src/Entities/Compoments/AIComponent.h2
3 files changed, 47 insertions, 16 deletions
diff --git a/src/Entities/Compoments/AIAgressiveComponent.h b/src/Entities/Compoments/AIAggressiveComponent.h
index 2cd3f2304..a99fa2693 100644
--- a/src/Entities/Compoments/AIAgressiveComponent.h
+++ b/src/Entities/Compoments/AIAggressiveComponent.h
@@ -1,22 +1,25 @@
#pragma once
#include "AIComponent.h"
-class cAIAgressiveComponent : public cAIComponent {
+class cAIAggressiveComponent : public cAIComponent {
+ typedef cAIComponent super;
protected:
enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
cEntity * m_Target;
public:
- cAIAgressiveComponent(cMonster * a_Monster) : cAIComponent(a_Monster), m_Target(null){}
+ cAIAggressiveComponent(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 EventLosePlayer(void);
virtual void CheckEventLostPlayer(void);
+ virtual void CheckEventSeePlayer(void);
+ virtual void EventLosePlayer(void);
+ virtual void EventSeePlayer(cEntity *);
bool IsMovingToTargetPosition();
-} \ No newline at end of file
+ bool ReachedFinalDestination();
+};
diff --git a/src/Entities/Compoments/AIAgresssiveComponent.cpp b/src/Entities/Compoments/AIAggresssiveComponent.cpp
index 4dcd3e618..de8c8d2a9 100644
--- a/src/Entities/Compoments/AIAgresssiveComponent.cpp
+++ b/src/Entities/Compoments/AIAggresssiveComponent.cpp
@@ -1,4 +1,8 @@
-#include "AIAgressiveComponent.h"
+
+#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"
@@ -18,10 +22,10 @@ void cAIAggressiveComponent::Tick(float a_Dt, cChunk & a_Chunk)
if (m_Target == NULL)
return;
- cTracer LineOfSight(GetWorld());
- Vector3d AttackDirection(m_Target->GetPosition() - GetPosition());
+ cTracer LineOfSight(m_Self->GetWorld());
+ Vector3d AttackDirection(m_Target->GetPosition() - m_Self->GetPosition());
- if (ReachedFinalDestination() && !LineOfSight.Trace(GetPosition(), AttackDirection, (int)AttackDirection.Length()))
+ if (ReachedFinalDestination() && !LineOfSight.Trace(m_Self->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);
@@ -38,10 +42,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_AttackDamage, 0);
+ m_Target->TakeDamage(dtMobAttack, m_Self, m_Self->GetAttackDamage(), 0);
}
- m_Self->SetAttackInterval(attack_interval)
+ m_Self->SetAttackInterval(attack_interval);
}
@@ -61,12 +65,37 @@ 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() - GetPosition()).Length() > m_Self->GetSightDistance())
+ if ((m_Target->GetPosition() - m_Self->GetPosition()).Length() > m_Self->GetSightDistance())
{
EventLosePlayer();
}
@@ -79,7 +108,7 @@ void cAIAggressiveComponent::CheckEventLostPlayer(void)
/// Event Handlers
-void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
+void cAIAggressiveComponent::EventSeePlayer(cEntity * a_Entity)
{
if (!((cPlayer *)a_Entity)->IsGameModeCreative())
{
@@ -97,9 +126,8 @@ void cAIAggressiveComponent::EventLosePlayer(void)
/// State Logic
-void cAggressiveMonster::InStateChasing(float a_Dt)
+void cAIAggressiveComponent::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 ac50a5a62..502516b85 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(cEntity * a_Entity) : m_Self(a_Entity){}
+ cAIComponent(cMonster * a_Entity) : m_Self(a_Entity){}
virtual void Tick(float a_Dt, cChunk & a_Chunk){}
};