From f336f624875ace025669673f5928bf0c5880ecfe Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Thu, 14 May 2009 18:16:03 +0400 Subject: [PATCH] [7826] Avoid use GetDistance* that used slow sqrt call where possible, other related speedups. --- src/bindings/universal/ScriptMgr.h | 2 +- src/game/AggressorAI.cpp | 2 +- src/game/Creature.cpp | 4 +- src/game/CreatureEventAI.cpp | 13 +++--- src/game/GridNotifiers.cpp | 12 +++--- src/game/GridNotifiers.h | 2 +- src/game/Group.cpp | 14 +++--- src/game/GuardAI.cpp | 2 +- src/game/LootHandler.cpp | 2 +- src/game/MiscHandler.cpp | 4 +- src/game/Object.cpp | 83 ++++++++++++++++++++++++++++++------ src/game/Object.h | 21 +++++++-- src/game/PetAI.cpp | 3 +- src/game/Player.cpp | 2 +- src/game/RandomMovementGenerator.cpp | 2 +- src/game/Spell.cpp | 19 ++++----- src/game/Spell.h | 16 ++++--- src/game/TradeHandler.cpp | 28 ++++++------ src/game/Unit.cpp | 14 +++--- src/game/Unit.h | 4 +- src/shared/revision_nr.h | 2 +- 21 files changed, 158 insertions(+), 93 deletions(-) diff --git a/src/bindings/universal/ScriptMgr.h b/src/bindings/universal/ScriptMgr.h index 5cfb164db..daf4b02a2 100644 --- a/src/bindings/universal/ScriptMgr.h +++ b/src/bindings/universal/ScriptMgr.h @@ -89,7 +89,7 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI // Is unit visible for MoveInLineOfSight bool IsVisible(Unit* who) const { - return !who->HasStealthAura() && m_creature->GetDistance(who) <= VISIBLE_RANGE; + return !who->HasStealthAura() && m_creature->IsWithinDist(who,VISIBLE_RANGE); } // Called at World update tick diff --git a/src/game/AggressorAI.cpp b/src/game/AggressorAI.cpp index 50878ee59..c1a544d5d 100644 --- a/src/game/AggressorAI.cpp +++ b/src/game/AggressorAI.cpp @@ -140,7 +140,7 @@ AggressorAI::UpdateAI(const uint32 /*diff*/) bool AggressorAI::IsVisible(Unit *pl) const { - return m_creature->GetDistance(pl) < sWorld.getConfig(CONFIG_SIGHT_MONSTER) + return m_creature->IsWithinDist(pl,sWorld.getConfig(CONFIG_SIGHT_MONSTER)) && pl->isVisibleForOrDetect(m_creature,true); } diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 250af557c..5210ba9a5 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1778,12 +1778,12 @@ bool Creature::IsOutOfThreatArea(Unit* pVictim) const if(sMapStore.LookupEntry(GetMapId())->IsDungeon()) return false; - float length = pVictim->GetDistance(CombatStartX,CombatStartY,CombatStartZ); float AttackDist = GetAttackDistance(pVictim); uint32 ThreatRadius = sWorld.getConfig(CONFIG_THREAT_RADIUS); //Use AttackDistance in distance check if threat radius is lower. This prevents creature bounce in and out of combat every update tick. - return ( length > (ThreatRadius > AttackDist ? ThreatRadius : AttackDist)); + return !pVictim->IsWithinDist(CombatStartX,CombatStartY,CombatStartZ, + ThreatRadius > AttackDist ? ThreatRadius : AttackDist); } CreatureDataAddon const* Creature::GetCreatureAddon() const diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 49d5634d4..10addd297 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -1277,13 +1277,10 @@ void CreatureEventAI::UpdateAI(const uint32 diff) break; case EVENT_T_RANGE: if (Combat) - { - if (m_creature->IsWithinDistInMap(m_creature->getVictim(),(float)(*i).Event.event_param2)) - { - if (m_creature->GetDistance(m_creature->getVictim()) >= (float)(*i).Event.event_param1) + if (m_creature->IsInMap(m_creature->getVictim())) + if (m_creature->IsInRange(m_creature->getVictim(), + (float)(*i).Event.event_param1,(float)(*i).Event.event_param2)) ProcessEvent(*i); - } - } break; } } @@ -1305,7 +1302,7 @@ void CreatureEventAI::UpdateAI(const uint32 diff) bool CreatureEventAI::IsVisible(Unit *pl) const { - return m_creature->GetDistance(pl) < sWorld.getConfig(CONFIG_SIGHT_MONSTER) + return m_creature->IsWithinDist(pl,sWorld.getConfig(CONFIG_SIGHT_MONSTER)) && pl->isVisibleForOrDetect(m_creature,true); } @@ -1584,7 +1581,7 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge return false; //Unit is out of range of this spell - if (m_creature->GetDistance(Target) > TempRange->maxRange || m_creature->GetDistance(Target) < TempRange->minRange) + if (!m_creature->IsInRange(Target,TempRange->minRange,TempRange->minRange)) return false; return true; diff --git a/src/game/GridNotifiers.cpp b/src/game/GridNotifiers.cpp index b1acc2b61..1aefbcb4a 100644 --- a/src/game/GridNotifiers.cpp +++ b/src/game/GridNotifiers.cpp @@ -176,14 +176,14 @@ MessageDistDeliverer::Visit(PlayerMapType &m) { for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) { - if( (i_toSelf || iter->getSource() != &i_player ) && + if ((i_toSelf || iter->getSource() != &i_player ) && (!i_ownTeamOnly || iter->getSource()->GetTeam() == i_player.GetTeam() ) && - (!i_dist || iter->getSource()->GetDistance(&i_player) <= i_dist) ) + (!i_dist || iter->getSource()->IsWithinDist(&i_player,i_dist))) { if (!i_player.InSamePhase(iter->getSource())) continue; - if(WorldSession* session = iter->getSource()->GetSession()) + if (WorldSession* session = iter->getSource()->GetSession()) session->SendPacket(i_message); } } @@ -194,12 +194,12 @@ ObjectMessageDistDeliverer::Visit(PlayerMapType &m) { for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter) { - if( !i_dist || iter->getSource()->GetDistance(&i_object) <= i_dist ) + if (!i_dist || iter->getSource()->IsWithinDist(&i_object,i_dist)) { - if( !i_object.InSamePhase(iter->getSource())) + if (!i_object.InSamePhase(iter->getSource())) continue; - if(WorldSession* session = iter->getSource()->GetSession()) + if (WorldSession* session = iter->getSource()->GetSession()) session->SendPacket(i_message); } } diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index daf393eff..d8798d58b 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -494,7 +494,7 @@ namespace MaNGOS void Visit(PlayerMapType &m) { for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr) - if(itr->getSource()->InSamePhase(i_searcher) && itr->getSource()->GetDistance(i_searcher) <= i_dist) + if (itr->getSource()->InSamePhase(i_searcher) && itr->getSource()->IsWithinDist(i_searcher,i_dist)) i_do(itr->getSource()); } diff --git a/src/game/Group.cpp b/src/game/Group.cpp index b2b495cb8..484e5fde7 100644 --- a/src/game/Group.cpp +++ b/src/game/Group.cpp @@ -567,7 +567,7 @@ void Group::GroupLoot(const uint64& playerGUID, Loot *loot, Creature *creature) continue; if ( i->AllowedForPlayer(member) ) { - if (member->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (member->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) { r->playerVote[member->GetGUID()] = NOT_EMITED_YET; ++r->totalPlayersRolling; @@ -617,7 +617,7 @@ void Group::NeedBeforeGreed(const uint64& playerGUID, Loot *loot, Creature *crea if (playerToRoll->CanUseItem(item) && i->AllowedForPlayer(playerToRoll) ) { - if (playerToRoll->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (playerToRoll->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) { r->playerVote[playerToRoll->GetGUID()] = NOT_EMITED_YET; ++r->totalPlayersRolling; @@ -665,7 +665,7 @@ void Group::MasterLoot(const uint64& playerGUID, Loot* /*loot*/, Creature *creat if (!looter->IsInWorld()) continue; - if (looter->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (looter->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) { data << looter->GetGUID(); ++real_count; @@ -677,7 +677,7 @@ void Group::MasterLoot(const uint64& playerGUID, Loot* /*loot*/, Creature *creat for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next()) { Player *looter = itr->getSource(); - if (looter->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (looter->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) looter->GetSession()->SendPacket(&data); } } @@ -1334,7 +1334,7 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed ) { // not update if only update if need and ok Player* looter = ObjectAccessor::FindPlayer(guid_itr->guid); - if(looter && looter->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if(looter && looter->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) return; } ++guid_itr; @@ -1347,7 +1347,7 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed ) { if(Player* pl = ObjectAccessor::FindPlayer(itr->guid)) { - if (pl->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (pl->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) { bool refresh = pl->GetLootGUID()==creature->GetGUID(); @@ -1368,7 +1368,7 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed ) { if(Player* pl = ObjectAccessor::FindPlayer(itr->guid)) { - if (pl->GetDistance2d(creature) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (pl->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) { bool refresh = pl->GetLootGUID()==creature->GetGUID(); diff --git a/src/game/GuardAI.cpp b/src/game/GuardAI.cpp index 8e0e5ba18..5dcbb5a23 100644 --- a/src/game/GuardAI.cpp +++ b/src/game/GuardAI.cpp @@ -125,7 +125,7 @@ void GuardAI::UpdateAI(const uint32 /*diff*/) bool GuardAI::IsVisible(Unit *pl) const { - return m_creature->GetDistance(pl) < sWorld.getConfig(CONFIG_SIGHT_GUARDER) + return m_creature->IsWithinDist(pl,sWorld.getConfig(CONFIG_SIGHT_GUARDER)) && pl->isVisibleForOrDetect(m_creature,true); } diff --git a/src/game/LootHandler.cpp b/src/game/LootHandler.cpp index 0dc2b5598..cfba29ad3 100644 --- a/src/game/LootHandler.cpp +++ b/src/game/LootHandler.cpp @@ -212,7 +212,7 @@ void WorldSession::HandleLootMoneyOpcode( WorldPacket & /*recv_data*/ ) Player* playerGroup = itr->getSource(); if(!playerGroup) continue; - if (player->GetDistance2d(playerGroup) < sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE)) + if (player->IsWithinDist(playerGroup,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false)) playersNear.push_back(playerGroup); } diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp index 6d2d15d91..2cc1dbde8 100644 --- a/src/game/MiscHandler.cpp +++ b/src/game/MiscHandler.cpp @@ -674,9 +674,7 @@ void WorldSession::HandleCorpseReclaimOpcode(WorldPacket &recv_data) if(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType()==CORPSE_RESURRECTABLE_PVP) > time(NULL)) return; - float dist = corpse->GetDistance2d(GetPlayer()); - sLog.outDebug("Corpse 2D Distance: \t%f",dist); - if (dist > CORPSE_RECLAIM_RADIUS) + if (!corpse->IsWithinDist(GetPlayer(),CORPSE_RECLAIM_RADIUS,false)) return; uint64 guid; diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 15963e84f..10b2ed8a5 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1087,7 +1087,7 @@ float WorldObject::GetDistance2d(float x, float y) const return ( dist > 0 ? dist : 0); } -float WorldObject::GetDistance(const float x, const float y, const float z) const +float WorldObject::GetDistance(float x, float y, float z) const { float dx = GetPositionX() - x; float dy = GetPositionY() - y; @@ -1114,10 +1114,24 @@ float WorldObject::GetDistanceZ(const WorldObject* obj) const return ( dist > 0 ? dist : 0); } -bool WorldObject::IsWithinDistInMap(const WorldObject* obj, const float dist2compare, const bool is3D) const +bool WorldObject::IsWithinDist(float x, float y, float z, float dist2compare, bool is3D) const { - if (!obj || !IsInMap(obj)) return false; + float dx = GetPositionX() - x; + float dy = GetPositionY() - y; + float distsq = dx*dx + dy*dy; + if(is3D) + { + float dz = GetPositionZ() - z; + distsq += dz*dz; + } + float sizefactor = GetObjectSize(); + float maxdist = dist2compare + sizefactor; + + return distsq < maxdist * maxdist; +} +bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const +{ float dx = GetPositionX() - obj->GetPositionX(); float dy = GetPositionY() - obj->GetPositionY(); float distsq = dx*dx + dy*dy; @@ -1140,7 +1154,7 @@ bool WorldObject::IsWithinLOSInMap(const WorldObject* obj) const return(IsWithinLOS(ox, oy, oz )); } -bool WorldObject::IsWithinLOS(const float ox, const float oy, const float oz ) const +bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const { float x,y,z; GetPosition(x,y,z); @@ -1148,6 +1162,54 @@ bool WorldObject::IsWithinLOS(const float ox, const float oy, const float oz ) c return vMapManager->isInLineOfSight(GetMapId(), x, y, z+2.0f, ox, oy, oz+2.0f); } +bool WorldObject::GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2) const +{ + float dx1 = GetPositionX() - obj1->GetPositionX(); + float dy1 = GetPositionY() - obj1->GetPositionY(); + float dz1 = GetPositionZ() - obj1->GetPositionZ(); + float distsq1 = dx1*dx1 + dy1*dy1 + dz1*dz1; + + float dx2 = GetPositionX() - obj2->GetPositionX(); + float dy2 = GetPositionY() - obj2->GetPositionY(); + float dz2 = GetPositionZ() - obj2->GetPositionZ(); + float distsq2 = dx2*dx2 + dy2*dy2 + dz2*dz2; + + return distsq1 < distsq2; +} + +bool WorldObject::IsInRange(WorldObject const* obj, float minRange, float maxRange) const +{ + float dx = GetPositionX() - obj->GetPositionX(); + float dy = GetPositionY() - obj->GetPositionY(); + float dz = GetPositionZ() - obj->GetPositionZ(); + float distsq = dx*dx + dy*dy + dz*dz; + + float sizefactor = GetObjectSize() + obj->GetObjectSize(); + + float mindist = minRange + sizefactor; + if(distsq < mindist * mindist) + return false; + + float maxdist = maxRange + sizefactor; + return distsq < maxdist * maxdist; +} + +bool WorldObject::IsInRange2d(float x, float y, float minRange, float maxRange) const +{ + float dx = GetPositionX() - x; + float dy = GetPositionY() - y; + float distsq = dx*dx + dy*dy; + + float sizefactor = GetObjectSize(); + + float mindist = minRange + sizefactor; + if(distsq < mindist * mindist) + return false; + + float maxdist = maxRange + sizefactor; + return distsq < maxdist * maxdist; +} + float WorldObject::GetAngle(const WorldObject* obj) const { if(!obj) return 0; @@ -1543,15 +1605,8 @@ namespace MaNGOS // we must add used pos that can fill places around center void add(WorldObject* u, float x, float y) const { - // dist include size of u - float dist2d = i_object.GetDistance2d(x,y); - - // u is too nearest to i_object - if(dist2d + i_object.GetObjectSize() + u->GetObjectSize() < i_selector.m_dist - i_selector.m_size) - return; - - // u is too far away from i_object - if(dist2d + i_object.GetObjectSize() - u->GetObjectSize() > i_selector.m_dist + i_selector.m_size) + // u is too nearest/far away to i_object + if(!i_object.IsInRange2d(x,y,i_selector.m_dist - i_selector.m_size,i_selector.m_dist + i_selector.m_size)) return; float angle = i_object.GetAngle(u)-i_angle; @@ -1562,6 +1617,8 @@ namespace MaNGOS while(angle < -M_PI) angle += 2.0f * M_PI; + // dist include size of u + float dist2d = i_object.GetDistance2d(x,y); i_selector.AddUsedPos(u->GetObjectSize(),angle,dist2d + i_object.GetObjectSize()); } private: diff --git a/src/game/Object.h b/src/game/Object.h index fc01e3a42..42ffdee2d 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -424,18 +424,31 @@ class MANGOS_DLL_SPEC WorldObject : public Object virtual const char* GetNameForLocaleIdx(int32 /*locale_idx*/) const { return GetName(); } float GetDistance( const WorldObject* obj ) const; - float GetDistance(const float x, const float y, const float z) const; + float GetDistance(float x, float y, float z) const; float GetDistance2d(const WorldObject* obj) const; - float GetDistance2d(const float x, const float y) const; + float GetDistance2d(float x, float y) const; float GetDistanceZ(const WorldObject* obj) const; bool IsInMap(const WorldObject* obj) const { return IsInWorld() && obj->IsInWorld() && GetMapId()==obj->GetMapId() && GetInstanceId()==obj->GetInstanceId() && InSamePhase(obj); } - bool IsWithinDistInMap(const WorldObject* obj, const float dist2compare, const bool is3D = true) const; - bool IsWithinLOS(const float x, const float y, const float z ) const; + bool IsWithinDist(float x, float y, float z, float dist2compare, bool is3D = true) const; + bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const; + bool IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D = true) const + // use only if you will sure about placing both object at same map + { + return obj && _IsWithinDist(obj,dist2compare,is3D); + } + bool IsWithinDistInMap(WorldObject const* obj, float dist2compare, bool is3D = true) const + { + return obj && IsInMap(obj) && _IsWithinDist(obj,dist2compare,is3D); + } + bool IsWithinLOS(float x, float y, float z) const; bool IsWithinLOSInMap(const WorldObject* obj) const; + bool GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2) const; + bool IsInRange(WorldObject const* obj, float minRange, float maxRange) const; + bool IsInRange2d(float x, float y, float minRange, float maxRange) const; float GetAngle( const WorldObject* obj ) const; float GetAngle( const float x, const float y ) const; diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index 3fc412c6f..8de2644f3 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -288,8 +288,7 @@ void PetAI::UpdateAI(const uint32 diff) bool PetAI::_isVisible(Unit *u) const { - //return false; //( ((Creature*)&i_pet)->GetDistanceSq(u) * 1.0<= sWorld.getConfig(CONFIG_SIGHT_GUARDER) && !u->m_stealth && u->isAlive()); - return m_creature->GetDistance(u) < sWorld.getConfig(CONFIG_SIGHT_GUARDER) + return m_creature->IsWithinDist(u,sWorld.getConfig(CONFIG_SIGHT_GUARDER)) && u->isVisibleForOrDetect(m_creature,true); } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index fd19a2412..35b2cb0e5 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -1616,7 +1616,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati if (!(options & TELE_TO_NOT_UNSUMMON_PET)) { //same map, only remove pet if out of range for new position - if(pet && pet->GetDistance(x,y,z) >= OWNER_MAX_DISTANCE) + if(pet && !pet->IsWithinDist(x,y,z, OWNER_MAX_DISTANCE)) UnsummonPetTemporaryIfAny(); } diff --git a/src/game/RandomMovementGenerator.cpp b/src/game/RandomMovementGenerator.cpp index d1d77eea2..de9d76fe8 100644 --- a/src/game/RandomMovementGenerator.cpp +++ b/src/game/RandomMovementGenerator.cpp @@ -153,7 +153,7 @@ RandomMovementGenerator::Update(Creature &creature, const uint32 &diff creature.SetUnitMovementFlags(irand(0,RUNNING_CHANCE_RANDOMMV) > 0 ? MOVEMENTFLAG_WALK_MODE : MOVEMENTFLAG_NONE); _setRandomLocation(creature); } - else if(creature.isPet() && creature.GetOwner() && creature.GetDistance(creature.GetOwner()) > PET_FOLLOW_DIST+2.5f) + else if(creature.isPet() && creature.GetOwner() && !creature.IsWithinDist(creature.GetOwner(),PET_FOLLOW_DIST+2.5f)) { creature.SetUnitMovementFlags(MOVEMENTFLAG_NONE); _setRandomLocation(creature); diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 02ec11a91..82147467c 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -1334,7 +1334,7 @@ struct TargetDistanceOrder : public std::binary_function" bool operator()(const Unit* _Left, const Unit* _Right) const { - return (MainTarget->GetDistance(_Left) < MainTarget->GetDistance(_Right)); + return MainTarget->GetDistanceOrder(_Left,_Right); } }; @@ -1427,7 +1427,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) //Now to get us a random target that's in the initial range of the spell uint32 t = 0; std::list::iterator itr = tempUnitMap.begin(); - while(itr!= tempUnitMap.end() && (*itr)->GetDistance(m_caster) < radius) + while(itr!= tempUnitMap.end() && (*itr)->IsWithinDist(m_caster,radius)) ++t, ++itr; if(!t) @@ -1448,7 +1448,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) while(t && next != tempUnitMap.end() ) { - if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) + if(!prev->IsWithinDist(*next,CHAIN_SPELL_JUMP_RADIUS)) break; if(!prev->IsWithinLOSInMap(*next)) @@ -1496,7 +1496,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) //Now to get us a random target that's in the initial range of the spell uint32 t = 0; std::list::iterator itr = tempUnitMap.begin(); - while(itr!= tempUnitMap.end() && (*itr)->GetDistance(m_caster) < radius) + while(itr!= tempUnitMap.end() && (*itr)->IsWithinDist(m_caster,radius)) ++t, ++itr; if(!t) @@ -1517,7 +1517,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) while(t && next != tempUnitMap.end() ) { - if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) + if(!prev->IsWithinDist(*next,CHAIN_SPELL_JUMP_RADIUS)) break; if(!prev->IsWithinLOSInMap(*next)) @@ -1602,7 +1602,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) while(t && next != tempUnitMap.end() ) { - if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) + if(!prev->IsWithinDist(*next,CHAIN_SPELL_JUMP_RADIUS)) break; if(!prev->IsWithinLOSInMap(*next)) @@ -2029,7 +2029,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,UnitList& TagUnitMap) while(t && next != tempUnitMap.end() ) { - if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) + if(!prev->IsWithinDist(*next,CHAIN_SPELL_JUMP_RADIUS)) break; if(!prev->IsWithinLOSInMap(*next)) @@ -4689,10 +4689,9 @@ SpellCastResult Spell::CheckRange(bool strict) if(m_targets.m_targetMask == TARGET_FLAG_DEST_LOCATION && m_targets.m_destX != 0 && m_targets.m_destY != 0 && m_targets.m_destZ != 0) { - float dist = m_caster->GetDistance(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ); - if(dist > max_range) + if(!m_caster->IsWithinDist(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ,max_range)) return SPELL_FAILED_OUT_OF_RANGE; - if(dist < min_range) + if(m_caster->IsWithinDist(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ,min_range)) return SPELL_FAILED_TOO_CLOSE; } diff --git a/src/game/Spell.h b/src/game/Spell.h index ac2544b59..402c3c2ff 100644 --- a/src/game/Spell.h +++ b/src/game/Spell.h @@ -621,7 +621,7 @@ namespace MaNGOS if( i_originalCaster->IsFriendlyTo(pPlayer) ) continue; - if( pPlayer->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius ) + if( pPlayer->IsWithinDist(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius)) i_data.push_back(pPlayer); } } @@ -656,6 +656,10 @@ namespace MaNGOS if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight())) continue; + // mostly phase check + if(!itr->getSource()->IsInMap(i_originalCaster)) + continue; + switch (i_TargetType) { case SPELL_TARGETS_HOSTILE: @@ -701,23 +705,23 @@ namespace MaNGOS switch(i_push_type) { case PUSH_IN_FRONT: - if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 )) + if(i_spell.GetCaster()->isInFrontInMap((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 )) i_data->push_back(itr->getSource()); break; case PUSH_IN_BACK: - if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 )) + if(i_spell.GetCaster()->isInBackInMap((Unit*)(itr->getSource()), i_radius, 2*M_PI/3 )) i_data->push_back(itr->getSource()); break; case PUSH_SELF_CENTER: - if(i_spell.GetCaster()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius)) + if(i_spell.GetCaster()->IsWithinDist((Unit*)(itr->getSource()), i_radius)) i_data->push_back(itr->getSource()); break; case PUSH_DEST_CENTER: - if((itr->getSource()->GetDistance(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ) < i_radius )) + if(itr->getSource()->IsWithinDist(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius)) i_data->push_back(itr->getSource()); break; case PUSH_TARGET_CENTER: - if(i_spell.m_targets.getUnitTarget()->IsWithinDistInMap((Unit*)(itr->getSource()), i_radius)) + if(i_spell.m_targets.getUnitTarget()->IsWithinDist((Unit*)(itr->getSource()), i_radius)) i_data->push_back(itr->getSource()); break; } diff --git a/src/game/TradeHandler.cpp b/src/game/TradeHandler.cpp index aa323c974..64408c6b5 100644 --- a/src/game/TradeHandler.cpp +++ b/src/game/TradeHandler.cpp @@ -459,30 +459,30 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket) { CHECK_PACKET_SIZE(recvPacket,8); - if( GetPlayer()->pTrader ) + if (GetPlayer()->pTrader) return; uint64 ID; - if( !GetPlayer()->isAlive() ) + if (!GetPlayer()->isAlive()) { SendTradeStatus(TRADE_STATUS_YOU_DEAD); return; } - if( GetPlayer()->hasUnitState(UNIT_STAT_STUNNED) ) + if (GetPlayer()->hasUnitState(UNIT_STAT_STUNNED)) { SendTradeStatus(TRADE_STATUS_YOU_STUNNED); return; } - if( isLogingOut() ) + if (isLogingOut()) { SendTradeStatus(TRADE_STATUS_YOU_LOGOUT); return; } - if( GetPlayer()->isInFlight() ) + if (GetPlayer()->isInFlight()) { SendTradeStatus(TRADE_STATUS_TARGET_TO_FAR); return; @@ -492,55 +492,55 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket) Player* pOther = ObjectAccessor::FindPlayer( ID ); - if( !pOther ) + if (!pOther) { SendTradeStatus(TRADE_STATUS_NO_TARGET); return; } - if( pOther == GetPlayer() || pOther->pTrader ) + if (pOther == GetPlayer() || pOther->pTrader) { SendTradeStatus(TRADE_STATUS_BUSY); return; } - if( !pOther->isAlive() ) + if (!pOther->isAlive()) { SendTradeStatus(TRADE_STATUS_TARGET_DEAD); return; } - if( pOther->isInFlight() ) + if (pOther->isInFlight()) { SendTradeStatus(TRADE_STATUS_TARGET_TO_FAR); return; } - if( pOther->hasUnitState(UNIT_STAT_STUNNED) ) + if (pOther->hasUnitState(UNIT_STAT_STUNNED)) { SendTradeStatus(TRADE_STATUS_TARGET_STUNNED); return; } - if( pOther->GetSession()->isLogingOut() ) + if (pOther->GetSession()->isLogingOut()) { SendTradeStatus(TRADE_STATUS_TARGET_LOGOUT); return; } - if( pOther->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow()) ) + if (pOther->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow())) { SendTradeStatus(TRADE_STATUS_IGNORE_YOU); return; } - if(pOther->GetTeam() !=_player->GetTeam() ) + if (pOther->GetTeam() !=_player->GetTeam() ) { SendTradeStatus(TRADE_STATUS_WRONG_FACTION); return; } - if( pOther->GetDistance2d( _player ) > 10.0f ) + if (!pOther->IsWithinDistInMap(_player,10.0f,false)) { SendTradeStatus(TRADE_STATUS_TARGET_TO_FAR); return; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 5ea368169..474b6009e 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -3200,7 +3200,7 @@ Spell* Unit::FindCurrentSpellBySpellId(uint32 spell_id) const return NULL; } -bool Unit::isInFront(Unit const* target, float distance, float arc) const +bool Unit::isInFrontInMap(Unit const* target, float distance, float arc) const { return IsWithinDistInMap(target, distance) && HasInArc( arc, target ); } @@ -3210,7 +3210,7 @@ void Unit::SetInFront(Unit const* target) SetOrientation(GetAngle(target)); } -bool Unit::isInBack(Unit const* target, float distance, float arc) const +bool Unit::isInBackInMap(Unit const* target, float distance, float arc) const { return IsWithinDistInMap(target, distance) && !HasInArc( 2 * M_PI - arc, target ); } @@ -9070,9 +9070,7 @@ bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList, return true; // If there is collision rogue is seen regardless of level difference - // TODO: check sizes in DB - float distance = GetDistance(u); - if (distance < 0.24f) + if (IsWithinDist(u,0.24f)) return true; //If a mob or player is stunned he will not be able to detect stealth @@ -9083,14 +9081,14 @@ bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList, if(u->GetTypeId() != TYPEID_PLAYER) { //Always invisible from back and out of aggro range - bool isInFront = u->isInFront(this,((Creature const*)u)->GetAttackDistance(this)); + bool isInFront = u->isInFrontInMap(this,((Creature const*)u)->GetAttackDistance(this)); if(!isInFront) return false; } else { //Always invisible from back - bool isInFront = u->isInFront(this,(GetTypeId()==TYPEID_PLAYER || GetCharmerOrOwnerGUID()) ? World::GetMaxVisibleDistanceForPlayer() : World::GetMaxVisibleDistanceForCreature()); + bool isInFront = u->isInFrontInMap(this,(GetTypeId()==TYPEID_PLAYER || GetCharmerOrOwnerGUID()) ? World::GetMaxVisibleDistanceForPlayer() : World::GetMaxVisibleDistanceForCreature()); if(!isInFront) return false; } @@ -9116,7 +9114,7 @@ bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList, //based on wowwiki every 5 mod we have 1 more level diff in calculation visibleDistance += (int32(u->GetTotalAuraModifier(SPELL_AURA_MOD_DETECT)) - stealthMod)/5.0f; - if(distance > visibleDistance) + if(!IsWithinDist(u,visibleDistance)) return false; } diff --git a/src/game/Unit.h b/src/game/Unit.h index 9ea6ca3e6..35ceb2fed 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1240,9 +1240,9 @@ class MANGOS_DLL_SPEC Unit : public WorldObject float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const; void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; } - bool isInFront(Unit const* target,float distance, float arc = M_PI) const; + bool isInFrontInMap(Unit const* target,float distance, float arc = M_PI) const; void SetInFront(Unit const* target); - bool isInBack(Unit const* target, float distance, float arc = M_PI) const; + bool isInBackInMap(Unit const* target, float distance, float arc = M_PI) const; // Visibility system UnitVisibility GetVisibility() const { return m_Visibility; } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 45b5a3244..e6f9a434b 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7825" + #define REVISION_NR "7826" #endif // __REVISION_NR_H__ -- 2.11.4.GIT