Skip to content

Commit

Permalink
Wolves can now be owned by an entity.
Browse files Browse the repository at this point in the history
They only sit when right clicked by their owner.
They beg if the closest player has meat or bones in his hand.
They follow their owner.
They teleport to their owner if they are more then 30 blocks away.
They don't attack players if they are not angry anymore.
They don't move if they are sitting.
  • Loading branch information
NiLSPACE committed Nov 10, 2013
1 parent fb3a175 commit 38f6fff
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 17 deletions.
94 changes: 83 additions & 11 deletions source/Mobs/Wolf.cpp
Expand Up @@ -14,7 +14,8 @@ cWolf::cWolf(void) :
m_bIsAngry(false),
m_bIsTame(false),
m_bIsSitting(false),
m_bIsBegging(false)
m_bIsBegging(false),
m_bOwner(NULL)
{
}

Expand All @@ -38,7 +39,7 @@ void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)

void cWolf::OnRightClicked(cPlayer & a_Player)
{
if ((!m_bIsTame) && (!m_bIsAngry))
if ((!IsTame()) && (!IsAngry()))
{
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
{
Expand All @@ -47,10 +48,11 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
a_Player.GetInventory().RemoveOneEquippedItem();
}

if (m_World->GetTickRandomNumber(10) == 5)
if (m_World->GetTickRandomNumber(7) == 0)
{
SetMaxHealth(20);
m_bIsTame = true;
SetIsTame(true);
SetOwner(&a_Player);
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
}
else
Expand All @@ -59,15 +61,18 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
}
}
}
else if (m_bIsTame)
else if (IsTame())
{
if (m_bIsSitting)
if (m_bOwner != NULL && a_Player.GetUniqueID() == m_bOwner->GetUniqueID()) // Is the player the owner of the dog?
{
m_bIsSitting = false;
}
else
{
m_bIsSitting = true;
if (IsSitting())
{
SetIsSitting(false);
}
else
{
SetIsSitting(true);
}
}
}

Expand All @@ -77,3 +82,70 @@ void cWolf::OnRightClicked(cPlayer & a_Player)




void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
{
if (!IsAngry())
{
super::cMonster::Tick(a_Dt, a_Chunk);

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Nov 10, 2013

Member

Either super, or cMonster. Choose one.

This comment has been minimized.

Copy link
@NiLSPACE

NiLSPACE Nov 10, 2013

Author Member

Then it's gonna be cMonster since super gives the cAgressive Tick ;)

} else {
super::Tick(a_Dt, a_Chunk);
}

if (IsSitting())
{
m_bMovingToDestination = false;
}

cPlayer * a_Closest_Player = FindClosestPlayer();
if (a_Closest_Player != NULL)
{
switch (a_Closest_Player->GetEquippedItem().m_ItemType)
{
case E_ITEM_BONE:
case E_ITEM_RAW_BEEF:
case E_ITEM_STEAK:
case E_ITEM_RAW_CHICKEN:
case E_ITEM_COOKED_CHICKEN:
case E_ITEM_ROTTEN_FLESH:
{
if (!IsBegging())
{
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;
break;
}
default:
{
if (IsBegging())
{
SetIsBegging(false);
m_World->BroadcastEntityMetadata(*this);
}
}
}
}

if (IsTame())
{
if (m_bOwner != NULL)
{
Vector3f OwnerCoords = m_bOwner->GetPosition();
double Distance = (OwnerCoords - GetPosition()).Length();
if (Distance < 3)
{
m_bMovingToDestination = false;
} else if((Distance > 30) && (!IsSitting())) {
TeleportToEntity(*m_bOwner);
} else {
m_Destination = OwnerCoords;
}
}
}

}
23 changes: 17 additions & 6 deletions source/Mobs/Wolf.h
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include "PassiveAggressiveMonster.h"
#include "../Entities/Entity.h"



Expand All @@ -19,19 +20,29 @@ class cWolf :

virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void OnRightClicked(cPlayer & a_Player) override;

bool IsSitting(void) const { return m_bIsSitting; }
bool IsTame(void) const { return m_bIsTame; }
bool IsBegging(void) const { return m_bIsBegging; }
bool IsAngry(void) const { return m_bIsAngry; }
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;

// Get functions
bool IsSitting(void) const { return m_bIsSitting; }
bool IsTame(void) const { return m_bIsTame; }
bool IsBegging(void) const { return m_bIsBegging; }
bool IsAngry(void) const { return m_bIsAngry; }
cEntity * GetOwner(void) const { return m_bOwner; }

// Set functions
void SetIsSitting(bool a_IsSitting) { m_bIsSitting = a_IsSitting; }
void SetIsTame(bool a_IsTame) { m_bIsTame = a_IsTame; }
void SetIsBegging(bool a_IsBegging) { m_bIsBegging = a_IsBegging; }
void SetIsAngry(bool a_IsAngry) { m_bIsAngry = a_IsAngry; }
void SetOwner(cEntity * a_Entity) { m_bOwner = a_Entity; }

private:

bool m_bIsSitting;
bool m_bIsTame;
bool m_bIsBegging;
bool m_bIsAngry;

cEntity * m_bOwner;
} ;


Expand Down

0 comments on commit 38f6fff

Please sign in to comment.