summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-30 16:13:31 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-30 16:13:31 +0200
commit48dff0f03c5df964a411e310f8905aaa3c84ac27 (patch)
treefe76a724ce321fabd6cb261a41799b741ca0a394 /src/Mobs/Behaviors
parentremoved agressiveMonster (diff)
downloadcuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.tar
cuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.tar.gz
cuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.tar.bz2
cuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.tar.lz
cuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.tar.xz
cuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.tar.zst
cuberite-48dff0f03c5df964a411e310f8905aaa3c84ac27.zip
Diffstat (limited to 'src/Mobs/Behaviors')
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.cpp5
-rw-r--r--src/Mobs/Behaviors/BehaviorAttacker.cpp11
-rw-r--r--src/Mobs/Behaviors/BehaviorAttacker.h3
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerMelee.h2
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.cpp1
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.h4
6 files changed, 14 insertions, 12 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp
index b55c1b476..2e3333e89 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.cpp
+++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp
@@ -34,6 +34,9 @@ void cBehaviorAggressive::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chu
cPawn * cBehaviorAggressive::FindNewTarget()
{
cPlayer * Closest = m_Parent->GetNearestPlayer();
- if (!Closest->CanMobsTarget()) return nullptr;
+ if ((Closest != nullptr) && (!Closest->CanMobsTarget()))
+ {
+ return nullptr;
+ }
return Closest; // May be null
}
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.cpp b/src/Mobs/Behaviors/BehaviorAttacker.cpp
index 00eb53179..67a27a277 100644
--- a/src/Mobs/Behaviors/BehaviorAttacker.cpp
+++ b/src/Mobs/Behaviors/BehaviorAttacker.cpp
@@ -16,6 +16,7 @@ cBehaviorAttacker::cBehaviorAttacker() :
, m_AttackCoolDownTicksLeft(0)
, m_TicksSinceLastDamaged(100)
, m_IsStriking(false)
+ , m_Target(nullptr)
{
}
@@ -24,13 +25,14 @@ cBehaviorAttacker::cBehaviorAttacker() :
-void cBehaviorAttacker::AttachToMonster(cMonster & a_Parent, cBehaviorStriker & a_ParentStriker)
+void cBehaviorAttacker::AttachToMonster(cMonster & a_Parent)
{
m_Parent = &a_Parent;
m_Parent->AttachTickBehavior(this);
m_Parent->AttachDestroyBehavior(this);
m_Parent->AttachPostTickBehavior(this);
m_Parent->AttachDoTakeDamageBehavior(this);
+ m_Parent->m_BehaviorAttackerPointer = this;
}
@@ -90,6 +92,7 @@ void cBehaviorAttacker::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
ASSERT((GetTarget() == nullptr) || (GetTarget()->IsPawn() && (GetTarget()->GetWorld() == m_Parent->GetWorld())));
if (GetTarget() != nullptr)
{
+ m_Parent->SetLookingAt(m_Target);
if (TargetOutOfSight())
{
SetTarget(nullptr);
@@ -237,8 +240,8 @@ bool cBehaviorAttacker::TargetIsInStrikeRadiusAndLineOfSight()
Vector3d MyHeadPosition = m_Parent->GetPosition() + Vector3d(0, m_Parent->GetHeight(), 0);
Vector3d AttackDirection(GetTarget()->GetPosition() + Vector3d(0, GetTarget()->GetHeight(), 0) - MyHeadPosition);
- if (TargetIsInStrikeRadius() &&
- !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())) &&
+ if (TargetIsInStrikeRadius()/* &&
+ !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length()))*/ &&
(m_Parent->GetHealth() > 0.0)
)
{
@@ -279,7 +282,7 @@ void cBehaviorAttacker::ResetStrikeCooldown()
void cBehaviorAttacker::StrikeTargetIfReady()
{
- if (m_AttackCoolDownTicksLeft != 0)
+ if (m_AttackCoolDownTicksLeft == 0)
{
StrikeTarget();
}
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.h b/src/Mobs/Behaviors/BehaviorAttacker.h
index 4d99fda21..78ed70994 100644
--- a/src/Mobs/Behaviors/BehaviorAttacker.h
+++ b/src/Mobs/Behaviors/BehaviorAttacker.h
@@ -3,7 +3,6 @@
class cBehaviorAttacker;
#include "Behavior.h"
-class cBehaviorStriker;
/** Grants attack capability to the mob. Note that this is not the same as agression!
@@ -15,7 +14,7 @@ class cBehaviorAttacker : public cBehavior
public:
cBehaviorAttacker();
- void AttachToMonster(cMonster & a_Parent, cBehaviorStriker & a_ParentStriker);
+ void AttachToMonster(cMonster & a_Parent);
// Our host monster will call these once it loads its config file
diff --git a/src/Mobs/Behaviors/BehaviorAttackerMelee.h b/src/Mobs/Behaviors/BehaviorAttackerMelee.h
index 49a51ff71..b079c94fc 100644
--- a/src/Mobs/Behaviors/BehaviorAttackerMelee.h
+++ b/src/Mobs/Behaviors/BehaviorAttackerMelee.h
@@ -4,7 +4,7 @@
/** Makes the mob fight back any other mob that damages it. Mob should have BehaviorAttacker to work.
This behavior does not make sense in combination with BehaviorCoward. */
-class cBehaviorAttackerMelee : cBehaviorAttacker
+class cBehaviorAttackerMelee : public cBehaviorAttacker
{
public:
bool StrikeTarget(int a_StrikeTickCnt) override;
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp
index d06a3cb96..7ede92c52 100644
--- a/src/Mobs/Behaviors/BehaviorBreeder.cpp
+++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp
@@ -26,6 +26,7 @@ void cBehaviorBreeder::AttachToMonster(cMonster & a_Parent)
m_Parent->AttachPostTickBehavior(this);
m_Parent->AttachRightClickBehavior(this);
m_Parent->AttachDestroyBehavior(this);
+ m_Parent->m_BehaviorBreederPointer = this;
}
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.h b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
index 780827910..07812b9db 100644
--- a/src/Mobs/Behaviors/BehaviorDayLightBurner.h
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
@@ -8,13 +8,9 @@ class cBehaviorDayLightBurner : cBehavior
{
public:
void AttachToMonster(cMonster & a_Parent);
-
void PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
bool WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk);
- // Functions our host Monster should invoke:
- void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
-
private:
cMonster * m_Parent; // Our Parent
cEntity * m_Attacker; // The entity we're running away from