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)
{
@ -108,7 +128,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
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)
{
switch (a_Closest_Player->GetEquippedItem().m_ItemType)
@ -125,9 +145,7 @@ 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_FinalDestination = a_Closest_Player->GetPosition();;
m_bMovingToDestination = false;
break;
}
@ -163,23 +181,19 @@ 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:
double Distance = (Callback.OwnerPos - GetPosition()).Length();
if (Distance < 3)
{
m_bMovingToDestination = false;
}
else if ((Distance > 30) && (!IsSitting()))
if ((Distance > 30) && (!IsSitting()))
{
TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
}
else
{
m_Destination = Callback.OwnerPos;
MoveToPosition(Callback.OwnerPos);
}
}
}

View File

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