summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-30 09:44:56 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-30 09:44:56 +0200
commit172943dcf6e621a691ed988b08fa065f09e258a4 (patch)
treec1a0f68c6ca4ef1b2561045d84bad2646d6112c6
parentd (diff)
downloadcuberite-172943dcf6e621a691ed988b08fa065f09e258a4.tar
cuberite-172943dcf6e621a691ed988b08fa065f09e258a4.tar.gz
cuberite-172943dcf6e621a691ed988b08fa065f09e258a4.tar.bz2
cuberite-172943dcf6e621a691ed988b08fa065f09e258a4.tar.lz
cuberite-172943dcf6e621a691ed988b08fa065f09e258a4.tar.xz
cuberite-172943dcf6e621a691ed988b08fa065f09e258a4.tar.zst
cuberite-172943dcf6e621a691ed988b08fa065f09e258a4.zip
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.cpp9
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.h4
-rw-r--r--src/Mobs/Behaviors/BehaviorAttacker.cpp14
-rw-r--r--src/Mobs/Behaviors/BehaviorItemFollower.h5
4 files changed, 14 insertions, 18 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp
index 65618e123..ccea67eb4 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.cpp
+++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp
@@ -1,7 +1,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "BehaviorAggressive.h"
-#include "BehaviorChaser.h"
+#include "BehaviorAttacker.h"
#include "../Monster.h"
#include "../../Chunk.h"
#include "../../Entities/Player.h"
@@ -17,10 +17,13 @@ void cBehaviorAggressive::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chu
{
UNUSED(a_Dt);
UNUSED(a_Chunk);
+
// Target something new if we have no target
- if (m_ParentChaser->GetTarget() == nullptr)
+ cBehaviorAttacker * BehaviorAttacker = m_Parent->GetBehaviorAttacker();
+ if ((BehaviorAttacker != nullptr) && (BehaviorAttacker->GetTarget() == nullptr))
{
- m_ParentChaser->SetTarget(FindNewTarget());
+ // mobTodo enhance this
+ BehaviorAttacker->SetTarget(FindNewTarget());
}
}
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h
index 944eee36c..840d925d5 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.h
+++ b/src/Mobs/Behaviors/BehaviorAggressive.h
@@ -4,10 +4,9 @@
class cBehaviorAggressive;
#include "Behavior.h"
-class cBehaviorAttacker;
/** The mob is agressive toward specific mobtypes, or toward the player.
-This Behavior has a dependency on BehaviorChaser. */
+This Behavior has a dependency on BehaviorAttacker. */
class cBehaviorAggressive : public cBehavior
{
@@ -26,7 +25,6 @@ private:
// Our parent
cMonster * m_Parent;
- cBehaviorAttacker * m_ParentChaser;
// The mob we want to attack
cPawn * m_Target;
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.cpp b/src/Mobs/Behaviors/BehaviorAttacker.cpp
index 14ce8a264..56a879e84 100644
--- a/src/Mobs/Behaviors/BehaviorAttacker.cpp
+++ b/src/Mobs/Behaviors/BehaviorAttacker.cpp
@@ -6,7 +6,7 @@
#include "../Monster.h"
#include "../../Entities/Pawn.h"
#include "../../Entities/Player.h"
-
+#include "../../Tracer.h"
cBehaviorAttacker::cBehaviorAttacker() :
@@ -193,23 +193,17 @@ bool cBehaviorAttacker::TargetIsInStrikeRange()
{
ASSERT(m_Target != nullptr);
ASSERT(m_Parent != nullptr);
- /*
- #include "../../Tracer.h"
+
+
cTracer LineOfSight(m_Parent->GetWorld());
Vector3d MyHeadPosition = m_Parent->GetPosition() + Vector3d(0, m_Parent->GetHeight(), 0);
- Vector3d AttackDirection(m_ParentChaser->GetTarget()->GetPosition() + Vector3d(0, GetTarget()->GetHeight(), 0) - MyHeadPosition);
+ Vector3d AttackDirection(GetTarget()->GetPosition() + Vector3d(0, GetTarget()->GetHeight(), 0) - MyHeadPosition);
-
- if (GetTarget() != nullptr)
- {
- MoveToPosition(GetTarget()->GetPosition());
- }
if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())) && (GetHealth() > 0.0))
{
// Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
Attack(a_Dt);
}
- */
return ((m_Target->GetPosition() - m_Parent->GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange));
}
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.h b/src/Mobs/Behaviors/BehaviorItemFollower.h
index e0a8a85e4..8c79ec763 100644
--- a/src/Mobs/Behaviors/BehaviorItemFollower.h
+++ b/src/Mobs/Behaviors/BehaviorItemFollower.h
@@ -1,10 +1,11 @@
#pragma once
-// Makes the mob follow specific held items
+
class cBehaviorItemFollower;
#include "Behavior.h"
-
+/** Makes the mob follow specific items when held by the player.
+Currently relies on cMonster::GetFollowedItems for the item list. */
class cBehaviorItemFollower : public cBehavior
{
public: