From 38f6fff3fbe7c90899b319f53b08d48714a3c845 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 10 Nov 2013 15:16:43 +0100 Subject: Wolves can now be owned by an entity. 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. --- source/Mobs/Wolf.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 11 deletions(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index 2baeb4b7b..e9d3ce394 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -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) { } @@ -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) { @@ -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 @@ -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); + } } } @@ -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); + } 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; + } + } + } + +} \ No newline at end of file -- cgit v1.2.3 From 09805679120dc5aa5f236664245c475a4a34d197 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 10 Nov 2013 15:51:32 +0100 Subject: Using cMonster::Tick instead of super::cMonster::Tick --- source/Mobs/Wolf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index e9d3ce394..ad8360445 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -87,7 +87,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) { if (!IsAngry()) { - super::cMonster::Tick(a_Dt, a_Chunk); + cMonster::Tick(a_Dt, a_Chunk); } else { super::Tick(a_Dt, a_Chunk); } -- cgit v1.2.3 From 4f11cd2f8a665dcda7f06c1b5e1c8b8cda7b38ad Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 10 Nov 2013 18:03:19 +0100 Subject: The owner object isn't stored anymore. Instead we use the name of the player. This means only players can now have a wolf, but it fixes the bug where when you log out the wolf isn't your wolf anymore. --- source/Mobs/Wolf.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index ad8360445..6d1c5565c 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -4,6 +4,7 @@ #include "Wolf.h" #include "../World.h" #include "../Entities/Player.h" +#include "../Root.h" @@ -15,7 +16,7 @@ cWolf::cWolf(void) : m_bIsTame(false), m_bIsSitting(false), m_bIsBegging(false), - m_bOwner(NULL) + m_bOwner("") { } @@ -52,7 +53,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player) { SetMaxHealth(20); SetIsTame(true); - SetOwner(&a_Player); + SetOwner(a_Player.GetName()); m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED); } else @@ -63,7 +64,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player) } else if (IsTame()) { - if (m_bOwner != NULL && a_Player.GetUniqueID() == m_bOwner->GetUniqueID()) // Is the player the owner of the dog? + if (a_Player.GetName() == m_bOwner) // Is the player the owner of the dog? { if (IsSitting()) { @@ -130,22 +131,35 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) } } } + + class cCallback : + public cPlayerListCallback + { + virtual bool Item(cPlayer * Player) override + { + OwnerCoords = Player->GetPosition(); + return false; + } + public: + Vector3f OwnerCoords; + } ; + cCallback Callback; + m_World->FindAndDoWithPlayer(m_bOwner, Callback); + Vector3f OwnerCoords = Callback.OwnerCoords; if (IsTame()) { - if (m_bOwner != NULL) + if (m_bOwner != "") { - Vector3f OwnerCoords = m_bOwner->GetPosition(); double Distance = (OwnerCoords - GetPosition()).Length(); if (Distance < 3) { m_bMovingToDestination = false; } else if((Distance > 30) && (!IsSitting())) { - TeleportToEntity(*m_bOwner); + TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z); } else { m_Destination = OwnerCoords; } } } - } \ No newline at end of file -- cgit v1.2.3 From e62858ec3d027de8c5c4605913ab6261ec19d624 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 10 Nov 2013 20:12:30 +0100 Subject: Using DoWithPlayer instead of FindAndDoWithPlayer for callbacks. You are able to dye the collar. --- source/Mobs/Wolf.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index 6d1c5565c..9880a3442 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -16,7 +16,8 @@ cWolf::cWolf(void) : m_bIsTame(false), m_bIsSitting(false), m_bIsBegging(false), - m_bOwner("") + m_bOwner(""), + m_bCollar(14) { } @@ -66,7 +67,15 @@ void cWolf::OnRightClicked(cPlayer & a_Player) { if (a_Player.GetName() == m_bOwner) // Is the player the owner of the dog? { - if (IsSitting()) + if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) + { + m_bCollar = 15 - a_Player.GetEquippedItem().m_ItemDamage; + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + } + else if (IsSitting()) { SetIsSitting(false); } @@ -144,7 +153,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) Vector3f OwnerCoords; } ; cCallback Callback; - m_World->FindAndDoWithPlayer(m_bOwner, Callback); + m_World->DoWithPlayer(m_bOwner, Callback); Vector3f OwnerCoords = Callback.OwnerCoords; if (IsTame()) -- cgit v1.2.3 From 2ccf9b2b32cbc2b9df7bd89b5dd4077c7bc20b80 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 10 Nov 2013 21:24:36 +0100 Subject: Renamed variables in cWolf. --- source/Mobs/Wolf.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index 9880a3442..ac094e870 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -12,12 +12,12 @@ cWolf::cWolf(void) : super("Wolf", mtWolf, "mob.wolf.hurt", "mob.wolf.death", 0.6, 0.8), - m_bIsAngry(false), - m_bIsTame(false), - m_bIsSitting(false), - m_bIsBegging(false), - m_bOwner(""), - m_bCollar(14) + m_IsAngry(false), + m_IsTame(false), + m_IsSitting(false), + m_IsBegging(false), + m_Owner(""), + m_Collar(14) { } @@ -28,9 +28,9 @@ cWolf::cWolf(void) : void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) { super::DoTakeDamage(a_TDI); - if (!m_bIsTame) + if (!m_IsTame) { - m_bIsAngry = true; + m_IsAngry = true; } m_World->BroadcastEntityMetadata(*this); // Broadcast health and possibly angry face } @@ -65,11 +65,11 @@ void cWolf::OnRightClicked(cPlayer & a_Player) } else if (IsTame()) { - if (a_Player.GetName() == m_bOwner) // Is the player the owner of the dog? + if (a_Player.GetName() == m_Owner) // Is the player the owner of the dog? { if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) { - m_bCollar = 15 - a_Player.GetEquippedItem().m_ItemDamage; + m_Collar = 15 - a_Player.GetEquippedItem().m_ItemDamage; if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); @@ -153,12 +153,12 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) Vector3f OwnerCoords; } ; cCallback Callback; - m_World->DoWithPlayer(m_bOwner, Callback); + m_World->DoWithPlayer(m_Owner, Callback); Vector3f OwnerCoords = Callback.OwnerCoords; if (IsTame()) { - if (m_bOwner != "") + if (m_Owner != "") { double Distance = (OwnerCoords - GetPosition()).Length(); if (Distance < 3) -- cgit v1.2.3 From dadae874f20259e88d20e7ccbb34c8617e69bf40 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 10 Nov 2013 21:55:32 +0100 Subject: Small code-style fixes. --- source/Mobs/Wolf.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index ac094e870..02052e374 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -17,7 +17,7 @@ cWolf::cWolf(void) : m_IsSitting(false), m_IsBegging(false), m_Owner(""), - m_Collar(14) + m_CollarColor(14) { } @@ -41,7 +41,7 @@ void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) void cWolf::OnRightClicked(cPlayer & a_Player) { - if ((!IsTame()) && (!IsAngry())) + if (!IsTame() && !IsAngry()) { if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE) { @@ -69,7 +69,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player) { if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) { - m_Collar = 15 - a_Player.GetEquippedItem().m_ItemDamage; + m_CollarColor = 15 - a_Player.GetEquippedItem().m_ItemDamage; if (!a_Player.IsGameModeCreative()) { a_Player.GetInventory().RemoveOneEquippedItem(); @@ -98,7 +98,9 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) if (!IsAngry()) { cMonster::Tick(a_Dt, a_Chunk); - } else { + } + else + { super::Tick(a_Dt, a_Chunk); } @@ -151,8 +153,7 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) } public: Vector3f OwnerCoords; - } ; - cCallback Callback; + } Callback; m_World->DoWithPlayer(m_Owner, Callback); Vector3f OwnerCoords = Callback.OwnerCoords; @@ -164,11 +165,19 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk) if (Distance < 3) { m_bMovingToDestination = false; - } else if((Distance > 30) && (!IsSitting())) { + } + else if ((Distance > 30) && (!IsSitting())) + { TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z); - } else { + } + else + { m_Destination = OwnerCoords; } } } -} \ No newline at end of file +} + + + + -- cgit v1.2.3 From 165f68b8d92975c0988cf79885f5ee5c967c8e13 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 10 Nov 2013 21:56:37 +0100 Subject: Removed #include "../Root.h" since it isn't needed. --- source/Mobs/Wolf.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'source/Mobs/Wolf.cpp') diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp index 02052e374..b9db53c7f 100644 --- a/source/Mobs/Wolf.cpp +++ b/source/Mobs/Wolf.cpp @@ -4,7 +4,6 @@ #include "Wolf.h" #include "../World.h" #include "../Entities/Player.h" -#include "../Root.h" -- cgit v1.2.3