AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
FlightPathMovementGenerator Class Reference

#include "WaypointMovementGenerator.h"

Inheritance diagram for FlightPathMovementGenerator:
MovementGeneratorMedium< Player, FlightPathMovementGenerator > PathMovementBase< Player, TaxiPathNodeList > MovementGenerator

Classes

struct  TaxiNodeChangeInfo
 node index where preloading starts More...
 

Public Member Functions

 FlightPathMovementGenerator (uint32 startNode=0)
 
void LoadPath (Player *player)
 
void DoInitialize (Player *)
 
void DoReset (Player *)
 
void DoFinalize (Player *)
 
bool DoUpdate (Player *, uint32)
 
MovementGeneratorType GetMovementGeneratorType () override
 
TaxiPathNodeList const & GetPath ()
 
uint32 GetPathAtMapEnd () const
 
bool HasArrived () const
 
void SetCurrentNodeAfterTeleport ()
 
void SkipCurrentNode ()
 
void DoEventIfAny (Player *player, TaxiPathNodeEntry const *node, bool departure)
 
bool GetResetPos (Player *, float &x, float &y, float &z)
 
void InitEndGridInfo ()
 
void PreloadEndGrid ()
 
- Public Member Functions inherited from MovementGeneratorMedium< Player, FlightPathMovementGenerator >
void Initialize (Unit *u) override
 
void Finalize (Unit *u) override
 
void Reset (Unit *u) override
 
bool Update (Unit *u, uint32 time_diff) override
 
- Public Member Functions inherited from MovementGenerator
virtual ~MovementGenerator ()
 
virtual uint32 GetSplineId () const
 
virtual void unitSpeedChanged ()
 
virtual void Pause (uint32)
 
virtual void Resume (uint32)
 
virtual bool GetResetPosition (float &, float &, float &)
 
- Public Member Functions inherited from PathMovementBase< Player, TaxiPathNodeList >
 PathMovementBase ()
 
 PathMovementBase (TaxiPathNodeList path)
 
virtual ~PathMovementBase ()
 
uint32 GetCurrentNode () const
 

Private Attributes

float _endGridX
 
float _endGridY
 X coord of last node location.
 
uint32 _endMapId
 Y coord of last node location.
 
uint32 _preloadTargetNode
 map Id of last node location
 
std::deque< TaxiNodeChangeInfo_pointsForPathSwitch
 

Additional Inherited Members

- Protected Attributes inherited from PathMovementBase< Player, TaxiPathNodeList >
TaxiPathNodeList i_path
 
uint32 i_currentNode
 

Detailed Description

FlightPathMovementGenerator generates movement of the player for the paths and hence generates ground and activities for the player.

Constructor & Destructor Documentation

◆ FlightPathMovementGenerator()

FlightPathMovementGenerator::FlightPathMovementGenerator ( uint32  startNode = 0)
inlineexplicit
104 {
105 i_currentNode = startNode;
106 _endGridX = 0.0f;
107 _endGridY = 0.0f;
108 _endMapId = 0;
110 }
float _endGridY
X coord of last node location.
Definition WaypointMovementGenerator.h:133
uint32 _preloadTargetNode
map Id of last node location
Definition WaypointMovementGenerator.h:135
float _endGridX
Definition WaypointMovementGenerator.h:132
uint32 _endMapId
Y coord of last node location.
Definition WaypointMovementGenerator.h:134
uint32 i_currentNode
Definition WaypointMovementGenerator.h:46

References _endGridX, _endGridY, _endMapId, _preloadTargetNode, and PathMovementBase< Player, TaxiPathNodeList >::i_currentNode.

Member Function Documentation

◆ DoEventIfAny()

