summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Behaviors')
-rw-r--r--src/Mobs/Behaviors/BehaviorAttacker.cpp1
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerRanged.cpp24
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerRanged.h11
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp44
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h15
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.cpp4
-rw-r--r--src/Mobs/Behaviors/BehaviorWanderer.cpp4
-rw-r--r--src/Mobs/Behaviors/CMakeLists.txt4
8 files changed, 103 insertions, 4 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.cpp b/src/Mobs/Behaviors/BehaviorAttacker.cpp
index 2f25bd3aa..280914f09 100644
--- a/src/Mobs/Behaviors/BehaviorAttacker.cpp
+++ b/src/Mobs/Behaviors/BehaviorAttacker.cpp
@@ -99,6 +99,7 @@ void cBehaviorAttacker::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
if (TargetIsInStrikeRadiusAndLineOfSight())
{
+ m_Parent->StopMovingToPosition();
StrikeTargetIfReady();
}
else
diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp
new file mode 100644
index 000000000..389c6b9f7
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp
@@ -0,0 +1,24 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorAttackerRanged.h"
+#include "../Monster.h"
+#include "../../Entities/Pawn.h"
+#include "../../BlockID.h"
+#include "../../Entities/ArrowEntity.h"
+
+bool cBehaviorAttackerRanged::StrikeTarget(int a_StrikeTickCnt)
+{
+ UNUSED(a_StrikeTickCnt);
+ auto & Random = GetRandomProvider();
+ if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0))
+ {
+ Vector3d Inaccuracy = Vector3d(Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25), Random.RandReal<double>(-0.25, 0.25));
+ Vector3d Speed = (GetTarget()->GetPosition() + Inaccuracy - m_Parent->GetPosition()) * 5;
+ Speed.y += Random.RandInt(-1, 1);
+
+ auto Arrow = cpp14::make_unique<cArrowEntity>(m_Parent, m_Parent->GetPosX(), m_Parent->GetPosY() + 1, m_Parent->GetPosZ(), Speed);
+ auto ArrowPtr = Arrow.get();
+ ArrowPtr->Initialize(std::move(Arrow), *m_Parent->GetWorld());
+ }
+ return true; // Finish the strike. It only takes 1 tick.
+}
diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.h b/src/Mobs/Behaviors/BehaviorAttackerRanged.h
new file mode 100644
index 000000000..9ccf4b2d6
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "BehaviorAttacker.h"
+
+/** Grants the mob that ability to approach a target and then melee attack it.
+Use BehaviorAttackerMelee::SetTarget to attack. */
+class cBehaviorAttackerRanged : public cBehaviorAttacker
+{
+public:
+ bool StrikeTarget(int a_StrikeTickCnt) override;
+};
diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp
new file mode 100644
index 000000000..a2ca50e5f
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp
@@ -0,0 +1,44 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorAttackerSuicideBomber.h"
+#include "../Monster.h"
+#include "../../Entities/Pawn.h"
+#include "../../BlockID.h"
+
+bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt)
+{
+ UNUSED(a_StrikeTickCnt);
+ //mobTodo
+ return true; // Finish the strike. It only takes 1 tick.
+}
+
+/*
+ if (!IsTicking())
+ {
+ // The base class tick destroyed us
+ return;
+ }
+
+ if (((GetTarget() == nullptr) || !TargetIsInRange()) && !m_BurnedWithFlintAndSteel)
+ {
+ if (m_bIsBlowing)
+ {
+ m_ExplodingTimer = 0;
+ m_bIsBlowing = false;
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ }
+ else
+ {
+ if (m_bIsBlowing)
+ {
+ m_ExplodingTimer += 1;
+ }
+
+ if ((m_ExplodingTimer == 30) && (GetHealth() > 0.0)) // only explode when not already dead
+ {
+ m_World->DoExplosionAt((m_bIsCharged ? 5 : 3), GetPosX(), GetPosY(), GetPosZ(), false, esMonster, this);
+ Destroy(); // Just in case we aren't killed by the explosion
+ }
+ }
+ */
diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h
new file mode 100644
index 000000000..dc071e2f4
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "BehaviorAttacker.h"
+
+/** Grants the mob that ability to approach a target and then melee attack it.
+Use BehaviorAttackerMelee::SetTarget to attack. */
+class cBehaviorAttackerSuicideBomber : public cBehaviorAttacker
+{
+public:
+ bool StrikeTarget(int a_StrikeTickCnt) override;
+ void OnRightClicked(cPlayer & a_Player) override;
+
+private:
+
+};
diff --git a/src/Mobs/Behaviors/BehaviorCoward.cpp b/src/Mobs/Behaviors/BehaviorCoward.cpp
index 55a5932cd..fc13cf5b9 100644
--- a/src/Mobs/Behaviors/BehaviorCoward.cpp
+++ b/src/Mobs/Behaviors/BehaviorCoward.cpp
@@ -40,7 +40,7 @@ bool cBehaviorCoward::ControlStarting(std::chrono::milliseconds a_Dt, cChunk & a
{
UNUSED(a_Dt);
UNUSED(a_Chunk);
- m_Parent->GetPathFinder().setDontCare(true); // We don't care we're we are going when
+ m_Parent->GetPathFinder().SetDontCare(true); // We don't care we're we are going when
// wandering. If a path is not found, the pathfinder just modifies our destination.
m_Parent->SetRelativeWalkSpeed(m_Parent->GetRelativeWalkSpeed() * 3);
return true;
@@ -52,7 +52,7 @@ bool cBehaviorCoward::ControlEnding(std::chrono::milliseconds a_Dt, cChunk & a_C
UNUSED(a_Dt);
UNUSED(a_Chunk);
m_Parent->SetRelativeWalkSpeed(m_Parent->GetRelativeWalkSpeed() / 3);
- m_Parent->GetPathFinder().setDontCare(false);
+ m_Parent->GetPathFinder().SetDontCare(false);
return true;
}
diff --git a/src/Mobs/Behaviors/BehaviorWanderer.cpp b/src/Mobs/Behaviors/BehaviorWanderer.cpp
index cc03d55cb..56316bd9f 100644
--- a/src/Mobs/Behaviors/BehaviorWanderer.cpp
+++ b/src/Mobs/Behaviors/BehaviorWanderer.cpp
@@ -39,7 +39,7 @@ bool cBehaviorWanderer::ControlStarting(std::chrono::milliseconds a_Dt, cChunk &
{
UNUSED(a_Dt);
UNUSED(a_Chunk);
- m_Parent->GetPathFinder().setDontCare(true); // We don't care we're we are going when
+ m_Parent->GetPathFinder().SetDontCare(true); // We don't care we're we are going when
// wandering. If a path is not found, the pathfinder just modifies our destination.
return true;
}
@@ -49,7 +49,7 @@ bool cBehaviorWanderer::ControlEnding(std::chrono::milliseconds a_Dt, cChunk & a
{
UNUSED(a_Dt);
UNUSED(a_Chunk);
- m_Parent->GetPathFinder().setDontCare(false);
+ m_Parent->GetPathFinder().SetDontCare(false);
return true;
}
diff --git a/src/Mobs/Behaviors/CMakeLists.txt b/src/Mobs/Behaviors/CMakeLists.txt
index e92c850e3..f205e9cb4 100644
--- a/src/Mobs/Behaviors/CMakeLists.txt
+++ b/src/Mobs/Behaviors/CMakeLists.txt
@@ -17,6 +17,8 @@ SET (SRCS
BehaviorItemFollower.cpp
BehaviorItemReplacer.cpp
BehaviorAttackerMelee.cpp
+ BehaviorAttackerRanged.cpp
+ BehaviorAttackerSuicideBomber.cpp
BehaviorWanderer.cpp
)
@@ -33,6 +35,8 @@ SET (HDRS
BehaviorItemFollower.h
BehaviorItemReplacer.h
BehaviorAttackerMelee.h
+ BehaviorAttackerRanged.h
+ BehaviorAttackerSuicideBomber.h
BehaviorWanderer.h
)