11-16-2013, 07:53 AM
Don't wolves attack *all* players when they are aggravated? So just flipping their "IsAngry" flag should be enough.
I expect a code like this should work (written from the top of my head, may not compile):
I expect a code like this should work (written from the top of my head, may not compile):
function cWolf::DoTakeDamage(TakeDamageInfo & a_TDI) { super:DoTakeDamage(a_TDI); if (m_IsTame) { // No aggravating for tame wolves return; } if (a_TDI.DamageType != dtAttack) { // Not attacked by a player, bail out // TODO: projectiles use dtRangedAttack with a projectile entity in the Attacker field, handle that too return; } ASSERT(a_TDI.Attacker != NULL); class cCallback : public cEntityCallback { public: Vector3f m_AttackerPos; cCallback(const Vector3f & a_AttackerPos) : m_AttackerPos(a_AttackerPos) {} virtual bool OnEntity(cEntity & a_Entity) override { // AGGRAVATE_RANGE is the range in blocks in which the wolves become angry; define that constant at the top of Wolf.cpp as static const double if (a_Entity.IsMob() && (((cMonster &)a_Entity).GetMobType() == mtWolf) && ((a_Entity.GetPos() - m_AttackerPos).SqrLength() < AGGRAVATE_RANGE * AGGRAVATE_RANGE)) { ((cWolf &)a_Entity).SetAngry(true); } return false; } } Callback(a_TDI.Attacker.GetPos()); m_World->ForEachEntity(Callback); }