Generate random movement points in advance.
Fixes https://github.com/vmangos/core/issues/1902
This commit is contained in:
+32
-14
@@ -1848,13 +1848,12 @@ bool WorldObject::GetRandomPoint(float x, float y, float z, float distance, floa
|
||||
rand_z = z;
|
||||
return true;
|
||||
}
|
||||
ASSERT(FindMap());
|
||||
Map const* map = GetMap();
|
||||
|
||||
Map const* pMap = GetMap();
|
||||
Unit const* pUnit = ToUnit();
|
||||
|
||||
bool is_air_ok = isType(TYPEMASK_UNIT) ? ((Unit*)this)->CanFly() : false;
|
||||
|
||||
// 1er cas on peut voler => Position en l'air, facile.
|
||||
if (is_air_ok)
|
||||
// 1st case we can fly => Position in the air, easy.
|
||||
if (pUnit && pUnit->CanFly())
|
||||
{
|
||||
float randAngle1 = rand_norm_f() * 2 * M_PI;
|
||||
float randAngle2 = rand_norm_f() * 2 * M_PI;
|
||||
@@ -1865,25 +1864,44 @@ bool WorldObject::GetRandomPoint(float x, float y, float z, float distance, floa
|
||||
// May happen in the border of the map
|
||||
if (!MaNGOS::IsValidMapCoord(x, y, z) || !MaNGOS::IsValidMapCoord(rand_x, rand_y, rand_z))
|
||||
return false;
|
||||
map->GetLosHitPosition(x, y, z, rand_x, rand_y, rand_z, -0.5f);
|
||||
pMap->GetLosHitPosition(x, y, z, rand_x, rand_y, rand_z, -0.5f);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
// Get swimming position using just vmaps.
|
||||
if (pUnit && pUnit->CanSwim() && pUnit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_USE_SWIM_ANIMATION))
|
||||
{
|
||||
// Sinon, on trouve une position au sol, ou dans l'eau, ou dans la lave (pas pour les joueurs)
|
||||
GridMapLiquidData liquid_status;
|
||||
GridMapLiquidStatus res = pMap->GetTerrain()->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status);
|
||||
if (res & (LIQUID_MAP_UNDER_WATER | LIQUID_MAP_IN_WATER))
|
||||
{
|
||||
rand_x = x;
|
||||
rand_y = y;
|
||||
rand_z = z;
|
||||
if (pMap->GetSwimRandomPosition(rand_x, rand_y, rand_z, distance, liquid_status, true))
|
||||
{
|
||||
pMap->GetLosHitPosition(x, y, z, rand_x, rand_y, rand_z, -0.5f);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Otherwise, we find a position on the ground, or in water, or in lava (not for players)
|
||||
uint32 moveAllowed = NAV_GROUND | NAV_WATER;
|
||||
if (GetTypeId() != TYPEID_PLAYER)
|
||||
moveAllowed |= NAV_MAGMA | NAV_SLIME;
|
||||
rand_x = x;
|
||||
rand_y = y;
|
||||
rand_z = z;
|
||||
if (map->GetWalkRandomPosition(GetTransport(), rand_x, rand_y, rand_z, distance, moveAllowed))
|
||||
if (pMap->GetWalkRandomPosition(GetTransport(), rand_x, rand_y, rand_z, distance, moveAllowed))
|
||||
{
|
||||
// Giant type creatures walk underwater
|
||||
if ((isType(TYPEMASK_UNIT) && !ToUnit()->CanSwim()) ||
|
||||
(IsCreature() && ToCreature()->GetCreatureInfo()->type == CREATURE_TYPE_GIANT))
|
||||
if ((pUnit && !pUnit->CanSwim()) ||
|
||||
(IsCreature() && !pUnit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_USE_SWIM_ANIMATION)))
|
||||
return true;
|
||||
// La position renvoyee par le pathfinding est tout au fond de l'eau. On randomise ca un peu ...
|
||||
|
||||
// The position returned by the pathfinding is at the bottom of the water. We're randomizing it a bit...
|
||||
float ground = 0.0f;
|
||||
float waterSurface = GetTerrain()->GetWaterLevel(x, y, z, &ground);
|
||||
if (waterSurface == VMAP_INVALID_HEIGHT_VALUE)
|
||||
@@ -1893,7 +1911,7 @@ bool WorldObject::GetRandomPoint(float x, float y, float z, float distance, floa
|
||||
rand_z += rand_norm_f() * distance / 2.0f;
|
||||
if (rand_z < ground)
|
||||
rand_z = ground;
|
||||
// Ici 'is_air_ok' = false, donc on reste SOUS l'eau.
|
||||
// Flying case checked before that, so we stay UNDER water.
|
||||
if (rand_z > waterSurface)
|
||||
rand_z = waterSurface;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user