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
109 {
110 i_currentNode = startNode;
111 _endGridX = 0.0f;
112 _endGridY = 0.0f;
113 _endMapId = 0;
115 }
float _endGridY
X coord of last node location.
Definition WaypointMovementGenerator.h:138
uint32 _preloadTargetNode
map Id of last node location
Definition WaypointMovementGenerator.h:140
float _endGridX
Definition WaypointMovementGenerator.h:137
uint32 _endMapId
Y coord of last node location.
Definition WaypointMovementGenerator.h:139
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 
)
515{
516 if (uint32 eventid = departure ? node->departureEventID : node->arrivalEventID)
517 {
518 LOG_DEBUG("maps.script", "Taxi {} event {} of node {} of path {} for player {}", departure ? "departure" : "arrival", eventid, node->index, node->path, player->GetName());
519 player->GetMap()->ScriptsStart(sEventScripts, eventid, player, player);
520 }
521}
std::uint32_t uint32
Definition Define.h:107
#define LOG_DEBUG(filterType__,...)
Definition Log.h:169
ScriptMapMap sEventScripts
Definition ObjectMgr.cpp:60
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:536
bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:257

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)
401{
402 // remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack)
404
406 player->Dismount();
408
409 if (player->m_taxi.empty())
410 {
412 // update z position to ground and orientation for landing point
413 // this prevent cheating with landing point at lags
414 // when client side flight end early in comparison server side
415 player->StopMoving();
416
417 // When the player reaches the last flight point, teleport to destination taxi node location
418 player->SetFallInformation(GameTime::GetGameTime().count(), player->GetPositionZ());
419 }
420
422}
@ PLAYER_FLAGS_TAXI_BENCHMARK
Definition Player.h:496
@ UNIT_STATE_IN_FLIGHT
Definition UnitDefines.h:178
@ UNIT_FLAG_TAXI_FLIGHT
Definition UnitDefines.h:270
@ UNIT_FLAG_DISABLE_MOVE
Definition UnitDefines.h:252
void setOnlineOfflineState(bool isOnline)
Definition HostileRefMgr.cpp:98
bool empty() const
Definition PlayerTaxi.h:73
void ClearTaxiDestinations()
Definition PlayerTaxi.h:61
void RemovePlayerFlag(PlayerFlags flags)
Definition Player.h:1127
void SetFallInformation(uint32 time, float z)
Definition Player.h:2344
PlayerTaxi m_taxi
Definition Player.h:1160
void ClearUnitState(uint32 f)
Definition Unit.h:708
void Dismount()
Definition Unit.cpp:13569
void StopMoving()
Definition Unit.cpp:16702
HostileRefMgr & getHostileRefMgr()
Definition Unit.h:916
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:720
Seconds GetGameTime()
Definition GameTime.cpp:38
float GetPositionZ() const
Definition Position.h:123

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

◆ DoInitialize()

void FlightPathMovementGenerator::DoInitialize ( Player player)
395{
396 Reset(player);
398}
void InitEndGridInfo()
Definition WaypointMovementGenerator.cpp:532
void Reset(Unit *u) override
Definition MovementGenerator.h:70

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

◆ DoReset()

void FlightPathMovementGenerator::DoReset ( Player player)
427{
428 uint32 end = GetPathAtMapEnd();
429 uint32 currentNodeId = GetCurrentNode();
430
431 if (currentNodeId == end)
432 {
433 LOG_DEBUG("movement.flightpath", "FlightPathMovementGenerator::DoReset: trying to start a flypath from the end point. {}", player->GetGUID().ToString());
434 return;
435 }
436
440
441 Movement::MoveSplineInit init(player);
442 // Providing a starting vertex since the taxi paths do not provide such
443 init.Path().push_back(G3D::Vector3(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()));
444 for (uint32 i = currentNodeId; i != end; ++i)
445 {
446 G3D::Vector3 vertice(i_path[i]->x, i_path[i]->y, i_path[i]->z);
447 init.Path().push_back(vertice);
448 }
449 init.SetFirstPointId(GetCurrentNode());
450 init.SetFly();
451 init.SetVelocity(PLAYER_FLIGHT_SPEED);
452 init.Launch();
453}
#define PLAYER_FLIGHT_SPEED
Definition WaypointMovementGenerator.cpp:424
uint32 GetPathAtMapEnd() const
Definition WaypointMovementGenerator.cpp:304
Definition MoveSplineInit.h:71
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:112
TaxiPathNodeList i_path
Definition WaypointMovementGenerator.h:45
uint32 GetCurrentNode() const
Definition WaypointMovementGenerator.h:42
void AddUnitState(uint32 f)
Definition Unit.h:706
void SetUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:719
float GetPositionX() const
Definition Position.h:121
float GetPositionY() const
Definition Position.h:122

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

