summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Wolf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Wolf.cpp')
-rw-r--r--src/Mobs/Wolf.cpp68
1 files changed, 53 insertions, 15 deletions
diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp
index 3d4e97c80..c0c7892e3 100644
--- a/src/Mobs/Wolf.cpp
+++ b/src/Mobs/Wolf.cpp
@@ -37,6 +37,26 @@ void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)
+void cWolf::Attack(float a_Dt)
+{
+ UNUSED(a_Dt);
+
+ if ((m_Target != NULL) && (m_Target->IsPlayer()))
+ {
+ if (((cPlayer *)m_Target)->GetName() != m_OwnerName)
+ {
+ super::Attack(a_Dt);
+ }
+ }
+ else
+ {
+ super::Attack(a_Dt);
+ }
+}
+
+
+
+
void cWolf::OnRightClicked(cPlayer & a_Player)
{
@@ -55,10 +75,12 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
SetIsTame(true);
SetOwner(a_Player.GetName());
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
+ m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
}
else
{
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMING);
+ m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
}
}
}
@@ -102,13 +124,14 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
}
-
+
+ // The wolf is sitting so don't move him at all.
if (IsSitting())
{
m_bMovingToDestination = false;
}
- cPlayer * a_Closest_Player = FindClosestPlayer();
+ cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
switch (a_Closest_Player->GetEquippedItem().m_ItemType)
@@ -125,10 +148,18 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
SetIsBegging(true);
m_World->BroadcastEntityMetadata(*this);
}
- Vector3f a_NewDestination = a_Closest_Player->GetPosition();
- a_NewDestination.y = a_NewDestination.y + 1; // Look at the head of the player, not his feet.
- m_Destination = Vector3f(a_NewDestination);
- m_bMovingToDestination = false;
+ // Don't move to the player if the wolf is sitting.
+ if (IsSitting())
+ {
+ m_bMovingToDestination = false;
+ }
+ else
+ {
+ m_bMovingToDestination = true;
+ }
+ Vector3d PlayerPos = a_Closest_Player->GetPosition();
+ PlayerPos.y++;
+ m_FinalDestination = PlayerPos;
break;
}
default:
@@ -163,23 +194,30 @@ void cWolf::TickFollowPlayer()
return false;
}
public:
- Vector3f OwnerPos;
+ Vector3d OwnerPos;
} Callback;
if (m_World->DoWithPlayer(m_OwnerName, Callback))
{
- // The player is present in the world, follow them:
+ // The player is present in the world, follow him:
double Distance = (Callback.OwnerPos - GetPosition()).Length();
- if (Distance < 3)
- {
- m_bMovingToDestination = false;
- }
- else if ((Distance > 30) && (!IsSitting()))
+ if (Distance > 30)
{
- TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
+ if (!IsSitting())
+ {
+ TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
+ }
}
else
{
- m_Destination = Callback.OwnerPos;
+ m_FinalDestination = Callback.OwnerPos;
+ if (IsSitting())
+ {
+ m_bMovingToDestination = false;
+ }
+ else
+ {
+ m_bMovingToDestination = true;
+ }
}
}
}