summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Behaviors')
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.cpp26
-rw-r--r--src/Mobs/Behaviors/BehaviorAggressive.h2
-rw-r--r--src/Mobs/Behaviors/BehaviorBreeder.cpp8
-rw-r--r--src/Mobs/Behaviors/BehaviorChaser.cpp148
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.cpp152
-rw-r--r--src/Mobs/Behaviors/BehaviorDayLightBurner.h16
6 files changed, 190 insertions, 162 deletions
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.cpp b/src/Mobs/Behaviors/BehaviorAggressive.cpp
index 74eee0e17..2113cb1e6 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.cpp
+++ b/src/Mobs/Behaviors/BehaviorAggressive.cpp
@@ -10,9 +10,9 @@
cBehaviorAggressive::cBehaviorAggressive(cMonster * a_Parent) : m_Parent(a_Parent)
{
- ASSERT(m_Parent != nullptr);
- m_ParentChaser = m_Parent->GetBehaviorChaser();
- ASSERT(m_ParentChaser != nullptr);
+ ASSERT(m_Parent != nullptr);
+ m_ParentChaser = m_Parent->GetBehaviorChaser();
+ ASSERT(m_ParentChaser != nullptr);
}
@@ -21,12 +21,12 @@ cBehaviorAggressive::cBehaviorAggressive(cMonster * a_Parent) : m_Parent(a_Paren
bool cBehaviorAggressive::ActiveTick()
{
- // Target something new if we have no target
- if (m_ParentChaser->GetTarget() == nullptr)
- {
- m_ParentChaser->SetTarget(FindNewTarget());
- }
- return false;
+ // Target something new if we have no target
+ if (m_ParentChaser->GetTarget() == nullptr)
+ {
+ m_ParentChaser->SetTarget(FindNewTarget());
+ }
+ return false;
}
@@ -35,15 +35,15 @@ bool cBehaviorAggressive::ActiveTick()
void cBehaviorAggressive::Destroyed()
{
- m_Target = nullptr;
+ m_Target = nullptr;
}
-bool cBehaviorAggressive::FindNewTarget()
+cPawn * cBehaviorAggressive::FindNewTarget()
{
- cPlayer * Closest = m_Parent->GetNearestPlayer();
- return Closest; // May be null
+ cPlayer * Closest = m_Parent->GetNearestPlayer();
+ return Closest; // May be null
}
diff --git a/src/Mobs/Behaviors/BehaviorAggressive.h b/src/Mobs/Behaviors/BehaviorAggressive.h
index 0235aa99b..ca2ad577b 100644
--- a/src/Mobs/Behaviors/BehaviorAggressive.h
+++ b/src/Mobs/Behaviors/BehaviorAggressive.h
@@ -9,7 +9,7 @@ class cBehaviorAggressive
{
public:
- cBehaviorAggressive(cMonster * a_Parent, int a_MinimumLight);
+ cBehaviorAggressive(cMonster * a_Parent);
// cBehaviorAggressive(cMonster * a_Parent, bool a_HatesPlayer);
// TODO agression toward specific players, and specific mobtypes, etc
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp
index ddca1715a..8ba991989 100644
--- a/src/Mobs/Behaviors/BehaviorBreeder.cpp
+++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp
@@ -14,7 +14,7 @@ cBehaviorBreeder::cBehaviorBreeder(cMonster * a_Parent) :
m_LovePartner(nullptr),
m_LoveTimer(0),
m_LoveCooldown(0),
- m_MatingTimer(0),
+ m_MatingTimer(0)
{
m_Parent = a_Parent;
ASSERT(m_Parent != nullptr);
@@ -62,7 +62,7 @@ bool cBehaviorBreeder::ActiveTick()
}
cFastRandom Random;
- World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, 1 + Random.NextInt(6));
+ World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, 1 + (Random.RandInt() % 6));
m_LovePartner->GetBehaviorBreeder()->ResetLoveMode();
ResetLoveMode();
@@ -169,7 +169,9 @@ void cBehaviorBreeder::OnRightClicked(cPlayer & a_Player)
if ((m_LoveCooldown == 0) && !IsInLove() && !m_Parent->IsBaby())
{
short HeldItem = a_Player.GetEquippedItem().m_ItemType;
- if (m_BreedingItems.ContainsType(HeldItem))
+ cItems BreedingItems;
+ m_Parent->GetFollowedItems(BreedingItems);
+ if (BreedingItems.ContainsType(HeldItem))
{
if (!a_Player.IsGameModeCreative())
{
diff --git a/src/Mobs/Behaviors/BehaviorChaser.cpp b/src/Mobs/Behaviors/BehaviorChaser.cpp
index 22a95fe73..b022495eb 100644
--- a/src/Mobs/Behaviors/BehaviorChaser.cpp
+++ b/src/Mobs/Behaviors/BehaviorChaser.cpp
@@ -7,18 +7,19 @@
#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)
+ m_Parent(a_Parent)
+ , m_AttackRate(3)
+ , m_AttackDamage(1)
+ , m_AttackRange(1)
+ , m_AttackCoolDownTicksLeft(0)
+ , m_TicksSinceLastDamaged(50)
{
- 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
+ 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
}
@@ -27,27 +28,27 @@ cBehaviorChaser::cBehaviorChaser(cMonster * a_Parent) :
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;
+ // Stop targeting out of range targets
+ if (GetTarget() != nullptr)
+ {
+ if (TargetOutOfSight())
+ {
+ SetTarget(nullptr);
+ }
+ else
+ {
+ if (TargetIsInStrikeRange())
+ {
+ StrikeTarget();
+ }
+ else
+ {
+ ApproachTarget();
+ }
+ return true;
+ }
+ }
+ return false;
}
@@ -56,11 +57,11 @@ bool cBehaviorChaser::ActiveTick()
void cBehaviorChaser::Tick()
{
- ++m_TicksSinceLastDamaged;
- if (m_AttackCoolDownTicksLeft > 0)
- {
- m_AttackCoolDownTicksLeft -= 1;
- }
+ ++m_TicksSinceLastDamaged;
+ if (m_AttackCoolDownTicksLeft > 0)
+ {
+ m_AttackCoolDownTicksLeft -= 1;
+ }
}
@@ -69,7 +70,7 @@ void cBehaviorChaser::Tick()
void cBehaviorChaser::Destroyed()
{
- m_Target = nullptr;
+ m_Target = nullptr;
}
@@ -78,7 +79,7 @@ void cBehaviorChaser::Destroyed()
void cBehaviorChaser::SetAttackRate(float a_AttackRate)
{
- m_AttackRate = a_AttackRate;
+ m_AttackRate = a_AttackRate;
}
@@ -87,7 +88,7 @@ void cBehaviorChaser::SetAttackRate(float a_AttackRate)
void cBehaviorChaser::SetAttackRange(int a_AttackRange)
{
- m_AttackRange = a_AttackRange;
+ m_AttackRange = a_AttackRange;
}
@@ -96,7 +97,7 @@ void cBehaviorChaser::SetAttackRange(int a_AttackRange)
void cBehaviorChaser::SetAttackDamage(int a_AttackDamage)
{
- m_AttackDamage = a_AttackDamage;
+ m_AttackDamage = a_AttackDamage;
}
@@ -104,7 +105,7 @@ void cBehaviorChaser::SetAttackDamage(int a_AttackDamage)
cPawn * cBehaviorChaser::GetTarget()
{
- return m_Target;
+ return m_Target;
}
@@ -113,7 +114,7 @@ cPawn * cBehaviorChaser::GetTarget()
void cBehaviorChaser::SetTarget(cPawn * a_Target)
{
- m_Target = a_Target;
+ m_Target = a_Target;
}
@@ -131,26 +132,26 @@ 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));
+ 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));
}
@@ -159,12 +160,12 @@ bool cBehaviorChaser::TargetIsInStrikeRange()
bool cBehaviorChaser::TargetOutOfSight()
{
- ASSERT(m_Target != nullptr);
- if ((GetTarget()->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance())
- {
- return true;
- }
- return false;
+ ASSERT(m_Target != nullptr);
+ if ((GetTarget()->GetPosition() - m_Parent->GetPosition()).Length() > m_Parent->GetSightDistance())
+ {
+ return true;
+ }
+ return false;
}
@@ -173,7 +174,7 @@ bool cBehaviorChaser::TargetOutOfSight()
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
+ 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
}
@@ -182,9 +183,10 @@ void cBehaviorChaser::ResetStrikeCooldown()
void cBehaviorChaser::StrikeTarget()
{
- if (m_AttackCoolDownTicksLeft != 0)
- {
- m_StrikeBehavior->Strike(m_Target); // LogicParrot Todo animations (via counter passing?)
- ResetStrikeCooldown();
- }
+ if (m_AttackCoolDownTicksLeft != 0)
+ {
+ // mobTodo
+ // m_StrikeBehavior->Strike(m_Target); // LogicParrot Todo animations (via counter passing?)
+ ResetStrikeCooldown();
+ }
}
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
index f15247071..9f182a359 100644
--- a/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.cpp
@@ -1,85 +1,93 @@
-void cMonster::HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn)
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "BehaviorDayLightBurner.h"
+#include "../Monster.h"
+#include "../../World.h"
+#include "../../Entities/Player.h"
+#include "../../Entities/Entity.h"
+
+cBehaviorDayLightBurner::cBehaviorDayLightBurner(cMonster * a_Parent) : m_Parent(a_Parent)
{
- if (!m_BurnsInDaylight)
- {
- return;
- }
+ ASSERT(m_Parent != nullptr);
+}
- int RelY = POSY_TOINT;
- if ((RelY < 0) || (RelY >= cChunkDef::Height))
- {
- // Outside the world
- return;
- }
- if (!a_Chunk.IsLightValid())
- {
- m_World->QueueLightChunk(GetChunkX(), GetChunkZ());
- return;
- }
+void cBehaviorDayLightBurner::Tick(cChunk & a_Chunk, bool WouldBurn)
+{
+ 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);
- }
+ if (!IsOnFire() && WouldBurn)
+ {
+ // Burn for 100 ticks, then decide again
+ StartBurning(100);
+ }
}
-bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk)
+bool cBehaviorDayLightBurner::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;
- }
+ 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;
- }
+ 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;
+ 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;
+ }
+ return false;
}
diff --git a/src/Mobs/Behaviors/BehaviorDayLightBurner.h b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
index 9d4cbe874..b54a863af 100644
--- a/src/Mobs/Behaviors/BehaviorDayLightBurner.h
+++ b/src/Mobs/Behaviors/BehaviorDayLightBurner.h
@@ -1,5 +1,21 @@
+#pragma once
+
+// fwds
+class cMonster;
+class cEntity;
+class cChunk;
+class Vector3d;
class cBehaviorDayLightBurner
{
+ cBehaviorDayLightBurner(cMonster * a_Parent);
+
+ bool WouldBurnAt(Vector3d & a_Location, cChunk & a_Chunk);
+
+ // Functions our host Monster should invoke:
+ void Tick();
+private:
+ cMonster * m_Parent; // Our Parent
+ cEntity * m_Attacker; // The entity we're running away from
};