void FlightPathMovementGenerator::DoEventIfAny ( Player player,
TaxiPathNodeEntry const *  node,
bool  departure 
)
757{
758 if (uint32 eventid = departure ? node->departureEventID : node->arrivalEventID)
759 {
760 LOG_DEBUG("maps.script", "Taxi {} event {} of node {} of path {} for player {}", departure ? "departure" : "arrival", eventid, node->index, node->path, player->GetName());
761 player->GetMap()->ScriptsStart(sEventScripts, eventid, player, player);
762 }
763}
std::uint32_t uint32
Definition Define.h:107
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
ScriptMapMap sEventScripts
Definition ObjectMgr.cpp:61
void ScriptsStart(std::map< uint32, std::multimap< uint32, ScriptInfo > > const &scripts, uint32 id, Object *source, Object *target)
Put scripts in the execution queue.
Definition MapScripts.cpp:31
Map * GetMap() const
Definition Object.h:625
bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:264

References TaxiPathNodeEntry::arrivalEventID, TaxiPathNodeEntry::departureEventID, WorldObject::GetMap(), WorldObject::GetName(), TaxiPathNodeEntry::index, LOG_DEBUG, TaxiPathNodeEntry::path, Map::ScriptsStart(), and sEventScripts.

Referenced by DoUpdate().

◆ DoFinalize()

void FlightPathMovementGenerator::DoFinalize ( Player player)
641{
642 // remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack)
644
646 player->Dismount();
648 player->UpdatePvPState(); // to account for cases such as flying into a PvP territory, as it does not flag on the way in
649
650 if (player->m_taxi.empty())
651 {
652 // update z position to ground and orientation for landing point
653 // this prevent cheating with landing point at lags
654 // when client side flight end early in comparison server side
655 player->StopMoving();
656
657 // When the player reaches the last flight point, teleport to destination taxi node location
658 player->SetFallInformation(GameTime::GetGameTime().count(), player->GetPositionZ());
659 }
660
662}
@ PLAYER_FLAGS_TAXI_BENCHMARK
Definition Player.h:476
@ UNIT_STATE_IN_FLIGHT
Definition UnitDefines.h:181
@ UNIT_FLAG_TAXI_FLIGHT
Definition UnitDefines.h:277
@ UNIT_FLAG_DISABLE_MOVE
Definition UnitDefines.h:259
bool empty() const
Definition PlayerTaxi.h:76
void ClearTaxiDestinations()
Definition PlayerTaxi.h:61
void RemovePlayerFlag(PlayerFlags flags)
Definition Player.h:1125
void SetFallInformation(uint32 time, float z)
Definition Player.h:2371
void UpdatePvPState()
Definition PlayerUpdates.cpp:1432
PlayerTaxi m_taxi
Definition Player.h:1158
void ClearUnitState(uint32 f)
Definition Unit.h:737
void Dismount()
Definition Unit.cpp:10539
void StopMoving()
Definition Unit.cpp:12997
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:749
Seconds GetGameTime()
Definition GameTime.cpp:38
float GetPositionZ() const
Definition Position.h:123

References PlayerTaxi::ClearTaxiDestinations(), Unit::ClearUnitState(), Unit::Dismount(), PlayerTaxi::empty(), GameTime::GetGameTime(), Position::GetPositionZ(), Player::m_taxi, PLAYER_FLAGS_TAXI_BENCHMARK, Player::RemovePlayerFlag(), Unit::RemoveUnitFlag(), Player::SetFallInformation(), Unit::StopMoving(), UNIT_FLAG_DISABLE_MOVE, UNIT_FLAG_TAXI_FLIGHT, UNIT_STATE_IN_FLIGHT, and Player::UpdatePvPState().

◆ DoInitialize()

void FlightPathMovementGenerator::DoInitialize ( Player player)
635{
636 Reset(player);
638}
void InitEndGridInfo()
Definition WaypointMovementGenerator.cpp:774
void Reset(Unit *u) override
Definition MovementGenerator.h:70

References InitEndGridInfo(), and MovementGeneratorMedium< Player, FlightPathMovementGenerator >::Reset().

◆ DoReset()

