mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-03 19:13:49 +00:00
feature(SmartAI/Movement) - Unify waypoint systems (#23251)
This commit is contained in:
@@ -108,20 +108,20 @@ void SmartAI::UpdateDespawn(const uint32 diff)
|
||||
mDespawnTime -= diff;
|
||||
}
|
||||
|
||||
WayPoint* SmartAI::GetNextWayPoint()
|
||||
WaypointData const* SmartAI::GetNextWayPoint()
|
||||
{
|
||||
if (!mWayPoints || mWayPoints->empty())
|
||||
return nullptr;
|
||||
|
||||
mCurrentWPID++;
|
||||
WPPath::const_iterator itr = mWayPoints->find(mCurrentWPID);
|
||||
auto itr = mWayPoints->find(mCurrentWPID);
|
||||
if (itr != mWayPoints->end())
|
||||
{
|
||||
mLastWP = (*itr).second;
|
||||
mLastWP = &(*itr).second;
|
||||
if (mLastWP->id != mCurrentWPID)
|
||||
LOG_ERROR("scripts.ai.sai", "SmartAI::GetNextWayPoint: Got not expected waypoint id {}, expected {}", mLastWP->id, mCurrentWPID);
|
||||
|
||||
return (*itr).second;
|
||||
return &(*itr).second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -138,12 +138,15 @@ void SmartAI::GenerateWayPointArray(Movement::PointsArray* points)
|
||||
points->clear();
|
||||
points->push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
|
||||
uint32 wpCounter = mCurrentWPID;
|
||||
WPPath::const_iterator itr;
|
||||
while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end())
|
||||
auto itr = mWayPoints->find(wpCounter++);
|
||||
do
|
||||
{
|
||||
WayPoint* wp = (*itr).second;
|
||||
points->push_back(G3D::Vector3(wp->x, wp->y, wp->z));
|
||||
WaypointData const& wp = (*itr).second;
|
||||
points->push_back(G3D::Vector3(wp.x, wp.y, wp.z));
|
||||
|
||||
itr = mWayPoints->find(wpCounter++);
|
||||
}
|
||||
while (itr != mWayPoints->end());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -152,16 +155,17 @@ void SmartAI::GenerateWayPointArray(Movement::PointsArray* points)
|
||||
std::vector<G3D::Vector3> pVector;
|
||||
// xinef: first point in vector is unit real position
|
||||
pVector.push_back(G3D::Vector3(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ()));
|
||||
uint32 length = (mWayPoints->size() - mCurrentWPID) * size;
|
||||
|
||||
uint32 cnt = 0;
|
||||
uint32 wpCounter = mCurrentWPID;
|
||||
WPPath::const_iterator itr;
|
||||
while ((itr = mWayPoints->find(wpCounter++)) != mWayPoints->end() && cnt++ <= length)
|
||||
|
||||
auto itr = mWayPoints->find(wpCounter++);
|
||||
do
|
||||
{
|
||||
WayPoint* wp = (*itr).second;
|
||||
pVector.push_back(G3D::Vector3(wp->x, wp->y, wp->z));
|
||||
WaypointData const& wp = (*itr).second;
|
||||
pVector.push_back(G3D::Vector3(wp.x, wp.y, wp.z));
|
||||
|
||||
itr = mWayPoints->find(wpCounter++);
|
||||
}
|
||||
while (itr != mWayPoints->end());
|
||||
|
||||
if (pVector.size() > 2) // more than source + dest
|
||||
{
|
||||
@@ -189,21 +193,21 @@ void SmartAI::GenerateWayPointArray(Movement::PointsArray* points)
|
||||
}
|
||||
}
|
||||
|
||||
void SmartAI::StartPath(ForcedMovement forcedMovement, uint32 path, bool repeat, Unit* invoker)
|
||||
void SmartAI::StartPath(ForcedMovement forcedMovement, uint32 path, bool repeat, Unit* invoker, PathSource pathSource)
|
||||
{
|
||||
if (HasEscortState(SMART_ESCORT_ESCORTING))
|
||||
StopPath();
|
||||
|
||||
if (path)
|
||||
{
|
||||
if (!LoadPath(path))
|
||||
if (!LoadPath(path, pathSource))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mWayPoints || mWayPoints->empty())
|
||||
return;
|
||||
|
||||
if (WayPoint* wp = GetNextWayPoint())
|
||||
if (WaypointData const* wp = GetNextWayPoint())
|
||||
{
|
||||
AddEscortState(SMART_ESCORT_ESCORTING);
|
||||
mCanRepeatPath = repeat;
|
||||
@@ -219,20 +223,37 @@ void SmartAI::StartPath(ForcedMovement forcedMovement, uint32 path, bool repeat,
|
||||
GenerateWayPointArray(&pathPoints);
|
||||
|
||||
me->GetMotionMaster()->MoveSplinePath(&pathPoints, mForcedMovement);
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_START, nullptr, wp->id, GetScript()->GetPathId());
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_START, nullptr, wp->id, GetScript()->GetPathId());
|
||||
}
|
||||
}
|
||||
|
||||
bool SmartAI::LoadPath(uint32 entry)
|
||||
bool SmartAI::LoadPath(uint32 entry, PathSource pathSource)
|
||||
{
|
||||
if (HasEscortState(SMART_ESCORT_ESCORTING))
|
||||
return false;
|
||||
|
||||
mWayPoints = sSmartWaypointMgr->GetPath(entry);
|
||||
if (!mWayPoints)
|
||||
switch (pathSource)
|
||||
{
|
||||
GetScript()->SetPathId(0);
|
||||
return false;
|
||||
case PathSource::SMART_WAYPOINT_MGR:
|
||||
{
|
||||
mWayPoints = sSmartWaypointMgr->GetPath(entry);
|
||||
if (!mWayPoints)
|
||||
{
|
||||
GetScript()->SetPathId(0);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PathSource::WAYPOINT_MGR:
|
||||
{
|
||||
mWayPoints = sWaypointMgr->GetPath(entry);
|
||||
if (!mWayPoints)
|
||||
{
|
||||
GetScript()->SetPathId(0);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GetScript()->SetPathId(entry);
|
||||
@@ -262,12 +283,12 @@ void SmartAI::PausePath(uint32 delay, bool forced)
|
||||
me->GetMotionMaster()->MoveIdle();//force stop
|
||||
|
||||
auto waypoint = mWayPoints->find(mCurrentWPID);
|
||||
if (waypoint->second->o.has_value())
|
||||
if (waypoint->second.orientation.has_value())
|
||||
{
|
||||
me->SetFacingTo(waypoint->second->o.has_value());
|
||||
me->SetFacingTo(*waypoint->second.orientation);
|
||||
}
|
||||
}
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_PAUSED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_PAUSED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
}
|
||||
|
||||
void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
|
||||
@@ -285,7 +306,7 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)
|
||||
|
||||
me->StopMoving();
|
||||
me->GetMotionMaster()->MoveIdle();
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_STOPPED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_STOPPED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
EndPath(fail);
|
||||
}
|
||||
|
||||
@@ -354,13 +375,13 @@ void SmartAI::EndPath(bool fail)
|
||||
return;
|
||||
}
|
||||
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_ENDED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
mCurrentWPID = 0;
|
||||
|
||||
if (mCanRepeatPath)
|
||||
{
|
||||
if (IsAIControlled())
|
||||
StartPath(FORCED_MOVEMENT_NONE, GetScript()->GetPathId(), true);
|
||||
StartPath(mForcedMovement, GetScript()->GetPathId(), true);
|
||||
}
|
||||
else
|
||||
GetScript()->SetPathId(0);
|
||||
@@ -420,7 +441,7 @@ void SmartAI::UpdatePath(const uint32 diff)
|
||||
{
|
||||
if (!me->IsInCombat() && !HasEscortState(SMART_ESCORT_RETURNING) && (mWPReached || mForcedPaused))
|
||||
{
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_RESUMED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_RESUMED, nullptr, mCurrentWPID, GetScript()->GetPathId());
|
||||
RemoveEscortState(SMART_ESCORT_PAUSED);
|
||||
if (mForcedPaused)// if paused between 2 wps resend movement
|
||||
{
|
||||
@@ -599,7 +620,7 @@ void SmartAI::MovepointReached(uint32 id)
|
||||
}
|
||||
|
||||
mWPReached = true;
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, mCurrentWPID);
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_ESCORT_REACHED, nullptr, mCurrentWPID);
|
||||
|
||||
if (mLastWP)
|
||||
{
|
||||
@@ -636,7 +657,7 @@ void SmartAI::MovementInform(uint32 MovementType, uint32 Data)
|
||||
me->ClearUnitState(UNIT_STATE_EVADE);
|
||||
|
||||
if (MovementType == WAYPOINT_MOTION_TYPE)
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_REACHED, nullptr, Data + 1); // Data + 1 to align smart_scripts and waypoint_data Id rows
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_REACHED, nullptr, Data); // data now corresponds to columns
|
||||
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
|
||||
if (!HasEscortState(SMART_ESCORT_ESCORTING))
|
||||
@@ -786,7 +807,7 @@ void SmartAI::JustReachedHome()
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_REACHED_HOME);
|
||||
|
||||
if (!UpdateVictim() && me->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE && me->GetWaypointPath())
|
||||
me->GetMotionMaster()->MovePath(me->GetWaypointPath(), true);
|
||||
me->GetMotionMaster()->MoveWaypoint(me->GetWaypointPath(), true);
|
||||
}
|
||||
|
||||
mJustReset = false;
|
||||
@@ -943,7 +964,7 @@ void SmartAI::OnCharmed(bool /* apply */)
|
||||
if (!charmed && !me->IsInEvadeMode())
|
||||
{
|
||||
if (mCanRepeatPath)
|
||||
StartPath(FORCED_MOVEMENT_NONE, GetScript()->GetPathId(), true);
|
||||
StartPath(mForcedMovement, GetScript()->GetPathId(), true);
|
||||
|
||||
if (Unit* charmer = me->GetCharmer())
|
||||
AttackStart(charmer);
|
||||
@@ -1149,7 +1170,7 @@ void SmartAI::OnSpellClick(Unit* clicker, bool& /*result*/)
|
||||
|
||||
void SmartAI::PathEndReached(uint32 /*pathId*/)
|
||||
{
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_ENDED, nullptr, 0, me->GetWaypointPath());
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_ENDED, nullptr, 0, me->GetWaypointPath());
|
||||
me->LoadPath(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user