feature(SmartAI/Movement) - Unify waypoint systems (#23251)
This commit is contained in:
parent
af2cb8d227
commit
6292f80219
71 changed files with 447 additions and 485 deletions
|
|
@ -28,13 +28,26 @@
|
|||
#include "Spell.h"
|
||||
#include "Transport.h"
|
||||
#include "World.h"
|
||||
#include "SmartScriptMgr.h"
|
||||
|
||||
void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
|
||||
{
|
||||
if (!path_id)
|
||||
path_id = creature->GetWaypointPath();
|
||||
switch (i_pathSource)
|
||||
{
|
||||
case PathSource::WAYPOINT_MGR:
|
||||
{
|
||||
if (!path_id)
|
||||
path_id = creature->GetWaypointPath();
|
||||
|
||||
i_path = sWaypointMgr->GetPath(path_id);
|
||||
i_path = sWaypointMgr->GetPath(path_id);
|
||||
break;
|
||||
}
|
||||
case PathSource::SMART_WAYPOINT_MGR:
|
||||
{
|
||||
i_path = sSmartWaypointMgr->GetPath(path_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!i_path)
|
||||
{
|
||||
|
|
@ -44,6 +57,8 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
|
|||
return;
|
||||
}
|
||||
|
||||
i_currentNode = i_path->begin()->first;
|
||||
|
||||
StartMoveNow(creature);
|
||||
}
|
||||
|
||||
|
|
@ -78,22 +93,24 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
|
|||
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
|
||||
m_isArrivalDone = true;
|
||||
|
||||
if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance)
|
||||
auto currentNodeItr = i_path->find(i_currentNode);
|
||||
|
||||
if (currentNodeItr->second.event_id && urand(0, 99) < currentNodeItr->second.event_chance)
|
||||
{
|
||||
LOG_DEBUG("maps.script", "Creature movement start script {} at point {} for {}.",
|
||||
i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID().ToString());
|
||||
currentNodeItr->second.event_id, i_currentNode, creature->GetGUID().ToString());
|
||||
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
|
||||
creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, nullptr);
|
||||
creature->GetMap()->ScriptsStart(sWaypointScripts, currentNodeItr->second.event_id, creature, nullptr);
|
||||
}
|
||||
|
||||
// Inform script
|
||||
MovementInform(creature);
|
||||
creature->UpdateWaypointID(i_currentNode);
|
||||
|
||||
if (i_path->at(i_currentNode)->delay)
|
||||
if (currentNodeItr->second.delay)
|
||||
{
|
||||
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
|
||||
Stop(i_path->at(i_currentNode)->delay);
|
||||
Stop(currentNodeItr->second.delay);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,9 +133,10 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
|
|||
// Xinef: not true... update this at every waypoint!
|
||||
//if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
|
||||
{
|
||||
float x = i_path->at(i_currentNode)->x;
|
||||
float y = i_path->at(i_currentNode)->y;
|
||||
float z = i_path->at(i_currentNode)->z;
|
||||
auto currentNodeItr = i_path->find(i_currentNode);
|
||||
float x = currentNodeItr->second.x;
|
||||
float y = currentNodeItr->second.y;
|
||||
float z = currentNodeItr->second.z;
|
||||
float o = creature->GetOrientation();
|
||||
|
||||
if (!transportPath)
|
||||
|
|
@ -146,7 +164,9 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
|
|||
return false;
|
||||
}
|
||||
|
||||
i_currentNode = (i_currentNode + 1) % i_path->size();
|
||||
++i_currentNode;
|
||||
if (i_path->rbegin()->first < i_currentNode)
|
||||
i_currentNode = i_path->begin()->first;
|
||||
}
|
||||
|
||||
// xinef: do not initialize motion if we got stunned in movementinform
|
||||
|
|
@ -155,13 +175,14 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
|
|||
return true;
|
||||
}
|
||||
|
||||
WaypointData const* node = i_path->at(i_currentNode);
|
||||
auto currentNodeItr = i_path->find(i_currentNode);
|
||||
WaypointData const& node = currentNodeItr->second;
|
||||
|
||||
m_isArrivalDone = false;
|
||||
|
||||
creature->AddUnitState(UNIT_STATE_ROAMING_MOVE);
|
||||
|
||||
Movement::Location formationDest(node->x, node->y, node->z, 0.0f);
|
||||
Movement::Location formationDest(node.x, node.y, node.z, 0.0f);
|
||||
Movement::MoveSplineInit init(creature);
|
||||
|
||||
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
|
||||
|
|
@ -172,16 +193,16 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
|
|||
trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation);
|
||||
}
|
||||
|
||||
float z = node->z;
|
||||
creature->UpdateAllowedPositionZ(node->x, node->y, z);
|
||||
float z = node.z;
|
||||
creature->UpdateAllowedPositionZ(node.x, node.y, z);
|
||||
//! Do not use formationDest here, MoveTo requires transport offsets due to DisableTransportPathTransformations() call
|
||||
//! but formationDest contains global coordinates
|
||||
init.MoveTo(node->x, node->y, z, true, true);
|
||||
init.MoveTo(node.x, node.y, z, true, true);
|
||||
|
||||
if (node->orientation.has_value() && node->delay > 0)
|
||||
init.SetFacing(*node->orientation);
|
||||
if (node.orientation.has_value() && node.delay > 0)
|
||||
init.SetFacing(*node.orientation);
|
||||
|
||||
switch (node->move_type)
|
||||
switch (node.move_type)
|
||||
{
|
||||
case WAYPOINT_MOVE_TYPE_LAND:
|
||||
init.SetAnimation(Movement::ToGround);
|
||||
|
|
@ -203,7 +224,7 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
|
|||
|
||||
//Call for creature group update
|
||||
if (creature->GetFormation() && creature->GetFormation()->GetLeader() == creature)
|
||||
creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z, node->move_type);
|
||||
creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z, node.move_type);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue