Skip to content

Instantly share code, notes, and snippets.

@VladimirMangos
Last active August 29, 2015 14:12
Show Gist options
  • Save VladimirMangos/e9b4133b06c74d5d1588 to your computer and use it in GitHub Desktop.
Save VladimirMangos/e9b4133b06c74d5d1588 to your computer and use it in GitHub Desktop.
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 24ccb14..0bd9ff3 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1318,8 +1318,11 @@ void WorldObject::UpdateGroundPositionZ(float x, float y, float& z) const
z = new_z + 0.05f; // just to be sure that we are not a few pixel under the surface
}
-void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
+void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z, Map* atMap) const
{
+ if (!atMap)
+ atMap = GetMap();
+
switch (GetTypeId())
{
case TYPEID_UNIT:
@@ -1331,8 +1334,8 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
bool canSwim = ((Creature const*)this)->CanSwim();
float ground_z = z;
float max_z = canSwim
- ? GetTerrain()->GetWaterOrGroundLevel(x, y, z, &ground_z, !((Unit const*)this)->HasAuraType(SPELL_AURA_WATER_WALK))
- : ((ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z)));
+ ? atMap->GetTerrain()->GetWaterOrGroundLevel(x, y, z, &ground_z, !((Unit const*)this)->HasAuraType(SPELL_AURA_WATER_WALK))
+ : ((ground_z = atMap->GetHeight(GetPhaseMask(), x, y, z)));
if (max_z > INVALID_HEIGHT)
{
if (z > max_z)
@@ -1343,7 +1346,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
}
else
{
- float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z);
+ float ground_z = atMap->GetHeight(GetPhaseMask(), x, y, z);
if (z < ground_z)
z = ground_z;
}
@@ -1355,7 +1358,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
if (!((Player const*)this)->CanFly())
{
float ground_z = z;
- float max_z = GetTerrain()->GetWaterOrGroundLevel(x, y, z, &ground_z, !((Unit const*)this)->HasAuraType(SPELL_AURA_WATER_WALK));
+ float max_z = atMap->GetTerrain()->GetWaterOrGroundLevel(x, y, z, &ground_z, !((Unit const*)this)->HasAuraType(SPELL_AURA_WATER_WALK));
if (max_z > INVALID_HEIGHT)
{
if (z > max_z)
@@ -1366,7 +1369,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
}
else
{
- float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z);
+ float ground_z = atMap->GetHeight(GetPhaseMask(), x, y, z);
if (z < ground_z)
z = ground_z;
}
@@ -1374,7 +1377,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
}
default:
{
- float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z);
+ float ground_z = atMap->GetHeight(GetPhaseMask(), x, y, z);
if (ground_z > INVALID_HEIGHT)
z = ground_z;
break;
@@ -1715,7 +1718,7 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y,
if (!sWorld.getConfig(CONFIG_BOOL_DETECT_POS_COLLISION))
{
if (searcher)
- searcher->UpdateAllowedPositionZ(x, y, z); // update to LOS height if available
+ searcher->UpdateAllowedPositionZ(x, y, z, GetMap()); // update to LOS height if available
else
UpdateGroundPositionZ(x, y, z);
return;
@@ -1743,7 +1746,7 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y,
if (selector.CheckOriginalAngle())
{
if (searcher)
- searcher->UpdateAllowedPositionZ(x, y, z); // update to LOS height if available
+ searcher->UpdateAllowedPositionZ(x, y, z, GetMap()); // update to LOS height if available
else
UpdateGroundPositionZ(x, y, z);
@@ -1765,7 +1768,7 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y,
z = GetPositionZ();
if (searcher)
- searcher->UpdateAllowedPositionZ(x, y, z); // update to LOS height if available
+ searcher->UpdateAllowedPositionZ(x, y, z, GetMap()); // update to LOS height if available
else
UpdateGroundPositionZ(x, y, z);
@@ -1781,7 +1784,7 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y,
y = first_y;
if (searcher)
- searcher->UpdateAllowedPositionZ(x, y, z); // update to LOS height if available
+ searcher->UpdateAllowedPositionZ(x, y, z, GetMap()); // update to LOS height if available
else
UpdateGroundPositionZ(x, y, z);
return;
@@ -1797,7 +1800,7 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y,
z = GetPositionZ();
if (searcher)
- searcher->UpdateAllowedPositionZ(x, y, z); // update to LOS height if available
+ searcher->UpdateAllowedPositionZ(x, y, z, GetMap()); // update to LOS height if available
else
UpdateGroundPositionZ(x, y, z);
@@ -1810,7 +1813,7 @@ void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y,
y = first_y;
if (searcher)
- searcher->UpdateAllowedPositionZ(x, y, z); // update to LOS height if available
+ searcher->UpdateAllowedPositionZ(x, y, z, GetMap());// update to LOS height if available
else
UpdateGroundPositionZ(x, y, z);
}
diff --git a/src/game/Object.h b/src/game/Object.h
index 5409ab1..a4f2799 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -496,7 +496,7 @@ class MANGOS_DLL_SPEC WorldObject : public Object
bool IsPositionValid() const;
void UpdateGroundPositionZ(float x, float y, float& z) const;
- void UpdateAllowedPositionZ(float x, float y, float& z) const;
+ void UpdateAllowedPositionZ(float x, float y, float& z, Map* atMap = NULL) const;
void GetRandomPoint(float x, float y, float z, float distance, float& rand_x, float& rand_y, float& rand_z) const;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment