Core/Objects: restore the original UpdateAllowedPositionZ helper from TC to fix some broken mechanics in terms of disabling gravity

This commit is contained in:
Ovahlord
2019-03-05 22:07:36 +01:00
parent ac3e401c2f
commit 7ccd3f9d8d

View File

@@ -1663,28 +1663,33 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
if (Unit const* unit = ToUnit())
{
// Unit is flying, ignore.
if (unit->IsFlying())
return;
bool canSwim = unit->CanSwim();
float ground_z = z;
float max_z;
if (canSwim)
max_z = GetMapWaterOrGroundLevel(x, y, z, &ground_z);
else
max_z = ground_z = GetMapHeight(x, y, z);
if (max_z > INVALID_HEIGHT)
if (!unit->CanFly())
{
// hovering units cannot go below their hover height
float hoverOffset = unit->GetHoverOffset();
max_z += hoverOffset;
ground_z += hoverOffset;
bool canSwim = unit->CanSwim();
float ground_z = z;
float max_z;
if (canSwim)
max_z = GetMapWaterOrGroundLevel(x, y, z, &ground_z);
else
max_z = ground_z = GetMapHeight(x, y, z);
if (z > max_z && !unit->CanFly())
z = max_z;
else if (z < ground_z)
if (max_z > INVALID_HEIGHT)
{
// hovering units cannot go below their hover height
float hoverOffset = unit->GetHoverOffset();
max_z += hoverOffset;
ground_z += hoverOffset;
if (z > max_z)
z = max_z;
else if (z < ground_z)
z = ground_z;
}
}
else
{
float ground_z = GetMapHeight(x, y, z) + unit->GetHoverOffset();
if (z < ground_z)
z = ground_z;
}
}