diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 15:09:18 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 15:09:18 +0200 |
commit | 0030ea9010cc7c621056f3b93a340a87fb745a79 (patch) | |
tree | 9da29a8c8e7ca216b22dc32c0e862e613ff83d88 /src/Mobs | |
parent | Initial creeper behaviors (diff) | |
download | cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.tar cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.tar.gz cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.tar.bz2 cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.tar.lz cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.tar.xz cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.tar.zst cuberite-0030ea9010cc7c621056f3b93a340a87fb745a79.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttacker.cpp | 8 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttacker.h | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerMelee.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerMelee.h | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerRanged.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerRanged.h | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp | 60 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h | 8 |
8 files changed, 37 insertions, 49 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.cpp b/src/Mobs/Behaviors/BehaviorAttacker.cpp index 2365ee3a3..2a22b3666 100644 --- a/src/Mobs/Behaviors/BehaviorAttacker.cpp +++ b/src/Mobs/Behaviors/BehaviorAttacker.cpp @@ -55,15 +55,11 @@ void cBehaviorAttacker::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) UNUSED(a_Dt); UNUSED(a_Chunk); - if (m_Parent->GetHealth() <= 0.0) - { - // mobTodo put this elsewhere? - return; - } + ASSERT(m_Parent->GetHealth() > 0.0); if (m_IsStriking) { - if (StrikeTarget(++m_StrikeTickCnt)) + if (DoStrikeTarget(++m_StrikeTickCnt)) { m_Parent->UnpinBehavior(this); m_IsStriking = false; diff --git a/src/Mobs/Behaviors/BehaviorAttacker.h b/src/Mobs/Behaviors/BehaviorAttacker.h index fe3805c66..eeb6de2a0 100644 --- a/src/Mobs/Behaviors/BehaviorAttacker.h +++ b/src/Mobs/Behaviors/BehaviorAttacker.h @@ -48,7 +48,7 @@ protected: it returns false. a_StrikeTickCnt tracks how many times it was called. It is 1 the first call. It increments by 1 each call. This mechanism allows multi-tick attacks, like blazes shooting multiple fireballs, but most attacks are single tick and return true the first call. */ - virtual bool StrikeTarget(int a_StrikeTickCnt) = 0; + virtual bool DoStrikeTarget(int a_StrikeTickCnt) = 0; // Target related methods bool TargetIsInStrikeRadius(); diff --git a/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp b/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp index 337d8d216..8203326e6 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerMelee.cpp @@ -5,7 +5,7 @@ #include "../../Entities/Pawn.h" #include "../../BlockID.h" -bool cBehaviorAttackerMelee::StrikeTarget(int a_StrikeTickCnt) +bool cBehaviorAttackerMelee::DoStrikeTarget(int a_StrikeTickCnt) { UNUSED(a_StrikeTickCnt); GetTarget()->TakeDamage(dtMobAttack, m_Parent, m_AttackDamage, 0); diff --git a/src/Mobs/Behaviors/BehaviorAttackerMelee.h b/src/Mobs/Behaviors/BehaviorAttackerMelee.h index 6e990f04c..bfde615f8 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerMelee.h +++ b/src/Mobs/Behaviors/BehaviorAttackerMelee.h @@ -7,5 +7,5 @@ Use BehaviorAttackerMelee::SetTarget to attack. */ class cBehaviorAttackerMelee : public cBehaviorAttacker { public: - bool StrikeTarget(int a_StrikeTickCnt) override; + bool DoStrikeTarget(int a_StrikeTickCnt) override; }; diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp index 389c6b9f7..2d5e0f0e3 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.cpp @@ -6,7 +6,7 @@ #include "../../BlockID.h" #include "../../Entities/ArrowEntity.h" -bool cBehaviorAttackerRanged::StrikeTarget(int a_StrikeTickCnt) +bool cBehaviorAttackerRanged::DoStrikeTarget(int a_StrikeTickCnt) { UNUSED(a_StrikeTickCnt); auto & Random = GetRandomProvider(); diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.h b/src/Mobs/Behaviors/BehaviorAttackerRanged.h index 9ccf4b2d6..069f9092f 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerRanged.h +++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.h @@ -7,5 +7,5 @@ Use BehaviorAttackerMelee::SetTarget to attack. */ class cBehaviorAttackerRanged : public cBehaviorAttacker { public: - bool StrikeTarget(int a_StrikeTickCnt) override; + bool DoStrikeTarget(int a_StrikeTickCnt) override; }; diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp index d7791319d..ddf30326a 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp @@ -22,51 +22,41 @@ cBehaviorAttackerSuicideBomber::cBehaviorAttackerSuicideBomber() : -void cBehaviorAttackerSuicideBomber::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) { - if (((GetTarget() == nullptr) || !TargetIsInStrikeRadius()) && !m_BurnedWithFlintAndSteel) + UNUSED(a_StrikeTickCnt); + + ASSERT(GetTarget() != nullptr);// mobTodo guaranteed ? + + if ((!TargetIsInStrikeRadius()) && (!m_BurnedWithFlintAndSteel)) { if (m_bIsBlowing) { - m_ExplodingTimer = 0; m_bIsBlowing = false; m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); } } - else - { - if (m_bIsBlowing) - { - m_ExplodingTimer += 1; - } - - if ((m_ExplodingTimer == 30) && (m_Parent->GetHealth() > 0.0)) // only explode when not already dead - { - m_Parent->GetWorld()->DoExplosionAt((m_bIsCharged ? 5 : 3), m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), false, esMonster, this); - m_Parent->Destroy(); // Just in case we aren't killed by the explosion - } - } - - cBehaviorAttacker::Tick(a_Dt, a_Chunk); -} - - - - -bool cBehaviorAttackerSuicideBomber::StrikeTarget(int a_StrikeTickCnt) -{ - UNUSED(a_StrikeTickCnt); - - if (!m_bIsBlowing) + // phase 1: start blowing up + if (a_StrikeTickCnt == 1) { + 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)); m_bIsBlowing = true; m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); - return true; + return false; } return false; + + + if (a_StrikeTickCnt == 30) + { + // mobTodo && (m_Parent->GetHealth() > 0.0) guaranteed ? + m_Parent->GetWorld()->DoExplosionAt((m_bIsCharged ? 5 : 3), m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), false, esMonster, this); + m_Parent->Destroy(); // Just in case we aren't killed by the explosion + } } @@ -81,10 +71,14 @@ void cBehaviorAttackerSuicideBomber::OnRightClicked(cPlayer & a_Player) { a_Player.UseEquippedItem(); } - 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)); - m_bIsBlowing = true; - m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); - m_BurnedWithFlintAndSteel = true; + if (!m_BurnedWithFlintAndSteel) + { + 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)); + m_bIsBlowing = true; + m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent); + m_BurnedWithFlintAndSteel = true; + m_Parent->PinBehavior(this); + } } } diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h index 99707f083..706bf0739 100644 --- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h +++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h @@ -10,17 +10,15 @@ public: cBehaviorAttackerSuicideBomber(); // cBehaviorAttacker also implements those and we need to call super on them - void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; void DoTakeDamage(TakeDamageInfo & a_TDI) override; bool StrikeTarget(int a_StrikeTickCnt) override; void OnRightClicked(cPlayer & a_Player) override; - bool IsBlowing(void) const {return m_bIsBlowing; } - bool IsCharged(void) const {return m_bIsCharged; } - bool IsBurnedWithFlintAndSteel(void) const {return m_BurnedWithFlintAndSteel; } + bool IsBlowing(void) const; + bool IsCharged(void) const; + bool IsBurnedWithFlintAndSteel(void) const; private: bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel; - int m_ExplodingTimer; }; |