1
0

Made wolves compatible with new AI code

This commit is contained in:
Tiger Wang 2014-01-24 20:46:47 +00:00
parent 1f82b6e192
commit 0583b9df39
2 changed files with 26 additions and 11 deletions

View File

@ -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) void cWolf::OnRightClicked(cPlayer & a_Player)
{ {
@ -108,7 +128,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
m_bMovingToDestination = false; m_bMovingToDestination = false;
} }
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), m_SightDistance); cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL) if (a_Closest_Player != NULL)
{ {
switch (a_Closest_Player->GetEquippedItem().m_ItemType) switch (a_Closest_Player->GetEquippedItem().m_ItemType)
@ -125,9 +145,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
SetIsBegging(true); SetIsBegging(true);
m_World->BroadcastEntityMetadata(*this); m_World->BroadcastEntityMetadata(*this);
} }
Vector3f a_NewDestination = a_Closest_Player->GetPosition(); m_FinalDestination = 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; m_bMovingToDestination = false;
break; break;
} }
@ -163,23 +181,19 @@ void cWolf::TickFollowPlayer()
return false; return false;
} }
public: public:
Vector3f OwnerPos; Vector3d OwnerPos;
} Callback; } Callback;
if (m_World->DoWithPlayer(m_OwnerName, 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 them:
double Distance = (Callback.OwnerPos - GetPosition()).Length(); double Distance = (Callback.OwnerPos - GetPosition()).Length();
if (Distance < 3) if ((Distance > 30) && (!IsSitting()))
{
m_bMovingToDestination = false;
}
else if ((Distance > 30) && (!IsSitting()))
{ {
TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
} }
else else
{ {
m_Destination = Callback.OwnerPos; MoveToPosition(Callback.OwnerPos);
} }
} }
} }

View File

@ -22,6 +22,7 @@ public:
virtual void OnRightClicked(cPlayer & a_Player) override; virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void TickFollowPlayer(); virtual void TickFollowPlayer();
virtual void Attack(float a_Dt) override;
// Get functions // Get functions
bool IsSitting (void) const { return m_IsSitting; } bool IsSitting (void) const { return m_IsSitting; }