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 (TransportBase* trans = creature->GetDirectTransport()) trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation); } // 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 (!i_path || i_path->empty()) return false; // Xinef: Dont allow dead creatures to move if (!creature->IsAlive()) return false; if (Stopped()) return true; bool transportPath = creature->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && creature->GetTransGUID(); if (m_isArrivalDone) { // 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; float o = creature->GetOrientation(); if (!transportPath) creature->SetHomePosition(x, y, z, o); else { if (Transport* trans = (creature->GetTransport() ? creature->GetTransport()->ToMotionTransport() : NULL)) { o -= trans->GetOrientation(); creature->SetTransportHomePosition(x, y, z, o); trans->CalculatePassengerPosition(x, y, z, &o); creature->SetHomePosition(x, y, z, o); } else transportPath = false; // else if (vehicle) - this should never happen, vehicle offsets are const } } // Xinef: moved the upper IF here if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint { creature->GetMotionMaster()->Initialize(); return false; } i_currentNode = (i_currentNode+1) % i_path->size(); } // xinef: do not initialize motion if we got stunned in movementinform if (creature->HasUnitState(UNIT_STATE_NOT_MOVE)) return true; WaypointData const* node = i_path->at(i_currentNode); m_isArrivalDone = false; creature->AddUnitState(UNIT_STATE_ROAMING_MOVE); 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 if (transportPath) { init.DisableTransportPathTransformations(); if (TransportBase* trans = creature->GetDirectTransport()) trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation); } //! 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); //! 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); break; case WAYPOINT_MOVE_TYPE_TAKEOFF: init.SetAnimation(Movement::ToFly); break; case WAYPOINT_MOVE_TYPE_RUN: init.SetWalk(false); break; case WAYPOINT_MOVE_TYPE_WALK: init.SetWalk(true); break; } init.Launch(); //Call for creature group update if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature) creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z, node->move_type == WAYPOINT_MOVE_TYPE_RUN); return true; }
bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature) { if (!i_path || i_path->empty()) return false; if (Stopped()) return true; bool transportPath = creature->GetTransport() != NULL; if (m_isArrivalDone) { 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; float o = creature->GetOrientation(); if (!transportPath) creature->SetHomePosition(x, y, z, o); else { if (Transport* trans = creature->GetTransport()) { o -= trans->GetOrientation(); creature->SetTransportHomePosition(x, y, z, o); trans->CalculatePassengerPosition(x, y, z, &o); creature->SetHomePosition(x, y, z, o); } else 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->size(); } WaypointData const* node = i_path->at(i_currentNode); m_isArrivalDone = false; creature->AddUnitState(UNIT_STATE_ROAMING_MOVE); 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 if (transportPath) { init.DisableTransportPathTransformations(); if (TransportBase* trans = creature->GetDirectTransport()) trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation); } //! 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); //! 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); init.SetWalk(!node->run); init.Launch(); //Call for creature group update if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature) creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z); return true; }
bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature) { if (!creature || !creature->IsAlive()) return false; if (!i_path || i_path->nodes.empty()) return false; bool transportPath = creature->GetTransport() != nullptr; if (IsArrivalDone) { if ((i_currentNode == i_path->nodes.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 o = creature->GetOrientation(); if (!transportPath) creature->SetHomePosition(x, y, z, o); else { if (Transport* trans = creature->GetTransport()) { o -= trans->GetOrientation(); creature->SetTransportHomePosition(x, y, z, o); trans->CalculatePassengerPosition(x, y, z, &o); creature->SetHomePosition(x, y, z, o); } else transportPath = false; // else if (vehicle) - this should never happen, vehicle offsets are const } return false; } i_currentNode = (i_currentNode + 1) % i_path->nodes.size(); } float finalOrient = 0.0f; uint8 finalMove = WAYPOINT_MOVE_TYPE_WALK; 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; creature->AddUnitState(UNIT_STATE_ROAMING_MOVE); Movement::MoveSplineInit init(creature); 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); //! If creature is on transport, we assume waypoints set in DB are already transport offsets if (transportPath) { init.DisableTransportPathTransformations(); if (TransportBase* trans = creature->GetDirectTransport()) trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation); } init.MovebyPath(pathing, i_currentNode); switch (finalMove) { case WAYPOINT_MOVE_TYPE_LAND: init.SetAnimation(Movement::ToGround); break; case WAYPOINT_MOVE_TYPE_TAKEOFF: init.SetAnimation(Movement::ToFly); break; case WAYPOINT_MOVE_TYPE_RUN: init.SetWalk(false); break; case WAYPOINT_MOVE_TYPE_WALK: init.SetWalk(true); break; } if (finalOrient != 0.0f) init.SetFacing(finalOrient); init.Launch(); //Call for creature group update if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature) creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z); return true; }