Merge pull request #5649 from Elron103/pull-requests2

Core/Movement: Fix random position finding near edges, avoid big z-coordinate differences
This commit is contained in:
click
2012-03-30 18:14:58 -07:00
+36 -2
View File
@@ -2692,8 +2692,42 @@ void WorldObject::GetNearPoint(WorldObject const* /*searcher*/, float &x, float
void WorldObject::MovePosition(Position &pos, float dist, float angle)
{
angle += m_orientation;
pos.m_positionX += dist * cos(angle);
pos.m_positionY += dist * sin(angle);
float destx, desty, destz, ground, floor;
destx = pos.m_positionX + dist * cos(angle);
desty = pos.m_positionY + dist * sin(angle);
// Prevent invalid coordinates here, position is unchanged
if (!Trinity::IsValidMapCoord(destx, desty))
{
sLog->outCrash("WorldObject::MovePosition invalid coordinates X: %f and Y: %f were passed!", destx, desty);
return;
}
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
float step = dist/10.0f;
for (uint8 j = 0; j < 10; ++j)
{
// do not allow too big z changes
if (fabs(pos.m_positionZ - destz) > 6)
{
destx -= step * cos(angle);
desty -= step * sin(angle);
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
}
// we have correct destz now
else
{
pos.Relocate(destx, desty, destz);
break;
}
}
Trinity::NormalizeMapCoord(pos.m_positionX);
Trinity::NormalizeMapCoord(pos.m_positionY);
UpdateGroundPositionZ(pos.m_positionX, pos.m_positionY, pos.m_positionZ);