summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2014-07-10 22:14:21 +0200
committerSamuel Barney <samjbarney@gmail.com>2014-07-10 22:15:07 +0200
commite0f240424c0f172a5bbb08851620dc31b59104cd (patch)
tree3b4a7798283deb4a0cebad91b636341529f306db /src/Entities
parentReworked the AIComponent to focus on cMonster instead of the more general cEntity. (diff)
downloadcuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.tar
cuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.tar.gz
cuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.tar.bz2
cuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.tar.lz
cuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.tar.xz
cuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.tar.zst
cuberite-e0f240424c0f172a5bbb08851620dc31b59104cd.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Compoments/AIAgressiveComponent.h18
-rw-r--r--src/Entities/Compoments/AIAgresssiveComponent.cpp31
-rw-r--r--src/Entities/Compoments/AllComponents.h3
3 files changed, 52 insertions, 0 deletions
diff --git a/src/Entities/Compoments/AIAgressiveComponent.h b/src/Entities/Compoments/AIAgressiveComponent.h
new file mode 100644
index 000000000..338d311e3
--- /dev/null
+++ b/src/Entities/Compoments/AIAgressiveComponent.h
@@ -0,0 +1,18 @@
+#pragma once
+#include "AIComponent.h"
+
+class cAIAgressiveComponent : public cAIComponent {
+protected:
+ cEntity * m_Target;
+public:
+ 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:
+ bool IsMovingToTargetPosition();
+} \ No newline at end of file
diff --git a/src/Entities/Compoments/AIAgresssiveComponent.cpp b/src/Entities/Compoments/AIAgresssiveComponent.cpp
new file mode 100644
index 000000000..ae89ef5b9
--- /dev/null
+++ b/src/Entities/Compoments/AIAgresssiveComponent.cpp
@@ -0,0 +1,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;
+} \ No newline at end of file
diff --git a/src/Entities/Compoments/AllComponents.h b/src/Entities/Compoments/AllComponents.h
new file mode 100644
index 000000000..3d182cfde
--- /dev/null
+++ b/src/Entities/Compoments/AllComponents.h
@@ -0,0 +1,3 @@
+#pragma once
+
+#include "AIAgressiveComponent.h"; \ No newline at end of file