void FlightPathMovementGenerator::DoReset ( Player player)
667{
668 uint32 end = GetPathAtMapEnd();
669 uint32 currentNodeId = GetCurrentNode();
670
671 if (currentNodeId == end)
672 {
673 LOG_DEBUG("movement.flightpath", "FlightPathMovementGenerator::DoReset: trying to start a flypath from the end point. {}", player->GetGUID().ToString());
674 return;
675 }
676
677 if (player->pvpInfo.EndTimer)
678 player->UpdatePvP(false, true); // PvP flag timer immediately ends when starting taxi
679
682
683 Movement::MoveSplineInit init(player);
684 // Providing a starting vertex since the taxi paths do not provide such
685 init.Path().push_back(G3D::Vector3(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()));
686 for (uint32 i = currentNodeId; i != end; ++i)
687 {
688 G3D::Vector3 vertice(i_path[i]->x, i_path[i]->y, i_path[i]->z);
689 init.Path().push_back(vertice);
690 }
691 init.SetFirstPointId(GetCurrentNode());
692 init.SetFly();
693 init.SetVelocity(PLAYER_FLIGHT_SPEED);
694 init.Launch();
695}
#define PLAYER_FLIGHT_SPEED
Definition WaypointMovementGenerator.cpp:664
uint32 GetPathAtMapEnd() const
Definition WaypointMovementGenerator.cpp:544
Definition MoveSplineInit.h:63
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
TaxiPathNodeList i_path
Definition WaypointMovementGenerator.h:45
uint32 GetCurrentNode() const
Definition WaypointMovementGenerator.h:42
void UpdatePvP(bool state, bool _override=false)
Definition PlayerUpdates.cpp:1525
PvPInfo pvpInfo
Definition Player.h:1863
void AddUnitState(uint32 f)
Definition Unit.h:735
void SetUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:748
float GetPositionX() const
Definition Position.h:121
float GetPositionY() const
Definition Position.h:122
time_t EndTimer
‍Marks if player is in an FFAPvP area (such as Gurubashi Arena)
Definition Player.h:351

References Unit::AddUnitState(), PvPInfo::EndTimer, PathMovementBase< Player, TaxiPathNodeList >::GetCurrentNode(), Object::GetGUID(), GetPathAtMapEnd(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), PathMovementBase< Player, TaxiPathNodeList >::i_path, Movement::MoveSplineInit::Launch(), LOG_DEBUG, Movement::MoveSplineInit::Path(), PLAYER_FLIGHT_SPEED, Player::pvpInfo, Movement::MoveSplineInit::SetFirstPointId(), Movement::MoveSplineInit::SetFly(), Unit::SetUnitFlag(), Movement::MoveSplineInit::SetVelocity(), ObjectGuid::ToString(), UNIT_FLAG_DISABLE_MOVE, UNIT_FLAG_TAXI_FLIGHT, UNIT_STATE_IN_FLIGHT, and Player::UpdatePvP().

◆ DoUpdate()

bool FlightPathMovementGenerator::DoUpdate ( Player player,
uint32   
)
698{
699 // skipping the first spline path point because it's our starting point and not a taxi path point
700 uint32 pointId = player->movespline->currentPathIdx() <= 0 ? 0 : player->movespline->currentPathIdx() - 1;
701 if (pointId > i_currentNode && i_currentNode < i_path.size() - 1)
702 {
703 bool departureEvent = true;
704 do
705 {
706 ASSERT(i_currentNode < i_path.size(), "Point Id: {}\n{}", pointId, player->GetGUID().ToString());
707
708 DoEventIfAny(player, i_path[i_currentNode], departureEvent);
709 while (!_pointsForPathSwitch.empty() && _pointsForPathSwitch.front().PathIndex <= i_currentNode)
710 {
711 _pointsForPathSwitch.pop_front();
712 player->m_taxi.NextTaxiDestination();
713 if (!_pointsForPathSwitch.empty())
714 {
716 player->ModifyMoney(-_pointsForPathSwitch.front().Cost);
717 }
718 }
719
720 if (pointId == i_currentNode)
721 {
722 break;
723 }
724
726 {
728 }
729
730 i_currentNode += departureEvent ? 1 : 0;
731 departureEvent = !departureEvent;
732 } while (i_currentNode < i_path.size() - 1);
733 }
734
735 return i_currentNode < (i_path.size() - 1);
736}
@ ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING
Definition DBCEnums.h:176
#define ASSERT
Definition Errors.h:68
std::deque< TaxiNodeChangeInfo > _pointsForPathSwitch
Definition WaypointMovementGenerator.h:143
void PreloadEndGrid()
Definition WaypointMovementGenerator.cpp:797
void DoEventIfAny(Player *player, TaxiPathNodeEntry const *node, bool departure)
Definition WaypointMovementGenerator.cpp:756
int32 currentPathIdx() const
Definition MoveSpline.cpp:318
uint32 NextTaxiDestination()
Definition PlayerTaxi.h:66
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, Unit *unit=nullptr)
Definition PlayerUpdates.cpp:2169
bool ModifyMoney(int32 amount, bool sendError=true)
Definition Player.cpp:11424
Movement::MoveSpline * movespline
Definition Unit.h:2114

