summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Monster.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-22 14:33:04 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-22 19:55:30 +0200
commit5e9421bba327d79f9876a5cab2882b8b89fbeef7 (patch)
tree9e9122400dc4550afb2d92654c6caaf45007091f /src/Mobs/Monster.cpp
parentd (diff)
downloadcuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.tar
cuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.tar.gz
cuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.tar.bz2
cuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.tar.lz
cuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.tar.xz
cuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.tar.zst
cuberite-5e9421bba327d79f9876a5cab2882b8b89fbeef7.zip
Diffstat (limited to 'src/Mobs/Monster.cpp')
-rw-r--r--src/Mobs/Monster.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 3666b9bee..beb743818 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -84,6 +84,7 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A
: super(etMonster, a_Width, a_Height)
, m_EMState(IDLE)
, m_EMPersonality(AGGRESSIVE)
+ , m_NearestPlayerIsStale(true)
, m_PathFinder(a_Width, a_Height)
, m_PathfinderActivated(false)
, m_JumpCoolDown(0)
@@ -282,6 +283,7 @@ void cMonster::StopMovingToPosition()
void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
+ m_NearestPlayerIsStale = true;
super::Tick(a_Dt, a_Chunk);
if (!IsTicking())
{
@@ -1192,6 +1194,29 @@ void cMonster::GetBreedingItems(cItems & a_Items)
return GetFollowedItems(a_Items);
}
+
+
+
+
+cPlayer * cMonster::GetNearestPlayer()
+{
+ if (m_NearestPlayerIsStale)
+ {
+ // TODO: Rewrite this to use cWorld's DoWithPlayers()
+ m_NearestPlayer = GetWorld()->FindClosestPlayer(GetPosition(), static_cast<float>(GetSightDistance()));
+ m_NearestPlayerIsStale = false;
+ }
+ if ((m_NearestPlayer != nullptr) && (!m_NearestPlayer->IsTicking()))
+ {
+ m_NearestPlayer = nullptr;
+ }
+ return m_NearestPlayer;
+}
+
+
+
+
+
std::unique_ptr<cMonster> cMonster::NewMonsterFromType(eMonsterType a_MobType)
{
auto & Random = GetRandomProvider();