summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2014-08-20 16:29:06 +0200
committerSamuel Barney <samjbarney@gmail.com>2014-08-20 16:29:06 +0200
commit72e2182daf9b99a4aca3d7c06e96ff96c0862629 (patch)
treec52aa9ee39db1f1f77489545c395b08db3f5b9b1
parentRevert "Fixed include paths." (diff)
downloadcuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.tar
cuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.tar.gz
cuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.tar.bz2
cuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.tar.lz
cuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.tar.xz
cuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.tar.zst
cuberite-72e2182daf9b99a4aca3d7c06e96ff96c0862629.zip
-rw-r--r--src/Entities/Compoments/AIAgressiveComponent.h4
-rw-r--r--src/Entities/Compoments/AIAgresssiveComponent.cpp95
2 files changed, 2 insertions, 97 deletions
diff --git a/src/Entities/Compoments/AIAgressiveComponent.h b/src/Entities/Compoments/AIAgressiveComponent.h
index 2cd3f2304..338d311e3 100644
--- a/src/Entities/Compoments/AIAgressiveComponent.h
+++ b/src/Entities/Compoments/AIAgressiveComponent.h
@@ -3,7 +3,6 @@
class cAIAgressiveComponent : public cAIComponent {
protected:
- enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
cEntity * m_Target;
public:
cAIAgressiveComponent(cMonster * a_Monster) : cAIComponent(a_Monster), m_Target(null){}
@@ -15,8 +14,5 @@ public:
virtual void Attack(float a_Dt);
protected:
- virtual void EventLosePlayer(void);
- virtual void CheckEventLostPlayer(void);
-
bool IsMovingToTargetPosition();
} \ No newline at end of file
diff --git a/src/Entities/Compoments/AIAgresssiveComponent.cpp b/src/Entities/Compoments/AIAgresssiveComponent.cpp
index 4dcd3e618..ae89ef5b9 100644
--- a/src/Entities/Compoments/AIAgresssiveComponent.cpp
+++ b/src/Entities/Compoments/AIAgresssiveComponent.cpp
@@ -1,34 +1,5 @@
#include "AIAgressiveComponent.h"
-
-
-void cAIAggressiveComponent::Tick(float a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
-
- if (m_EMState == CHASING)
- {
- CheckEventLostPlayer();
- }
- else
- {
- CheckEventSeePlayer();
- }
-
- if (m_Target == NULL)
- return;
-
- cTracer LineOfSight(GetWorld());
- Vector3d AttackDirection(m_Target->GetPosition() - GetPosition());
-
- 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);
- }
-}
-
-
void cAIAggressiveComponent::Attack(float a_Dt)
{
float attack_interval = m_Self->GetAttackInterval();
@@ -38,13 +9,12 @@ 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, 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)
@@ -58,65 +28,4 @@ bool cAIAggressiveComponent::IsMovingToTargetPosition()
return false;
}
return true;
-}
-
-
-/// Event Checkers
-void cAIAggressiveComponent::CheckEventLostPlayer(void)
-{
- if (m_Target != NULL)
- {
- if ((m_Target->GetPosition() - GetPosition()).Length() > m_Self->GetSightDistance())
- {
- EventLosePlayer();
- }
- }
- else
- {
- EventLosePlayer();
- }
-}
-
-
-/// Event Handlers
-void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
-{
- if (!((cPlayer *)a_Entity)->IsGameModeCreative())
- {
- m_Target = a_Entity;
- m_EMState = CHASING;
- }
-}
-
-
-void cAIAggressiveComponent::EventLosePlayer(void)
-{
- m_Target = NULL;
- m_EMState = IDLE;
-}
-
-
-/// State Logic
-void cAggressiveMonster::InStateChasing(float a_Dt)
-{
- super::InStateChasing(a_Dt);
-
- if (m_Target != NULL)
- {
- if (m_Target->IsPlayer())
- {
- if (((cPlayer *)m_Target)->IsGameModeCreative())
- {
- m_EMState = IDLE;
- return;
- }
- }
-
- if (!IsMovingToTargetPosition())
- {
- m_Self->MoveToPosition(m_Target->GetPosition());
- }
- }
-}
-
-
+} \ No newline at end of file