aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2018-02-12 23:44:18 +0100
committerShauren <shauren.trinity@gmail.com>2021-06-20 01:34:48 +0200
commitcecb91ad3d77d622a3b36d36e06a9220b2c44204 (patch)
treeb8ba5aaa87d20bd3b6924233ffa0890276e58837
parenta342b864030941423b12c9d974705bc268be8f44 (diff)
Core/Movement: fe1ba18905 followup
ref https://github.com/TrinityCore/TrinityCore/commit/fe1ba1890540283b8d330fe98b96770fe372ba8d#r27507316 plus I noticed a logic error on speedchange call (cherry picked from commit 28c6db0807a604b0178abe24daa0e4eb21f560fb)
-rw-r--r--src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp65
-rwxr-xr-xsrc/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h2
2 files changed, 41 insertions, 26 deletions
diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
index 43207d01568..9e6c33152ee 100644
--- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
@@ -116,19 +116,19 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
creature->UpdateCurrentWaypointInfo(waypoint.id, _path->id);
}
-void WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
+void WaypointMovementGenerator<Creature>::StartMove(Creature* creature, bool relaunch/* = false*/)
{
- if (!creature || !creature->IsAlive())
- return;
-
- if (_done || !_path || _path->nodes.empty())
+ // sanity checks
+ if (!creature || !creature->IsAlive() || _done || !_path || _path->nodes.empty() || (relaunch && _isArrivalDone))
return;
- // if the owner is the leader of its formation, check members status
- if (!CanMove(creature) || (creature->IsFormationLeader() && !creature->IsFormationLeaderMoveAllowed()))
+ if (!relaunch) // on relaunch, can avoid this since its only called on valid movement
{
- _nextMoveTime.Reset(1000);
- return;
+ if (!CanMove(creature) || (creature->IsFormationLeader() && !creature->IsFormationLeaderMoveAllowed())) // if cannot move OR cannot move because of formation
+ {
+ _nextMoveTime.Reset(1000); // delay 1s
+ return;
+ }
}
bool transportPath = creature->GetTransport() != nullptr;
@@ -229,8 +229,6 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
// inform formation
creature->SignalFormationMovement(formationDest, waypoint.id, waypoint.moveType, (waypoint.orientation && waypoint.delay) ? true : false);
-
- return;
}
bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 diff)
@@ -239,30 +237,47 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
return true;
if (_done || !_path || _path->nodes.empty())
- return false;
+ return true;
if (_stalled || creature->HasUnitState(UNIT_STATE_NOT_MOVE) || creature->IsMovementPreventedByCasting())
{
- creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
creature->StopMoving();
return true;
}
- if (!_nextMoveTime.Passed())
- _nextMoveTime.Update(diff);
-
- if (creature->HasUnitState(UNIT_STATE_ROAMING_MOVE) && creature->movespline->Finalized() && !_isArrivalDone)
+ // if it's moving
+ if (!creature->movespline->Finalized())
{
- OnArrived(creature);
- _isArrivalDone = true;
- }
+ // set home position at place (every MotionMaster::UpdateMotion)
+ if (creature->GetTransGUID().IsEmpty())
+ creature->SetHomePosition(creature->GetPosition());
- // Set home position at place on waypoint movement.
- if (creature->GetTransGUID().IsEmpty())
- creature->SetHomePosition(creature->GetPosition());
+ // relaunch movement if its speed has changed
+ if (_recalculateSpeed)
+ StartMove(creature, true);
+ }
+ else
+ {
+ // check if there is a wait time for the next movement
+ if (!_nextMoveTime.Passed())
+ {
+ // dont update wait timer while moving
+ _nextMoveTime.Update(diff);
+ if (_nextMoveTime.Passed())
+ {
+ _nextMoveTime.Reset(0);
+ StartMove(creature); // check path status, get next point and move if necessary & can
+ }
+ }
+ else // if it's not moving and there is no timer, assume node is reached
+ {
+ OnArrived(creature); // hooks and wait timer reset (if necessary)
+ _isArrivalDone = true; // signals that the next move will happen after reaching a node
- if (_recalculateSpeed || (_nextMoveTime.Passed() && (!creature->HasUnitState(UNIT_STATE_ROAMING_MOVE) || creature->movespline->Finalized())))
- StartMove(creature);
+ if (_nextMoveTime.Passed())
+ StartMove(creature); // check path status, get next point and move if necessary & can
+ }
+ }
return true;
}
diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h
index eecb4c2d7f6..da1a5659f5c 100755
--- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h
+++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h
@@ -61,7 +61,7 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium<Creat
private:
void OnArrived(Creature*);
- void StartMove(Creature*);
+ void StartMove(Creature*, bool relaunch = false);
static bool CanMove(Creature*);
TimeTrackerSmall _nextMoveTime;