Core/Movement: Store delay in WaypointNode as Milliseconds instead of raw integer and revert c5097114d1

This commit is contained in:
Shauren
2024-04-19 15:16:17 +02:00
parent ff9db332f5
commit e1f43900d1
6 changed files with 19 additions and 28 deletions

View File

@@ -253,17 +253,16 @@ void EscortAI::UpdateEscortAI(uint32 /*diff*/)
void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, bool run)
{
AddWaypoint(id, x, y, z, 0.0f, 0s, run);
AddWaypoint(id, x, y, z, 0.0f, {}, run);
}
void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientation/* = 0*/, Milliseconds waitTime/* = 0s*/, bool run /*= false*/)
void EscortAI::AddWaypoint(uint32 id, float x, float y, float z, float orientation/* = 0*/, Optional<Milliseconds> waitTime/* = {}*/, bool run /*= false*/)
{
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
WaypointNode waypoint(id, x, y, z, orientation, waitTime.count());
WaypointNode& waypoint = _path.Nodes.emplace_back(id, x, y, z, orientation, waitTime);
waypoint.MoveType = run ? WaypointMoveType::Run : WaypointMoveType::Walk;
_path.Nodes.push_back(std::move(waypoint));
}
void EscortAI::ResetPath()

View File

@@ -49,7 +49,7 @@ struct TC_GAME_API EscortAI : public ScriptedAI
virtual void UpdateEscortAI(uint32 diff); // used when it's needed to add code in update (abilities, scripted events, etc)
void AddWaypoint(uint32 id, float x, float y, float z, bool run);
void AddWaypoint(uint32 id, float x, float y, float z, float orientation = 0.f, Milliseconds waitTime = 0s, bool run = false);
void AddWaypoint(uint32 id, float x, float y, float z, float orientation = 0.f, Optional<Milliseconds> waitTime = {}, bool run = false);
void ResetPath();
void LoadPath(uint32 pathId);
void Start(bool isActiveAttacker = true, ObjectGuid playerGUID = ObjectGuid::Empty, Quest const* quest = nullptr, bool instantRespawn = false, bool canLoopPath = false);

View File

@@ -293,22 +293,10 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* owner)
ASSERT(_currentNode < path->Nodes.size(), "WaypointMovementGenerator::OnArrived: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, path->Id);
WaypointNode const& waypoint = path->Nodes[_currentNode];
Milliseconds delay = [&]
{
if (!_isReturningToStart)
return Milliseconds(waypoint.Delay);
// when traversing the path backwards, use delays from "next" waypoint to make sure pauses happen between the same points as in forward direction
if (_currentNode > 0)
return Milliseconds(path->Nodes[_currentNode - 1].Delay);
return 0ms;
}();
if (delay > 0ms)
if (waypoint.Delay)
{
owner->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
_nextMoveTime.Reset(delay);
_nextMoveTime.Reset(*waypoint.Delay);
}
if (_waitTimeRangeAtPathEnd && IsFollowingPathBackwardsFromEndToStart()
@@ -414,7 +402,7 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun
init.MoveTo(waypoint.X, waypoint.Y, waypoint.Z, _generatePath);
if (waypoint.Orientation.has_value() && (waypoint.Delay > 0 || _currentNode == path->Nodes.size() - 1))
if (waypoint.Orientation.has_value() && (waypoint.Delay || _currentNode == path->Nodes.size() - 1))
init.SetFacing(*waypoint.Orientation);
switch (path->MoveType)

View File

@@ -19,11 +19,12 @@
#define TRINITY_WAYPOINTDEFINES_H
#include "Define.h"
#include "Duration.h"
#include "EnumFlag.h"
#include "Optional.h"
#include <vector>
#define WAYPOINT_PATH_FLAG_FOLLOW_PATH_BACKWARDS_MINIMUM_NODES 2
static inline constexpr std::size_t WAYPOINT_PATH_FLAG_FOLLOW_PATH_BACKWARDS_MINIMUM_NODES = 2;
enum class WaypointMoveType : uint8
{
@@ -45,8 +46,8 @@ DEFINE_ENUM_FLAG(WaypointPathFlags);
struct WaypointNode
{
WaypointNode() : Id(0), X(0.f), Y(0.f), Z(0.f), Delay(0), MoveType(WaypointMoveType::Walk) { }
WaypointNode(uint32 id, float x, float y, float z, Optional<float> orientation = { }, uint32 delay = 0)
WaypointNode() : Id(0), X(0.f), Y(0.f), Z(0.f), MoveType(WaypointMoveType::Walk) { }
WaypointNode(uint32 id, float x, float y, float z, Optional<float> orientation = { }, Optional<Milliseconds> delay = {})
{
Id = id;
X = x;
@@ -62,7 +63,7 @@ struct WaypointNode
float Y;
float Z;
Optional<float> Orientation;
uint32 Delay;
Optional<Milliseconds> Delay;
WaypointMoveType MoveType;
};

View File

@@ -80,7 +80,6 @@ void WaypointMgr::_LoadPathNodes()
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded {} waypoint path nodes in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
DoPostLoadingChecks();
}
void WaypointMgr::LoadPathFromDB(Field* fields)
@@ -89,7 +88,7 @@ void WaypointMgr::LoadPathFromDB(Field* fields)
WaypointPath& path = _pathStore[pathId];
path.MoveType = WaypointMoveType(fields[1].GetUInt8());;
path.MoveType = WaypointMoveType(fields[1].GetUInt8());
if (path.MoveType >= WaypointMoveType::Max)
{
TC_LOG_ERROR("sql.sql", "PathId {} in `waypoint_path` has invalid MoveType {}, ignoring", pathId, AsUnderlyingType(path.MoveType));
@@ -128,10 +127,14 @@ void WaypointMgr::LoadPathNodesFromDB(Field* fields)
if (!fields[5].IsNull())
o = fields[5].GetFloat();
Optional<Milliseconds> delay;
if (uint32 delayMs = fields[6].GetUInt32())
delay.emplace(delayMs);
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
path->Nodes.emplace_back(fields[1].GetUInt32(), x, y, z, o, fields[6].GetUInt32());
path->Nodes.emplace_back(fields[1].GetUInt32(), x, y, z, o, delay);
}
void WaypointMgr::DoPostLoadingChecks()

View File

@@ -878,7 +878,7 @@ struct violet_hold_trashAI : public EscortAI
if (path)
{
for (uint32 i = 0; i <= _lastWaypointId; i++)
AddWaypoint(i, path[i].GetPositionX() + irand(-1, 1), path[i].GetPositionY() + irand(-1, 1), path[i].GetPositionZ(), 0, 0s, true);
AddWaypoint(i, path[i].GetPositionX() + irand(-1, 1), path[i].GetPositionY() + irand(-1, 1), path[i].GetPositionZ(), 0, {}, true);
me->SetHomePosition(path[_lastWaypointId].GetPositionX(), path[_lastWaypointId].GetPositionY(), path[_lastWaypointId].GetPositionZ(), float(M_PI));
}