mirror of
https://github.com/mangosfour/server.git
synced 2025-12-19 13:37:01 +00:00
[12695] Improve WaypointMMGen
* Add correct Reset position (Npc will evade now to the last reached waypoint, and not to the next waypoint) * Add proper return value for the CONDITION_LAST_WAYPOINT * Let WaypointMMGen behave better after evading (keep PAUSED state, keep waittimer (original author @Schmoozerd)
This commit is contained in:
parent
1c381f206b
commit
6658234c07
3 changed files with 21 additions and 13 deletions
|
|
@ -67,17 +67,16 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature& creature)
|
||||||
if (i_path->empty())
|
if (i_path->empty())
|
||||||
return;
|
return;
|
||||||
i_currentNode = i_path->begin()->first;
|
i_currentNode = i_path->begin()->first;
|
||||||
|
m_lastReachedWaypoint = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointMovementGenerator<Creature>::Initialize(Creature& creature)
|
void WaypointMovementGenerator<Creature>::Initialize(Creature& creature)
|
||||||
{
|
{
|
||||||
creature.addUnitState(UNIT_STAT_ROAMING);
|
creature.addUnitState(UNIT_STAT_ROAMING);
|
||||||
|
creature.clearUnitState(UNIT_STAT_WAYPOINT_PAUSED);
|
||||||
|
|
||||||
LoadPath(creature);
|
LoadPath(creature);
|
||||||
|
|
||||||
if (!creature.isAlive() || creature.hasUnitState(UNIT_STAT_NOT_MOVE))
|
|
||||||
return;
|
|
||||||
|
|
||||||
creature.addUnitState(UNIT_STAT_ROAMING_MOVE);
|
|
||||||
StartMoveNow(creature);
|
StartMoveNow(creature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,8 +95,8 @@ void WaypointMovementGenerator<Creature>::Interrupt(Creature& creature)
|
||||||
|
|
||||||
void WaypointMovementGenerator<Creature>::Reset(Creature& creature)
|
void WaypointMovementGenerator<Creature>::Reset(Creature& creature)
|
||||||
{
|
{
|
||||||
creature.addUnitState(UNIT_STAT_ROAMING | UNIT_STAT_ROAMING_MOVE);
|
creature.addUnitState(UNIT_STAT_ROAMING);
|
||||||
StartMoveNow(creature);
|
StartMove(creature);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
|
void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
|
||||||
|
|
@ -105,6 +104,8 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
|
||||||
if (!i_path || i_path->empty())
|
if (!i_path || i_path->empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_lastReachedWaypoint = i_currentNode;
|
||||||
|
|
||||||
if (m_isArrivalDone)
|
if (m_isArrivalDone)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -161,7 +162,6 @@ void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
|
||||||
void WaypointMovementGenerator<Creature>::StartMoveNow(Creature& creature)
|
void WaypointMovementGenerator<Creature>::StartMoveNow(Creature& creature)
|
||||||
{
|
{
|
||||||
i_nextMoveTime.Reset(0);
|
i_nextMoveTime.Reset(0);
|
||||||
creature.clearUnitState(UNIT_STAT_WAYPOINT_PAUSED);
|
|
||||||
StartMove(creature);
|
StartMove(creature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,6 +173,9 @@ void WaypointMovementGenerator<Creature>::StartMove(Creature& creature)
|
||||||
if (Stopped(creature))
|
if (Stopped(creature))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!creature.isAlive() || creature.hasUnitState(UNIT_STAT_NOT_MOVE))
|
||||||
|
return;
|
||||||
|
|
||||||
WaypointPath::const_iterator currPoint = i_path->find(i_currentNode);
|
WaypointPath::const_iterator currPoint = i_path->find(i_currentNode);
|
||||||
MANGOS_ASSERT(currPoint != i_path->end());
|
MANGOS_ASSERT(currPoint != i_path->end());
|
||||||
|
|
||||||
|
|
@ -253,10 +256,14 @@ bool WaypointMovementGenerator<Creature>::GetResetPosition(Creature&, float& x,
|
||||||
if (!i_path || i_path->empty())
|
if (!i_path || i_path->empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
WaypointPath::const_iterator currPoint = i_path->find(i_currentNode);
|
WaypointPath::const_iterator lastPoint = i_path->find(m_lastReachedWaypoint);
|
||||||
MANGOS_ASSERT(currPoint != i_path->end());
|
// Special case: Before the first waypoint is reached, m_lastReachedWaypoint is set to 0 (which may not be contained in i_path)
|
||||||
|
if (!m_lastReachedWaypoint && lastPoint == i_path->end())
|
||||||
|
return false;
|
||||||
|
|
||||||
x = currPoint->second.x; y = currPoint->second.y; z = currPoint->second.z;
|
MANGOS_ASSERT(lastPoint != i_path->end());
|
||||||
|
|
||||||
|
x = lastPoint->second.x; y = lastPoint->second.y; z = lastPoint->second.z;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class MANGOS_DLL_SPEC WaypointMovementGenerator<Creature>
|
||||||
public PathMovementBase<Creature, WaypointPath const*>
|
public PathMovementBase<Creature, WaypointPath const*>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WaypointMovementGenerator(Creature&) : i_nextMoveTime(0), m_isArrivalDone(false) {}
|
WaypointMovementGenerator(Creature&) : i_nextMoveTime(0), m_isArrivalDone(false), m_lastReachedWaypoint(0) {}
|
||||||
~WaypointMovementGenerator() { i_path = NULL; }
|
~WaypointMovementGenerator() { i_path = NULL; }
|
||||||
void Initialize(Creature& u);
|
void Initialize(Creature& u);
|
||||||
void Interrupt(Creature&);
|
void Interrupt(Creature&);
|
||||||
|
|
@ -84,7 +84,7 @@ class MANGOS_DLL_SPEC WaypointMovementGenerator<Creature>
|
||||||
|
|
||||||
void AddToWaypointPauseTime(int32 waitTimeDiff);
|
void AddToWaypointPauseTime(int32 waitTimeDiff);
|
||||||
|
|
||||||
uint32 getLastReachedWaypoint() const { return m_isArrivalDone ? i_currentNode + 1 : i_currentNode; }
|
uint32 getLastReachedWaypoint() const { return m_lastReachedWaypoint; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Stop(int32 time) { i_nextMoveTime.Reset(time); }
|
void Stop(int32 time) { i_nextMoveTime.Reset(time); }
|
||||||
|
|
@ -98,6 +98,7 @@ class MANGOS_DLL_SPEC WaypointMovementGenerator<Creature>
|
||||||
|
|
||||||
ShortTimeTracker i_nextMoveTime;
|
ShortTimeTracker i_nextMoveTime;
|
||||||
bool m_isArrivalDone;
|
bool m_isArrivalDone;
|
||||||
|
uint32 m_lastReachedWaypoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** FlightPathMovementGenerator generates movement of the player for the paths
|
/** FlightPathMovementGenerator generates movement of the player for the paths
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "12694"
|
#define REVISION_NR "12695"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue