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.
 
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
106 {
107 i_currentNode = startNode;
108 _endGridX = 0.0f;
109 _endGridY = 0.0f;
110 _endMapId = 0;
112 }
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:46
float _endGridY
X coord of last node location.
Definition: WaypointMovementGenerator.h:135
uint32 _preloadTargetNode
map Id of last node location
Definition: WaypointMovementGenerator.h:137
float _endGridX
Definition: WaypointMovementGenerator.h:134
uint32 _endMapId
Y coord of last node location.
Definition: WaypointMovementGenerator.h:136

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 
)
473{
474 if (uint32 eventid = departure ? node->departureEventID : node->arrivalEventID)
475 {
476 LOG_DEBUG("maps.script", "Taxi {} event {} of node {} of path {} for player {}", departure ? "departure" : "arrival", eventid, node->index, node->path, player->GetName());
477 player->GetMap()->ScriptsStart(sEventScripts, eventid, player, player);
478 }
479}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
ScriptMapMap sEventScripts
Definition: ObjectMgr.cpp:58
Map * GetMap() const
Definition: Object.h:517
std::string const & GetName() const
Definition: Object.h:446
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:33

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)
359{
360 // remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack)
362
364 player->Dismount();
366
367 if (player->m_taxi.empty())
368 {
370 // update z position to ground and orientation for landing point
371 // this prevent cheating with landing point at lags
372 // when client side flight end early in comparison server side
373 player->StopMoving();
374
375 // When the player reaches the last flight point, teleport to destination taxi node location
376 player->SetFallInformation(GameTime::GetGameTime().count(), player->GetPositionZ());
377 }
378
380}
@ PLAYER_FLAGS_TAXI_BENCHMARK
Definition: Player.h:492
@ UNIT_STATE_IN_FLIGHT
Definition: Unit.h:333
@ UNIT_FLAG_TAXI_FLIGHT
Definition: Unit.h:468
@ UNIT_FLAG_DISABLE_MOVE
Definition: Unit.h:450
Seconds GetGameTime()
Definition: GameTime.cpp:38
void setOnlineOfflineState(bool isOnline)
Definition: HostileRefMgr.cpp:98
float GetPositionZ() const
Definition: Position.h:119
void RemovePlayerFlag(PlayerFlags flags)
Definition: Player.h:1102
void SetFallInformation(uint32 time, float z)
Definition: Player.h:2298
PlayerTaxi m_taxi
Definition: Player.h:1133
bool empty() const
Definition: PlayerTaxi.h:74
void ClearTaxiDestinations()
Definition: PlayerTaxi.h:62
void ClearUnitState(uint32 f)
Definition: Unit.h:1411
void Dismount()
Definition: Unit.cpp:13518
void StopMoving()
Definition: Unit.cpp:16918
HostileRefMgr & getHostileRefMgr()
Definition: Unit.h:2163
void RemoveUnitFlag(UnitFlags flags)
Definition: Unit.h:1496

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)
353{
354 Reset(player);
356}
void Reset(Unit *u) override
Definition: MovementGenerator.h:72
void InitEndGridInfo()
Definition: WaypointMovementGenerator.cpp:490

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

◆ DoReset()

