summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.cpp49
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.h31
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.cpp233
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.h60
-rw-r--r--src/Mobs/Behaviors/BehaviorChaser.cpp190
-rw-r--r--src/Mobs/Behaviors/BehaviorChaser.h62
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.cpp53
-rw-r--r--src/Mobs/Behaviors/BehaviorCoward.h24
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.cpp85
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.h5
-rw-r--r--src/Mobs/Behaviors/BehaviorItemDropper.cpp1
-rw-r--r--src/Mobs/Behaviors/BehaviorItemDropper.h1
-rw-r--r--src/Mobs/Behaviors/BehaviorItemFollower.cpp44
-rw-r--r--src/Mobs/Behaviors/BehaviorItemFollower.h29
-rw-r--r--src/Mobs/Behaviors/BehaviorStriker.cpp7
-rw-r--r--src/Mobs/Behaviors/BehaviorStriker.h13
-rw-r--r--src/Mobs/Behaviors/BehaviorWanderer.cpp60
-rw-r--r--src/Mobs/Behaviors/BehaviorWanderer.h23
-rw-r--r--src/Mobs/Behaviors/CMakeLists.txt33
19 files changed, 1003 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp
new file mode 100644
index 000000000..74eee0e17
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp
@@ -0,0 +1,49 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorAggressive.h"
+#include "BehaviorChaser.h"
+#include "../Monster.h"
+#include "../../Chunk.h"
+#include "../../Entities/Player.h"
+
+
+
+cBehaviorAggressive::cBehaviorAggressive(cMonster * a_Parent) : m_Parent(a_Parent)
+{
+ ASSERT(m_Parent != nullptr);
+ m_ParentChaser = m_Parent->GetBehaviorChaser();
+ ASSERT(m_ParentChaser != nullptr);
+}
+
+
+
+
+
+bool cBehaviorAggressive::ActiveTick()
+{
+ // Target something new if we have no target
+ if (m_ParentChaser->GetTarget() == nullptr)
+ {
+ m_ParentChaser->SetTarget(FindNewTarget());
+ }
+ return false;
+}
+
+
+
+
+
+void cBehaviorAggressive::Destroyed()
+{
+ m_Target = nullptr;
+}
+
+
+
+
+
+bool cBehaviorAggressive::FindNewTarget()
+{
+ cPlayer * Closest = m_Parent->GetNearestPlayer();
+ return Closest; // May be null
+}
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h
new file mode 100644
index 000000000..43747d0e2
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorAggressive.h
@@ -0,0 +1,31 @@
+// The mob is agressive toward specific mobtypes, or toward the player.
+// This Behavior has a dependency on BehaviorChaser.
+#pragma once
+class cPawn;
+class cMonster;
+class cBehaviorChaser;
+
+class cBehaviorAggressive
+{
+
+public:
+ cBehaviorAggressive(cMonster * a_Parent, int a_MinimumLight);
+
+ // cBehaviorAggressive(cMonster * a_Parent, bool a_HatesPlayer);
+ // TODO agression toward specific players, and specific mobtypes, etc
+ // Agression under specific conditions (nighttime, etc)
+
+ // Functions our host Monster should invoke:
+ bool ActiveTick();
+ void Destroyed();
+
+private:
+ cPawn * FindNewTarget();
+
+ // Our parent
+ cMonster * m_Parent;
+ cBehaviorChaser * m_ParentChaser;
+
+ // The mob we want to attack
+ cPawn * m_Target;
+};
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp
new file mode 100644
index 000000000..ea3e10026
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp
@@ -0,0 +1,233 @@
+
+#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"
+#include "../../Item.h"
+#include "../../BoundingBox.h"
+
+iBehaviorBreeder::~iBehaviorBreeder()
+{
+
+}
+
+
+
+
+
+cBehaviorBreeder::cBehaviorBreeder(cMonster * a_Parent, cItems & a_BreedingItems) :
+ m_Parent(a_Parent),
+ m_LovePartner(nullptr),
+ m_LoveTimer(0),
+ m_LoveCooldown(0),
+ m_MatingTimer(0),
+ m_BreedingItems(a_BreedingItems)
+{
+ m_Parent = dynamic_cast<cMonster *>(m_ParentInterface);
+ ASSERT(m_Parent != nullptr);
+}
+
+
+
+
+
+bool cBehaviorBreeder::ActiveTick()
+{
+ cWorld * World = m_Parent->GetWorld();
+ // if we have a partner, mate
+ if (m_LovePartner != nullptr)
+ {
+ if (m_MatingTimer > 0)
+ {
+ // If we should still mate, keep bumping into them until baby is made
+ Vector3d Pos = m_LovePartner->GetPosition();
+ m_Parent->MoveToPosition(Pos);
+ }
+ else
+ {
+ // Mating finished. Spawn baby
+ Vector3f Pos = (m_Parent->GetPosition() + m_LovePartner->GetPosition()) * 0.5;
+ UInt32 BabyID = World->SpawnMob(Pos.x, Pos.y, Pos.z, m_Parent->GetMobType(), true);
+
+ class cBabyInheritCallback :
+ public cEntityCallback
+ {
+ public:
+ cMonster * Baby;
+ cBabyInheritCallback() : Baby(nullptr) { }
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ Baby = static_cast<cMonster *>(a_Entity);
+ return true;
+ }
+ } Callback;
+
+ m_Parent->GetWorld()->DoWithEntityByID(BabyID, Callback);
+ if (Callback.Baby != nullptr)
+ {
+ Callback.Baby->InheritFromParents(m_Parent, m_LovePartner);
+ }
+
+ cFastRandom Random;
+ World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, 1 + Random.NextInt(6));
+
+ m_LovePartner->GetBehaviorBreeder()->ResetLoveMode();
+ ResetLoveMode();
+ }
+ return true;
+ }
+
+ // If we are in love mode and we have no partner
+ if (m_LoveTimer > 0)
+ {
+ class LookForLover : public cEntityCallback
+ {
+ public:
+ cMonster * m_Me;
+ LookForLover(cMonster * a_Me) :
+ m_Me(a_Me)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ // If the entity is not a monster, don't breed with it
+ // Also, do not self-breed
+ if ((a_Entity->GetEntityType() != cEntity::eEntityType::etMonster) || (a_Entity == m_Me))
+ {
+ return false;
+ }
+
+ auto PotentialPartner = static_cast<cMonster*>(a_Entity);
+
+ // If the potential partner is not of the same species, don't breed with it
+ if (PotentialPartner->GetMobType() != m_Me->GetMobType())
+ {
+ return false;
+ }
+
+ auto PartnerBreedingBehavior = PotentialPartner->GetBehaviorBreeder();
+ auto MyBreedingBehavior = m_Me->GetBehaviorBreeder();
+
+ // If the potential partner is not in love
+ // Or they already have a mate, do not breed with them
+
+ if ((!PartnerBreedingBehavior->IsInLove()) || (PartnerBreedingBehavior->GetPartner() != nullptr))
+ {
+ return false;
+ }
+
+ // All conditions met, let's breed!
+ PartnerBreedingBehavior->EngageLoveMode(m_Me);
+ MyBreedingBehavior->EngageLoveMode(PotentialPartner);
+ return true;
+ }
+ } Callback(m_Parent);
+
+ World->ForEachEntityInBox(cBoundingBox(m_Parent->GetPosition(), 8, 8), Callback);
+ if (m_LovePartner != nullptr)
+ {
+ return true; // We found love and took control of the monster, prevent other Behaviors from doing so
+ }
+ }
+
+ return false;
+}
+
+
+
+
+
+void cBehaviorBreeder::Tick()
+{
+ if (m_MatingTimer > 0)
+ {
+ m_MatingTimer--;
+ }
+ if (m_LoveCooldown > 0)
+ {
+ m_LoveCooldown--;
+ }
+ if (m_LoveTimer > 0)
+ {
+ m_LoveTimer--;
+ }
+}
+
+
+
+
+
+void cBehaviorBreeder::Destroyed()
+{
+ if (m_LovePartner != nullptr)
+ {
+ m_LovePartner->GetBehaviorBreeder()->ResetLoveMode();
+ }
+}
+
+
+
+
+
+void cBehaviorBreeder::OnRightClicked(cPlayer & a_Player)
+{
+ // If a player holding breeding items right-clicked me, go into love mode
+ if ((m_LoveCooldown == 0) && !IsInLove() && !m_Parent->IsBaby())
+ {
+ short HeldItem = a_Player.GetEquippedItem().m_ItemType;
+ if (m_BreedingItems.ContainsType(HeldItem))
+ {
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ m_LoveTimer = 20 * 30; // half a minute
+ m_Parent->GetWorld()->BroadcastEntityStatus(*m_Parent, cEntity::eEntityStatus::esMobInLove);
+ }
+ }
+}
+
+
+
+void cBehaviorBreeder::EngageLoveMode(cMonster * a_Partner)
+{
+ m_LovePartner = a_Partner;
+ m_MatingTimer = 50; // about 3 seconds of mating
+}
+
+
+
+
+
+void cBehaviorBreeder::ResetLoveMode()
+{
+ m_LovePartner = nullptr;
+ m_LoveTimer = 0;
+ m_MatingTimer = 0;
+ m_LoveCooldown = 20 * 60 * 5; // 5 minutes
+
+ // when an animal is in love mode, the client only stops sending the hearts if we let them know it's in cooldown, which is done with the "age" metadata
+ m_Parent->GetWorld()->BroadcastEntityMetadata(*m_Parent);
+}
+
+
+
+
+
+bool cBehaviorBreeder::IsInLove() const
+{
+ return m_LoveTimer > 0;
+}
+
+
+
+
+
+bool cBehaviorBreeder::IsInLoveCooldown() const
+{
+ return (m_LoveCooldown > 0);
+}
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.h b/src/Mobs/Behaviors/BehaviorBreeder.h
new file mode 100644
index 000000000..4d7dc1aa4
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorBreeder.h
@@ -0,0 +1,60 @@
+#pragma once
+
+// Grants breeding capabilities to the mob
+
+class cBehaviorBreeder;
+
+class cWorld;
+class cMonster;
+class cPlayer;
+class cItems;
+
+
+
+
+
+class cBehaviorBreeder
+{
+
+public:
+ cBehaviorBreeder(cMonster * a_Parent, cItems & a_BreedingItems);
+
+ // Functions our host Monster should invoke:
+ void Tick();
+ bool ActiveTick();
+ void OnRightClicked(cPlayer & a_Player);
+ void Destroyed();
+
+ /** Returns the partner which the monster is currently mating with. */
+ cMonster * GetPartner(void) const { return m_LovePartner; }
+
+ /** Start the mating process. Causes the monster to keep bumping into the partner until m_MatingTimer reaches zero. */
+ void EngageLoveMode(cMonster * a_Partner);
+
+ /** Finish the mating process. Called after a baby is born. Resets all breeding related timers and sets m_LoveCooldown to 20 minutes. */
+ void ResetLoveMode();
+
+ /** Returns whether the monster has just been fed and is ready to mate. If this is "true" and GetPartner isn't "nullptr", then the monster is mating. */
+ bool IsInLove() const;
+
+ /** Returns whether the monster is tired of breeding and is in the cooldown state. */
+ bool IsInLoveCooldown() const;
+
+private:
+ /** Our parent */
+ cMonster * m_Parent;
+
+ /** The monster's breeding partner. */
+ cMonster * m_LovePartner;
+
+ /** 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;
+
+ /** If above 0, the monster is in cooldown mode and will refuse to breed. Decrements by 1 per tick till reaching zero. */
+ int m_LoveCooldown;
+
+ /** The monster is engaged in mating, once this reaches zero, a baby will be born. Decrements by 1 per tick till reaching zero, then a baby is made and ResetLoveMode() is called. */
+ int m_MatingTimer;
+
+ cItems & m_BreedingItems;
+};
diff --git a/src/Mobs/Behaviors/BehaviorChaser.cpp b/src/Mobs/Behaviors/BehaviorChaser.cpp
new file mode 100644
index 000000000..22a95fe73
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorChaser.cpp
@@ -0,0 +1,190 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorChaser.h"
+#include "../Monster.h"
+#include "../../Entities/Pawn.h"
+#include "BehaviorStriker.h"
+
+
+, m_AttackRate(3)
+, m_AttackDamage(1)
+, m_AttackRange(1)
+, m_AttackCoolDownTicksLeft(0)
+, m_TicksSinceLastDamaged(50)
+
+cBehaviorChaser::cBehaviorChaser(cMonster * a_Parent) :
+ m_Parent(a_Parent)
+{
+ ASSERT(m_Parent != nullptr);
+ m_StrikeBehavior = m_Parent->GetBehaviorStriker();
+ ASSERT(m_StrikeBehavior != nullptr); // The monster that has an Attacker behavior must also have a Striker behavior
+}
+
+
+
+
+
+bool cBehaviorChaser::ActiveTick()
+{
+ // Stop targeting out of range targets
+ if (GetTarget() != nullptr)
+ {
+ if (TargetOutOfSight())
+ {
+ SetTarget(nullptr);
+ }
+ else
+ {
+ if (TargetIsInStrikeRange())
+ {
+ StrikeTarget();
+ }
+ else
+ {
+ ApproachTarget();
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+void cBehaviorChaser::Tick()
+{
+ ++m_TicksSinceLastDamaged;
+ if (m_AttackCoolDownTicksLeft > 0)
+ {
+ m_AttackCoolDownTicksLeft -= 1;
+ }
+}
+
+
+
+
+
+void cBehaviorChaser::Destroyed()
+{
+ m_Target = nullptr;
+}
+
+
+
+
+
+void cBehaviorChaser::SetAttackRate(float a_AttackRate)
+{
+ m_AttackRate = a_AttackRate;
+}
+
+
+
+
+
+void cBehaviorChaser::SetAttackRange(int a_AttackRange)
+{
+ m_AttackRange = a_AttackRange;
+}
+
+
+
+
+
+void cBehaviorChaser::SetAttackDamage(int a_AttackDamage)
+{
+ m_AttackDamage = a_AttackDamage;
+}
+
+
+
+
+cPawn * cBehaviorChaser::GetTarget()
+{
+ return m_Target;
+}
+
+
+
+
+
+void cBehaviorChaser::SetTarget(cPawn * a_Target)
+{
+ m_Target = a_Target;
+}
+
+
+
+
+
+cBehaviorChaser::~cBehaviorChaser()
+{
+
+}
+
+
+
+
+
+bool cBehaviorChaser::TargetIsInStrikeRange()
+{
+ ASSERT(m_Target != nullptr);
+ ASSERT(m_Parent != nullptr);
+ /*
+ #include "../../Tracer.h"
+ cTracer LineOfSight(m_Parent->GetWorld());
+ Vector3d MyHeadPosition = m_Parent->GetPosition() + Vector3d(0, m_Parent->GetHeight(), 0);
+ Vector3d AttackDirection(m_ParentChaser->GetTarget()->GetPosition() + Vector3d(0, GetTarget()->GetHeight(), 0) - MyHeadPosition);
+
+
+ if (GetTarget() != nullptr)
+ {
+ MoveToPosition(GetTarget()->GetPosition());
+ }
+ if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())) && (GetHealth() > 0.0))
+ {
+ // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
+ Attack(a_Dt);
+ }
+ */
+ return ((m_Target->GetPosition() - m_Parent->GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange));
+}
+
+
+
+
+
+bool cBehaviorChaser::TargetOutOfSight()
+{
+ ASSERT(m_Target != nullptr);
+ if ((GetTarget()->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance())
+ {
+ return true;
+ }
+ return false;
+}
+
+
+
+
+
+void cBehaviorChaser::ResetStrikeCooldown()
+{
+ m_AttackCoolDownTicksLeft = static_cast<int>(3 * 20 * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every 3 seconds
+}
+
+
+
+
+
+void cBehaviorChaser::StrikeTarget()
+{
+ if (m_AttackCoolDownTicksLeft != 0)
+ {
+ m_StrikeBehavior->Strike(m_Target); // LogicParrot Todo animations (via counter passing?)
+ ResetStrikeCooldown();
+ }
+}
diff --git a/src/Mobs/Behaviors/BehaviorChaser.h b/src/Mobs/Behaviors/BehaviorChaser.h
new file mode 100644
index 000000000..fff5ebfa3
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorChaser.h
@@ -0,0 +1,62 @@
+
+#pragma once
+
+class cMonster;
+class cPawn;
+class cBehaviorStriker;
+
+
+/** 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. */
+class cBehaviorChaser
+{
+
+public:
+ cBehaviorChaser(cMonster * a_Parent);
+
+ // Functions our host Monster should invoke:
+ bool ActiveTick();
+ void Destroyed();
+ void Tick();
+
+ // Our host monster will call these once it loads its config file
+ void SetAttackRate(float a_AttackRate);
+ void SetAttackRange(int a_AttackRange);
+ void SetAttackDamage(int a_AttackDamage);
+
+ /** Returns the target pointer, or a nullptr if we're not targeting anyone. */
+ cPawn * GetTarget();
+
+ /** Sets the target. */
+ void SetTarget(cPawn * a_Target);
+
+ virtual ~cBehaviorChaser();
+protected:
+ virtual void ApproachTarget() = 0;
+private:
+
+ /** Our parent */
+ cMonster * m_Parent;
+ cBehaviorStriker * m_StrikeBehavior;
+
+ // The mob we want to attack
+ cPawn * m_Target;
+
+ // Target stuff
+ bool TargetIsInStrikeRange();
+ bool TargetOutOfSight();
+ void StrikeTarget();
+
+ // Cooldown stuff
+ void ResetStrikeCooldown();
+
+ // Our attacking parameters (Set by the setter methods, loaded from a config file in cMonster)
+ float m_AttackRate;
+ int m_AttackDamage;
+ int m_AttackRange;
+ int m_AttackCoolDownTicksLeft;
+
+ int m_TicksSinceLastDamaged; // How many ticks ago were we last damaged by a player?
+};
diff --git a/src/Mobs/Behaviors/BehaviorCoward.cpp b/src/Mobs/Behaviors/BehaviorCoward.cpp
new file mode 100644
index 000000000..017227340
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorCoward.cpp
@@ -0,0 +1,53 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorCoward.h"
+#include "../Monster.h"
+#include "../../World.h"
+#include "../../Entities/Player.h"
+#include "../../Entities/Entity.h"
+
+cBehaviorCoward::cBehaviorCoward(cMonster * a_Parent) :
+ m_Parent(a_Parent),
+ m_Attacker(nullptr)
+{
+ ASSERT(m_Parent != nullptr);
+}
+
+
+
+
+
+bool cBehaviorCoward::ActiveTick()
+{
+ if (m_Attacker == nullptr)
+ {
+ return false;
+ }
+
+ // TODO NOT SAFE
+ if (m_Attacker->IsDestroyed() || (m_Attacker->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance())
+ {
+ // We lost the attacker
+ m_Attacker = nullptr;
+ return false;
+ }
+
+ Vector3d newloc = m_Parent->GetPosition();
+ newloc.x = (m_Attacker->GetPosition().x < newloc.x)? (newloc.x + m_Parent->GetSightDistance()): (newloc.x - m_Parent->GetSightDistance());
+ newloc.z = (m_Attacker->GetPosition().z < newloc.z)? (newloc.z + m_Parent->GetSightDistance()): (newloc.z - m_Parent->GetSightDistance());
+ m_Parent->MoveToPosition(newloc);
+ return true;
+}
+
+
+
+
+
+void cBehaviorCoward::DoTakeDamage(TakeDamageInfo & a_TDI)
+{
+ if ((a_TDI.Attacker != m_Parent) && (a_TDI.Attacker != nullptr))
+ {
+ m_Attacker = a_TDI.Attacker;
+ }
+}
+
diff --git a/src/Mobs/Behaviors/BehaviorCoward.h b/src/Mobs/Behaviors/BehaviorCoward.h
new file mode 100644
index 000000000..227715c00
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorCoward.h
@@ -0,0 +1,24 @@
+#pragma once
+
+// Makes the mob run away from any other mob that damages it
+
+//fwds
+class cMonster;
+class cItems;
+class cEntity;
+struct TakeDamageInfo;
+
+class cBehaviorCoward
+{
+public:
+ cBehaviorCoward(cMonster * a_Parent);
+
+ // Functions our host Monster should invoke:
+ bool ActiveTick();
+ void DoTakeDamage(TakeDamageInfo & a_TDI);
+
+
+private:
+ cMonster * m_Parent; // Our Parent
+ cEntity * m_Attacker; // The entity we're running away from
+};
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
new file mode 100644
index 000000000..f15247071
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
@@ -0,0 +1,85 @@
+void cMonster::HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn)
+{
+ if (!m_BurnsInDaylight)
+ {
+ return;
+ }
+
+ int RelY = POSY_TOINT;
+ if ((RelY < 0) || (RelY >= cChunkDef::Height))
+ {
+ // Outside the world
+ return;
+ }
+ if (!a_Chunk.IsLightValid())
+ {
+ m_World->QueueLightChunk(GetChunkX(), GetChunkZ());
+ return;
+ }
+
+ if (!IsOnFire() && WouldBurn)
+ {
+ // Burn for 100 ticks, then decide again
+ StartBurning(100);
+ }
+}
+
+
+
+
+bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk)
+{
+ int RelY = FloorC(a_Location.y);
+ if (RelY <= 0)
+ {
+ // The mob is about to die, no point in burning
+ return false;
+ }
+ if (RelY >= cChunkDef::Height)
+ {
+ // Always burn above the world
+ return true;
+ }
+
+ PREPARE_REL_AND_CHUNK(a_Location, a_Chunk);
+ if (!RelSuccess)
+ {
+ return false;
+ }
+
+ if (
+ (Chunk->GetBlock(Rel.x, Rel.y, Rel.z) != E_BLOCK_SOULSAND) && // Not on soulsand
+ (GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime
+ GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) // Not raining
+ )
+ {
+ int MobHeight = static_cast<int>(a_Location.y) + round(GetHeight()) - 1; // The height of the mob head
+ if (MobHeight >= cChunkDef::Height)
+ {
+ return true;
+ }
+ // Start with the highest block and scan down to the mob's head.
+ // If a non transparent is found, return false (do not burn). Otherwise return true.
+ // Note that this loop is not a performance concern as transparent blocks are rare and the loop almost always bailes out
+ // instantly.(An exception is e.g. standing under a long column of glass).
+ int CurrentBlock = Chunk->GetHeight(Rel.x, Rel.z);
+ while (CurrentBlock >= MobHeight)
+ {
+ BLOCKTYPE Block = Chunk->GetBlock(Rel.x, CurrentBlock, Rel.z);
+ if (
+ // Do not burn if a block above us meets one of the following conditions:
+ (!cBlockInfo::IsTransparent(Block)) ||
+ (Block == E_BLOCK_LEAVES) ||
+ (Block == E_BLOCK_NEW_LEAVES) ||
+ (IsBlockWater(Block))
+ )
+ {
+ return false;
+ }
+ --CurrentBlock;
+ }
+ return true;
+
+ }
+ return false;
+}
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.h b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
new file mode 100644
index 000000000..9d4cbe874
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
@@ -0,0 +1,5 @@
+
+class cBehaviorDayLightBurner
+{
+
+};
diff --git a/src/Mobs/Behaviors/BehaviorItemDropper.cpp b/src/Mobs/Behaviors/BehaviorItemDropper.cpp
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorItemDropper.cpp
@@ -0,0 +1 @@
+
diff --git a/src/Mobs/Behaviors/BehaviorItemDropper.h b/src/Mobs/Behaviors/BehaviorItemDropper.h
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorItemDropper.h
@@ -0,0 +1 @@
+
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.cpp b/src/Mobs/Behaviors/BehaviorItemFollower.cpp
new file mode 100644
index 000000000..7cc0f8dfc
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorItemFollower.cpp
@@ -0,0 +1,44 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorItemFollower.h"
+#include "../Monster.h"
+#include "../../World.h"
+#include "../../Entities/Player.h"
+
+iBehaviorItemFollower::~iBehaviorItemFollower()
+{
+
+}
+
+cBehaviorItemFollower::cBehaviorItemFollower(iBehaviorItemFollower * a_ParentInterface) :
+ m_ParentInterface(a_ParentInterface)
+{
+ m_Parent = dynamic_cast<cMonster *>(m_ParentInterface);
+ ASSERT(m_Parent != nullptr);
+}
+
+
+
+
+
+bool cBehaviorItemFollower::ActiveTick()
+{
+ cWorld * World = m_Parent->GetWorld();
+ cItems FollowedItems;
+ m_ParentInterface->GetFollowedItems(FollowedItems);
+ if (FollowedItems.Size() > 0)
+ {
+ cPlayer * a_Closest_Player = m_Parent->GetNearestPlayer();
+ if (a_Closest_Player != nullptr)
+ {
+ cItem EquippedItem = a_Closest_Player->GetEquippedItem();
+ if (FollowedItems.ContainsType(EquippedItem))
+ {
+ Vector3d PlayerPos = a_Closest_Player->GetPosition();
+ m_Parent->MoveToPosition(PlayerPos);
+ return true; // We took control of the monster, prevent other Behaviors from doing so
+ }
+ }
+ }
+ return false;
+}
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.h b/src/Mobs/Behaviors/BehaviorItemFollower.h
new file mode 100644
index 000000000..ed47dab04
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorItemFollower.h
@@ -0,0 +1,29 @@
+#pragma once
+
+// Makes the mob follow specific held items
+
+class cBehaviorItemFollower;
+class iBehaviorItemFollower;
+
+//fwds
+class cMonster;
+class cItems;
+
+
+
+
+
+class cBehaviorItemFollower
+{
+public:
+ cBehaviorItemFollower(iBehaviorItemFollower * a_Parent);
+
+ // Functions our host Monster should invoke:
+ bool ActiveTick();
+
+
+private:
+ /** Our parent */
+ iBehaviorItemFollower * m_ParentInterface;
+ cMonster * m_Parent;
+};
diff --git a/src/Mobs/Behaviors/BehaviorStriker.cpp b/src/Mobs/Behaviors/BehaviorStriker.cpp
new file mode 100644
index 000000000..e09bb45f9
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorStriker.cpp
@@ -0,0 +1,7 @@
+/*
+bool cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
+{
+ GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
+
+ return true;
+} */
diff --git a/src/Mobs/Behaviors/BehaviorStriker.h b/src/Mobs/Behaviors/BehaviorStriker.h
new file mode 100644
index 000000000..6fc094476
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorStriker.h
@@ -0,0 +1,13 @@
+#pragma once
+class cBehaviorStriker
+{
+
+};
+
+/*
+bool cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
+{
+ GetTarget()->TakeDamage(dtMobAttack, this, m_AttackDamage, 0);
+
+ return true;
+} */
diff --git a/src/Mobs/Behaviors/BehaviorWanderer.cpp b/src/Mobs/Behaviors/BehaviorWanderer.cpp
new file mode 100644
index 000000000..53efd407c
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorWanderer.cpp
@@ -0,0 +1,60 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "BehaviorWanderer.h"
+#include "../Monster.h"
+#include "../../Chunk.h"
+#include "../../World.h"
+
+cBehaviorWanderer::cBehaviorWanderer(cMonster * a_Parent)
+ : m_Parent(a_Parent)
+ , m_IdleInterval(0)
+{
+ ASSERT(m_Parent != nullptr);
+}
+
+bool cBehaviorWanderer::ActiveTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ if (m_Parent->IsPathFinderActivated())
+ {
+ return true; // Still getting there
+ }
+
+ m_IdleInterval += a_Dt;
+
+ if (m_IdleInterval > std::chrono::seconds(1))
+ {
+ // At this interval the results are predictable
+ int rem = m_Parent->GetWorld()->GetTickRandomNumber(6) + 1;
+ m_IdleInterval -= std::chrono::seconds(1); // So nothing gets dropped when the server hangs for a few seconds
+
+ Vector3d Dist;
+ Dist.x = static_cast<double>(m_Parent->GetWorld()->GetTickRandomNumber(10)) - 5.0;
+ Dist.z = static_cast<double>(m_Parent->GetWorld()->GetTickRandomNumber(10)) - 5.0;
+
+ if ((Dist.SqrLength() > 2) && (rem >= 3))
+ {
+
+ Vector3d Destination(m_Parent->GetPosX() + Dist.x, m_Parent->GetPosition().y, m_Parent->GetPosZ() + Dist.z);
+
+ cChunk * Chunk = a_Chunk.GetNeighborChunk(static_cast<int>(Destination.x), static_cast<int>(Destination.z));
+ if ((Chunk == nullptr) || !Chunk->IsValid())
+ {
+ return true;
+ }
+
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta;
+ int RelX = static_cast<int>(Destination.x) - Chunk->GetPosX() * cChunkDef::Width;
+ int RelZ = static_cast<int>(Destination.z) - Chunk->GetPosZ() * cChunkDef::Width;
+ int YBelowUs = static_cast<int>(Destination.y) - 1;
+ if (YBelowUs >= 0)
+ {
+ Chunk->GetBlockTypeMeta(RelX, YBelowUs, RelZ, BlockType, BlockMeta);
+ if (BlockType != E_BLOCK_STATIONARY_WATER) // Idle mobs shouldn't enter water on purpose
+ {
+ m_Parent->MoveToPosition(Destination);
+ }
+ }
+ }
+ }
+ return true;
+}
diff --git a/src/Mobs/Behaviors/BehaviorWanderer.h b/src/Mobs/Behaviors/BehaviorWanderer.h
new file mode 100644
index 000000000..23d86f0d2
--- /dev/null
+++ b/src/Mobs/Behaviors/BehaviorWanderer.h
@@ -0,0 +1,23 @@
+#pragma once
+
+// The mob will wander around
+
+class cMonster;
+class cEntity;
+class cChunk;
+
+class cBehaviorWanderer
+{
+
+public:
+ cBehaviorWanderer(cMonster * a_Parent);
+
+ // Functions our host Monster should invoke:
+ bool ActiveTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
+
+
+private:
+ cMonster * m_Parent; // Our Parent
+
+ std::chrono::milliseconds m_IdleInterval;
+};
diff --git a/src/Mobs/Behaviors/CMakeLists.txt b/src/Mobs/Behaviors/CMakeLists.txt
new file mode 100644
index 000000000..3e0a063d1
--- /dev/null
+++ b/src/Mobs/Behaviors/CMakeLists.txt
@@ -0,0 +1,33 @@
+
+cmake_minimum_required (VERSION 2.6)
+project (Cuberite)
+
+include_directories ("${PROJECT_SOURCE_DIR}/../")
+
+SET (SRCS
+ BehaviorAggressive.cpp
+ BehaviorChaser.cpp
+ BehaviorBreeder.cpp
+ BehaviorDayLightBurner.cpp
+ BehaviorCoward.cpp
+ BehaviorItemDropper.cpp
+ BehaviorItemFollower.cpp
+ BehaviorStriker.cpp
+ BehaviorWanderer.cpp
+)
+
+SET (HDRS
+ BehaviorAggressive.h
+ BehaviorChaser.h
+ BehaviorBreeder.h
+ BehaviorDayLightBurner.h
+ BehaviorCoward.h
+ BehaviorItemDropper.h
+ BehaviorItemFollower.h
+ BehaviorStriker.h
+ BehaviorWanderer.h
+)
+
+if(NOT MSVC)
+ add_library(Behaviors ${SRCS} ${HDRS})
+endif()