Revert "Core/Movement: merged smooth waypoints (commit: 05fb27dae4e8af859e01e5b9e52b082cba217657)"

This reverts commit 6dddfc812c.
This commit is contained in:
Ovahlord committed 2018-03-27 22:04:30 +02:00
1 parent d2b2dc8fca
commit 53e989dcd3
16 files changed
+630 -606

No files matched your search

@@ -30,17 +30,13 @@
#include "Player.h"
#include "MoveSplineInit.h"
#include "MoveSpline.h"
#include "WaypointManager.h"
void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
{
if (LoadedFromDB)
{
if (!path_id)
path_id = creature->GetWaypointPath();
if (!path_id)
path_id = creature->GetWaypointPath();
i_path = sWaypointMgr->GetPath(path_id);
}
i_path = sWaypointMgr->GetPath(path_id);
if (!i_path)
{
@@ -49,13 +45,13 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
return;
}
if (!Stopped())
StartMoveNow(creature);
StartMoveNow(creature);
}
void WaypointMovementGenerator<Creature>::DoInitialize(Creature* creature)
{
LoadPath(creature);
creature->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
}
void WaypointMovementGenerator<Creature>::DoFinalize(Creature* creature)
@@ -66,75 +62,58 @@ void WaypointMovementGenerator<Creature>::DoFinalize(Creature* creature)
void WaypointMovementGenerator<Creature>::DoReset(Creature* creature)
{
if (!Stopped())
StartMoveNow(creature);
creature->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
StartMoveNow(creature);
}
void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
{
if (!i_path || i_path->nodes.empty())
if (!i_path || i_path->empty())
return;
if (m_isArrivalDone)
return;
WaypointNode const &waypoint = i_path->nodes.at(i_currentNode);
if (waypoint.delay)
{
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
Stop(waypoint.delay);
}
m_isArrivalDone = true;
if (waypoint.eventId && urand(0, 99) < waypoint.eventChance)
if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance)
{
TC_LOG_DEBUG("maps.script", "Creature movement start script %u at point %u for %s.", waypoint.eventId, i_currentNode, creature->GetGUID().ToString().c_str());
TC_LOG_DEBUG("maps.script", "Creature movement start script %u at point %u for %s.", i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID().ToString().c_str());
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
creature->GetMap()->ScriptsStart(sWaypointScripts, waypoint.eventId, creature, nullptr);
creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, nullptr);
}
// Inform script
MovementInform(creature);
creature->UpdateWaypointID(i_currentNode);
creature->SetWalk(waypoint.moveType != WAYPOINT_MOVE_TYPE_RUN);
}
void WaypointMovementGenerator<Creature>::FormationMove(Creature* creature)
{
bool transportPath = creature->GetTransport() != nullptr;
WaypointNode const &waypoint = i_path->nodes.at(i_currentNode);
Movement::Location formationDest(waypoint.x, waypoint.y, waypoint.z, 0.0f);
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
if (transportPath)
if (i_path->at(i_currentNode)->delay)
{
if (TransportBase* trans = creature->GetDirectTransport())
trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation);
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
Stop(i_path->at(i_currentNode)->delay);
}
// Call for creature group update
if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z);
}
bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
{
if (!creature || !creature->IsAlive())
if (!i_path || i_path->empty())
return false;
if (!i_path || i_path->nodes.empty())
// Dont allow dead creatures to move
if (!creature->IsAlive())
return false;
bool transportPath = creature->GetTransport() != nullptr;
if (Stopped())
return true;
if (IsArrivalDone)
bool transportPath = creature->GetTransport() != NULL;
if (m_isArrivalDone)
{
if ((i_currentNode == i_path->nodes.size() - 1) && !repeating) // If that's our last waypoint
if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
{
WaypointNode const &waypoint = i_path->nodes.at(i_currentNode);
float x = waypoint.x;
float y = waypoint.y;
float z = waypoint.z;
float x = i_path->at(i_currentNode)->x;
float y = i_path->at(i_currentNode)->y;
float z = i_path->at(i_currentNode)->z;
float o = creature->GetOrientation();
if (!transportPath)
@@ -152,44 +131,23 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
transportPath = false;
// else if (vehicle) - this should never happen, vehicle offsets are const
}
creature->GetMotionMaster()->Initialize();
return false;
}
i_currentNode = (i_currentNode + 1) % i_path->nodes.size();
i_currentNode = (i_currentNode+1) % i_path->size();
}
float finalOrient = 0.0f;
uint8 finalMove = WAYPOINT_MOVE_TYPE_WALK;
WaypointData const* node = i_path->at(i_currentNode);
Movement::PointsArray pathing;
pathing.reserve((i_path->nodes.size() - i_currentNode) + 1);
pathing.push_back(G3D::Vector3(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ()));
for (uint32 i = i_currentNode; i < i_path->nodes.size(); ++i)
{
WaypointNode const &waypoint = i_path->nodes.at(i);
pathing.push_back(G3D::Vector3(waypoint.x, waypoint.y, waypoint.z));
finalOrient = waypoint.orientation;
finalMove = waypoint.moveType;
if (waypoint.delay)
break;
}
// if we have only 1 point, only current position, we shall return
if (pathing.size() < 2)
return false;
IsArrivalDone = false;
i_recalculateSpeed = false;
m_isArrivalDone = false;
creature->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(creature);
Movement::Location formationDest(node->x, node->y, node->z, 0.0f);
Movement::Location formationDest(i_path->nodes.at(i_currentNode).x, i_path->nodes.at(i_currentNode).y, i_path->nodes.at(i_currentNode).z, 0.0f);
Movement::MoveSplineInit init(creature);
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
if (transportPath)
@@ -199,9 +157,15 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation);
}
init.MovebyPath(pathing, i_currentNode);
//! Do not use formationDest here, MoveTo requires transport offsets due to DisableTransportPathTransformations() call
//! but formationDest contains global coordinates
init.MoveTo(node->x, node->y, node->z);
switch (finalMove)
//! Accepts angles such as 0.00001 and -0.00001, 0 must be ignored, default value in waypoint table
if (node->orientation && node->delay)
init.SetFacing(node->orientation);
switch (node->move_type)
{
case WAYPOINT_MOVE_TYPE_LAND:
init.SetAnimation(Movement::ToGround);
@@ -217,23 +181,20 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
break;
}
if (finalOrient != 0.0f)
init.SetFacing(finalOrient);
init.Launch();
//Call for creature group update
if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
{
creature->SetWalk(node->move_type != WAYPOINT_MOVE_TYPE_RUN);
creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z);
}
return true;
}
bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 diff)
{
if (!creature || !creature->IsAlive())
return false;
// Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff
if (creature->HasUnitState(UNIT_STATE_NOT_MOVE))
@@ -241,15 +202,14 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true;
}
// prevent a crash at empty waypoint path.
if (!i_path || i_path->nodes.empty())
if (!i_path || i_path->empty())
return false;
if (Stopped())
{
if (CanMove(diff))
return StartMoveNow(creature);
return StartMove(creature);
}
else
{
@@ -258,40 +218,11 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
creature->SetHomePosition(creature->GetPosition());
if (creature->IsStopped())
Stop(LoadedFromDB ? sWorld->getIntConfig(CONFIG_CREATURE_STOP_FOR_PLAYER) : 2 * HOUR * IN_MILLISECONDS);
Stop(sWorld->getIntConfig(CONFIG_CREATURE_STOP_FOR_PLAYER));
else if (creature->movespline->Finalized())
{
OnArrived(creature);
IsArrivalDone = true;
if (!Stopped())
{
if (creature->IsStopped())
Stop(LoadedFromDB ? sWorld->getIntConfig(CONFIG_CREATURE_STOP_FOR_PLAYER) : 2 * HOUR * IN_MILLISECONDS);
else
return StartMove(creature);
}
}
else
{
// speed changed during path execution, calculate remaining path and launch it once more
if (i_recalculateSpeed)
{
i_recalculateSpeed = false;
if (!Stopped())
return StartMove(creature);
}
else
{
uint32 pointId = uint32(creature->movespline->currentPathIdx());
if (pointId > i_currentNode)
{
OnArrived(creature);
i_currentNode = pointId;
FormationMove(creature);
}
}
return StartMove(creature);
}
}
return true;
@@ -306,14 +237,11 @@ void WaypointMovementGenerator<Creature>::MovementInform(Creature* creature)
bool WaypointMovementGenerator<Creature>::GetResetPos(Creature*, float& x, float& y, float& z)
{
// prevent a crash at empty waypoint path.
if (!i_path || i_path->nodes.empty())
if (!i_path || i_path->empty())
return false;
WaypointNode const &waypoint = i_path->nodes.at(i_currentNode);
x = waypoint.x;
y = waypoint.y;
z = waypoint.z;
const WaypointData* node = i_path->at(i_currentNode);
x = node->x; y = node->y; z = node->z;
return true;
}
@@ -417,12 +345,12 @@ void FlightPathMovementGenerator::DoReset(Player* player)
Movement::MoveSplineInit init(player);
uint32 end = GetPathAtMapEnd();
for (uint32 i = i_currentNode; i != end; ++i)
for (uint32 i = GetCurrentNode(); i != end; ++i)
{
G3D::Vector3 vertice(i_path[i]->LocX, i_path[i]->LocY, i_path[i]->LocZ);
init.Path().push_back(vertice);
}
init.SetFirstPointId(i_currentNode);
init.SetFirstPointId(GetCurrentNode());
init.SetFly();
init.SetSmooth();
init.SetUncompressed();
@@ -26,6 +26,7 @@
*/
#include "MovementGenerator.h"
#include "WaypointManager.h"
#include "Player.h"
#include "World.h"
@@ -56,16 +57,8 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
public:
WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true)
: i_nextMoveTime(0), IsArrivalDone(false), path_id(_path_id), repeating(_repeating), LoadedFromDB(true) { }
WaypointMovementGenerator(WaypointPath& path, bool _repeating = true)
: i_nextMoveTime(0), IsArrivalDone(false), path_id(0), repeating(_repeating), LoadedFromDB(false)
{
i_path = &path;
}
: i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) { }
~WaypointMovementGenerator() { i_path = nullptr; }
void DoInitialize(Creature*);
void DoFinalize(Creature*);
void DoReset(Creature*);
@@ -80,9 +73,6 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
bool GetResetPos(Creature*, float& x, float& y, float& z);
TimeTrackerSmall & GetTrackerTimer() { return i_nextMoveTime; }
void UnitSpeedChanged() { i_recalculateSpeed = true; }
private:
void Stop(int32 time) { i_nextMoveTime.Reset(time);}
@@ -97,21 +87,17 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
void OnArrived(Creature*);
bool StartMove(Creature*);
void FormationMove(Creature*);
bool StartMoveNow(Creature* creature)
void StartMoveNow(Creature* creature)
{
i_nextMoveTime.Reset(0);
return StartMove(creature);
StartMove(creature);
}
TimeTrackerSmall i_nextMoveTime;
bool i_recalculateSpeed;
bool IsArrivalDone;
bool m_isArrivalDone;
uint32 path_id;
bool repeating;
bool LoadedFromDB;
};
/** FlightPathMovementGenerator generates movement of the player for the paths