summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorAggressive.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorAggressive.cpp')
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp
new file mode 100644
index 000000000..2e3333e89
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp
@@ -0,0 +1,42 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorAggressive.h"
+#include "BehaviorAttacker.h"
+#include "../Monster.h"
+#include "../../Chunk.h"
+#include "../../Entities/Player.h"
+
+void cBehaviorAggressive::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_Parent->AttachPreTickBehavior(this);
+}
+
+
+void cBehaviorAggressive::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ UNUSED(a_Dt);
+ UNUSED(a_Chunk);
+
+ // Target something new if we have no target
+ cBehaviorAttacker * BehaviorAttacker = m_Parent->GetBehaviorAttacker();
+ if ((BehaviorAttacker != nullptr) && (BehaviorAttacker->GetTarget() == nullptr))
+ {
+ // mobTodo enhance this
+ BehaviorAttacker->SetTarget(FindNewTarget());
+ }
+}
+
+
+
+
+
+cPawn * cBehaviorAggressive::FindNewTarget()
+{
+ cPlayer * Closest = m_Parent->GetNearestPlayer();
+ if ((Closest != nullptr) && (!Closest->CanMobsTarget()))
+ {
+ return nullptr;
+ }
+ return Closest; // May be null
+}