summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockFence.h1
-rw-r--r--src/Mobs/Bat.h6
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.cpp1
-rw-r--r--src/Mobs/CMakeLists.txt2
-rw-r--r--src/Mobs/Chicken.h7
-rw-r--r--src/Mobs/Cow.cpp7
-rw-r--r--src/Mobs/Cow.h2
-rw-r--r--src/Mobs/Horse.cpp295
-rw-r--r--src/Mobs/Horse.h62
-rw-r--r--src/Mobs/Mooshroom.cpp23
-rw-r--r--src/Mobs/Mooshroom.h19
-rw-r--r--src/Mobs/Ocelot.cpp1
-rw-r--r--src/Mobs/Ocelot.h6
-rw-r--r--src/Mobs/PassiveMonster.cpp91
-rw-r--r--src/Mobs/PassiveMonster.h33
-rw-r--r--src/Mobs/Path.h2
-rw-r--r--src/Mobs/Pig.cpp28
-rw-r--r--src/Mobs/Pig.h22
-rw-r--r--src/Mobs/Rabbit.cpp22
-rw-r--r--src/Mobs/Rabbit.h18
-rw-r--r--src/Mobs/Sheep.cpp321
-rw-r--r--src/Mobs/Sheep.h29
-rw-r--r--src/Mobs/Squid.cpp1
-rw-r--r--src/Mobs/Squid.h6
-rw-r--r--src/Mobs/Villager.cpp5
-rw-r--r--src/Mobs/Villager.h17
26 files changed, 527 insertions, 500 deletions
diff --git a/src/Blocks/BlockFence.h b/src/Blocks/BlockFence.h
index 63390cd37..9c25013f0 100644
--- a/src/Blocks/BlockFence.h
+++ b/src/Blocks/BlockFence.h
@@ -6,7 +6,6 @@
#include "../EffectID.h"
#include "Entities/LeashKnot.h"
#include "BoundingBox.h"
-#include "../Mobs/PassiveMonster.h"
diff --git a/src/Mobs/Bat.h b/src/Mobs/Bat.h
index 2da2dc3f2..0c3ed647f 100644
--- a/src/Mobs/Bat.h
+++ b/src/Mobs/Bat.h
@@ -1,16 +1,16 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Monster.h"
class cBat :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
cBat(void);
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp
index d1d167b8b..d06a3cb96 100644
--- a/src/Mobs/Behaviors/BehaviorBreeder.cpp
+++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp
@@ -1,7 +1,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "BehaviorBreeder.h"
-#include "../PassiveMonster.h"
#include "../../World.h"
#include "../Monster.h"
#include "../../Entities/Player.h"
diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt
index 55ae36e1e..bccf98735 100644
--- a/src/Mobs/CMakeLists.txt
+++ b/src/Mobs/CMakeLists.txt
@@ -22,7 +22,6 @@ SET (SRCS
Mooshroom.cpp
Ocelot.cpp
PassiveAggressiveMonster.cpp
- PassiveMonster.cpp
Path.cpp
PathFinder.cpp
Pig.cpp
@@ -62,7 +61,6 @@ SET (HDRS
Mooshroom.h
Ocelot.h
PassiveAggressiveMonster.h
- PassiveMonster.h
Path.h
PathFinder.h
Pig.h
diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h
index 6d99dd8c2..f60f3672f 100644
--- a/src/Mobs/Chicken.h
+++ b/src/Mobs/Chicken.h
@@ -1,8 +1,11 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Behaviors/BehaviorBreeder.h"
+#include "Behaviors/BehaviorItemFollower.h"
+#include "Behaviors/BehaviorCoward.h"
+#include "Behaviors/BehaviorWanderer.h"
#include "Behaviors/BehaviorItemDropper.h"
-
+#include "Monster.h"
diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp
index f3c5c821b..b5703fc1f 100644
--- a/src/Mobs/Cow.cpp
+++ b/src/Mobs/Cow.cpp
@@ -10,6 +10,7 @@ cCow::cCow(void) :
super("Cow", mtCow, "entity.cow.hurt", "entity.cow.death", 0.9, 1.3),
m_BehaviorItemReplacer(E_ITEM_BUCKET, E_ITEM_MILK)
{
+ m_EMPersonality = PASSIVE;
m_BehaviorBreeder.AttachToMonster(*this);
m_BehaviorCoward.AttachToMonster(*this);
m_BehaviorItemFollower.AttachToMonster(*this);
@@ -36,12 +37,6 @@ void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-
-
-
-
-
-
cBehaviorBreeder * cCow::GetBehaviorBreeder()
{
return &m_BehaviorBreeder;
diff --git a/src/Mobs/Cow.h b/src/Mobs/Cow.h
index 337d0674d..78b584bdc 100644
--- a/src/Mobs/Cow.h
+++ b/src/Mobs/Cow.h
@@ -2,9 +2,9 @@
#include "Behaviors/BehaviorBreeder.h"
#include "Behaviors/BehaviorItemFollower.h"
-#include "Behaviors/BehaviorItemReplacer.h"
#include "Behaviors/BehaviorCoward.h"
#include "Behaviors/BehaviorWanderer.h"
+#include "Behaviors/BehaviorItemReplacer.h"
#include "Monster.h"
class cCow : public cMonster
diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp
index 21a58489d..484864afe 100644
--- a/src/Mobs/Horse.cpp
+++ b/src/Mobs/Horse.cpp
@@ -11,22 +11,23 @@
cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
- super("Horse", mtHorse, "entity.horse.hurt", "entity.horse.death", 1.4, 1.6),
- m_bHasChest(false),
- m_bIsEating(false),
- m_bIsRearing(false),
- m_bIsMouthOpen(false),
- m_bIsTame(false),
- m_bIsSaddled(false),
- m_Type(Type),
- m_Color(Color),
- m_Style(Style),
- m_Armour(0),
- m_TimesToTame(TameTimes),
- m_TameAttemptTimes(0),
- m_RearTickCount(0),
- m_MaxSpeed(14.0)
+ super("Horse", mtHorse, "entity.horse.hurt", "entity.horse.death", 1.4, 1.6),
+ m_bHasChest(false),
+ m_bIsEating(false),
+ m_bIsRearing(false),
+ m_bIsMouthOpen(false),
+ m_bIsTame(false),
+ m_bIsSaddled(false),
+ m_Type(Type),
+ m_Color(Color),
+ m_Style(Style),
+ m_Armour(0),
+ m_TimesToTame(TameTimes),
+ m_TameAttemptTimes(0),
+ m_RearTickCount(0),
+ m_MaxSpeed(14.0)
{
+ m_EMPersonality = PASSIVE;
}
@@ -35,67 +36,67 @@ cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
- super::Tick(a_Dt, a_Chunk);
- if (!IsTicking())
- {
- // The base class tick destroyed us
- return;
- }
-
- auto & Random = GetRandomProvider();
-
- if (!m_bIsMouthOpen)
- {
- if (Random.RandBool(0.02))
- {
- m_bIsMouthOpen = true;
- }
- }
- else
- {
- if (Random.RandBool(0.10))
- {
- m_bIsMouthOpen = false;
- }
- }
-
- if ((m_Attachee != nullptr) && (!m_bIsTame))
- {
- if (m_TameAttemptTimes < m_TimesToTame)
- {
- if (Random.RandBool(0.02))
- {
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_EAST));
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_WEST));
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_EAST));
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_WEST));
-
- m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f);
- m_Attachee->Detach();
- m_bIsRearing = true;
- }
- }
- else
- {
- m_World->GetBroadcaster().BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5);
- m_bIsTame = true;
- }
- }
-
- if (m_bIsRearing)
- {
- if (m_RearTickCount == 20)
- {
- m_bIsRearing = false;
- m_RearTickCount = 0;
- }
- else
- {
- m_RearTickCount++;
- }
- }
-
- m_World->BroadcastEntityMetadata(*this);
+ super::Tick(a_Dt, a_Chunk);
+ if (!IsTicking())
+ {
+ // The base class tick destroyed us
+ return;
+ }
+
+ auto & Random = GetRandomProvider();
+
+ if (!m_bIsMouthOpen)
+ {
+ if (Random.RandBool(0.02))
+ {
+ m_bIsMouthOpen = true;
+ }
+ }
+ else
+ {
+ if (Random.RandBool(0.10))
+ {
+ m_bIsMouthOpen = false;
+ }
+ }
+
+ if ((m_Attachee != nullptr) && (!m_bIsTame))
+ {
+ if (m_TameAttemptTimes < m_TimesToTame)
+ {
+ if (Random.RandBool(0.02))
+ {
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_EAST));
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_WEST));
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_EAST));
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_WEST));
+
+ m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f);
+ m_Attachee->Detach();
+ m_bIsRearing = true;
+ }
+ }
+ else
+ {
+ m_World->GetBroadcaster().BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5);
+ m_bIsTame = true;
+ }
+ }
+
+ if (m_bIsRearing)
+ {
+ if (m_RearTickCount == 20)
+ {
+ m_bIsRearing = false;
+ m_RearTickCount = 0;
+ }
+ else
+ {
+ m_RearTickCount++;
+ }
+ }
+
+ m_World->BroadcastEntityMetadata(*this);
}
@@ -104,63 +105,63 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cHorse::OnRightClicked(cPlayer & a_Player)
{
- super::OnRightClicked(a_Player);
-
- if (m_bIsTame)
- {
- if (!m_bIsSaddled)
- {
- if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE)
- {
- // Saddle the horse:
- if (!a_Player.IsGameModeCreative())
- {
- a_Player.GetInventory().RemoveOneEquippedItem();
- }
- m_bIsSaddled = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- else
- {
- a_Player.AttachTo(this);
- }
- }
- else
- {
- a_Player.AttachTo(this);
- }
- }
- else if (a_Player.GetEquippedItem().IsEmpty())
- {
- // Check if leashed / unleashed to player before try to ride
- if (!m_IsLeashActionJustDone)
- {
- if (m_Attachee != nullptr)
- {
- if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
- {
- a_Player.Detach();
- return;
- }
-
- if (m_Attachee->IsPlayer())
- {
- return;
- }
-
- m_Attachee->Detach();
- }
-
- m_TameAttemptTimes++;
- a_Player.AttachTo(this);
- }
- }
- else
- {
- m_bIsRearing = true;
- m_RearTickCount = 0;
- m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f);
- }
+ super::OnRightClicked(a_Player);
+
+ if (m_bIsTame)
+ {
+ if (!m_bIsSaddled)
+ {
+ if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE)
+ {
+ // Saddle the horse:
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ m_bIsSaddled = true;
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ else
+ {
+ a_Player.AttachTo(this);
+ }
+ }
+ else
+ {
+ a_Player.AttachTo(this);
+ }
+ }
+ else if (a_Player.GetEquippedItem().IsEmpty())
+ {
+ // Check if leashed / unleashed to player before try to ride
+ if (!m_IsLeashActionJustDone)
+ {
+ if (m_Attachee != nullptr)
+ {
+ if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
+ {
+ a_Player.Detach();
+ return;
+ }
+
+ if (m_Attachee->IsPlayer())
+ {
+ return;
+ }
+
+ m_Attachee->Detach();
+ }
+
+ m_TameAttemptTimes++;
+ a_Player.AttachTo(this);
+ }
+ }
+ else
+ {
+ m_bIsRearing = true;
+ m_RearTickCount = 0;
+ m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f);
+ }
}
@@ -169,16 +170,16 @@ void cHorse::OnRightClicked(cPlayer & a_Player)
void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
- unsigned int LootingLevel = 0;
- if (a_Killer != nullptr)
- {
- LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
- }
- AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER);
- if (m_bIsSaddled)
- {
- a_Drops.push_back(cItem(E_ITEM_SADDLE, 1));
- }
+ unsigned int LootingLevel = 0;
+ if (a_Killer != nullptr)
+ {
+ LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
+ }
+ AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER);
+ if (m_bIsSaddled)
+ {
+ a_Drops.push_back(cItem(E_ITEM_SADDLE, 1));
+ }
}
@@ -187,8 +188,8 @@ void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cHorse::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
{
- if ((m_bIsTame) && (m_bIsSaddled))
- {
- super::HandleSpeedFromAttachee(a_Forward * m_MaxSpeed, a_Sideways * m_MaxSpeed);
- }
+ if ((m_bIsTame) && (m_bIsSaddled))
+ {
+ super::HandleSpeedFromAttachee(a_Forward * m_MaxSpeed, a_Sideways * m_MaxSpeed);
+ }
}
diff --git a/src/Mobs/Horse.h b/src/Mobs/Horse.h
index e84243360..60e9c5b71 100644
--- a/src/Mobs/Horse.h
+++ b/src/Mobs/Horse.h
@@ -1,49 +1,49 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Monster.h"
class cHorse :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
- cHorse(int Type, int Color, int Style, int TameTimes);
-
- CLASS_PROTODEF(cHorse)
-
- virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override;
- virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
- virtual void OnRightClicked(cPlayer & a_Player) override;
-
- bool IsSaddled (void) const {return m_bIsSaddled; }
- bool IsChested (void) const {return m_bHasChest; }
- bool IsEating (void) const {return m_bIsEating; }
- bool IsRearing (void) const {return m_bIsRearing; }
- bool IsMthOpen (void) const {return m_bIsMouthOpen; }
- bool IsTame (void) const override {return m_bIsTame; }
- int GetHorseType (void) const {return m_Type; }
- int GetHorseColor (void) const {return m_Color; }
- int GetHorseStyle (void) const {return m_Style; }
- int GetHorseArmour (void) const {return m_Armour;}
-
- virtual void GetBreedingItems(cItems & a_Items) override
- {
- a_Items.Add(E_ITEM_GOLDEN_CARROT);
- a_Items.Add(E_ITEM_GOLDEN_APPLE);
- }
+ cHorse(int Type, int Color, int Style, int TameTimes);
+
+ CLASS_PROTODEF(cHorse)
+
+ virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
+ virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override;
+ virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+ virtual void OnRightClicked(cPlayer & a_Player) override;
+
+ bool IsSaddled (void) const {return m_bIsSaddled; }
+ bool IsChested (void) const {return m_bHasChest; }
+ bool IsEating (void) const {return m_bIsEating; }
+ bool IsRearing (void) const {return m_bIsRearing; }
+ bool IsMthOpen (void) const {return m_bIsMouthOpen; }
+ bool IsTame (void) const override {return m_bIsTame; }
+ int GetHorseType (void) const {return m_Type; }
+ int GetHorseColor (void) const {return m_Color; }
+ int GetHorseStyle (void) const {return m_Style; }
+ int GetHorseArmour (void) const {return m_Armour;}
+
+ virtual void GetBreedingItems(cItems & a_Items) override
+ {
+ a_Items.Add(E_ITEM_GOLDEN_CARROT);
+ a_Items.Add(E_ITEM_GOLDEN_APPLE);
+ }
private:
- bool m_bHasChest, m_bIsEating, m_bIsRearing, m_bIsMouthOpen, m_bIsTame, m_bIsSaddled;
- int m_Type, m_Color, m_Style, m_Armour, m_TimesToTame, m_TameAttemptTimes, m_RearTickCount;
- float m_MaxSpeed;
+ bool m_bHasChest, m_bIsEating, m_bIsRearing, m_bIsMouthOpen, m_bIsTame, m_bIsSaddled;
+ int m_Type, m_Color, m_Style, m_Armour, m_TimesToTame, m_TameAttemptTimes, m_RearTickCount;
+ float m_MaxSpeed;
} ;
diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp
index b6feca76e..7a1feefcb 100644
--- a/src/Mobs/Mooshroom.cpp
+++ b/src/Mobs/Mooshroom.cpp
@@ -16,6 +16,11 @@
cMooshroom::cMooshroom(void) :
super("Mooshroom", mtMooshroom, "entity.cow.hurt", "entity.cow.death", 0.9, 1.3)
{
+ m_EMPersonality = PASSIVE;
+ m_BehaviorBreeder.AttachToMonster(*this);
+ m_BehaviorCoward.AttachToMonster(*this);
+ m_BehaviorItemFollower.AttachToMonster(*this);
+ m_BehaviorWanderer.AttachToMonster(*this);
}
@@ -39,6 +44,7 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cMooshroom::OnRightClicked(cPlayer & a_Player)
{
+ // mobTodo Behaviors
switch (a_Player.GetEquippedItem().m_ItemType)
{
case E_ITEM_BUCKET:
@@ -73,3 +79,20 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player)
}
}
+
+
+
+
+cBehaviorBreeder * cMooshroom::GetBehaviorBreeder()
+{
+ return &m_BehaviorBreeder;
+}
+
+
+
+
+
+const cBehaviorBreeder * cMooshroom::GetBehaviorBreeder() const
+{
+ return static_cast<const cBehaviorBreeder *>(&m_BehaviorBreeder);
+}
diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h
index 625963190..fa92c770f 100644
--- a/src/Mobs/Mooshroom.h
+++ b/src/Mobs/Mooshroom.h
@@ -1,16 +1,20 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Behaviors/BehaviorBreeder.h"
+#include "Behaviors/BehaviorItemFollower.h"
+#include "Behaviors/BehaviorCoward.h"
+#include "Behaviors/BehaviorWanderer.h"
+#include "Monster.h"
class cMooshroom :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
cMooshroom(void);
@@ -24,6 +28,15 @@ public:
{
a_Items.Add(E_ITEM_WHEAT);
}
+
+ virtual cBehaviorBreeder * GetBehaviorBreeder() override;
+ virtual const cBehaviorBreeder * GetBehaviorBreeder() const override;
+private:
+ // Tick controlling behaviors
+ cBehaviorBreeder m_BehaviorBreeder;
+ cBehaviorItemFollower m_BehaviorItemFollower;
+ cBehaviorCoward m_BehaviorCoward;
+ cBehaviorWanderer m_BehaviorWanderer;
} ;
diff --git a/src/Mobs/Ocelot.cpp b/src/Mobs/Ocelot.cpp
index e5004a1d1..e89b18186 100644
--- a/src/Mobs/Ocelot.cpp
+++ b/src/Mobs/Ocelot.cpp
@@ -20,6 +20,7 @@ cOcelot::cOcelot(void) :
m_CatType(ctWildOcelot),
m_OwnerName("")
{
+ m_EMPersonality = PASSIVE;
}
diff --git a/src/Mobs/Ocelot.h b/src/Mobs/Ocelot.h
index 75758a973..d27467683 100644
--- a/src/Mobs/Ocelot.h
+++ b/src/Mobs/Ocelot.h
@@ -1,7 +1,7 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Monster.h"
#include "../UUID.h"
@@ -9,9 +9,9 @@
class cOcelot :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
deleted file mode 100644
index 0b1349111..000000000
--- a/src/Mobs/PassiveMonster.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "PassiveMonster.h"
-#include "../World.h"
-#include "../Entities/Player.h"
-#include "BoundingBox.h"
-
-
-
-
-cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
- super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
-{
- m_EMPersonality = PASSIVE;
-}
-
-
-
-
-
-cPassiveMonster::~cPassiveMonster()
-{
-
-}
-
-
-
-
-
-bool cPassiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
-{
- if (!super::DoTakeDamage(a_TDI))
- {
- return false;
- }
- m_BehaviorCoward.DoTakeDamage(a_TDI);
- return true;
-}
-
-
-
-
-
-void cPassiveMonster::Destroyed()
-{
- m_BehaviorBreeder.Destroyed();
- super::Destroyed();
-}
-
-
-
-void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
-
- for (;;)
- {
- /*if (m_BehaviorCoward.Tick())
- {
- break;
- }
- if (m_BehaviorBreeder.Tick())
- {
- break;
- }
- if (m_BehaviorItemFollower.Tick())
- {
- break;
- }
- if (m_BehaviorWanderer.ActiveTick(a_Dt, a_Chunk))
- {
- break;
- }*/
-
- ASSERT(!"Not a single Behavior took control, this is not normal. ");
- break;
- }
-
- m_BehaviorBreeder.PostTick(a_Dt, a_Chunk);
-}
-
-
-
-
-
-void cPassiveMonster::OnRightClicked(cPlayer & a_Player)
-{
- super::OnRightClicked(a_Player);
- m_BehaviorBreeder.OnRightClicked(a_Player);
-}
diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h
deleted file mode 100644
index 0c1d00a3e..000000000
--- a/src/Mobs/PassiveMonster.h
+++ /dev/null
@@ -1,33 +0,0 @@
-
-#pragma once
-
-#include "Monster.h"
-#include "Behaviors/BehaviorBreeder.h"
-#include "Behaviors/BehaviorItemFollower.h"
-#include "Behaviors/BehaviorCoward.h"
-#include "Behaviors/BehaviorWanderer.h"
-
-
-typedef std::string AString;
-class cPassiveMonster : public cMonster
-{
- typedef cMonster super;
-
-public:
- cPassiveMonster(const AString & a_ConfigName, eMonsterType a_MobType,
- const AString & a_SoundHurt, const AString & a_SoundDeath,
- double a_Width, double a_Height);
- virtual ~cPassiveMonster();
- virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
- virtual void OnRightClicked(cPlayer & a_Player) override;
-
- /** When hit by someone, run away */
- virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
-
- virtual void Destroyed(void) override;
-private:
- cBehaviorBreeder m_BehaviorBreeder;
- cBehaviorItemFollower m_BehaviorItemFollower;
- cBehaviorCoward m_BehaviorCoward;
- cBehaviorWanderer m_BehaviorWanderer;
-};
diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h
index 977c5be1c..40e1de6f0 100644
--- a/src/Mobs/Path.h
+++ b/src/Mobs/Path.h
@@ -10,7 +10,7 @@ class cPath;
#include "../FastRandom.h"
#ifdef COMPILING_PATHFIND_DEBUGGER
- /* Note: the COMPILING_PATHFIND_DEBUGGER flag is used by Native / WiseOldMan95 to debug
+ /* Note: the COMPILING_PATHFIND_DEBUGGER flag is used by LogicParrot to debug
this class outside of Cuberite. This preprocessor flag is never set when compiling Cuberite. */
#include "PathFinderIrrlicht_Head.h"
#endif
diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp
index 82901b061..6c3de4427 100644
--- a/src/Mobs/Pig.cpp
+++ b/src/Mobs/Pig.cpp
@@ -13,6 +13,11 @@ cPig::cPig(void) :
super("Pig", mtPig, "entity.pig.hurt", "entity.pig.death", 0.9, 0.9),
m_bIsSaddled(false)
{
+ m_EMPersonality = PASSIVE;
+ m_BehaviorBreeder.AttachToMonster(*this);
+ m_BehaviorCoward.AttachToMonster(*this);
+ m_BehaviorItemFollower.AttachToMonster(*this);
+ m_BehaviorWanderer.AttachToMonster(*this);
}
@@ -41,6 +46,9 @@ void cPig::OnRightClicked(cPlayer & a_Player)
{
super::OnRightClicked(a_Player);
+ // Behavior note: saddling is pig-specific. It is not transferrable to other mobs.
+ // Therefore saddling is not a standalone behavior and is hardcoded into the pig.
+
if (m_bIsSaddled)
{
if (m_Attachee != nullptr)
@@ -91,6 +99,9 @@ void cPig::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
return;
}
+ // Behavior note: saddling is pig-specific. It is not transferrable to other mobs.
+ // Therefore saddling is not a standalone behavior and is hardcoded into the pig.
+
// If the attachee player is holding a carrot-on-stick, let them drive this pig:
if (m_bIsSaddled && (m_Attachee != nullptr))
{
@@ -124,3 +135,20 @@ bool cPig::DoTakeDamage(TakeDamageInfo & a_TDI)
+
+cBehaviorBreeder * cPig::GetBehaviorBreeder()
+{
+ return &m_BehaviorBreeder;
+}
+
+
+
+
+
+const cBehaviorBreeder * cPig::GetBehaviorBreeder() const
+{
+ return static_cast<const cBehaviorBreeder *>(&m_BehaviorBreeder);
+}
+
+
+
diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h
index ed0685e5f..276ac1df8 100644
--- a/src/Mobs/Pig.h
+++ b/src/Mobs/Pig.h
@@ -1,16 +1,16 @@
-
#pragma once
-#include "PassiveMonster.h"
-
-
-
+#include "Behaviors/BehaviorBreeder.h"
+#include "Behaviors/BehaviorItemFollower.h"
+#include "Behaviors/BehaviorCoward.h"
+#include "Behaviors/BehaviorWanderer.h"
+#include "Monster.h"
class cPig :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
cPig(void);
@@ -30,8 +30,14 @@ public:
}
bool IsSaddled(void) const { return m_bIsSaddled; }
-
+ virtual cBehaviorBreeder * GetBehaviorBreeder() override;
+ virtual const cBehaviorBreeder * GetBehaviorBreeder() const override;
private:
+ // Tick controlling behaviors
+ cBehaviorBreeder m_BehaviorBreeder;
+ cBehaviorItemFollower m_BehaviorItemFollower;
+ cBehaviorCoward m_BehaviorCoward;
+ cBehaviorWanderer m_BehaviorWanderer;
bool m_bIsSaddled;
diff --git a/src/Mobs/Rabbit.cpp b/src/Mobs/Rabbit.cpp
index f4de0ba0c..070396ded 100644
--- a/src/Mobs/Rabbit.cpp
+++ b/src/Mobs/Rabbit.cpp
@@ -14,6 +14,11 @@ cRabbit::cRabbit(void) :
static_cast<UInt8>(eRabbitType::SaltAndPepper) // Max possible Rabbit-Type
)), 0)
{
+ m_EMPersonality = PASSIVE;
+ m_BehaviorBreeder.AttachToMonster(*this);
+ m_BehaviorCoward.AttachToMonster(*this);
+ m_BehaviorItemFollower.AttachToMonster(*this);
+ m_BehaviorWanderer.AttachToMonster(*this);
}
@@ -45,3 +50,20 @@ void cRabbit::GetDrops(cItems & a_Drops, cEntity * a_Killer)
AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel);
}
+
+
+
+
+cBehaviorBreeder * cRabbit::GetBehaviorBreeder()
+{
+ return &m_BehaviorBreeder;
+}
+
+
+
+
+
+const cBehaviorBreeder * cRabbit::GetBehaviorBreeder() const
+{
+ return static_cast<const cBehaviorBreeder *>(&m_BehaviorBreeder);
+}
diff --git a/src/Mobs/Rabbit.h b/src/Mobs/Rabbit.h
index 289ff0282..89760cd7c 100644
--- a/src/Mobs/Rabbit.h
+++ b/src/Mobs/Rabbit.h
@@ -1,8 +1,11 @@
#pragma once
-#include "PassiveMonster.h"
-
+#include "Behaviors/BehaviorBreeder.h"
+#include "Behaviors/BehaviorItemFollower.h"
+#include "Behaviors/BehaviorCoward.h"
+#include "Behaviors/BehaviorWanderer.h"
+#include "Monster.h"
@@ -23,9 +26,9 @@ enum class eRabbitType : UInt8
class cRabbit :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
cRabbit();
@@ -44,7 +47,14 @@ public:
eRabbitType GetRabbitType() const { return m_Type; }
int GetMoreCarrotTicks() const { return m_MoreCarrotTicks; }
+ virtual cBehaviorBreeder * GetBehaviorBreeder() override;
+ virtual const cBehaviorBreeder * GetBehaviorBreeder() const override;
private:
+ // Tick controlling behaviors
+ cBehaviorBreeder m_BehaviorBreeder;
+ cBehaviorItemFollower m_BehaviorItemFollower;
+ cBehaviorCoward m_BehaviorCoward;
+ cBehaviorWanderer m_BehaviorWanderer;
eRabbitType m_Type;
int m_MoreCarrotTicks; // Ticks until the Rabbit eat planted Carrots
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index 312bf74e2..ae06a0055 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -12,21 +12,27 @@
cSheep::cSheep(int a_Color) :
- super("Sheep", mtSheep, "entity.sheep.hurt", "entity.sheep.death", 0.6, 1.3),
- m_IsSheared(false),
- m_WoolColor(a_Color),
- m_TimeToStopEating(-1)
+ super("Sheep", mtSheep, "entity.sheep.hurt", "entity.sheep.death", 0.6, 1.3),
+ m_IsSheared(false),
+ m_WoolColor(a_Color),
+ m_TimeToStopEating(-1)
{
- // Generate random wool color.
- if (m_WoolColor == -1)
- {
- m_WoolColor = GenerateNaturalRandomColor();
- }
-
- if ((m_WoolColor < 0) || (m_WoolColor > 15))
- {
- m_WoolColor = 0;
- }
+ m_EMPersonality = PASSIVE;
+ m_BehaviorBreeder.AttachToMonster(*this);
+ m_BehaviorCoward.AttachToMonster(*this);
+ m_BehaviorItemFollower.AttachToMonster(*this);
+ m_BehaviorWanderer.AttachToMonster(*this);
+
+ // Generate random wool color.
+ if (m_WoolColor == -1)
+ {
+ m_WoolColor = GenerateNaturalRandomColor();
+ }
+
+ if ((m_WoolColor < 0) || (m_WoolColor > 15))
+ {
+ m_WoolColor = 0;
+ }
}
@@ -35,17 +41,17 @@ cSheep::cSheep(int a_Color) :
void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
- if (!m_IsSheared)
- {
- a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, static_cast<short>(m_WoolColor)));
- }
-
- unsigned int LootingLevel = 0;
- if (a_Killer != nullptr)
- {
- LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
- }
- AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_MUTTON : E_ITEM_RAW_MUTTON);
+ if (!m_IsSheared)
+ {
+ a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, static_cast<short>(m_WoolColor)));
+ }
+
+ unsigned int LootingLevel = 0;
+ if (a_Killer != nullptr)
+ {
+ LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
+ }
+ AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_MUTTON : E_ITEM_RAW_MUTTON);
}
@@ -54,30 +60,30 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cSheep::OnRightClicked(cPlayer & a_Player)
{
- super::OnRightClicked(a_Player);
-
- const cItem & EquippedItem = a_Player.GetEquippedItem();
- if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && !IsSheared() && !IsBaby())
- {
- m_IsSheared = true;
- m_World->BroadcastEntityMetadata(*this);
- a_Player.UseEquippedItem();
-
- cItems Drops;
- char NumDrops = GetRandomProvider().RandInt<char>(1, 3);
- Drops.emplace_back(E_BLOCK_WOOL, NumDrops, static_cast<short>(m_WoolColor));
- m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
- m_World->BroadcastSoundEffect("entity.sheep.shear", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f);
- }
- else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage))
- {
- m_WoolColor = 15 - EquippedItem.m_ItemDamage;
- if (!a_Player.IsGameModeCreative())
- {
- a_Player.GetInventory().RemoveOneEquippedItem();
- }
- m_World->BroadcastEntityMetadata(*this);
- }
+ super::OnRightClicked(a_Player);
+
+ const cItem & EquippedItem = a_Player.GetEquippedItem();
+ if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && !IsSheared() && !IsBaby())
+ {
+ m_IsSheared = true;
+ m_World->BroadcastEntityMetadata(*this);
+ a_Player.UseEquippedItem();
+
+ cItems Drops;
+ char NumDrops = GetRandomProvider().RandInt<char>(1, 3);
+ Drops.emplace_back(E_BLOCK_WOOL, NumDrops, static_cast<short>(m_WoolColor));
+ m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
+ m_World->BroadcastSoundEffect("entity.sheep.shear", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f);
+ }
+ else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage))
+ {
+ m_WoolColor = 15 - EquippedItem.m_ItemDamage;
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ m_World->BroadcastEntityMetadata(*this);
+ }
}
@@ -86,49 +92,49 @@ void cSheep::OnRightClicked(cPlayer & a_Player)
void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
- super::Tick(a_Dt, a_Chunk);
- if (!IsTicking())
- {
- // The base class tick destroyed us
- return;
- }
- int PosX = POSX_TOINT;
- int PosY = POSY_TOINT - 1;
- int PosZ = POSZ_TOINT;
-
- if ((PosY <= 0) || (PosY >= cChunkDef::Height))
- {
- return;
- }
-
- if (m_TimeToStopEating > 0)
- {
- StopMovingToPosition();
- m_TimeToStopEating--;
-
- if (m_TimeToStopEating == 0)
- {
- if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) // Make sure grass hasn't been destroyed in the meantime
- {
- // The sheep ate the grass so we change it to dirt
- m_World->SetBlock(PosX, PosY, PosZ, E_BLOCK_DIRT, 0);
- GetWorld()->BroadcastSoundParticleEffect(EffectID::PARTICLE_BLOCK_BREAK, PosX, PosY, PosX, E_BLOCK_GRASS);
- m_IsSheared = false;
- m_World->BroadcastEntityMetadata(*this);
- }
- }
- }
- else
- {
- if (GetRandomProvider().RandBool(1.0 / 600.0))
- {
- if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS)
- {
- m_World->BroadcastEntityStatus(*this, esSheepEating);
- m_TimeToStopEating = 40;
- }
- }
- }
+ super::Tick(a_Dt, a_Chunk);
+ if (!IsTicking())
+ {
+ // The base class tick destroyed us
+ return;
+ }
+ int PosX = POSX_TOINT;
+ int PosY = POSY_TOINT - 1;
+ int PosZ = POSZ_TOINT;
+
+ if ((PosY <= 0) || (PosY >= cChunkDef::Height))
+ {
+ return;
+ }
+
+ if (m_TimeToStopEating > 0)
+ {
+ StopMovingToPosition();
+ m_TimeToStopEating--;
+
+ if (m_TimeToStopEating == 0)
+ {
+ if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS) // Make sure grass hasn't been destroyed in the meantime
+ {
+ // The sheep ate the grass so we change it to dirt
+ m_World->SetBlock(PosX, PosY, PosZ, E_BLOCK_DIRT, 0);
+ GetWorld()->BroadcastSoundParticleEffect(EffectID::PARTICLE_BLOCK_BREAK, PosX, PosY, PosX, E_BLOCK_GRASS);
+ m_IsSheared = false;
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ }
+ }
+ else
+ {
+ if (GetRandomProvider().RandBool(1.0 / 600.0))
+ {
+ if (m_World->GetBlock(PosX, PosY, PosZ) == E_BLOCK_GRASS)
+ {
+ m_World->BroadcastEntityStatus(*this, esSheepEating);
+ m_TimeToStopEating = 40;
+ }
+ }
+ }
}
@@ -137,37 +143,37 @@ void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cSheep::InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2)
{
- static const struct
- {
- short Parent1, Parent2, Child;
- } ColorInheritance[] =
- {
- { E_META_WOOL_BLUE, E_META_WOOL_RED, E_META_WOOL_PURPLE },
- { E_META_WOOL_BLUE, E_META_WOOL_GREEN, E_META_WOOL_CYAN },
- { E_META_WOOL_YELLOW, E_META_WOOL_RED, E_META_WOOL_ORANGE },
- { E_META_WOOL_GREEN, E_META_WOOL_WHITE, E_META_WOOL_LIGHTGREEN },
- { E_META_WOOL_RED, E_META_WOOL_WHITE, E_META_WOOL_PINK },
- { E_META_WOOL_WHITE, E_META_WOOL_BLACK, E_META_WOOL_GRAY },
- { E_META_WOOL_PURPLE, E_META_WOOL_PINK, E_META_WOOL_MAGENTA },
- { E_META_WOOL_WHITE, E_META_WOOL_GRAY, E_META_WOOL_LIGHTGRAY },
- { E_META_WOOL_BLUE, E_META_WOOL_WHITE, E_META_WOOL_LIGHTBLUE },
- };
- cSheep * Parent1 = static_cast<cSheep *>(a_Parent1);
- cSheep * Parent2 = static_cast<cSheep *>(a_Parent2);
- for (size_t i = 0; i < ARRAYCOUNT(ColorInheritance); i++)
- {
- if (
- ((Parent1->GetFurColor() == ColorInheritance[i].Parent1) && (Parent2->GetFurColor() == ColorInheritance[i].Parent2)) ||
- ((Parent1->GetFurColor() == ColorInheritance[i].Parent2) && (Parent2->GetFurColor() == ColorInheritance[i].Parent1))
- )
- {
- SetFurColor(ColorInheritance[i].Child);
- m_World->BroadcastEntityMetadata(*this);
- return;
- }
- }
- SetFurColor(GetRandomProvider().RandBool() ? Parent1->GetFurColor() : Parent2->GetFurColor());
- m_World->BroadcastEntityMetadata(*this);
+ static const struct
+ {
+ short Parent1, Parent2, Child;
+ } ColorInheritance[] =
+ {
+ { E_META_WOOL_BLUE, E_META_WOOL_RED, E_META_WOOL_PURPLE },
+ { E_META_WOOL_BLUE, E_META_WOOL_GREEN, E_META_WOOL_CYAN },
+ { E_META_WOOL_YELLOW, E_META_WOOL_RED, E_META_WOOL_ORANGE },
+ { E_META_WOOL_GREEN, E_META_WOOL_WHITE, E_META_WOOL_LIGHTGREEN },
+ { E_META_WOOL_RED, E_META_WOOL_WHITE, E_META_WOOL_PINK },
+ { E_META_WOOL_WHITE, E_META_WOOL_BLACK, E_META_WOOL_GRAY },
+ { E_META_WOOL_PURPLE, E_META_WOOL_PINK, E_META_WOOL_MAGENTA },
+ { E_META_WOOL_WHITE, E_META_WOOL_GRAY, E_META_WOOL_LIGHTGRAY },
+ { E_META_WOOL_BLUE, E_META_WOOL_WHITE, E_META_WOOL_LIGHTBLUE },
+ };
+ cSheep * Parent1 = static_cast<cSheep *>(a_Parent1);
+ cSheep * Parent2 = static_cast<cSheep *>(a_Parent2);
+ for (size_t i = 0; i < ARRAYCOUNT(ColorInheritance); i++)
+ {
+ if (
+ ((Parent1->GetFurColor() == ColorInheritance[i].Parent1) && (Parent2->GetFurColor() == ColorInheritance[i].Parent2)) ||
+ ((Parent1->GetFurColor() == ColorInheritance[i].Parent2) && (Parent2->GetFurColor() == ColorInheritance[i].Parent1))
+ )
+ {
+ SetFurColor(ColorInheritance[i].Child);
+ m_World->BroadcastEntityMetadata(*this);
+ return;
+ }
+ }
+ SetFurColor(GetRandomProvider().RandBool() ? Parent1->GetFurColor() : Parent2->GetFurColor());
+ m_World->BroadcastEntityMetadata(*this);
}
@@ -176,31 +182,48 @@ void cSheep::InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2)
NIBBLETYPE cSheep::GenerateNaturalRandomColor(void)
{
- int Chance = GetRandomProvider().RandInt(100);
-
- if (Chance <= 81)
- {
- return E_META_WOOL_WHITE;
- }
- else if (Chance <= 86)
- {
- return E_META_WOOL_BLACK;
- }
- else if (Chance <= 91)
- {
- return E_META_WOOL_GRAY;
- }
- else if (Chance <= 96)
- {
- return E_META_WOOL_LIGHTGRAY;
- }
- else if (Chance <= 99)
- {
- return E_META_WOOL_BROWN;
- }
- else
- {
- return E_META_WOOL_PINK;
- }
+ int Chance = GetRandomProvider().RandInt(100);
+
+ if (Chance <= 81)
+ {
+ return E_META_WOOL_WHITE;
+ }
+ else if (Chance <= 86)
+ {
+ return E_META_WOOL_BLACK;
+ }
+ else if (Chance <= 91)
+ {
+ return E_META_WOOL_GRAY;
+ }
+ else if (Chance <= 96)
+ {
+ return E_META_WOOL_LIGHTGRAY;
+ }
+ else if (Chance <= 99)
+ {
+ return E_META_WOOL_BROWN;
+ }
+ else
+ {
+ return E_META_WOOL_PINK;
+ }
}
+
+
+
+
+cBehaviorBreeder * cSheep::GetBehaviorBreeder()
+{
+ return &m_BehaviorBreeder;
+}
+
+
+
+
+
+const cBehaviorBreeder * cSheep::GetBehaviorBreeder() const
+{
+ return static_cast<const cBehaviorBreeder *>(&m_BehaviorBreeder);
+}
diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h
index 01f90c968..8ed91915e 100644
--- a/src/Mobs/Sheep.h
+++ b/src/Mobs/Sheep.h
@@ -1,16 +1,18 @@
#pragma once
-#include "PassiveMonster.h"
-
-
+#include "Behaviors/BehaviorBreeder.h"
+#include "Behaviors/BehaviorItemFollower.h"
+#include "Behaviors/BehaviorCoward.h"
+#include "Behaviors/BehaviorWanderer.h"
+#include "Monster.h"
class cSheep :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
@@ -41,12 +43,23 @@ public:
int GetFurColor(void) const { return m_WoolColor; }
void SetFurColor(int a_WoolColor) { m_WoolColor = a_WoolColor; }
-
+ virtual cBehaviorBreeder * GetBehaviorBreeder() override;
+ virtual const cBehaviorBreeder * GetBehaviorBreeder() const override;
private:
- bool m_IsSheared;
- int m_WoolColor;
+
+ // Tick controlling behaviors
+ cBehaviorBreeder m_BehaviorBreeder;
+ cBehaviorItemFollower m_BehaviorItemFollower;
+ cBehaviorCoward m_BehaviorCoward;
+ cBehaviorWanderer m_BehaviorWanderer;
+
+ // mobTodo transfer this to a behavior
int m_TimeToStopEating;
+ // Behavior note: These are ship-specific things not transferrable to other mobs.
+ // Therefore they do not need a Behavior and can stay hardcoded in the sheep.
+ bool m_IsSheared;
+ int m_WoolColor;
} ;
diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp
index 8ae688a1b..37aa70064 100644
--- a/src/Mobs/Squid.cpp
+++ b/src/Mobs/Squid.cpp
@@ -11,6 +11,7 @@
cSquid::cSquid(void) :
super("Squid", mtSquid, "entity.squid.hurt", "entity.squid.death", 0.95, 0.95)
{
+ m_EMPersonality = PASSIVE;
}
diff --git a/src/Mobs/Squid.h b/src/Mobs/Squid.h
index 590c50495..42ad6938e 100644
--- a/src/Mobs/Squid.h
+++ b/src/Mobs/Squid.h
@@ -1,16 +1,16 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Monster.h"
class cSquid :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
cSquid();
diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp
index 26462ba31..ded1bfbdb 100644
--- a/src/Mobs/Villager.cpp
+++ b/src/Mobs/Villager.cpp
@@ -17,6 +17,11 @@ cVillager::cVillager(eVillagerType VillagerType) :
m_Type(VillagerType),
m_VillagerAction(false)
{
+ m_EMPersonality = PASSIVE;
+ m_BehaviorBreeder.AttachToMonster(*this);
+ m_BehaviorCoward.AttachToMonster(*this);
+ m_BehaviorItemFollower.AttachToMonster(*this);
+ m_BehaviorWanderer.AttachToMonster(*this);
}
diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h
index 6f3e7b4e8..141193212 100644
--- a/src/Mobs/Villager.h
+++ b/src/Mobs/Villager.h
@@ -1,16 +1,21 @@
#pragma once
-#include "PassiveMonster.h"
+#include "Monster.h"
#include "Blocks/ChunkInterface.h"
+#include "Behaviors/BehaviorBreeder.h"
+#include "Behaviors/BehaviorItemFollower.h"
+#include "Behaviors/BehaviorCoward.h"
+#include "Behaviors/BehaviorWanderer.h"
+#include "Monster.h"
class cVillager :
- public cPassiveMonster
+ public cMonster
{
- typedef cPassiveMonster super;
+ typedef cMonster super;
public:
@@ -53,6 +58,12 @@ public:
bool DoesHaveActionActivated(void) const { return m_VillagerAction; }
private:
+ // Tick controlling behaviors
+ cBehaviorBreeder m_BehaviorBreeder;
+ cBehaviorItemFollower m_BehaviorItemFollower;
+ cBehaviorCoward m_BehaviorCoward;
+ cBehaviorWanderer m_BehaviorWanderer;
+
int m_ActionCountDown;
int m_Type;