diff options
Diffstat (limited to 'src/Mobs/Behaviors')
-rw-r--r-- | src/Mobs/Behaviors/Behavior.cpp | 10 | ||||
-rw-r--r-- | src/Mobs/Behaviors/Behavior.h | 6 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAggressive.cpp | 9 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorBreeder.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorChaser.cpp | 36 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorChaser.h | 5 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorCoward.cpp | 14 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorCoward.h | 7 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemFollower.cpp | 27 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemFollower.h | 5 |
10 files changed, 88 insertions, 33 deletions
diff --git a/src/Mobs/Behaviors/Behavior.cpp b/src/Mobs/Behaviors/Behavior.cpp index a8f719f66..7b54a3340 100644 --- a/src/Mobs/Behaviors/Behavior.cpp +++ b/src/Mobs/Behaviors/Behavior.cpp @@ -79,3 +79,13 @@ void cBehavior::Destroyed() LOGD("ERROR: Called Destroyed on a behavior that doesn't have one."); ASSERT(1 == 0); } + + + + +void cBehavior::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + UNUSED(a_TDI); + LOGD("ERROR: Called DoTakeDamage on a behavior that doesn't have one."); + ASSERT(1 == 0); +} diff --git a/src/Mobs/Behaviors/Behavior.h b/src/Mobs/Behaviors/Behavior.h index ce719f7e4..81499eade 100644 --- a/src/Mobs/Behaviors/Behavior.h +++ b/src/Mobs/Behaviors/Behavior.h @@ -1,5 +1,6 @@ #pragma once +struct TakeDamageInfo; class cBehavior { public: @@ -9,7 +10,10 @@ public: virtual void Tick(); virtual void PostTick(); virtual void PreTick(); + + virtual void onRightClicked(); virtual void Destroyed(); - virtual ~cBehavior() = 0; + virtual void DoTakeDamage(TakeDamageInfo & a_TDI); + virtual ~cBehavior() {} }; diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp index b2c7cc9ef..d629d83ac 100644 --- a/src/Mobs/Behaviors/BehaviorAggressive.cpp +++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp @@ -32,15 +32,6 @@ void cBehaviorAggressive::PreTick() -void cBehaviorAggressive::Destroyed() -{ - m_ParentChaser->SetTarget(nullptr); -} - - - - - cPawn * cBehaviorAggressive::FindNewTarget() { cPlayer * Closest = m_Parent->GetNearestPlayer(); diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp index 34f5142e0..219846367 100644 --- a/src/Mobs/Behaviors/BehaviorBreeder.cpp +++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp @@ -66,7 +66,7 @@ void cBehaviorBreeder::Tick() m_LovePartner->GetBehaviorBreeder()->ResetLoveMode(); ResetLoveMode(); - }d + } } } diff --git a/src/Mobs/Behaviors/BehaviorChaser.cpp b/src/Mobs/Behaviors/BehaviorChaser.cpp index d4a72896a..71a50c55b 100644 --- a/src/Mobs/Behaviors/BehaviorChaser.cpp +++ b/src/Mobs/Behaviors/BehaviorChaser.cpp @@ -2,10 +2,10 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "BehaviorChaser.h" +#include "BehaviorStriker.h" #include "../Monster.h" #include "../../Entities/Pawn.h" -#include "BehaviorStriker.h" - +#include "../../Entities/Player.h" @@ -15,7 +15,7 @@ cBehaviorChaser::cBehaviorChaser(cMonster * a_Parent) : , m_AttackDamage(1) , m_AttackRange(1) , m_AttackCoolDownTicksLeft(0) - , m_TicksSinceLastDamaged(50) + , m_TicksSinceLastDamaged(100) { ASSERT(m_Parent != nullptr); } @@ -36,8 +36,7 @@ bool cBehaviorChaser::IsControlDesired() void cBehaviorChaser::Tick() { - ASSERT((GetTarget() == nullptr) || (GetTarget()->IsPawn() && (GetTarget()->GetWorld() == GetWorld()))); - + ASSERT((GetTarget() == nullptr) || (GetTarget()->IsPawn() && (GetTarget()->GetWorld() == m_Parent->GetWorld()))); // Stop targeting out of range targets if (GetTarget() != nullptr) { @@ -71,7 +70,11 @@ void cBehaviorChaser::ApproachTarget() void cBehaviorChaser::PostTick() { - ++m_TicksSinceLastDamaged; + if (m_TicksSinceLastDamaged < 100) + { + ++m_TicksSinceLastDamaged; + } + if (m_AttackCoolDownTicksLeft > 0) { m_AttackCoolDownTicksLeft -= 1; @@ -82,6 +85,25 @@ void cBehaviorChaser::PostTick() +void cBehaviorChaser::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPawn()) + { + if ( + (!a_TDI.Attacker->IsPlayer()) || + (static_cast<cPlayer *>(a_TDI.Attacker)->CanMobsTarget()) + ) + { + SetTarget(static_cast<cPawn*>(a_TDI.Attacker)); + } + m_TicksSinceLastDamaged = 0; + } +} + + + + + void cBehaviorChaser::Destroyed() { SetTarget(nullptr); @@ -194,7 +216,7 @@ void cBehaviorChaser::StrikeTarget() cBehaviorStriker * Striker = m_Parent->GetBehaviorStriker(); if (Striker != nullptr) { - Striker->Strike(m_Target); + // Striker->Strike(m_Target); //mobTodo } ResetStrikeCooldown(); } diff --git a/src/Mobs/Behaviors/BehaviorChaser.h b/src/Mobs/Behaviors/BehaviorChaser.h index 75f3fc121..b71d503b3 100644 --- a/src/Mobs/Behaviors/BehaviorChaser.h +++ b/src/Mobs/Behaviors/BehaviorChaser.h @@ -24,6 +24,7 @@ public: void Tick() override; void Destroyed() override; void PostTick() override; + void DoTakeDamage(TakeDamageInfo & a_TDI) override; // Our host monster will call these once it loads its config file void SetAttackRate(float a_AttackRate); @@ -35,11 +36,9 @@ public: /** Sets the target. */ void SetTarget(cPawn * a_Target); - - virtual ~cBehaviorChaser(); protected: void ApproachTarget(); - // virtual void ApproachTarget() = 0; + // virtual void ApproachTarget() = 0; //mobTodo private: /** Our parent */ diff --git a/src/Mobs/Behaviors/BehaviorCoward.cpp b/src/Mobs/Behaviors/BehaviorCoward.cpp index ec3626807..31927a5e8 100644 --- a/src/Mobs/Behaviors/BehaviorCoward.cpp +++ b/src/Mobs/Behaviors/BehaviorCoward.cpp @@ -16,12 +16,20 @@ cBehaviorCoward::cBehaviorCoward(cMonster * a_Parent) : +bool cBehaviorCoward::IsControlDesired() +{ + return (m_Attacker != nullptr); //mobTodo probably not so safe pointer (and cChaser m_Target too) +} + + + + -bool cBehaviorCoward::Tick() +void cBehaviorCoward::Tick() { if (m_Attacker == nullptr) { - return false; + return; } // TODO NOT SAFE @@ -29,14 +37,12 @@ bool cBehaviorCoward::Tick() { // 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; } diff --git a/src/Mobs/Behaviors/BehaviorCoward.h b/src/Mobs/Behaviors/BehaviorCoward.h index ed0ad3ed5..13deece61 100644 --- a/src/Mobs/Behaviors/BehaviorCoward.h +++ b/src/Mobs/Behaviors/BehaviorCoward.h @@ -10,14 +10,15 @@ class cItems; class cEntity; struct TakeDamageInfo; -class cBehaviorCoward +class cBehaviorCoward : cBehavior { public: cBehaviorCoward(cMonster * a_Parent); // Functions our host Monster should invoke: - bool Tick(); - void DoTakeDamage(TakeDamageInfo & a_TDI); + bool IsControlDesired() override; + void Tick() override; + void DoTakeDamage(TakeDamageInfo & a_TDI) override; private: diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.cpp b/src/Mobs/Behaviors/BehaviorItemFollower.cpp index 2b0377c46..22c20d6b4 100644 --- a/src/Mobs/Behaviors/BehaviorItemFollower.cpp +++ b/src/Mobs/Behaviors/BehaviorItemFollower.cpp @@ -17,7 +17,30 @@ cBehaviorItemFollower::cBehaviorItemFollower(cMonster * a_Parent) : -bool cBehaviorItemFollower::Tick() +bool cBehaviorItemFollower::IsControlDesired() +{ + cItems FollowedItems; + m_Parent->GetFollowedItems(FollowedItems); + if (FollowedItems.Size() > 0) + { + cPlayer * a_Closest_Player = m_Parent->GetNearestPlayer(); + if (a_Closest_Player != nullptr) + { + cItem EquippedItem = a_Closest_Player->GetEquippedItem(); + if (FollowedItems.ContainsType(EquippedItem)) + { + return true; // We take control of the monster. Now it'll call our tick + } + } + } + return false; +} + + + + + +void cBehaviorItemFollower::Tick() { cItems FollowedItems; m_Parent->GetFollowedItems(FollowedItems); @@ -31,9 +54,7 @@ bool cBehaviorItemFollower::Tick() { Vector3d PlayerPos = a_Closest_Player->GetPosition(); m_Parent->MoveToPosition(PlayerPos); - return true; // We took control of the monster, prevent other Behaviors from doing so } } } - return false; } diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.h b/src/Mobs/Behaviors/BehaviorItemFollower.h index 09acfe473..ab33de65f 100644 --- a/src/Mobs/Behaviors/BehaviorItemFollower.h +++ b/src/Mobs/Behaviors/BehaviorItemFollower.h @@ -9,7 +9,7 @@ class cBehaviorItemFollower; class cMonster; class cItems; -class cBehaviorItemFollower +class cBehaviorItemFollower : public cBehavior { public: cBehaviorItemFollower(cMonster * a_Parent); @@ -17,7 +17,8 @@ public: void GetBreedingItems(cItems & a_Items); // Functions our host Monster should invoke: - void Tick(); + bool IsControlDesired() override; + void Tick() override; private: |