summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.h13
-rw-r--r--src/Mobs/Behaviors/BehaviorAttacker.h10
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerMelee.h11
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerRanged.h10
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp16
-rw-r--r--src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h17
-rw-r--r--src/Mobs/Behaviors/BehaviorBrave.h13
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.h18
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.h11
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.h10
-rw-r--r--src/Mobs/Behaviors/BehaviorDoNothing.h3
-rw-r--r--src/Mobs/Behaviors/BehaviorItemDropper.h10
-rw-r--r--src/Mobs/Behaviors/BehaviorItemFollower.h10
-rw-r--r--src/Mobs/Behaviors/BehaviorItemReplacer.h7
-rw-r--r--src/Mobs/Behaviors/BehaviorPet.cpp0
-rw-r--r--src/Mobs/Behaviors/BehaviorPet.h33
-rw-r--r--src/Mobs/Behaviors/BehaviorPetTamableWithItem.cpp0
-rw-r--r--src/Mobs/Behaviors/BehaviorPetTamableWithItem.h0
-rw-r--r--src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.cpp0
-rw-r--r--src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.h0
-rw-r--r--src/Mobs/Behaviors/CMakeLists.txt6
21 files changed, 177 insertions, 21 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h
index 923d646e0..9ac726bce 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.h
+++ b/src/Mobs/Behaviors/BehaviorAggressive.h
@@ -6,8 +6,17 @@ 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. */
+/** The mob is agressive toward specific mobtypes (mobTodo), or toward the player.
+ *
+
+Connections to other behaviors:
+ - The mob should also have a cBehaviorAttacker, otherwise this behavior will not work.
+ - This behavior does not make sense in combination with BehaviorCoward or cBehaviorBrave.
+
+Special connections:
+ - Relies on cMonster::GetAttackerBehavior to obtain the attacker behavior and alter its target.
+
+*/
typedef std::function<bool(cBehaviorAggressive & a_Behavior, cMonster & a_Monster, cChunk & a_Chunk)> ShouldBeAggressiveFunction;
diff --git a/src/Mobs/Behaviors/BehaviorAttacker.h b/src/Mobs/Behaviors/BehaviorAttacker.h
index 428e7a340..51a446eca 100644
--- a/src/Mobs/Behaviors/BehaviorAttacker.h
+++ b/src/Mobs/Behaviors/BehaviorAttacker.h
@@ -8,7 +8,15 @@ class cBehaviorAttacker;
/** Grants attack capability to the mob. Note that this is not the same as agression!
The mob may possess this trait and not attack anyone or only attack when provoked.
Unlike most traits, this one has several forms, and therefore it is an abstract type
-You should use one of its derived classes, and you cannot use it directly. */
+You should use one of its derived classes, and you cannot use it directly.
+
+Connections to other behaviors:
+ - Some behaviors may call cBehaviorAttacker::SetTarget
+
+Special connections:
+ - None.
+
+*/
class cBehaviorAttacker : public cBehavior
{
diff --git a/src/Mobs/Behaviors/BehaviorAttackerMelee.h b/src/Mobs/Behaviors/BehaviorAttackerMelee.h
index 69d626fbc..f744d0955 100644
--- a/src/Mobs/Behaviors/BehaviorAttackerMelee.h
+++ b/src/Mobs/Behaviors/BehaviorAttackerMelee.h
@@ -5,7 +5,16 @@
class cBehaviorAttackerMelee;
/** Grants the mob that ability to approach a target and then melee attack it.
-Use BehaviorAttackerMelee::SetTarget to attack. */
+Use BehaviorAttackerMelee::SetTarget to attack.
+
+
+Connections to other behaviors:
+ - See cBehaviorAttacker.
+
+Special connections:
+ - None.
+
+*/
typedef std::function<void(cBehaviorAttackerMelee & a_Behavior, cMonster & a_Attacker, cPawn & a_Attacked)> PostAttackFunction;
class cBehaviorAttackerMelee : public cBehaviorAttacker
{
diff --git a/src/Mobs/Behaviors/BehaviorAttackerRanged.h b/src/Mobs/Behaviors/BehaviorAttackerRanged.h
index 1d9e4fcd9..801c6fb46 100644
--- a/src/Mobs/Behaviors/BehaviorAttackerRanged.h
+++ b/src/Mobs/Behaviors/BehaviorAttackerRanged.h
@@ -5,7 +5,15 @@
class cBehaviorAttackerRanged;
/** Grants the mob that ability to approach a target and then melee attack it.
-Use BehaviorAttackerMelee::SetTarget to attack. */
+Use cBehaviorAttackerRanged::SetTarget to attack.
+
+Connections to other behaviors:
+ - See cBehaviorAttacker.
+
+Special connections:
+ - None.
+
+*/
typedef std::function<void(cBehaviorAttackerRanged & a_Behavior,
cMonster & a_Attacker, cPawn & a_Attacked)> RangedShootingFunction;
diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp
index 843cc58ef..5120e4a57 100644
--- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp
+++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.cpp
@@ -9,10 +9,11 @@
-cBehaviorAttackerSuicideBomber::cBehaviorAttackerSuicideBomber() :
+cBehaviorAttackerSuicideBomber::cBehaviorAttackerSuicideBomber(bool a_ShouldBroadcastEntityMetadata) :
m_bIsBlowing(false),
m_bIsCharged(false),
- m_BurnedWithFlintAndSteel(false)
+ m_BurnedWithFlintAndSteel(false),
+ m_ShouldBroadcastEntityMetadata(a_ShouldBroadcastEntityMetadata)
{
}
@@ -42,8 +43,10 @@ bool cBehaviorAttackerSuicideBomber::DoStrike(int a_StrikeTickCnt)
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);
-
+ if (m_ShouldBroadcastEntityMetadata)
+ {
+ m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
+ }
return false;
}
@@ -51,7 +54,10 @@ bool cBehaviorAttackerSuicideBomber::DoStrike(int a_StrikeTickCnt)
if (((GetTarget() == nullptr) || (!TargetIsInStrikeRadius())) && (!m_BurnedWithFlintAndSteel))
{
m_bIsBlowing = false;
- m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
+ if (m_ShouldBroadcastEntityMetadata)
+ {
+ m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
+ }
return true;
}
diff --git a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h
index b9cb155e8..bc0a31341 100644
--- a/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h
+++ b/src/Mobs/Behaviors/BehaviorAttackerSuicideBomber.h
@@ -2,12 +2,22 @@
#include "BehaviorAttacker.h"
-/** Grants the mob that ability to approach a target and then melee attack it.
-Use BehaviorAttackerMelee::SetTarget to attack. */
+/** Grants the mob that ability to approach a target and then blow up.
+Use cBehaviorAttackerSuicideBomber::SetTarget to attack.
+
+Connections to other behaviors:
+ - See cBehaviorAttacker.
+
+Special connections:
+ - The creeper will determine animation state by calling IsBlowing, IsCharged, and IsBurnedWithFlintAndSteel
+
+*/
class cBehaviorAttackerSuicideBomber : public cBehaviorAttacker
{
public:
- cBehaviorAttackerSuicideBomber();
+ /** a_ShouldBroadcastEntityMetadata should only be true for creepers or
+ any future mobs that animate explosions. */
+ cBehaviorAttackerSuicideBomber(bool a_ShouldBroadcastEntityMetadata = false);
void AttachToMonster(cMonster & a_Parent) override;
// cBehaviorAttacker also implements those and we need to call super on them
void DoTakeDamage(TakeDamageInfo & a_TDI) override;
@@ -21,4 +31,5 @@ public:
private:
bool m_bIsBlowing, m_bIsCharged, m_BurnedWithFlintAndSteel;
+ bool m_ShouldBroadcastEntityMetadata;
};
diff --git a/src/Mobs/Behaviors/BehaviorBrave.h b/src/Mobs/Behaviors/BehaviorBrave.h
index 0a59f90b8..1562c0089 100644
--- a/src/Mobs/Behaviors/BehaviorBrave.h
+++ b/src/Mobs/Behaviors/BehaviorBrave.h
@@ -2,8 +2,17 @@
#include "Behavior.h"
-/** Makes the mob fight back any other mob that damages it. Mob should have BehaviorAttacker to work.
-This behavior does not make sense in combination with BehaviorCoward. */
+/** Makes the mob fight back any other mob that damages it. Unlike cBehaviorAggressive, it will
+not attack unless provoked.
+
+Connections to other behaviors:
+ - The mob should also have a cBehaviorAttacker, otherwise this behavior will not work.
+ - This behavior does not make sense in combination with BehaviorCoward or cBehaviorAggressive.
+
+Special connections:
+ - Relies on cMonster::GetAttackerBehavior to obtain the attacker behavior and alter its target.
+
+*/
class cBehaviorBrave : cBehavior
{
public:
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.h b/src/Mobs/Behaviors/BehaviorBreeder.h
index a3d0b51af..59bd916f7 100644
--- a/src/Mobs/Behaviors/BehaviorBreeder.h
+++ b/src/Mobs/Behaviors/BehaviorBreeder.h
@@ -3,14 +3,25 @@
class cBehaviorBreeder;
#include "Behavior.h"
+#include "BehaviorPet.h"
-/** Grants breeding capabilities to the mob. */
+/** Grants breeding capabilities to the mob.
+Recommended combination with cBehaviorItemFollower.
+
+Connections to other behaviors:
+ - If the mob also has cBehaviorPet, this behavior is suppressed unless the mob has an owner.
+
+Special connections:
+ - Relies on the polymorphic cMonster::GetBreedingItems function to determine the breeding items.
+
+
+*/
class cBehaviorBreeder : public cBehavior
{
public:
cBehaviorBreeder();
- void AttachToMonster(cMonster & a_Parent);
+ void AttachToMonster(cMonster & a_Parent, cBehaviorPet * a_BehaviorPet = nullptr);
// Functions our host Monster should invoke:
bool IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
@@ -41,6 +52,9 @@ private:
/** The monster's breeding partner. */
cMonster * m_LovePartner;
+ /** The monster's pet behavior, if present. */
+ cMonster * m_BehaviorPet;
+
/** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by 1 per tick till reaching zero. */
int m_LoveTimer;
diff --git a/src/Mobs/Behaviors/BehaviorCoward.h b/src/Mobs/Behaviors/BehaviorCoward.h
index 3232f807b..d33792ec2 100644
--- a/src/Mobs/Behaviors/BehaviorCoward.h
+++ b/src/Mobs/Behaviors/BehaviorCoward.h
@@ -2,7 +2,16 @@
#include "Behavior.h"
-/** Makes the mob run away from any other mob that damages it. */
+/** Makes the mob run away from any other mob that damages it.
+
+Connections to other behaviors:
+ - The mob should also have a cBehaviorAttacker, otherwise this behavior will not work.
+ - This behavior does not make sense in combination with BehaviorAggressive or cBehaviorBrave.
+
+Special connections:
+ - None.
+
+*/
class cBehaviorCoward : cBehavior
{
public:
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.h b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
index 920f9d5c7..ebdae9977 100644
--- a/src/Mobs/Behaviors/BehaviorDayLightBurner.h
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
@@ -4,6 +4,16 @@
#include "Behavior.h"
#include "../../World.h"
+/**
+The mob will burn in daylight.
+
+Connections to other behaviors:
+ - None.
+
+Special connections:
+ - Alters the pathfinder, so that the mob will try avoiding sunlight.
+
+*/
class cBehaviorDayLightBurner : cBehavior
{
public:
diff --git a/src/Mobs/Behaviors/BehaviorDoNothing.h b/src/Mobs/Behaviors/BehaviorDoNothing.h
index 52c0c7c08..564032091 100644
--- a/src/Mobs/Behaviors/BehaviorDoNothing.h
+++ b/src/Mobs/Behaviors/BehaviorDoNothing.h
@@ -1,11 +1,12 @@
#pragma once
-// Always takes control of the tick and does nothing. Used for unimplemented mobs like squids.
+
class cBehaviorDoNothing;
#include "Behavior.h"
+/** Always takes control of the tick and does nothing. Used for unimplemented mobs like squids. */
class cBehaviorDoNothing : public cBehavior
{
public:
diff --git a/src/Mobs/Behaviors/BehaviorItemDropper.h b/src/Mobs/Behaviors/BehaviorItemDropper.h
index 2b9623ecf..64d2f761e 100644
--- a/src/Mobs/Behaviors/BehaviorItemDropper.h
+++ b/src/Mobs/Behaviors/BehaviorItemDropper.h
@@ -4,7 +4,15 @@
#include "Behavior.h"
-/** Makes the mob periodically lay eggs. */
+/** Makes the mob periodically drop eggs. MobTodo: Make this more generic.
+
+Connections to other behaviors:
+ - None
+
+Special connections:
+ - None.
+
+*/
class cBehaviorItemDropper : cBehavior
{
public:
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.h b/src/Mobs/Behaviors/BehaviorItemFollower.h
index 8c79ec763..e381b5e36 100644
--- a/src/Mobs/Behaviors/BehaviorItemFollower.h
+++ b/src/Mobs/Behaviors/BehaviorItemFollower.h
@@ -5,7 +5,15 @@ class cBehaviorItemFollower;
#include "Behavior.h"
/** Makes the mob follow specific items when held by the player.
-Currently relies on cMonster::GetFollowedItems for the item list. */
+Currently relies on cMonster::GetFollowedItems for the item list.
+
+Connections to other behaviors:
+ - None
+
+Special connections:
+ - Relies on the polymorphic cMonster::GetFollowedItems function to determine the followed items.
+
+*/
class cBehaviorItemFollower : public cBehavior
{
public:
diff --git a/src/Mobs/Behaviors/BehaviorItemReplacer.h b/src/Mobs/Behaviors/BehaviorItemReplacer.h
index e35729f0e..5a45a830b 100644
--- a/src/Mobs/Behaviors/BehaviorItemReplacer.h
+++ b/src/Mobs/Behaviors/BehaviorItemReplacer.h
@@ -7,6 +7,13 @@ class cBehaviorItemReplacer;
/** When right clicked while holding a_OriginalItem, a mob having this behavior replaces the original item
with a_NewItem. This is used for milking cows.
+
+Connections to other behaviors:
+ - None.
+
+Special connections:
+ - None.
+
*/
class cBehaviorItemReplacer : public cBehavior
{
diff --git a/src/Mobs/Behaviors/BehaviorPet.cpp b/src/Mobs/Behaviors/BehaviorPet.cpp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorPet.cpp
diff --git a/src/Mobs/Behaviors/BehaviorPet.h b/src/Mobs/Behaviors/BehaviorPet.h
new file mode 100644
index 000000000..444532827
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorPet.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "Behavior.h"
+
+/** Makes the mob tamable. Once tamed, the mob will have an owner and will follow it around.
+The mob can optionally be granted sitting ability via the CanSit flag, and the ability to defend
+its owner via the IsProtector flag.
+
+If the mob is not sitting and the owner strays too far, the mob will teleport to the owner.
+
+This base class behavior does not permit in-game taming (except when used by horses).
+The derived classes determine how the mob should be tamed and they should be used instead.
+
+Connections to other behaviors:
+ - Suppresses cBehaviorBreeder until the mob has an owner.
+ - If IsProtecter is set to true, the mob should also have a cBehaviorAttacker
+
+Special connections:
+ - relies on cMonster::NeverDespawn (TODO) and ensures the mob never despawns if it has an owner.
+ - mobTodo cMonster::NeverDespawn + cWorld changes
+ - Horse taming is horse-specific, so the horse taming logic is in the horse class, and
+it will call cBehaviorBrave::SetOwner once tamed.
+
+*/
+class cBehaviorBrave : cBehavior
+{
+public:
+ void AttachToMonster(cMonster & a_Parent);
+ void DoTakeDamage(TakeDamageInfo & a_TDI) override;
+
+private:
+ cMonster * m_Parent; // Our Parent
+};
diff --git a/src/Mobs/Behaviors/BehaviorPetTamableWithItem.cpp b/src/Mobs/Behaviors/BehaviorPetTamableWithItem.cpp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorPetTamableWithItem.cpp
diff --git a/src/Mobs/Behaviors/BehaviorPetTamableWithItem.h b/src/Mobs/Behaviors/BehaviorPetTamableWithItem.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorPetTamableWithItem.h
diff --git a/src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.cpp b/src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.cpp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.cpp
diff --git a/src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.h b/src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorPetTamableWithItemShy.h
diff --git a/src/Mobs/Behaviors/CMakeLists.txt b/src/Mobs/Behaviors/CMakeLists.txt
index f205e9cb4..75f0490a0 100644
--- a/src/Mobs/Behaviors/CMakeLists.txt
+++ b/src/Mobs/Behaviors/CMakeLists.txt
@@ -20,6 +20,9 @@ SET (SRCS
BehaviorAttackerRanged.cpp
BehaviorAttackerSuicideBomber.cpp
BehaviorWanderer.cpp
+ BehaviorPet.cpp
+ BehaviorPetTamableWithItem.cpp
+ BehaviorPetTamableWithItemShy.cpp
)
SET (HDRS
@@ -38,6 +41,9 @@ SET (HDRS
BehaviorAttackerRanged.h
BehaviorAttackerSuicideBomber.h
BehaviorWanderer.h
+ BehaviorPet.h
+ BehaviorPetTamableWithItem.h
+ BehaviorPetTamableWithItemShy.h
)
if(NOT MSVC)