void FlightPathMovementGenerator::DoReset ( Player player)
385{
386 uint32 end = GetPathAtMapEnd();
387 uint32 currentNodeId = GetCurrentNode();
388
389 if (currentNodeId == end)
390 {
391 LOG_DEBUG("movement.flightpath", "FlightPathMovementGenerator::DoReset: trying to start a flypath from the end point. {}", player->GetGUID().ToString());
392 return;
393 }
394
398
399 Movement::MoveSplineInit init(player);
400 // Providing a starting vertex since the taxi paths do not provide such
401 init.Path().push_back(G3D::Vector3(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()));
402 for (uint32 i = currentNodeId; i != end; ++i)
403 {
404 G3D::Vector3 vertice(i_path[i]->x, i_path[i]->y, i_path[i]->z);
405 init.Path().push_back(vertice);
406 }
407 init.SetFirstPointId(GetCurrentNode());
408 init.SetFly();
409 init.SetVelocity(PLAYER_FLIGHT_SPEED);
410 init.Launch();
411}
#define PLAYER_FLIGHT_SPEED
Definition: WaypointMovementGenerator.cpp:382
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
std::string ToString() const
Definition: ObjectGuid.cpp:47
float GetPositionX() const
Definition: Position.h:117
float GetPositionY() const
Definition: Position.h:118
void AddUnitState(uint32 f)
Definition: Unit.h:1409
void SetUnitFlag(UnitFlags flags)
Definition: Unit.h:1495
TaxiPathNodeList i_path
Definition: WaypointMovementGenerator.h:45
uint32 GetCurrentNode() const
Definition: WaypointMovementGenerator.h:42
uint32 GetPathAtMapEnd() const
Definition: WaypointMovementGenerator.cpp:283
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   
)
414{
415 // skipping the first spline path point because it's our starting point and not a taxi path point
416 uint32 pointId = player->movespline->currentPathIdx() <= 0 ? 0 : player->movespline->currentPathIdx() - 1;
417 if (pointId > i_currentNode && i_currentNode < i_path.size() - 1)
418 {
419 bool departureEvent = true;
420 do
421 {
422 ASSERT(i_currentNode < i_path.size(), "Point Id: {}\n{}", pointId, player->GetGUID().ToString());
423
424 DoEventIfAny(player, i_path[i_currentNode], departureEvent);
425 while (!_pointsForPathSwitch.empty() && _pointsForPathSwitch.front().PathIndex <= i_currentNode)
426 {
427 _pointsForPathSwitch.pop_front();
428 player->m_taxi.NextTaxiDestination();
429 if (!_pointsForPathSwitch.empty())
430 {
432 player->ModifyMoney(-_pointsForPathSwitch.front().Cost);
433 }
434 }
435
436 if (pointId == i_currentNode)
437 {
438 break;
439 }
440
442 {
444 }
445
446 i_currentNode += departureEvent ? 1 : 0;
447 departureEvent = !departureEvent;
448 } while (i_currentNode < i_path.size() - 1);
449 }
450
451 return i_currentNode < (i_path.size() - 1);
452}
#define ASSERT
Definition: Errors.h:68
@ ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING
Definition: DBCEnums.h:184
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:11430
uint32 NextTaxiDestination()
Definition: PlayerTaxi.h:67
Movement::MoveSpline * movespline
Definition: Unit.h:2454
std::deque< TaxiNodeChangeInfo > _pointsForPathSwitch
Definition: WaypointMovementGenerator.h:145
void PreloadEndGrid()
Definition: WaypointMovementGenerator.cpp:513
void DoEventIfAny(Player *player, TaxiPathNodeEntry const *node, bool departure)
Definition: WaypointMovementGenerator.cpp:472
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.

118{ return FLIGHT_MOTION_TYPE; }
@ FLIGHT_MOTION_TYPE
Definition: MotionMaster.h:45

References FLIGHT_MOTION_TYPE.

◆ GetPath()

TaxiPathNodeList const & FlightPathMovementGenerator::GetPath ( )
inline

◆ GetPathAtMapEnd()

uint32 FlightPathMovementGenerator::GetPathAtMapEnd ( ) const
284{
285 if (i_currentNode >= i_path.size())
286 {
287 return i_path.size();
288 }
289
290 uint32 curMapId = i_path[i_currentNode]->mapid;
291 for (uint32 i = i_currentNode; i < i_path.size(); ++i)
292 {
293 if (i_path[i]->mapid != curMapId)
294 {
295 return i;
296 }
297 }
298
299 return i_path.size();
300}

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 
)
482{
484 x = node->x;
485 y = node->y;
486 z = node->z;
487 return true;
488}
Definition: DBCStructure.h:1974
float y
Definition: DBCStructure.h:1980
float x
Definition: DBCStructure.h:1979
float z
Definition: DBCStructure.h:1981

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

491{
494 uint32 nodeCount = i_path.size();
495 _endMapId = i_path[nodeCount - 1]->mapid;
496
497 // pussywizard:
498 {
499 _preloadTargetNode = nodeCount - 1;
500 for (uint8 i = 3; i > 0; --i)
501 if (nodeCount >= i && _endMapId == i_path[nodeCount - i]->mapid)
502 {
503 _preloadTargetNode = nodeCount - i;
504 break;
505 }
506 //_preloadTargetNode = nodeCount - 3; // pussywizard: this can be on other map
507 }
508
509 _endGridX = i_path[nodeCount - 1]->x;
510 _endGridY = i_path[nodeCount - 1]->y;
511}
std::uint8_t uint8
Definition: Define.h:110

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

Referenced by DoInitialize().