References _pointsForPathSwitch, _preloadTargetNode, ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING, ASSERT, Movement::MoveSpline::currentPathIdx(), DoEventIfAny(), Object::GetGUID(), PathMovementBase< Player, TaxiPathNodeList >::i_currentNode, PathMovementBase< Player, TaxiPathNodeList >::i_path, Player::m_taxi, Player::ModifyMoney(), Unit::movespline, PlayerTaxi::NextTaxiDestination(), PreloadEndGrid(), ObjectGuid::ToString(), and Player::UpdateAchievementCriteria().

◆ GetMovementGeneratorType()

MovementGeneratorType FlightPathMovementGenerator::GetMovementGeneratorType ( )
inlineoverridevirtual

Implements MovementGenerator.

116{ return FLIGHT_MOTION_TYPE; }
@ FLIGHT_MOTION_TYPE
Definition MotionMaster.h:47

References FLIGHT_MOTION_TYPE.

◆ GetPath()

TaxiPathNodeList const & FlightPathMovementGenerator::GetPath ( )
inline

◆ GetPathAtMapEnd()

uint32 FlightPathMovementGenerator::GetPathAtMapEnd ( ) const
545{
546 if (i_currentNode >= i_path.size())
547 {
548 return i_path.size();
549 }
550
551 uint32 curMapId = i_path[i_currentNode]->mapid;
552 for (uint32 i = i_currentNode; i < i_path.size(); ++i)
553 {
554 if (i_path[i]->mapid != curMapId)
555 {
556 return i;
557 }
558 }
559
560 return i_path.size();
561}

References PathMovementBase< Player, TaxiPathNodeList >::i_currentNode, and PathMovementBase< Player, TaxiPathNodeList >::i_path.

Referenced by DoReset().

◆ GetResetPos()

bool FlightPathMovementGenerator::GetResetPos ( Player ,
float &  x,
float &  y,
float &  z 
)
766{
768 x = node->x;
769 y = node->y;
770 z = node->z;
771 return true;
772}
Definition DBCStructure.h:1973
float y
Definition DBCStructure.h:1979
float x
Definition DBCStructure.h:1978
float z
Definition DBCStructure.h:1980

References PathMovementBase< Player, TaxiPathNodeList >::i_currentNode, PathMovementBase< Player, TaxiPathNodeList >::i_path, TaxiPathNodeEntry::x, TaxiPathNodeEntry::y, and TaxiPathNodeEntry::z.

◆ HasArrived()

bool FlightPathMovementGenerator::HasArrived ( ) const
inline

◆ InitEndGridInfo()

void FlightPathMovementGenerator::InitEndGridInfo ( )

Storage to preload flightmaster grid at end of flight. For multi-stop flights, this will be reinitialized for each flightmaster at the end of each spline (or stop) in the flight.

Number of nodes in path.

MapId of last node

