From 9711b06578e25fb92c8e6d10bd0f12bf593ed9db Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Tue, 22 Aug 2017 17:41:48 +0300 Subject: d --- src/Mobs/Behaviors/BehaviorChaser.cpp | 148 +++++++++++++++++----------------- 1 file changed, 75 insertions(+), 73 deletions(-) (limited to 'src/Mobs/Behaviors/BehaviorChaser.cpp') diff --git a/src/Mobs/Behaviors/BehaviorChaser.cpp b/src/Mobs/Behaviors/BehaviorChaser.cpp index 22a95fe73..b022495eb 100644 --- a/src/Mobs/Behaviors/BehaviorChaser.cpp +++ b/src/Mobs/Behaviors/BehaviorChaser.cpp @@ -7,18 +7,19 @@ #include "BehaviorStriker.h" -, m_AttackRate(3) -, m_AttackDamage(1) -, m_AttackRange(1) -, m_AttackCoolDownTicksLeft(0) -, m_TicksSinceLastDamaged(50) + cBehaviorChaser::cBehaviorChaser(cMonster * a_Parent) : - m_Parent(a_Parent) + m_Parent(a_Parent) + , m_AttackRate(3) + , m_AttackDamage(1) + , m_AttackRange(1) + , m_AttackCoolDownTicksLeft(0) + , m_TicksSinceLastDamaged(50) { - ASSERT(m_Parent != nullptr); - m_StrikeBehavior = m_Parent->GetBehaviorStriker(); - ASSERT(m_StrikeBehavior != nullptr); // The monster that has an Attacker behavior must also have a Striker behavior + ASSERT(m_Parent != nullptr); + m_StrikeBehavior = m_Parent->GetBehaviorStriker(); + ASSERT(m_StrikeBehavior != nullptr); // The monster that has an Attacker behavior must also have a Striker behavior } @@ -27,27 +28,27 @@ cBehaviorChaser::cBehaviorChaser(cMonster * a_Parent) : bool cBehaviorChaser::ActiveTick() { - // Stop targeting out of range targets - if (GetTarget() != nullptr) - { - if (TargetOutOfSight()) - { - SetTarget(nullptr); - } - else - { - if (TargetIsInStrikeRange()) - { - StrikeTarget(); - } - else - { - ApproachTarget(); - } - return true; - } - } - return false; + // Stop targeting out of range targets + if (GetTarget() != nullptr) + { + if (TargetOutOfSight()) + { + SetTarget(nullptr); + } + else + { + if (TargetIsInStrikeRange()) + { + StrikeTarget(); + } + else + { + ApproachTarget(); + } + return true; + } + } + return false; } @@ -56,11 +57,11 @@ bool cBehaviorChaser::ActiveTick() void cBehaviorChaser::Tick() { - ++m_TicksSinceLastDamaged; - if (m_AttackCoolDownTicksLeft > 0) - { - m_AttackCoolDownTicksLeft -= 1; - } + ++m_TicksSinceLastDamaged; + if (m_AttackCoolDownTicksLeft > 0) + { + m_AttackCoolDownTicksLeft -= 1; + } } @@ -69,7 +70,7 @@ void cBehaviorChaser::Tick() void cBehaviorChaser::Destroyed() { - m_Target = nullptr; + m_Target = nullptr; } @@ -78,7 +79,7 @@ void cBehaviorChaser::Destroyed() void cBehaviorChaser::SetAttackRate(float a_AttackRate) { - m_AttackRate = a_AttackRate; + m_AttackRate = a_AttackRate; } @@ -87,7 +88,7 @@ void cBehaviorChaser::SetAttackRate(float a_AttackRate) void cBehaviorChaser::SetAttackRange(int a_AttackRange) { - m_AttackRange = a_AttackRange; + m_AttackRange = a_AttackRange; } @@ -96,7 +97,7 @@ void cBehaviorChaser::SetAttackRange(int a_AttackRange) void cBehaviorChaser::SetAttackDamage(int a_AttackDamage) { - m_AttackDamage = a_AttackDamage; + m_AttackDamage = a_AttackDamage; } @@ -104,7 +105,7 @@ void cBehaviorChaser::SetAttackDamage(int a_AttackDamage) cPawn * cBehaviorChaser::GetTarget() { - return m_Target; + return m_Target; } @@ -113,7 +114,7 @@ cPawn * cBehaviorChaser::GetTarget() void cBehaviorChaser::SetTarget(cPawn * a_Target) { - m_Target = a_Target; + m_Target = a_Target; } @@ -131,26 +132,26 @@ cBehaviorChaser::~cBehaviorChaser() bool cBehaviorChaser::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); - - - if (GetTarget() != nullptr) - { - MoveToPosition(GetTarget()->GetPosition()); - } - if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast(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)); + 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); + + + if (GetTarget() != nullptr) + { + MoveToPosition(GetTarget()->GetPosition()); + } + if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast(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)); } @@ -159,12 +160,12 @@ bool cBehaviorChaser::TargetIsInStrikeRange() bool cBehaviorChaser::TargetOutOfSight() { - ASSERT(m_Target != nullptr); - if ((GetTarget()->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance()) - { - return true; - } - return false; + ASSERT(m_Target != nullptr); + if ((GetTarget()->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance()) + { + return true; + } + return false; } @@ -173,7 +174,7 @@ bool cBehaviorChaser::TargetOutOfSight() void cBehaviorChaser::ResetStrikeCooldown() { - m_AttackCoolDownTicksLeft = static_cast(3 * 20 * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every 3 seconds + m_AttackCoolDownTicksLeft = static_cast(3 * 20 * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every 3 seconds } @@ -182,9 +183,10 @@ void cBehaviorChaser::ResetStrikeCooldown() void cBehaviorChaser::StrikeTarget() { - if (m_AttackCoolDownTicksLeft != 0) - { - m_StrikeBehavior->Strike(m_Target); // LogicParrot Todo animations (via counter passing?) - ResetStrikeCooldown(); - } + if (m_AttackCoolDownTicksLeft != 0) + { + // mobTodo + // m_StrikeBehavior->Strike(m_Target); // LogicParrot Todo animations (via counter passing?) + ResetStrikeCooldown(); + } } -- cgit v1.2.3