◆ LoadPath()

void FlightPathMovementGenerator::LoadPath ( Player player)
310{
311 _pointsForPathSwitch.clear();
312 std::deque<uint32> const& taxi = player->m_taxi.GetPath();
313 float discount = player->GetReputationPriceDiscount(player->m_taxi.GetFlightMasterFactionTemplate());
314 for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
315 {
316 uint32 path, cost;
317 sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
318 if (path > sTaxiPathNodesByPath.size())
319 {
320 return;
321 }
322
323 TaxiPathNodeList const& nodes = sTaxiPathNodesByPath[path];
324 if (!nodes.empty())
325 {
326 TaxiPathNodeEntry const* start = nodes[0];
327 TaxiPathNodeEntry const* end = nodes[nodes.size() - 1];
328 bool passedPreviousSegmentProximityCheck = false;
329 for (uint32 i = 0; i < nodes.size(); ++i)
330 {
331 if (passedPreviousSegmentProximityCheck || !src || i_path.empty() || IsNodeIncludedInShortenedPath(i_path[i_path.size() - 1], nodes[i]))
332 {
333 if ((!src || (IsNodeIncludedInShortenedPath(start, nodes[i]) && i >= 2)) &&
334 (dst == taxi.size() - 1 || (IsNodeIncludedInShortenedPath(end, nodes[i]) && i < nodes.size() - 1)))
335 {
336 passedPreviousSegmentProximityCheck = true;
337 i_path.push_back(nodes[i]);
338 }
339 }
340 else
341 {
342 i_path.pop_back();
343 --_pointsForPathSwitch.back().PathIndex;
344 }
345 }
346 }
347
348 _pointsForPathSwitch.push_back({ uint32(i_path.size() - 1), int32(ceil(cost * discount)) });
349 }
350}
std::int32_t int32
Definition: Define.h:104
TaxiPathNodesByPath sTaxiPathNodesByPath
Definition: DBCStores.cpp:186
#define sObjectMgr
Definition: ObjectMgr.h:1640
bool IsNodeIncludedInShortenedPath(TaxiPathNodeEntry const *p1, TaxiPathNodeEntry const *p2)
Definition: WaypointMovementGenerator.cpp:304
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition: DBCStructure.h:2243
float GetReputationPriceDiscount(Creature const *creature) const
Definition: Player.cpp:12257
std::deque< uint32 > const & GetPath() const
Definition: PlayerTaxi.h:73
FactionTemplateEntry const * GetFlightMasterFactionTemplate() const
Definition: PlayerTaxi.cpp:235

References _pointsForPathSwitch, PlayerTaxi::GetFlightMasterFactionTemplate(), PlayerTaxi::GetPath(), Player::GetReputationPriceDiscount(), PathMovementBase< Player, TaxiPathNodeList >::i_path, IsNodeIncludedInShortenedPath(), Player::m_taxi, sObjectMgr, and sTaxiPathNodesByPath.

Referenced by MotionMaster::MoveTaxiFlight().

◆ PreloadEndGrid()

void FlightPathMovementGenerator::PreloadEndGrid ( )
514{
515 // used to preload the final grid where the flightmaster is
516 Map* endMap = sMapMgr->FindBaseNonInstanceMap(_endMapId);
517
518 // Load the grid
519 if (endMap)
520 {
521 LOG_DEBUG("misc", "Preloading grid ({}, {}) for map {} at node index {}/{}", _endGridX, _endGridY, _endMapId, _preloadTargetNode, (uint32)(i_path.size() - 1));
522 endMap->LoadGrid(_endGridX, _endGridY);
523 }
524 else
525 {
526 LOG_DEBUG("misc", "Unable to determine map to preload flightmaster grid");
527 }
528}
#define sMapMgr
Definition: MapMgr.h:221
Definition: Map.h:313
void LoadGrid(float x, float y)
Definition: Map.cpp:492

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

Referenced by DoUpdate().

◆ SetCurrentNodeAfterTeleport()

void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport ( )
455{
456 if (i_path.empty() || i_currentNode >= i_path.size())
457 {
458 return;
459 }
460
461 uint32 map0 = i_path[i_currentNode]->mapid;
462 for (size_t i = i_currentNode + 1; i < i_path.size(); ++i)
463 {
464 if (i_path[i]->mapid != map0)
465 {
466 i_currentNode = i;
467 return;
468 }
469 }
470}

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