From 359e772dee0ef4595c8ad982f17e13725f255219 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Mon, 11 Jan 2016 21:34:41 +0200 Subject: Tamed wolf assists owner (attack / defence) --- src/Entities/Player.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 80f07cb65..c5a1e0f95 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2,6 +2,8 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Player.h" +#include "Mobs/Wolf.h" +#include "../BoundingBox.h" #include #include "../ChatColor.h" #include "../Server.h" @@ -850,6 +852,7 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) AddFoodExhaustion(0.3f); SendHealth(); + NotifyFriendlyWolves(a_TDI.Attacker); m_Stats.AddValue(statDamageTaken, FloorC(a_TDI.FinalDamage * 10 + 0.5)); return true; } @@ -860,6 +863,42 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) +void cPlayer::NotifyFriendlyWolves(cEntity * a_Opponent) +{ + class LookForWolves : public cEntityCallback + { + public: + cPlayer * m_Player; + cEntity * m_Attacker; + + LookForWolves(cPlayer * a_Me, cEntity * a_MyAttacker) : + m_Player(a_Me), + m_Attacker(a_MyAttacker) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + if (a_Entity->IsMob()) + { + cMonster * Mob = static_cast(a_Entity); + if (Mob->GetMobType() == mtWolf) + { + cWolf * Wolf = static_cast(Mob); + Wolf->NearbyPlayerIsFighting(m_Player, m_Attacker); + } + } + return false; + } + } Callback(this, a_Opponent); + + m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 16, 16), Callback); +} + + + + + void cPlayer::KilledBy(TakeDamageInfo & a_TDI) { super::KilledBy(a_TDI); -- cgit v1.2.3