diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-30 09:36:24 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-30 09:36:24 +0200 |
commit | 5eadfdb281f1b602fe3aa3724096545a685b96e1 (patch) | |
tree | 82aa8107e23cefef770505529208ee5f7b1e5d6f /src/Mobs/Behaviors | |
parent | Added BehaviorBrave, chaser > attacker (diff) | |
download | cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.tar cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.tar.gz cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.tar.bz2 cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.tar.lz cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.tar.xz cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.tar.zst cuberite-5eadfdb281f1b602fe3aa3724096545a685b96e1.zip |
Diffstat (limited to 'src/Mobs/Behaviors')
-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 |
3 files changed, 43 insertions, 4 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; |