summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Wolf.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-09-11 23:20:49 +0200
committerMattes D <github@xoft.cz>2017-09-11 23:20:49 +0200
commite225b7f8262df48ad4d7094bc295add3007b0649 (patch)
treea42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Mobs/Wolf.cpp
parentcBlockArea: change MakeIndex to return size_t (diff)
downloadcuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar
cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.gz
cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.bz2
cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.lz
cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.xz
cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.zst
cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/Wolf.cpp45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp
index f3b859c76..45df3dd05 100644
--- a/src/Mobs/Wolf.cpp
+++ b/src/Mobs/Wolf.cpp
@@ -80,19 +80,13 @@ void cWolf::NotifyAlliesOfFight(cPawn * a_Opponent)
return;
}
m_NotificationCooldown = 15;
- class cCallback : public cPlayerListCallback
- {
- virtual bool Item(cPlayer * a_Player) override
+
+ m_World->DoWithPlayerByUUID(m_OwnerUUID, [=](cPlayer & a_Player)
{
- a_Player->NotifyNearbyWolves(m_Opponent, false);
+ a_Player.NotifyNearbyWolves(a_Opponent, false);
return false;
}
- public:
- cPawn * m_Opponent;
- } Callback;
-
- Callback.m_Opponent = a_Opponent;
- m_World->DoWithPlayerByUUID(m_OwnerUUID, Callback);
+ );
}
bool cWolf::Attack(std::chrono::milliseconds a_Dt)
@@ -347,30 +341,25 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cWolf::TickFollowPlayer()
{
- class cCallback :
- public cPlayerListCallback
+ Vector3d OwnerPos;
+ bool OwnerFlying;
+ auto Callback = [&](cPlayer & a_Player)
{
- virtual bool Item(cPlayer * a_Player) override
- {
- OwnerPos = a_Player->GetPosition();
- OwnerFlying = a_Player->IsFlying();
- return true;
- }
- public:
- Vector3d OwnerPos;
- bool OwnerFlying;
- } Callback;
+ OwnerPos = a_Player.GetPosition();
+ OwnerFlying = a_Player.IsFlying();
+ return true;
+ };
if (m_World->DoWithPlayerByUUID(m_OwnerUUID, Callback))
{
// The player is present in the world, follow him:
- double Distance = (Callback.OwnerPos - GetPosition()).Length();
+ double Distance = (OwnerPos - GetPosition()).Length();
if (Distance > 20)
{
- if (!Callback.OwnerFlying)
+ if (!OwnerFlying)
{
- Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z);
- TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
+ OwnerPos.y = FindFirstNonAirBlockPosition(OwnerPos.x, OwnerPos.z);
+ TeleportToCoords(OwnerPos.x, OwnerPos.y, OwnerPos.z);
SetTarget(nullptr);
}
}
@@ -385,9 +374,9 @@ void cWolf::TickFollowPlayer()
{
if (GetTarget() == nullptr)
{
- if (!Callback.OwnerFlying)
+ if (!OwnerFlying)
{
- MoveToPosition(Callback.OwnerPos);
+ MoveToPosition(OwnerPos);
}
}
}