diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-29 20:06:16 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-29 20:06:16 +0200 |
commit | 186321d3c780e9b1937c9fb387993f7e5cd9b9b0 (patch) | |
tree | 75c8e37bc3d4aff7f66de84042648dd51efd444f /src | |
parent | Horse (diff) | |
download | cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.tar cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.tar.gz cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.tar.bz2 cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.tar.lz cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.tar.xz cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.tar.zst cuberite-186321d3c780e9b1937c9fb387993f7e5cd9b9b0.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/AggressiveMonster.cpp | 2 | ||||
-rw-r--r-- | src/Mobs/AggressiveMonster.h | 11 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorDoNothing.cpp | 24 | ||||
-rw-r--r-- | src/Mobs/Behaviors/BehaviorDoNothing.h | 19 | ||||
-rw-r--r-- | src/Mobs/Behaviors/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 1 | ||||
-rw-r--r-- | src/Mobs/Squid.cpp | 1 | ||||
-rw-r--r-- | src/Mobs/Squid.h | 4 |
8 files changed, 60 insertions, 8 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index f06412e49..6cfeee4a5 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -16,7 +16,7 @@ cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eMonsterTyp super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height) { m_EMPersonality = AGGRESSIVE; - ASSERT(GetBehaviorChaser() != nullptr); + m_BehaviorWanderer.AttachToMonster(*this); } diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h index 27ad88834..853504b7a 100644 --- a/src/Mobs/AggressiveMonster.h +++ b/src/Mobs/AggressiveMonster.h @@ -7,16 +7,17 @@ typedef std::string AString; class cAggressiveMonster : - public cMonster + public cMonster { - typedef cMonster super; + typedef cMonster super; public: - cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height); + cAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height); - virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; private: - cBehaviorAggressive m_BehaviorAggressive; + cBehaviorAggressive m_BehaviorAggressive; + cBehaviorWanderer m_BehaviorWanderer; } ; diff --git a/src/Mobs/Behaviors/BehaviorDoNothing.cpp b/src/Mobs/Behaviors/BehaviorDoNothing.cpp new file mode 100644 index 000000000..aeb4b815e --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorDoNothing.cpp @@ -0,0 +1,24 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BehaviorDoNothing.h" +#include "../Monster.h" + +void cBehaviorDoNothing::AttachToMonster(cMonster & a_Parent) +{ + m_Parent = &a_Parent; + m_Parent->AttachTickBehavior(this); +} + +bool cBehaviorDoNothing::IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +{ + UNUSED(a_Dt); + UNUSED(a_Chunk); + return true; +} + +void cBehaviorDoNothing::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +{ + UNUSED(a_Dt); + UNUSED(a_Chunk); + return; +} diff --git a/src/Mobs/Behaviors/BehaviorDoNothing.h b/src/Mobs/Behaviors/BehaviorDoNothing.h new file mode 100644 index 000000000..52c0c7c08 --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorDoNothing.h @@ -0,0 +1,19 @@ +#pragma once + +// Always takes control of the tick and does nothing. Used for unimplemented mobs like squids. + +class cBehaviorDoNothing; + +#include "Behavior.h" + +class cBehaviorDoNothing : public cBehavior +{ +public: + void AttachToMonster(cMonster & a_Parent); + bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); + void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk); + +private: + /** Our parent */ + cMonster * m_Parent; +}; diff --git a/src/Mobs/Behaviors/CMakeLists.txt b/src/Mobs/Behaviors/CMakeLists.txt index 68b4bf731..a075cd12c 100644 --- a/src/Mobs/Behaviors/CMakeLists.txt +++ b/src/Mobs/Behaviors/CMakeLists.txt @@ -7,8 +7,9 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") SET (SRCS Behavior.cpp BehaviorAggressive.cpp - BehaviorChaser.cpp BehaviorBreeder.cpp + BehaviorChaser.cpp + BehaviorDoNothing.cpp BehaviorDayLightBurner.cpp BehaviorCoward.cpp BehaviorItemDropper.cpp @@ -21,8 +22,9 @@ SET (SRCS SET (HDRS Behavior.h BehaviorAggressive.h - BehaviorChaser.h BehaviorBreeder.h + BehaviorChaser.h + BehaviorDoNothing.h BehaviorDayLightBurner.h BehaviorCoward.h BehaviorItemDropper.h diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index a2e16080b..d864f9971 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -4,6 +4,7 @@ #include "../Entities/Pawn.h" #include "MonsterTypes.h" #include "PathFinder.h" +#include "Behaviors/BehaviorWanderer.h" #include <vector> class cItem; diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 37aa70064..69f918935 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -12,6 +12,7 @@ cSquid::cSquid(void) : super("Squid", mtSquid, "entity.squid.hurt", "entity.squid.death", 0.95, 0.95) { m_EMPersonality = PASSIVE; + m_BehaviorDoNothing.AttachToMonster(*this); } diff --git a/src/Mobs/Squid.h b/src/Mobs/Squid.h index 42ad6938e..20d87dbca 100644 --- a/src/Mobs/Squid.h +++ b/src/Mobs/Squid.h @@ -2,6 +2,7 @@ #pragma once #include "Monster.h" +#include "Behaviors/BehaviorDoNothing.h" @@ -24,6 +25,9 @@ public: // Squids do not drown (or float) virtual void HandleAir(void) override {} virtual void SetSwimState(cChunk & a_Chunk) override {} + +private: + cBehaviorDoNothing m_BehaviorDoNothing; } ; |