aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Movement
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2017-11-06 22:19:23 +0100
committerccrs <ccrs@users.noreply.github.com>2017-11-06 22:19:23 +0100
commite10d7dd45cfc073c791cd5e5f3f964d14b37df3d (patch)
tree04f695772c2b253fbde2fde6511465b776e1e104 /src/server/game/Movement
parentd7de84b0277699fa12776864906e393f414aee08 (diff)
Core/Misc: waypoint movement
- Creature: update current waypoint to store nodeId and pathId - MotionMaster: change variable type on GetMotionSlotType and GetMotionSlot to keep consistency and prevent errors (ASSERT is now no longer needed) - UnitAI: add new waypoint hooks WaypointPathStarted and WaypointPathEnded - SAI: handle WAYPOINT related events if creature is no escorting * SMART_EVENT_WAYPOINT_RESUMED still not implemented for no escorting TODO: the new hooks can save, now duplicated, logic on EscortAI and SAI closes #20777 updates #20310 updates 21bd52cb99
Diffstat (limited to 'src/server/game/Movement')
-rw-r--r--src/server/game/Movement/MotionMaster.cpp14
-rw-r--r--src/server/game/Movement/MotionMaster.h4
-rwxr-xr-xsrc/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp28
3 files changed, 28 insertions, 18 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp
index b2027144487..3f77e472189 100644
--- a/src/server/game/Movement/MotionMaster.cpp
+++ b/src/server/game/Movement/MotionMaster.cpp
@@ -155,17 +155,19 @@ MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const
return top()->GetMovementGeneratorType();
}
-MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const
+MovementGeneratorType MotionMaster::GetMotionSlotType(MovementSlot slot) const
{
- if (!_slot[slot])
+ if (empty() || slot >= MAX_MOTION_SLOT || !_slot[slot])
return MAX_MOTION_TYPE;
- else
- return _slot[slot]->GetMovementGeneratorType();
+
+ return _slot[slot]->GetMovementGeneratorType();
}
-MovementGenerator* MotionMaster::GetMotionSlot(int slot) const
+MovementGenerator* MotionMaster::GetMotionSlot(MovementSlot slot) const
{
- ASSERT(slot >= 0);
+ if (empty() || slot >= MAX_MOTION_SLOT || !_slot[slot])
+ return nullptr;
+
return _slot[slot];
}
diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h
index dcee98cdaaa..d132d8b30d0 100644
--- a/src/server/game/Movement/MotionMaster.h
+++ b/src/server/game/Movement/MotionMaster.h
@@ -110,8 +110,8 @@ class TC_GAME_API MotionMaster
void MovementExpired(bool reset = true);
MovementGeneratorType GetCurrentMovementGeneratorType() const;
- MovementGeneratorType GetMotionSlotType(int slot) const;
- MovementGenerator* GetMotionSlot(int slot) const;
+ MovementGeneratorType GetMotionSlotType(MovementSlot slot) const;
+ MovementGenerator* GetMotionSlot(MovementSlot slot) const;
void PropagateSpeedChange();
diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
index c772cc055a6..3fba420059e 100755
--- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
@@ -59,6 +59,10 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
}
_nextMoveTime.Reset(1000);
+
+ // inform AI
+ if (creature->AI())
+ creature->AI()->WaypointPathStarted(1, _path->id);
}
void WaypointMovementGenerator<Creature>::DoInitialize(Creature* creature)
@@ -90,6 +94,7 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
if (!_path || _path->nodes.empty())
return;
+ 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.at(_currentNode);
if (waypoint.delay)
{
@@ -108,12 +113,10 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
if (creature->AI())
{
creature->AI()->MovementInform(WAYPOINT_MOTION_TYPE, _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);
- creature->AI()->WaypointReached(_path->nodes[_currentNode].id, _path->id);
+ creature->AI()->WaypointReached(waypoint.id, _path->id);
}
- creature->UpdateWaypointID(_currentNode);
+ creature->UpdateCurrentWaypointInfo(waypoint.id, _path->id);
}
bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
@@ -135,10 +138,11 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
if (_isArrivalDone)
{
+ 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.at(_currentNode);
+
if ((_currentNode == _path->nodes.size() - 1) && !_repeating) // If that's our last waypoint
{
- WaypointNode const &waypoint = _path->nodes.at(_currentNode);
-
float x = waypoint.x;
float y = waypoint.y;
float z = waypoint.z;
@@ -160,6 +164,11 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
// else if (vehicle) - this should never happen, vehicle offsets are const
}
_done = true;
+ creature->UpdateCurrentWaypointInfo(0, 0);
+
+ // inform AI
+ if (creature->AI())
+ creature->AI()->WaypointPathEnded(waypoint.id, _path->id);
return true;
}
@@ -167,12 +176,10 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
// inform AI
if (creature->AI())
- {
- ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id);
- creature->AI()->WaypointStarted(_path->nodes[_currentNode].id, _path->id);
- }
+ creature->AI()->WaypointStarted(waypoint.id, _path->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);
WaypointNode const &waypoint = _path->nodes.at(_currentNode);
Position formationDest(waypoint.x, waypoint.y, waypoint.z, (waypoint.orientation && waypoint.delay) ? waypoint.orientation : 0.0f);
@@ -284,6 +291,7 @@ bool WaypointMovementGenerator<Creature>::GetResetPos(Creature*, float& x, float
if (!_path || _path->nodes.empty())
return false;
+ ASSERT(_currentNode < _path->nodes.size(), "WaypointMovementGenerator::GetResetPos: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, _path->id);
WaypointNode const &waypoint = _path->nodes.at(_currentNode);
x = waypoint.x;