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 void Initialize (Unit *)=0
 
virtual void Finalize (Unit *)=0
 
virtual void Reset (Unit *)=0
 
virtual bool Update (Unit *, uint32 time_diff)=0
 
virtual MovementGeneratorType GetMovementGeneratorType ()=0
 
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. More...
 
uint32 _endMapId
 Y coord of last node location. More...
 
uint32 _preloadTargetNode
 map Id of last node location More...
 
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 }
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:46
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

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 
)
514{
515 if (uint32 eventid = departure ? node->departureEventID : node->arrivalEventID)
516 {
517 LOG_DEBUG("maps.script", "Taxi {} event {} of node {} of path {} for player {}", departure ? "departure" : "arrival", eventid, node->index, node->path, player->GetName());
518 player->GetMap()->ScriptsStart(sEventScripts, eventid, player, player);
519 }
520}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
std::uint32_t uint32
Definition: Define.h:107
ScriptMapMap sEventScripts
Definition: ObjectMgr.cpp:60
Map * GetMap() const
Definition: Object.h:536
std::string const & GetName() const
Definition: Object.h:463
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

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

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)
394{
395 Reset(player);
397}
void Reset(Unit *u) override
Definition: MovementGenerator.h:70
void InitEndGridInfo()
Definition: WaypointMovementGenerator.cpp:531

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

◆ DoReset()

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

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

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

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 
)
523{
525 x = node->x;
526 y = node->y;
527 z = node->z;
528 return true;
529}
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

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

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 ( )
555{
556 // used to preload the final grid where the flightmaster is
557 Map* endMap = sMapMgr->FindBaseNonInstanceMap(_endMapId);
558
559 // Load the grid
560 if (endMap)
561 {
562 LOG_DEBUG("misc", "Preloading grid ({}, {}) for map {} at node index {}/{}", _endGridX, _endGridY, _endMapId, _preloadTargetNode, (uint32)(i_path.size() - 1));
563 endMap->LoadGrid(_endGridX, _endGridY);
564 }
565 else
566 {
567 LOG_DEBUG("misc", "Unable to determine map to preload flightmaster grid");
568 }
569}
#define sMapMgr
Definition: MapMgr.h:219
Definition: Map.h:311
void LoadGrid(float x, float y)
Definition: Map.cpp:495

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

Referenced by DoUpdate().

◆ SetCurrentNodeAfterTeleport()

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

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().