775{
778 uint32 nodeCount = i_path.size();
779 _endMapId = i_path[nodeCount - 1]->mapid;
780
781 // pussywizard:
782 {
783 _preloadTargetNode = nodeCount - 1;
784 for (uint8 i = 3; i > 0; --i)
785 if (nodeCount >= i && _endMapId == i_path[nodeCount - i]->mapid)
786 {
787 _preloadTargetNode = nodeCount - i;
788 break;
789 }
790 //_preloadTargetNode = nodeCount - 3; // pussywizard: this can be on other map
791 }
792
793 _endGridX = i_path[nodeCount - 1]->x;
794 _endGridY = i_path[nodeCount - 1]->y;
795}
std::uint8_t uint8
Definition Define.h:109

References _endGridX, _endGridY, _endMapId, _preloadTargetNode, and PathMovementBase< Player, TaxiPathNodeList >::i_path.

Referenced by DoInitialize().

◆ LoadPath()

void FlightPathMovementGenerator::LoadPath ( Player player)
571{
572 _pointsForPathSwitch.clear();
573 std::deque<uint32> const& taxi = player->m_taxi.GetPath();
574 float discount = player->GetReputationPriceDiscount(player->m_taxi.GetFlightMasterFactionTemplate());
575 for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
576 {
577 uint32 path, cost;
578 sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
579 if (path > sTaxiPathNodesByPath.size())
580 {
581 return;
582 }
583
584 TaxiPathNodeList const& nodes = sTaxiPathNodesByPath[path];
585 if (!nodes.empty())
586 {
587 TaxiPathNodeEntry const* start = nodes[0];
588 TaxiPathNodeEntry const* end = nodes[nodes.size() - 1];
589 bool passedPreviousSegmentProximityCheck = false;
590 for (uint32 i = 0; i < nodes.size(); ++i)
591 {
592 if (passedPreviousSegmentProximityCheck || !src || i_path.empty() || IsNodeIncludedInShortenedPath(i_path[i_path.size() - 1], nodes[i]))
593 {
594 if ((!src || (IsNodeIncludedInShortenedPath(start, nodes[i]) && i >= 2)) &&
595 (dst == taxi.size() - 1 || (IsNodeIncludedInShortenedPath(end, nodes[i]) && i < nodes.size() - 1)))
596 {
597 passedPreviousSegmentProximityCheck = true;
598 i_path.push_back(nodes[i]);
599 }
600 }
601 else
602 {
603 i_path.pop_back();
604 --_pointsForPathSwitch.back().PathIndex;
605 }
606 }
607 }
608
609 _pointsForPathSwitch.push_back({ uint32(i_path.size() - 1), int32(ceil(cost * discount)) });
610 }
611
612 // TODO: fixes crash, but can be handled in a better way once we will know how to reproduce it.
613 if (GetCurrentNode() >= i_path.size())
614 {
615 std::string paths;
616 std::deque<uint32> const& taxi = player->m_taxi.GetPath();
617 for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
618 {
619 uint32 path, cost;
620 sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
621 paths += std::to_string(path) + " ";
622 }
623
624 LOG_ERROR("movement.flightpath", "Failed to build correct path for player: {}. Current node: {}, max nodes: {}. Paths: {}. Player pos: {}.", player->GetGUID().ToString(), GetCurrentNode(), i_path.size(), paths, player->GetPosition().ToString());
625
626 // Lets choose the second last element so that a player would still have some flight.
627 if (i_path.size() >= 2)
628 i_currentNode = uint32(i_path.size() - 2);
629 else
630 i_currentNode = 0;
631 }
632}
TaxiPathNodesByPath sTaxiPathNodesByPath
Definition DBCStores.cpp:187
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition DBCStructure.h:2245
std::int32_t int32
Definition Define.h:103
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define sObjectMgr
Definition ObjectMgr.h:1712
bool IsNodeIncludedInShortenedPath(TaxiPathNodeEntry const *p1, TaxiPathNodeEntry const *p2)
Definition WaypointMovementGenerator.cpp:565
std::deque< uint32 > const & GetPath() const
Definition PlayerTaxi.h:75
FactionTemplateEntry const * GetFlightMasterFactionTemplate() const
Definition PlayerTaxi.cpp:235
float GetReputationPriceDiscount(Creature const *creature) const
Definition Player.cpp:12293
void GetPosition(float &x, float &y) const
Definition Position.h:126

