Core/Movement: fixed up logic in previously added random movement minumum wander distance check and prevent the random movement generator from launching too short splines

This commit is contained in:
Ovahlord committed 2023-08-19 14:51:31 +02:00
1 parent e9fecb39d8
commit dfa6f7a709
2 files changed
+16 -5

No files matched your search

+8 -3
View File
@@ -2176,16 +2176,21 @@ void ObjectMgr::LoadCreatures()
data.movementType = IDLE_MOTION_TYPE; data.movementType = IDLE_MOTION_TYPE;
} }
if (data.wanderDistance < 0.1f) if (data.wanderDistance < 0.0f)
{
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `wander_distance`< 0.0, set to 0.", guid, data.id);
data.wanderDistance = 0.0f;
}
else if (data.wanderDistance > 0.0f && data.wanderDistance < 0.1f)
{ {
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `wander_distance`< 0.1, set to 0.", guid, data.id); TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `wander_distance`< 0.1, set to 0.", guid, data.id);
data.wanderDistance = 0.0f; data.wanderDistance = 0.0f;
} }
else if (data.movementType == RANDOM_MOTION_TYPE) else if (data.movementType == RANDOM_MOTION_TYPE)
{ {
if (G3D::fuzzyEq(data.wanderDistance, 0.1f)) if (G3D::fuzzyEq(data.wanderDistance, 0.0f))
{ {
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `MovementType`= 1 (random movement) but with `wander_distance`= 0.1, replace by idle movement type (0).", guid, data.id); TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `MovementType`= 1 (random movement) but with `wander_distance`= 0, replace by idle movement type (0).", guid, data.id);
data.movementType = IDLE_MOTION_TYPE; data.movementType = IDLE_MOTION_TYPE;
} }
} }
@@ -113,9 +113,15 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
owner->AddUnitState(UNIT_STATE_ROAMING_MOVE); owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Position position(_reference); Position position(_reference);
float distance = frand(0.1f, _wanderDistance); float distance = _wanderDistance > 0.1f ? frand(0.1f, _wanderDistance) : _wanderDistance;
float angle = frand(0.f, float(M_PI * 2)); float angle = frand(0.f, static_cast<float>(M_PI * 2));
owner->MovePositionToFirstCollision(position, distance, angle); owner->MovePositionToFirstCollision(position, distance, angle);
if (owner->GetPosition().GetExactDist(position) < 0.1f)
{
// the path is too short for the spline system to be accepted. Let's try again soon.
_timer.Reset(500);
return;
}
if (!_path) if (!_path)
_path = new PathGenerator(owner); _path = new PathGenerator(owner);