diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorBrave.cpp | 27 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorBrave.h | 15 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorCoward.h | 5 | ||||
-rw-r--r-- | src/Mobs/Monster.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 2 |
5 files changed, 45 insertions, 6 deletions
diff --git a/src/Mobs/Behaviors/BehaviorBrave.cpp b/src/Mobs/Behaviors/BehaviorBrave.cpp index e69de29bb..6aba310a1 100644 --- a/src/Mobs/Behaviors/BehaviorBrave.cpp +++ b/src/Mobs/Behaviors/BehaviorBrave.cpp @@ -0,0 +1,27 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BehaviorBrave.h" +#include "BehaviorAttacker.h" +#include "../Monster.h" +#include "../../Entities/Entity.h" + +void cBehaviorBrave::AttachToMonster(cMonster & a_Parent) +{ + m_Parent = &a_Parent; + m_Parent->AttachDoTakeDamageBehavior(this); +} + + + + +void cBehaviorBrave::DoTakeDamage(TakeDamageInfo & a_TDI) +{ + cBehaviorAttacker * AttackBehavior = m_Parent->GetBehaviorAttacker(); + if ((AttackBehavior != nullptr) && (a_TDI.Attacker != m_Parent) && + (a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPawn()) + ) + { + AttackBehavior->SetTarget(static_cast<cPawn*>(a_TDI.Attacker)); + } +} + diff --git a/src/Mobs/Behaviors/BehaviorBrave.h b/src/Mobs/Behaviors/BehaviorBrave.h index e69de29bb..0a59f90b8 100644 --- a/src/Mobs/Behaviors/BehaviorBrave.h +++ b/src/Mobs/Behaviors/BehaviorBrave.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Behavior.h" + +/** 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 cBehaviorBrave : cBehavior +{ +public: + void AttachToMonster(cMonster & a_Parent); + void DoTakeDamage(TakeDamageInfo & a_TDI) override; + +private: + cMonster * m_Parent; // Our Parent +}; diff --git a/src/Mobs/Behaviors/BehaviorCoward.h b/src/Mobs/Behaviors/BehaviorCoward.h index 9058419e3..3232f807b 100644 --- a/src/Mobs/Behaviors/BehaviorCoward.h +++ b/src/Mobs/Behaviors/BehaviorCoward.h @@ -2,16 +2,13 @@ #include "Behavior.h" -// Makes the mob run away from any other mob that damages it - - +/** Makes the mob run away from any other mob that damages it. */ class cBehaviorCoward : cBehavior { public: cBehaviorCoward(); void AttachToMonster(cMonster & a_Parent); - // Functions our host Monster should invoke: bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; bool ControlStarting(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; bool ControlEnding(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 6e15fe626..013a14953 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -1035,7 +1035,7 @@ const cBehaviorBreeder * cMonster::GetBehaviorBreeder() const -cBehaviorAttacker * cMonster::GetBehaviorChaser() +cBehaviorAttacker * cMonster::GetBehaviorAttacker() { return nullptr; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index c28e240c1..c893aed49 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -202,7 +202,7 @@ public: // Behavior getters (most are probably not used. mobTodo - cleanup most of them) virtual cBehaviorBreeder * GetBehaviorBreeder(); virtual const cBehaviorBreeder * GetBehaviorBreeder() const; - virtual cBehaviorAttacker * GetBehaviorChaser(); + virtual cBehaviorAttacker * GetBehaviorAttacker(); virtual cBehaviorDayLightBurner * GetBehaviorDayLightBurner(); // mobTodo this is probably temporary // Polymorphic behavior functions |