diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 18:51:32 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 18:51:32 +0200 |
commit | afb65224879ccced98c5a3699f7732dc37fe3f40 (patch) | |
tree | e2b95d4acd2b4516f8244abd0e049a33aed6a293 /src/Mobs | |
parent | d (diff) | |
download | cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.tar cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.tar.gz cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.tar.bz2 cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.tar.lz cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.tar.xz cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.tar.zst cuberite-afb65224879ccced98c5a3699f7732dc37fe3f40.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAggressive.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAggressive.h | 2 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorAttacker.cpp | 6 | ||||
-rw-r--r-- | src/Mobs/Spider.cpp | 22 | ||||
-rw-r--r-- | src/Mobs/Spider.h | 11 |
5 files changed, 38 insertions, 5 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp index 3b0cf6eea..8cbacf5fa 100644 --- a/src/Mobs/Behaviors/BehaviorAggressive.cpp +++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp @@ -33,7 +33,7 @@ void cBehaviorAggressive::PreTick(std::chrono::milliseconds a_Dt, cChunk & a_Chu if (--m_AgressionCheckCountdown == 0) { m_AgressionCheckCountdown = 40; - m_ShouldBeAgressive = m_ShouldBeAggressiveFunction(*this, *m_Parent); + m_ShouldBeAgressive = m_ShouldBeAggressiveFunction(*this, *m_Parent, a_Chunk); } } diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h index 434565a65..923d646e0 100644 --- a/src/Mobs/Behaviors/BehaviorAggressive.h +++ b/src/Mobs/Behaviors/BehaviorAggressive.h @@ -9,7 +9,7 @@ class cBehaviorAggressive; /** 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; +typedef std::function<bool(cBehaviorAggressive & a_Behavior, cMonster & a_Monster, cChunk & a_Chunk)> ShouldBeAggressiveFunction; class cBehaviorAggressive : public cBehavior { diff --git a/src/Mobs/Behaviors/BehaviorAttacker.cpp b/src/Mobs/Behaviors/BehaviorAttacker.cpp index 50ce8f6ad..dd3b48de2 100644 --- a/src/Mobs/Behaviors/BehaviorAttacker.cpp +++ b/src/Mobs/Behaviors/BehaviorAttacker.cpp @@ -15,6 +15,7 @@ cBehaviorAttacker::cBehaviorAttacker() : , m_AttackCoolDownTicksLeft(0) , m_IsStriking(false) , m_Target(nullptr) + , m_ShouldRetaliate(true) { } @@ -130,6 +131,11 @@ void cBehaviorAttacker::PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chun void cBehaviorAttacker::DoTakeDamage(TakeDamageInfo & a_TDI) { + if (!m_ShouldRetaliate) + { + return; + } + if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPawn()) { if ( diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 845bc145b..0a824aca2 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -7,10 +7,26 @@ #include "../Entities/Player.h" #include "../Chunk.h" -bool AggressiveAtNightFunction(cBehaviorAggressive & a_Behavior, cMonster & a_Monster) +bool AggressiveAtNightFunction(cBehaviorAggressive & a_Behavior, cMonster & a_Monster, cChunk & a_Chunk) { - return - !((Chunk->GetSkyLightAltered(Rel.x, Rel.y, Rel.z) > 11) || (Chunk->GetBlockLight(Rel.x, Rel.y, Rel.z) > 11)) + UNUSED(a_Behavior); + if (!a_Monster.GetWorld()->IsChunkLighted(a_Monster.GetChunkX(), a_Monster.GetChunkZ())) + { + return false; + } + + PREPARE_REL_AND_CHUNK(a_Monster.GetPosition(), a_Chunk); + if (!RelSuccess) + { + return false; + } + + if ( + !((Chunk->GetSkyLightAltered(Rel.x, Rel.y, Rel.z) > 11) || (Chunk->GetBlockLight(Rel.x, Rel.y, Rel.z) > 11)) + ) + { + return true; + } } cSpider::cSpider(void) : diff --git a/src/Mobs/Spider.h b/src/Mobs/Spider.h index de2c8d533..7113b9a3e 100644 --- a/src/Mobs/Spider.h +++ b/src/Mobs/Spider.h @@ -2,6 +2,10 @@ #pragma once #include "Monster.h" +#include "Behaviors/BehaviorAttackerMelee.h" +#include "Behaviors/BehaviorWanderer.h" +#include "Behaviors/BehaviorAggressive.h" +#include "Behaviors/BehaviorDayLightBurner.h" @@ -19,6 +23,13 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; +private: + // tick behaviors + cBehaviorAttackerMelee m_BehaviorAttackerMelee; + cBehaviorWanderer m_BehaviorWanderer; + + // other behaviors + cBehaviorAggressive m_BehaviorAggressive; } ; |