1
0

Rewritten code.

Implemented xoft suggestion.
Using MoveToPosition as tigerw suggested.
This commit is contained in:
tonibm19 2014-01-29 19:15:26 +01:00
parent ba4865f7ee
commit 1c1832b6ce
12 changed files with 25 additions and 152 deletions

View File

@ -41,29 +41,6 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk)
{
m_EggDropTimer++;
}
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_SEEDS)
{
if (!IsBegging())
{
m_IsBegging = true;
m_World->BroadcastEntityMetadata(*this);
}
Vector3d PlayerPos = a_Closest_Player->GetPosition();
PlayerPos.y++;
m_FinalDestination = PlayerPos;
}
else
{
if (IsBegging())
{
m_IsBegging = false;
m_World->BroadcastEntityMetadata(*this);
}
}
}
}

View File

@ -19,13 +19,11 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
bool IsBegging (void) const { return m_IsBegging; }
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_SEEDS); }
private:
int m_EggDropTimer;
bool m_IsBegging;
} ;

View File

@ -41,30 +41,3 @@ void cCow::OnRightClicked(cPlayer & a_Player)
}
}
void cCow::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT)
{
if (!IsBegging())
{
m_IsBegging = true;
m_World->BroadcastEntityMetadata(*this);
}
Vector3d PlayerPos = a_Closest_Player->GetPosition();
PlayerPos.y++;
m_FinalDestination = PlayerPos;
}
else
{
if (IsBegging())
{
m_IsBegging = false;
m_World->BroadcastEntityMetadata(*this);
}
}
}
}

View File

@ -19,13 +19,8 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
bool IsBegging (void) const { return m_IsBegging; }
private:
bool m_IsBegging;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
} ;

View File

@ -30,32 +30,4 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer)
}
void cMooshroom::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT)
{
if (!IsBegging())
{
m_IsBegging = true;
m_World->BroadcastEntityMetadata(*this);
}
Vector3d PlayerPos = a_Closest_Player->GetPosition();
PlayerPos.y++;
m_FinalDestination = PlayerPos;
}
else
{
if (IsBegging())
{
m_IsBegging = false;
m_World->BroadcastEntityMetadata(*this);
}
}
}
}

View File

@ -18,14 +18,8 @@ public:
CLASS_PROTODEF(cMooshroom);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
bool IsBegging (void) const { return m_IsBegging; }
private:
bool m_IsBegging;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
} ;

View File

@ -3,7 +3,7 @@
#include "PassiveMonster.h"
#include "../World.h"
#include "../Entities/Player.h"
@ -39,6 +39,20 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
CheckEventLostPlayer();
}
cItem FollowedItem = GetFollowedItem();
if (FollowedItem.IsEmpty())
{
return;
}
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
if (a_Closest_Player->GetEquippedItem().m_ItemType == FollowedItem.m_ItemType)
{
Vector3d PlayerPos = a_Closest_Player->GetPosition();
MoveToPosition(PlayerPos);
}
}
}

View File

@ -20,6 +20,8 @@ public:
/// When hit by someone, run away
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual const cItem GetFollowedItem(void) const { return cItem(); }
} ;

View File

@ -71,33 +71,5 @@ void cPig::OnRightClicked(cPlayer & a_Player)
}
}
void cPig::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_CARROT)
{
if (!IsBegging())
{
m_IsBegging = true;
m_World->BroadcastEntityMetadata(*this);
}
Vector3d PlayerPos = a_Closest_Player->GetPosition();
PlayerPos.y++;
m_FinalDestination = PlayerPos;
}
else
{
if (IsBegging())
{
m_IsBegging = false;
m_World->BroadcastEntityMetadata(*this);
}
}
}
}

View File

@ -19,14 +19,13 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); }
bool IsSaddled(void) const { return m_bIsSaddled; }
bool IsBegging (void) const { return m_IsBegging; }
private:
bool m_IsBegging;
bool m_bIsSaddled;
} ;

View File

@ -95,29 +95,6 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk)
m_TimeToStopEating = 40;
}
}
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
if (a_Closest_Player != NULL)
{
if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT)
{
if (!IsBegging())
{
m_IsBegging = true;
m_World->BroadcastEntityMetadata(*this);
}
Vector3d PlayerPos = a_Closest_Player->GetPosition();
PlayerPos.y++;
m_FinalDestination = PlayerPos;
}
else
{
if (IsBegging())
{
m_IsBegging = false;
m_World->BroadcastEntityMetadata(*this);
}
}
}
}
}

View File

@ -21,13 +21,13 @@ public:
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
bool IsBegging(void) const { return m_IsBegging; }
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
bool IsSheared(void) const { return m_IsSheared; }
int GetFurColor(void) const { return m_WoolColor; }
private:
bool m_IsBegging;
bool m_IsSheared;
int m_WoolColor;
int m_TimeToStopEating;