diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-04-19 00:27:18 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-04-19 00:27:18 +0200 |
commit | ff9db332f5436fca0a9b14c15951cd8454ecdfb0 (patch) | |
tree | 81d94f6cc40487fa2ee891d824c265c7fb268b6c | |
parent | c5097114d1d08d6d6f7d2adc9f5f3f52f75c5818 (diff) |
Core/Movement: Minor cleanup in WaypointMovementGenerator - local variable for GetPath() (not a true trivial accessor)
-rw-r--r-- | src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index f41683bc3d4..0ae4b44cbc9 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -104,11 +104,12 @@ void WaypointMovementGenerator<Creature>::Resume(uint32 overrideTimer) bool WaypointMovementGenerator<Creature>::GetResetPosition(Unit* /*owner*/, float& x, float& y, float& z) { // prevent a crash at empty waypoint path. - if (!GetPath() || GetPath()->Nodes.empty()) + WaypointPath const* path = GetPath(); + if (!path || path->Nodes.empty()) return false; - ASSERT(_currentNode < GetPath()->Nodes.size(), "WaypointMovementGenerator::GetResetPosition: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id); - WaypointNode const& waypoint = GetPath()->Nodes[_currentNode]; + ASSERT(_currentNode < path->Nodes.size(), "WaypointMovementGenerator::GetResetPosition: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, path->Id); + WaypointNode const& waypoint = path->Nodes[_currentNode]; x = waypoint.X; y = waypoint.Y; @@ -128,13 +129,14 @@ void WaypointMovementGenerator<Creature>::DoInitialize(Creature* owner) _path = sWaypointMgr->GetPath(_pathId); } - if (!GetPath()) + WaypointPath const* path = GetPath(); + if (!path) { - TC_LOG_ERROR("sql.sql", "WaypointMovementGenerator::DoInitialize: couldn't load path for creature ({}) (_pathId: {})", owner->GetGUID().ToString(), _pathId); + TC_LOG_ERROR("sql.sql", "WaypointMovementGenerator::DoInitialize: couldn't load path for creature ({}) (_pathId: {})", owner->GetGUID(), _pathId); return; } - if (GetPath()->Nodes.size() == 1) + if (path->Nodes.size() == 1) _repeating = false; owner->StopMoving(); @@ -157,7 +159,11 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* owner, uint32 diff) if (!owner || !owner->IsAlive()) return true; - if (HasFlag(MOVEMENTGENERATOR_FLAG_FINALIZED | MOVEMENTGENERATOR_FLAG_PAUSED) || !GetPath() || GetPath()->Nodes.empty()) + if (HasFlag(MOVEMENTGENERATOR_FLAG_FINALIZED | MOVEMENTGENERATOR_FLAG_PAUSED)) + return true; + + WaypointPath const* path = GetPath(); + if (!path || path->Nodes.empty()) return true; if (_duration) @@ -269,21 +275,23 @@ void WaypointMovementGenerator<Creature>::DoFinalize(Creature* owner, bool activ void WaypointMovementGenerator<Creature>::MovementInform(Creature const* owner) const { - WaypointNode const& waypoint = GetPath()->Nodes[_currentNode]; + WaypointPath const* path = GetPath(); + WaypointNode const& waypoint = path->Nodes[_currentNode]; if (CreatureAI* AI = owner->AI()) { AI->MovementInform(WAYPOINT_MOTION_TYPE, waypoint.Id); - AI->WaypointReached(waypoint.Id, GetPath()->Id); + AI->WaypointReached(waypoint.Id, path->Id); } } void WaypointMovementGenerator<Creature>::OnArrived(Creature* owner) { - if (!GetPath() || GetPath()->Nodes.empty()) + WaypointPath const* path = GetPath(); + if (!path || path->Nodes.empty()) return; - ASSERT(_currentNode < GetPath()->Nodes.size(), "WaypointMovementGenerator::OnArrived: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id); - WaypointNode const& waypoint = GetPath()->Nodes[_currentNode]; + 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 = [&] { @@ -292,7 +300,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* owner) // 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(GetPath()->Nodes[_currentNode - 1].Delay); + return Milliseconds(path->Nodes[_currentNode - 1].Delay); return 0ms; }(); @@ -304,7 +312,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* owner) } if (_waitTimeRangeAtPathEnd && IsFollowingPathBackwardsFromEndToStart() - && ((_isReturningToStart && _currentNode == 0) || (!_isReturningToStart && _currentNode == GetPath()->Nodes.size() - 1))) + && ((_isReturningToStart && _currentNode == 0) || (!_isReturningToStart && _currentNode == path->Nodes.size() - 1))) { owner->ClearUnitState(UNIT_STATE_ROAMING_MOVE); Milliseconds waitTime = randtime(_waitTimeRangeAtPathEnd->first, _waitTimeRangeAtPathEnd->second); @@ -319,13 +327,17 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* owner) MovementInform(owner); - owner->UpdateCurrentWaypointInfo(waypoint.Id, GetPath()->Id); + owner->UpdateCurrentWaypointInfo(waypoint.Id, path->Id); } void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaunch/* = false*/) { // sanity checks - if (!owner || !owner->IsAlive() || HasFlag(MOVEMENTGENERATOR_FLAG_FINALIZED) || !GetPath() || GetPath()->Nodes.empty() || (relaunch && (HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED) || !HasFlag(MOVEMENTGENERATOR_FLAG_INITIALIZED)))) + if (!owner || !owner->IsAlive() || HasFlag(MOVEMENTGENERATOR_FLAG_FINALIZED) || (relaunch && (HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED) || !HasFlag(MOVEMENTGENERATOR_FLAG_INITIALIZED)))) + return; + + WaypointPath const* path = GetPath(); + if (!path || path->Nodes.empty()) return; if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting() || (owner->IsFormationLeader() && !owner->IsFormationLeaderMoveAllowed())) // if cannot move OR cannot move because of formation @@ -340,15 +352,15 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun { if (ComputeNextNode()) { - ASSERT(_currentNode < GetPath()->Nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id); + ASSERT(_currentNode < path->Nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, path->Id); // inform AI if (CreatureAI* AI = owner->AI()) - AI->WaypointStarted(GetPath()->Nodes[_currentNode].Id, GetPath()->Id); + AI->WaypointStarted(path->Nodes[_currentNode].Id, path->Id); } else { - WaypointNode const& waypoint = GetPath()->Nodes[_currentNode]; + WaypointNode const& waypoint = path->Nodes[_currentNode]; float x = waypoint.X; float y = waypoint.Y; float z = waypoint.Z; @@ -372,7 +384,7 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun // inform AI if (CreatureAI* AI = owner->AI()) - AI->WaypointPathEnded(waypoint.Id, GetPath()->Id); + AI->WaypointPathEnded(waypoint.Id, path->Id); SetScriptResult(MovementStopReason::Finished); return; @@ -384,11 +396,11 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun // inform AI if (CreatureAI* AI = owner->AI()) - AI->WaypointStarted(GetPath()->Nodes[_currentNode].Id, GetPath()->Id); + AI->WaypointStarted(path->Nodes[_currentNode].Id, path->Id); } - ASSERT(_currentNode < GetPath()->Nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id); - WaypointNode const &waypoint = GetPath()->Nodes[_currentNode]; + ASSERT(_currentNode < path->Nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, path->Id); + WaypointNode const &waypoint = path->Nodes[_currentNode]; RemoveFlag(MOVEMENTGENERATOR_FLAG_TRANSITORY | MOVEMENTGENERATOR_FLAG_INFORM_ENABLED | MOVEMENTGENERATOR_FLAG_TIMED_PAUSED); @@ -400,14 +412,12 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun if (transportPath) init.DisableTransportPathTransformations(); - //! Do not use formationDest here, MoveTo requires transport offsets due to DisableTransportPathTransformations() call - //! but formationDest contains global coordinates init.MoveTo(waypoint.X, waypoint.Y, waypoint.Z, _generatePath); - if (waypoint.Orientation.has_value() && (waypoint.Delay > 0 || _currentNode == GetPath()->Nodes.size() - 1)) + if (waypoint.Orientation.has_value() && (waypoint.Delay > 0 || _currentNode == path->Nodes.size() - 1)) init.SetFacing(*waypoint.Orientation); - switch (GetPath()->MoveType) + switch (path->MoveType) { case WaypointMoveType::Land: init.SetAnimation(AnimTier::Ground); @@ -439,8 +449,8 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun break; } - if (GetPath()->Velocity && !_speed) - _speed = GetPath()->Velocity; + if (path->Velocity && !_speed) + _speed = path->Velocity; if (_speed) init.SetVelocity(*_speed); @@ -453,16 +463,17 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* owner, bool relaun bool WaypointMovementGenerator<Creature>::ComputeNextNode() { - if ((_currentNode == GetPath()->Nodes.size() - 1) && !_repeating) + WaypointPath const* path = GetPath(); + if ((_currentNode == path->Nodes.size() - 1) && !_repeating) return false; - if (!IsFollowingPathBackwardsFromEndToStart() || GetPath()->Nodes.size() < WAYPOINT_PATH_FLAG_FOLLOW_PATH_BACKWARDS_MINIMUM_NODES) - _currentNode = (_currentNode + 1) % GetPath()->Nodes.size(); + if (!IsFollowingPathBackwardsFromEndToStart() || path->Nodes.size() < WAYPOINT_PATH_FLAG_FOLLOW_PATH_BACKWARDS_MINIMUM_NODES) + _currentNode = (_currentNode + 1) % path->Nodes.size(); else { if (!_isReturningToStart) { - if (++_currentNode >= GetPath()->Nodes.size()) + if (++_currentNode >= path->Nodes.size()) { _currentNode -= WAYPOINT_PATH_FLAG_FOLLOW_PATH_BACKWARDS_MINIMUM_NODES; _isReturningToStart = true; |