◆ DoUpdate()

bool FlightPathMovementGenerator::DoUpdate ( Player player,
uint32   
)
456{
457 // skipping the first spline path point because it's our starting point and not a taxi path point
458 uint32 pointId = player->movespline->currentPathIdx() <= 0 ? 0 : player->movespline->currentPathIdx() - 1;
459 if (pointId > i_currentNode && i_currentNode < i_path.size() - 1)
460 {
461 bool departureEvent = true;
462 do
463 {
464 ASSERT(i_currentNode < i_path.size(), "Point Id: {}\n{}", pointId, player->GetGUID().ToString());
465
466 DoEventIfAny(player, i_path[i_currentNode], departureEvent);
467 while (!_pointsForPathSwitch.empty() && _pointsForPathSwitch.front().PathIndex <= i_currentNode)
468 {
469 _pointsForPathSwitch.pop_front();
470 player->m_taxi.NextTaxiDestination();
471 if (!_pointsForPathSwitch.empty())
472 {
474 player->ModifyMoney(-_pointsForPathSwitch.front().Cost);
475 }
476 }
477
478 if (pointId == i_currentNode)
479 {
480 break;
481 }
482
484 {
486 }
487
488 i_currentNode += departureEvent ? 1 : 0;
489 departureEvent = !departureEvent;
490 } while (i_currentNode < i_path.size() - 1);
491 }
492
493 return i_currentNode < (i_path.size() - 1);
494}
@ ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING
Definition DBCEnums.h:176
#define ASSERT
Definition Errors.h:68
std::deque< TaxiNodeChangeInfo > _pointsForPathSwitch
Definition WaypointMovementGenerator.h:148
void PreloadEndGrid()
Definition WaypointMovementGenerator.cpp:555
void DoEventIfAny(Player *player, TaxiPathNodeEntry const *node, bool departure)
Definition WaypointMovementGenerator.cpp:514
int32 currentPathIdx() const
Definition MoveSpline.cpp:317
uint32 NextTaxiDestination()
Definition PlayerTaxi.h:66
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, Unit *unit=nullptr)
Definition PlayerUpdates.cpp:2177
bool ModifyMoney(int32 amount, bool sendError=true)
Definition Player.cpp:11576
Movement::MoveSpline * movespline
Definition Unit.h:2029

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.

121{ 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
305{
306 if (i_currentNode >= i_path.size())
307 {
308 return i_path.size();
309 }
310
311 uint32 curMapId = i_path[i_currentNode]->mapid;
312 for (uint32 i = i_currentNode; i < i_path.size(); ++i)
313 {
314 if (i_path[i]->mapid != curMapId)
315 {
316 return i;
317 }
318 }
319
320 return i_path.size();
321}

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 
)
524{
526 x = node->x;
527 y = node->y;
528 z = node->z;
529 return true;
530}
Definition DBCStructure.h:1972
float y
Definition DBCStructure.h:1978
float x
Definition DBCStructure.h:1977
float z
Definition DBCStructure.h:1979

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

