diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 18:36:24 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 18:36:24 +0200 |
commit | 2523af8f9a6f712dc6cc4007437349557b0bdfe1 (patch) | |
tree | dcd08777ca9672c331ff6b3503a899e59e2584fc /src/Mobs/Behaviors | |
parent | Reimplemented creepers using Behaviors (diff) | |
download | cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.tar cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.tar.gz cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.tar.bz2 cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.tar.lz cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.tar.xz cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.tar.zst cuberite-2523af8f9a6f712dc6cc4007437349557b0bdfe1.zip |
Diffstat (limited to 'src/Mobs/Behaviors')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAggressive.cpp | 24 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAggressive.h | 9 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerMelee.cpp | 14 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerMelee.h | 6 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp | 4 |
5 files changed, 53 insertions, 4 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp index 2e3333e89..3b0cf6eea 100644 --- a/src/Mobs/Behaviors/BehaviorAggressive.cpp +++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp @@ -6,6 +6,16 @@ #include "../../Chunk.h" #include "../../Entities/Player.h" + + +cBehaviorAggressive::cBehaviorAggressive(ShouldBeAggressiveFunction a_ShouldBeAggressiveFunction) + : m_ShouldBeAggressiveFunction(a_ShouldBeAggressiveFunction) + , m_ShouldBeAgressive(true) + , m_AgressionCheckCountdown(1) +{ + +} + void cBehaviorAggressive::AttachToMonster(cMonster & a_Parent) { m_Parent = &a_Parent; @@ -18,6 +28,20 @@ void cBehaviorAggressive::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chu UNUSED(a_Dt); UNUSED(a_Chunk); + if (m_ShouldBeAggressiveFunction != nullptr) + { + if (--m_AgressionCheckCountdown == 0) + { + m_AgressionCheckCountdown = 40; + m_ShouldBeAgressive = m_ShouldBeAggressiveFunction(*this, *m_Parent); + } + } + + if (!m_ShouldBeAgressive) + { + return; + } + // Target something new if we have no target cBehaviorAttacker * BehaviorAttacker = m_Parent->GetBehaviorAttacker(); if ((BehaviorAttacker != nullptr) && (BehaviorAttacker->GetTarget() == nullptr)) diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h index 840d925d5..434565a65 100644 --- a/src/Mobs/Behaviors/BehaviorAggressive.h +++ b/src/Mobs/Behaviors/BehaviorAggressive.h @@ -4,13 +4,18 @@ class cBehaviorAggressive; #include "Behavior.h" +#include <functional> /** The mob is agressive toward specific mobtypes, or toward the player. This Behavior has a dependency on BehaviorAttacker. */ + +typedef std::function<bool(cBehaviorAggressive & a_Behavior, cMonster & a_Monster)> ShouldBeAggressiveFunction; + class cBehaviorAggressive : public cBehavior { public: + cBehaviorAggressive(ShouldBeAggressiveFunction a_ShouldBeAggressiveFunction = nullptr); void AttachToMonster(cMonster & a_Parent); // cBehaviorAggressive(cMonster * a_Parent, bool a_HatesPlayer); @@ -28,4 +33,8 @@ private: // The mob we want to attack cPawn * m_Target; + + ShouldBeAggressiveFunction m_ShouldBeAggressiveFunction; + bool m_ShouldBeAgressive; + int m_AgressionCheckCountdown; }; diff --git a/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp b/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp index 2bc0ef29d..3d25f34b4 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp @@ -5,9 +5,23 @@ #include "../../Entities/Pawn.h" #include "../../BlockID.h" +cBehaviorAttackerMelee::cBehaviorAttackerMelee(PostAttackFunction a_PostAttackFunction) + : m_PostAttackFunction(a_PostAttackFunction) +{ + +} + + + + + bool cBehaviorAttackerMelee::DoStrike(int a_StrikeTickCnt) { UNUSED(a_StrikeTickCnt); GetTarget()->TakeDamage(dtMobAttack, m_Parent, m_AttackDamage, 0); + if (m_PostAttackFunction != nullptr) + { + m_PostAttackFunction(*this, *m_Parent, *GetTarget()); + } return true; // Finish the strike. It only takes 1 tick. } diff --git a/src/Mobs/Behaviors/BehaviorAttackerMelee.h b/src/Mobs/Behaviors/BehaviorAttackerMelee.h index 617b9d321..69d626fbc 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerMelee.h +++ b/src/Mobs/Behaviors/BehaviorAttackerMelee.h @@ -1,11 +1,17 @@ #pragma once #include "BehaviorAttacker.h" +#include <functional> +class cBehaviorAttackerMelee; /** Grants the mob that ability to approach a target and then melee attack it. Use BehaviorAttackerMelee::SetTarget to attack. */ +typedef std::function<void(cBehaviorAttackerMelee & a_Behavior, cMonster & a_Attacker, cPawn & a_Attacked)> PostAttackFunction; class cBehaviorAttackerMelee : public cBehaviorAttacker { public: + cBehaviorAttackerMelee(PostAttackFunction a_PostAttackFunction = nullptr); bool DoStrike(int a_StrikeTickCnt) override; +private: + PostAttackFunction m_PostAttackFunction; }; diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp index bab9fd88f..843cc58ef 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp @@ -35,13 +35,9 @@ bool cBehaviorAttackerSuicideBomber::DoStrike(int a_StrikeTickCnt) { UNUSED(a_StrikeTickCnt); - - LOGD("Suicide doStrike"); - // phase 1: start blowing up if (a_StrikeTickCnt == 1) { - LOGD("Suicide START"); ASSERT(!m_bIsBlowing); m_Parent->GetWorld()->BroadcastSoundEffect("entity.creeper.primed", m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 1.f, (0.75f + (static_cast<float>((m_Parent->GetUniqueID() * 23) % 32)) / 64)); |