summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Mobs/AggressiveMonster.cpp6
-rw-r--r--src/Mobs/AggressiveMonster.h2
-rw-r--r--src/Mobs/Enderman.cpp22
-rw-r--r--src/Mobs/Enderman.h4
-rw-r--r--src/Mobs/Monster.cpp6
-rw-r--r--src/Mobs/Monster.h4
-rw-r--r--src/Mobs/PassiveAggressiveMonster.cpp4
-rw-r--r--src/Mobs/PassiveAggressiveMonster.h4
-rw-r--r--src/Mobs/Spider.cpp15
-rw-r--r--src/Mobs/Spider.h4
10 files changed, 38 insertions, 33 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index faee4a049..512bfb4a1 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -36,11 +36,11 @@ void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk &
-void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity)
+void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk)
{
if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative())
{
- super::EventSeePlayer(a_Entity);
+ super::EventSeePlayer(a_Entity, a_Chunk);
m_EMState = CHASING;
}
}
@@ -59,7 +59,7 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
else
{
- CheckEventSeePlayer();
+ CheckEventSeePlayer(a_Chunk);
}
if (m_Target == nullptr)
diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h
index 13f59842f..f2d6366e2 100644
--- a/src/Mobs/AggressiveMonster.h
+++ b/src/Mobs/AggressiveMonster.h
@@ -19,7 +19,7 @@ public:
virtual void Tick (std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
- virtual void EventSeePlayer(cEntity *) override;
+ virtual void EventSeePlayer(cEntity * a_Player, cChunk & a_Chunk) override;
/** Try to perform attack
returns true if attack was deemed successful (hit player, fired projectile, creeper exploded, etc.) even if it didn't actually do damage
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index ac749e36a..4a30a0acd 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -28,32 +28,32 @@ public:
{
return false;
}
-
+
Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
-
+
// Don't check players who are more then SightDistance (64) blocks away
if (Direction.Length() > m_SightDistance)
{
return false;
}
-
+
// Don't check if the player has a pumpkin on his head
if (a_Player->GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
{
return false;
}
-
+
Vector3d LookVector = a_Player->GetLookVector();
double dot = Direction.Dot(LookVector);
-
+
// 0.09 rad ~ 5 degrees
// If the player's crosshair is within 5 degrees of the enderman, it counts as looking
if (dot <= cos(0.09))
{
return false;
}
-
+
cTracer LineOfSight(a_Player->GetWorld());
if (LineOfSight.Trace(m_EndermanPos, Direction, static_cast<int>(Direction.Length())))
{
@@ -64,7 +64,7 @@ public:
m_Player = a_Player;
return true;
}
-
+
cPlayer * GetPlayer(void) const { return m_Player; }
protected:
@@ -102,7 +102,7 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-void cEnderman::CheckEventSeePlayer()
+void cEnderman::CheckEventSeePlayer(cChunk & a_Chunk)
{
if (m_Target != nullptr)
{
@@ -114,7 +114,7 @@ void cEnderman::CheckEventSeePlayer()
{
return;
}
-
+
ASSERT(Callback.GetPlayer() != nullptr);
if (!CheckLight())
@@ -126,7 +126,7 @@ void cEnderman::CheckEventSeePlayer()
if (!Callback.GetPlayer()->IsGameModeCreative())
{
- cMonster::EventSeePlayer(Callback.GetPlayer());
+ cMonster::EventSeePlayer(Callback.GetPlayer(), a_Chunk);
m_EMState = CHASING;
m_bIsScreaming = true;
GetWorld()->BroadcastEntityMetadata(*this);
@@ -145,7 +145,7 @@ void cEnderman::CheckEventLostPlayer(void)
EventLosePlayer();
}
}
-
+
diff --git a/src/Mobs/Enderman.h b/src/Mobs/Enderman.h
index 8ccbf2ce7..54859c2cd 100644
--- a/src/Mobs/Enderman.h
+++ b/src/Mobs/Enderman.h
@@ -11,14 +11,14 @@ class cEnderman :
public cPassiveAggressiveMonster
{
typedef cPassiveAggressiveMonster super;
-
+
public:
cEnderman(void);
CLASS_PROTODEF(cEnderman)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual void CheckEventSeePlayer(void) override;
+ virtual void CheckEventSeePlayer(cChunk & a_Chunk) override;
virtual void CheckEventLostPlayer(void) override;
virtual void EventLosePlayer(void) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index a24df6bc2..4a543e400 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -560,14 +560,14 @@ void cMonster::OnRightClicked(cPlayer & a_Player)
// Checks to see if EventSeePlayer should be fired
// monster sez: Do I see the player
-void cMonster::CheckEventSeePlayer(void)
+void cMonster::CheckEventSeePlayer(cChunk & a_Chunk)
{
// TODO: Rewrite this to use cWorld's DoWithPlayers()
cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance), false);
if (Closest != nullptr)
{
- EventSeePlayer(Closest);
+ EventSeePlayer(Closest, a_Chunk);
}
}
@@ -596,7 +596,7 @@ void cMonster::CheckEventLostPlayer(void)
// What to do if player is seen
// default to change state to chasing
-void cMonster::EventSeePlayer(cEntity * a_SeenPlayer)
+void cMonster::EventSeePlayer(cEntity * a_SeenPlayer, cChunk & a_Chunk)
{
m_Target = a_SeenPlayer;
}
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 1304863b5..7c4683942 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -67,8 +67,8 @@ public:
eFamily GetMobFamily(void) const;
// tolua_end
- virtual void CheckEventSeePlayer(void);
- virtual void EventSeePlayer(cEntity * a_Player);
+ virtual void CheckEventSeePlayer(cChunk & a_Chunk);
+ virtual void EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk);
/** Reads the monster configuration for the specified monster name and assigns it to this object. */
void GetMonsterConfig(const AString & a_Name);
diff --git a/src/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp
index e0abd94a5..71ac7bd89 100644
--- a/src/Mobs/PassiveAggressiveMonster.cpp
+++ b/src/Mobs/PassiveAggressiveMonster.cpp
@@ -25,7 +25,7 @@ bool cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
{
return false;
}
-
+
if ((m_Target != nullptr) && (m_Target->IsPlayer()))
{
if (!static_cast<cPlayer *>(m_Target)->IsGameModeCreative())
@@ -39,7 +39,7 @@ bool cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
-void cPassiveAggressiveMonster::EventSeePlayer(cEntity *)
+void cPassiveAggressiveMonster::EventSeePlayer(cEntity *, cChunk & a_Chunk)
{
// don't do anything, neutral mobs don't react to just seeing the player
}
diff --git a/src/Mobs/PassiveAggressiveMonster.h b/src/Mobs/PassiveAggressiveMonster.h
index 02dad2f40..00db75385 100644
--- a/src/Mobs/PassiveAggressiveMonster.h
+++ b/src/Mobs/PassiveAggressiveMonster.h
@@ -11,12 +11,12 @@ class cPassiveAggressiveMonster :
public cAggressiveMonster
{
typedef cAggressiveMonster super;
-
+
public:
cPassiveAggressiveMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
- virtual void EventSeePlayer(cEntity *) override;
+ virtual void EventSeePlayer(cEntity *, cChunk & a_Chunk) override;
} ;
diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp
index a9da28750..a5f0d6a89 100644
--- a/src/Mobs/Spider.cpp
+++ b/src/Mobs/Spider.cpp
@@ -5,7 +5,7 @@
#include "../World.h"
#include "../Entities/Player.h"
-
+#include "../Chunk.h"
cSpider::cSpider(void) :
@@ -35,17 +35,22 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-void cSpider::EventSeePlayer(cEntity * a_Entity)
+void cSpider::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk)
{
if (!GetWorld()->IsChunkLighted(GetChunkX(), GetChunkZ()))
{
- GetWorld()->QueueLightChunk(GetChunkX(), GetChunkZ());
return;
}
- if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative() && (GetWorld()->GetBlockBlockLight(this->GetPosition()) <= 9))
+ PREPARE_REL_AND_CHUNK(GetPosition(), a_Chunk);
+ if (!RelSuccess)
+ {
+ return;
+ }
+
+ if (!static_cast<cPlayer *>(a_Entity)->IsGameModeCreative() && (Chunk->GetSkyLightAltered(Rel.x, Rel.y, Rel.z) <= 9))
{
- super::EventSeePlayer(a_Entity);
+ super::EventSeePlayer(a_Entity, a_Chunk);
}
}
diff --git a/src/Mobs/Spider.h b/src/Mobs/Spider.h
index 4f9df7887..85cae92fc 100644
--- a/src/Mobs/Spider.h
+++ b/src/Mobs/Spider.h
@@ -11,14 +11,14 @@ class cSpider :
public cAggressiveMonster
{
typedef cAggressiveMonster super;
-
+
public:
cSpider(void);
CLASS_PROTODEF(cSpider)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual void EventSeePlayer(cEntity *) override;
+ virtual void EventSeePlayer(cEntity *, cChunk & a_Chunk) override;
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
} ;