diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-04-19 15:16:17 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-04-19 15:16:17 +0200 |
commit | e1f43900d110e50a2021d605c61cfe7c436bcc54 (patch) | |
tree | 6c79a4d74f8c91eb1e3683f5bdc77d13d30662bf | |
parent | ff9db332f5436fca0a9b14c15951cd8454ecdfb0 (diff) |
Core/Movement: Store delay in WaypointNode as Milliseconds instead of raw integer and revert c5097114d1d08d6d6f7d2adc9f5f3f52f75c5818
6 files changed, 19 insertions, 28 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 19d11c4b957..1754fa6dfd5 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -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() diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h index 0108a7a8c21..85f50f83206 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h @@ -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); diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index 0ae4b44cbc9..c8545090156 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -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) diff --git a/src/server/game/Movement/Waypoints/WaypointDefines.h b/src/server/game/Movement/Waypoints/WaypointDefines.h index ebd31ea3da7..2d897c0eb09 100644 --- a/src/server/game/Movement/Waypoints/WaypointDefines.h +++ b/src/server/game/Movement/Waypoints/WaypointDefines.h @@ -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; }; diff --git a/src/server/game/Movement/Waypoints/WaypointManager.cpp b/src/server/game/Movement/Waypoints/WaypointManager.cpp index dd21721a66c..40106ecb2e4 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.cpp +++ b/src/server/game/Movement/Waypoints/WaypointManager.cpp @@ -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() diff --git a/src/server/scripts/Northrend/VioletHold/violet_hold.cpp b/src/server/scripts/Northrend/VioletHold/violet_hold.cpp index 91b087f1ef6..5111e238054 100644 --- a/src/server/scripts/Northrend/VioletHold/violet_hold.cpp +++ b/src/server/scripts/Northrend/VioletHold/violet_hold.cpp @@ -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)); } |