summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorCoward.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-22 12:23:03 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-22 19:55:30 +0200
commit80d9c26c12a5be619a757d0251525664bf7065a6 (patch)
tree66d4f553ae12fd90dd94ffde9b85f595319ba5cb /src/Mobs/Behaviors/BehaviorCoward.cpp
parentAdded check in cEntity::TickBurning for whether the entity is planning to change worlds. (#3943) (diff)
downloadcuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar
cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.gz
cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.bz2
cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.lz
cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.xz
cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.zst
cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.zip
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorCoward.cpp')
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorCoward.cpp b/src/Mobs/Behaviors/BehaviorCoward.cpp
new file mode 100644
index 000000000..017227340
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorCoward.cpp
@@ -0,0 +1,53 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorCoward.h"
+#include "../Monster.h"
+#include "../../World.h"
+#include "../../Entities/Player.h"
+#include "../../Entities/Entity.h"
+
+cBehaviorCoward::cBehaviorCoward(cMonster * a_Parent) :
+ m_Parent(a_Parent),
+ m_Attacker(nullptr)
+{
+ ASSERT(m_Parent != nullptr);
+}
+
+
+
+
+
+bool cBehaviorCoward::ActiveTick()
+{
+ if (m_Attacker == nullptr)
+ {
+ return false;
+ }
+
+ // TODO NOT SAFE
+ if (m_Attacker->IsDestroyed() || (m_Attacker->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance())
+ {
+ // We lost the attacker
+ m_Attacker = nullptr;
+ return false;
+ }
+
+ Vector3d newloc = m_Parent->GetPosition();
+ newloc.x = (m_Attacker->GetPosition().x < newloc.x)? (newloc.x + m_Parent->GetSightDistance()): (newloc.x - m_Parent->GetSightDistance());
+ newloc.z = (m_Attacker->GetPosition().z < newloc.z)? (newloc.z + m_Parent->GetSightDistance()): (newloc.z - m_Parent->GetSightDistance());
+ m_Parent->MoveToPosition(newloc);
+ return true;
+}
+
+
+
+
+
+void cBehaviorCoward::DoTakeDamage(TakeDamageInfo & a_TDI)
+{
+ if ((a_TDI.Attacker != m_Parent) && (a_TDI.Attacker != nullptr))
+ {
+ m_Attacker = a_TDI.Attacker;
+ }
+}
+