533{
536 uint32 nodeCount = i_path.size();
537 _endMapId = i_path[nodeCount - 1]->mapid;
538
539 // pussywizard:
540 {
541 _preloadTargetNode = nodeCount - 1;
542 for (uint8 i = 3; i > 0; --i)
543 if (nodeCount >= i && _endMapId == i_path[nodeCount - i]->mapid)
544 {
545 _preloadTargetNode = nodeCount - i;
546 break;
547 }
548 //_preloadTargetNode = nodeCount - 3; // pussywizard: this can be on other map
549 }
550
551 _endGridX = i_path[nodeCount - 1]->x;
552 _endGridY = i_path[nodeCount - 1]->y;
553}
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)
331{
332 _pointsForPathSwitch.clear();
333 std::deque<uint32> const& taxi = player->m_taxi.GetPath();
334 float discount = player->GetReputationPriceDiscount(player->m_taxi.GetFlightMasterFactionTemplate());
335 for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
336 {
337 uint32 path, cost;
338 sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
339 if (path > sTaxiPathNodesByPath.size())
340 {
341 return;
342 }
343
344 TaxiPathNodeList const& nodes = sTaxiPathNodesByPath[path];
345 if (!nodes.empty())
346 {
347 TaxiPathNodeEntry const* start = nodes[0];
348 TaxiPathNodeEntry const* end = nodes[nodes.size() - 1];
349 bool passedPreviousSegmentProximityCheck = false;
350 for (uint32 i = 0; i < nodes.size(); ++i)
351 {
352 if (passedPreviousSegmentProximityCheck || !src || i_path.empty() || IsNodeIncludedInShortenedPath(i_path[i_path.size() - 1], nodes[i]))
353 {
354 if ((!src || (IsNodeIncludedInShortenedPath(start, nodes[i]) && i >= 2)) &&
355 (dst == taxi.size() - 1 || (IsNodeIncludedInShortenedPath(end, nodes[i]) && i < nodes.size() - 1)))
356 {
357 passedPreviousSegmentProximityCheck = true;
358 i_path.push_back(nodes[i]);
359 }
360 }
361 else
362 {
363 i_path.pop_back();
364 --_pointsForPathSwitch.back().PathIndex;
365 }
366 }
367 }
368
369 _pointsForPathSwitch.push_back({ uint32(i_path.size() - 1), int32(ceil(cost * discount)) });
370 }
371
372 // TODO: fixes crash, but can be handled in a better way once we will know how to reproduce it.
373 if (GetCurrentNode() >= i_path.size())
374 {
375 std::string paths;
376 std::deque<uint32> const& taxi = player->m_taxi.GetPath();
377 for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
378 {
379 uint32 path, cost;
380 sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
381 paths += std::to_string(path) + " ";
382 }
383
384 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());
385
386 // Lets choose the second last element so that a player would still have some flight.
387 if (int(i_path.size()) - 2 >= 0)
388 i_currentNode = uint32(i_path.size() - 2);
389 else
390 i_currentNode = uint32(i_path.size() - 1);
391 }
392}
TaxiPathNodesByPath sTaxiPathNodesByPath
Definition DBCStores.cpp:187
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition DBCStructure.h:2244
std::int32_t int32
Definition Define.h:103
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
#define sObjectMgr
Definition ObjectMgr.h:1636
bool IsNodeIncludedInShortenedPath(TaxiPathNodeEntry const *p1, TaxiPathNodeEntry const *p2)
Definition WaypointMovementGenerator.cpp:325
std::deque< uint32 > const & GetPath() const
Definition PlayerTaxi.h:72
FactionTemplateEntry const * GetFlightMasterFactionTemplate() const
Definition PlayerTaxi.cpp:235
float GetReputationPriceDiscount(Creature const *creature) const
Definition Player.cpp:12397
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 ( )
556{
557 // used to preload the final grid where the flightmaster is
558 Map* endMap = sMapMgr->FindBaseNonInstanceMap(_endMapId);
559
560 // Load the grid
561 if (endMap)
562 {
563 LOG_DEBUG("misc", "Preloading grid ({}, {}) for map {} at node index {}/{}", _endGridX, _endGridY, _endMapId, _preloadTargetNode, (uint32)(i_path.size() - 1));
564 endMap->LoadGrid(_endGridX, _endGridY);
565 }
566 else
567 {
568 LOG_DEBUG("misc", "Unable to determine map to preload flightmaster grid");
569 }
570}
#define sMapMgr
Definition MapMgr.h:220
Definition Map.h:156
void LoadGrid(float x, float y)
Definition Map.cpp:301

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

Referenced by DoUpdate().

◆ SetCurrentNodeAfterTeleport()

void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport ( )
497{
498 if (i_path.empty() || i_currentNode >= i_path.size())
499 {
500 return;
501 }
502
503 uint32 map0 = i_path[i_currentNode]->mapid;
504 for (std::size_t i = i_currentNode + 1; i < i_path.size(); ++i)
505 {
506 if (i_path[i]->mapid != map0)
507 {
508 i_currentNode = i;
509 return;
510 }
511 }
512}

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: