Skip to content

Commit

Permalink
Core/GameObject: Fix interaction distance with GameObjects in all cor…
Browse files Browse the repository at this point in the history
…ner cases by overriding Object:_IsWithinDist. Distance calculation to GO's need to take in account GameObjectDisplayInfoDBC entries, otherwise distance would not be calculated from the edges properly and ie. quest interaction with large gameobjects would fail.
  • Loading branch information
Machiavell1 committed Aug 15, 2011
1 parent 69b7115 commit b560090
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/server/game/Entities/GameObject/GameObject.h
Expand Up @@ -816,6 +816,13 @@ class GameObject : public WorldObject, public GridObject<GameObject>
uint16 m_LootMode; // bitmask, default LOOT_MODE_DEFAULT, determines what loot will be lootable
private:
void SwitchDoorOrButton(bool activate, bool alternative = false);

//! Object distance/size - overridden from Object::_IsWithinDist. Needs to take in account proper GO size.
bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool /*is3D*/) const
{
//! Following check does check 3d distance
return IsInRange(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), dist2compare);
}
GameObjectAI* m_AI;
};
#endif
2 changes: 1 addition & 1 deletion src/server/game/Entities/Object/Object.h
Expand Up @@ -699,7 +699,7 @@ class WorldObject : public Object, public WorldLocation
{ return IsInDist2d(x, y, dist + GetObjectSize()); }
bool IsWithinDist2d(const Position *pos, float dist) const
{ return IsInDist2d(pos, dist + GetObjectSize()); }
bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const;
virtual bool _IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D) const;
// use only if you will sure about placing both object at same map
bool IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D = true) const
{
Expand Down

3 comments on commit b560090

@Warpten
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix the always seen hunter traps ?

@tobmaps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it shouldn't

@megamage
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a good idea. _IsWithinDist may be called frequently and virtual function is not efficient. Why not replace _IsWithinDist with IsInRange when object size needs to be considered, or override GameObject::_IsWithinDist without using virtual function (if WorldObject::_IsWithinDist is called you can use template or cast to apply GameObject::_IsWithinDist)?

Please sign in to comment.