References _pointsForPathSwitch, PathMovementBase< Player, TaxiPathNodeList >::GetCurrentNode(), PlayerTaxi::GetFlightMasterFactionTemplate(), Object::GetGUID(), PlayerTaxi::GetPath(), Position::GetPosition(), Player::GetReputationPriceDiscount(), PathMovementBase< Player, TaxiPathNodeList >::i_currentNode, PathMovementBase< Player, TaxiPathNodeList >::i_path, IsNodeIncludedInShortenedPath(), LOG_ERROR, Player::m_taxi, sObjectMgr, sTaxiPathNodesByPath, and ObjectGuid::ToString().

Referenced by MotionMaster::MoveTaxiFlight().

◆ PreloadEndGrid()

void FlightPathMovementGenerator::PreloadEndGrid ( )
798{
799 // used to preload the final grid where the flightmaster is
800 Map* endMap = sMapMgr->FindBaseNonInstanceMap(_endMapId);
801
802 // Load the grid
803 if (endMap)
804 {
805 LOG_DEBUG("misc", "Preloading grid ({}, {}) for map {} at node index {}/{}", _endGridX, _endGridY, _endMapId, _preloadTargetNode, (uint32)(i_path.size() - 1));
806 endMap->LoadGrid(_endGridX, _endGridY);
807 }
808 else
809 {
810 LOG_DEBUG("misc", "Unable to determine map to preload flightmaster grid");
811 }
812}
#define sMapMgr
Definition MapMgr.h:220
Definition Map.h:164
void LoadGrid(float x, float y)
Definition Map.cpp:212

References _endGridX, _endGridY, _endMapId, _preloadTargetNode, PathMovementBase< Player, TaxiPathNodeList >::i_path, Map::LoadGrid(), LOG_DEBUG, and sMapMgr.

Referenced by DoUpdate().

◆ SetCurrentNodeAfterTeleport()

void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport ( )
739{
740 if (i_path.empty() || i_currentNode >= i_path.size())
741 {
742 return;
743 }
744
745 uint32 map0 = i_path[i_currentNode]->mapid;
746 for (std::size_t i = i_currentNode + 1; i < i_path.size(); ++i)
747 {
748 if (i_path[i]->mapid != map0)
749 {
750 i_currentNode = i;
751 return;
752 }
753 }
754}

References PathMovementBase< Player, TaxiPathNodeList >::i_currentNode, and PathMovementBase< Player, TaxiPathNodeList >::i_path.

◆ SkipCurrentNode()

void FlightPathMovementGenerator::SkipCurrentNode ( )
inline

Member Data Documentation

◆ _endGridX

float FlightPathMovementGenerator::_endGridX
private

◆ _endGridY

float FlightPathMovementGenerator::_endGridY
private

X coord of last node location.

Referenced by FlightPathMovementGenerator(), InitEndGridInfo(), and PreloadEndGrid().

◆ _endMapId

uint32 FlightPathMovementGenerator::_endMapId
private

Y coord of last node location.

Referenced by FlightPathMovementGenerator(), InitEndGridInfo(), and PreloadEndGrid().

◆ _pointsForPathSwitch

std::deque<TaxiNodeChangeInfo> FlightPathMovementGenerator::_pointsForPathSwitch
private

Referenced by DoUpdate(), and LoadPath().

◆ _preloadTargetNode

uint32 FlightPathMovementGenerator::_preloadTargetNode
private

map Id of last node location

Referenced by DoUpdate(), FlightPathMovementGenerator(), InitEndGridInfo(), and PreloadEndGrid().


The documentation for this class was generated from the following files: