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 
)
460{
461 if (uint32 eventid = departure ? node->departureEventID : node->arrivalEventID)
462 {
463 LOG_DEBUG("maps.script", "Taxi {} event {} of node {} of path {} for player {}", departure ? "departure" : "arrival", eventid, node->index, node->path, player->GetName().c_str());
464 player->GetMap()->ScriptsStart(sEventScripts, eventid, player, player);
465 }
466}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
ScriptMapMap sEventScripts
Definition: ObjectMgr.cpp:60
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:34

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)
346{
347 // remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack)
349
351 player->Dismount();
353
354 if (player->m_taxi.empty())
355 {
357 // update z position to ground and orientation for landing point
358 // this prevent cheating with landing point at lags
359 // when client side flight end early in comparison server side
360 player->StopMoving();
361
362 // When the player reaches the last flight point, teleport to destination taxi node location
363 player->SetFallInformation(GameTime::GetGameTime().count(), player->GetPositionZ());
364 }
365
367}
@ 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:1092
void SetFallInformation(uint32 time, float z)
Definition: Player.h:2285
PlayerTaxi m_taxi
Definition: Player.h:1123
bool empty() const
Definition: PlayerTaxi.h:74
void ClearTaxiDestinations()
Definition: PlayerTaxi.h:62
void ClearUnitState(uint32 f)
Definition: Unit.h:1399
void Dismount()
Definition: Unit.cpp:13435
void StopMoving()
Definition: Unit.cpp:16824
HostileRefMgr & getHostileRefMgr()
Definition: Unit.h:2149
void RemoveUnitFlag(UnitFlags flags)
Definition: Unit.h:1482

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)
340{
341 Reset(player);
343}
void Reset(Unit *u) override
Definition: MovementGenerator.h:72
void InitEndGridInfo()
Definition: WaypointMovementGenerator.cpp:477

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

◆ DoReset()

void FlightPathMovementGenerator::DoReset ( Player player)
372{
373 uint32 end = GetPathAtMapEnd();
374 uint32 currentNodeId = GetCurrentNode();
375
376 if (currentNodeId == end)
377 {
378 LOG_DEBUG("movement.flightpath", "FlightPathMovementGenerator::DoReset: trying to start a flypath from the end point. {}", player->GetGUID().ToString().c_str());
379 return;
380 }
381
385
386 Movement::MoveSplineInit init(player);
387 // Providing a starting vertex since the taxi paths do not provide such
388 init.Path().push_back(G3D::Vector3(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ()));
389 for (uint32 i = currentNodeId; i != end; ++i)
390 {
391 G3D::Vector3 vertice(i_path[i]->x, i_path[i]->y, i_path[i]->z);
392 init.Path().push_back(vertice);
393 }
394 init.SetFirstPointId(GetCurrentNode());
395 init.SetFly();
396 init.SetVelocity(PLAYER_FLIGHT_SPEED);
397 init.Launch();
398}
#define PLAYER_FLIGHT_SPEED
Definition: WaypointMovementGenerator.cpp:369
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:1397
void SetUnitFlag(UnitFlags flags)
Definition: Unit.h:1481
TaxiPathNodeList i_path
Definition: WaypointMovementGenerator.h:45
uint32 GetCurrentNode() const
Definition: WaypointMovementGenerator.h:42
uint32 GetPathAtMapEnd() const
Definition: WaypointMovementGenerator.cpp:270
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   
)
401{
402 // skipping the first spline path point because it's our starting point and not a taxi path point
403 uint32 pointId = player->movespline->currentPathIdx() <= 0 ? 0 : player->movespline->currentPathIdx() - 1;
404 if (pointId > i_currentNode && i_currentNode < i_path.size() - 1)
405 {
406 bool departureEvent = true;
407 do
408 {
409 ASSERT(i_currentNode < i_path.size(), "Point Id: {}\n{}", pointId, player->GetGUID().ToString().c_str());
410
411 DoEventIfAny(player, i_path[i_currentNode], departureEvent);
412 while (!_pointsForPathSwitch.empty() && _pointsForPathSwitch.front().PathIndex <= i_currentNode)
413 {
414 _pointsForPathSwitch.pop_front();
415 player->m_taxi.NextTaxiDestination();
416 if (!_pointsForPathSwitch.empty())
417 {
419 player->ModifyMoney(-_pointsForPathSwitch.front().Cost);
420 }
421 }
422
423 if (pointId == i_currentNode)
424 {
425 break;
426 }
427
429 {
431 }
432
433 i_currentNode += departureEvent ? 1 : 0;
434 departureEvent = !departureEvent;
435 } while (i_currentNode < i_path.size() - 1);
436 }
437
438 return i_currentNode < (i_path.size() - 1);
439}
#define ASSERT
Definition: Errors.h:68
@ ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING
Definition: DBCEnums.h:182
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, Unit *unit=nullptr)
Definition: PlayerUpdates.cpp:2128
bool ModifyMoney(int32 amount, bool sendError=true)
Definition: Player.cpp:11409
uint32 NextTaxiDestination()
Definition: PlayerTaxi.h:67
Movement::MoveSpline * movespline
Definition: Unit.h:2440
std::deque< TaxiNodeChangeInfo > _pointsForPathSwitch
Definition: WaypointMovementGenerator.h:145
void PreloadEndGrid()
Definition: WaypointMovementGenerator.cpp:500
void DoEventIfAny(Player *player, TaxiPathNodeEntry const *node, bool departure)
Definition: WaypointMovementGenerator.cpp:459
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
271{
272 if (i_currentNode >= i_path.size())
273 {
274 return i_path.size();
275 }
276
277 uint32 curMapId = i_path[i_currentNode]->mapid;
278 for (uint32 i = i_currentNode; i < i_path.size(); ++i)
279 {
280 if (i_path[i]->mapid != curMapId)
281 {
282 return i;
283 }
284 }
285
286 return i_path.size();
287}

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 
)
469{
471 x = node->x;
472 y = node->y;
473 z = node->z;
474 return true;
475}
Definition: DBCStructure.h:1949
float y
Definition: DBCStructure.h:1955
float x
Definition: DBCStructure.h:1954
float z
Definition: DBCStructure.h:1956

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

478{
481 uint32 nodeCount = i_path.size();
482 _endMapId = i_path[nodeCount - 1]->mapid;
483
484 // pussywizard:
485 {
486 _preloadTargetNode = nodeCount - 1;
487 for (uint8 i = 3; i > 0; --i)
488 if (nodeCount >= i && _endMapId == i_path[nodeCount - i]->mapid)
489 {
490 _preloadTargetNode = nodeCount - i;
491 break;
492 }
493 //_preloadTargetNode = nodeCount - 3; // pussywizard: this can be on other map
494 }
495
496 _endGridX = i_path[nodeCount - 1]->x;
497 _endGridY = i_path[nodeCount - 1]->y;
498}
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)
297{
298 _pointsForPathSwitch.clear();
299 std::deque<uint32> const& taxi = player->m_taxi.GetPath();
300 float discount = player->GetReputationPriceDiscount(player->m_taxi.GetFlightMasterFactionTemplate());
301 for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
302 {
303 uint32 path, cost;
304 sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
305 if (path > sTaxiPathNodesByPath.size())
306 {
307 return;
308 }
309
310 TaxiPathNodeList const& nodes = sTaxiPathNodesByPath[path];
311 if (!nodes.empty())
312 {
313 TaxiPathNodeEntry const* start = nodes[0];
314 TaxiPathNodeEntry const* end = nodes[nodes.size() - 1];
315 bool passedPreviousSegmentProximityCheck = false;
316 for (uint32 i = 0; i < nodes.size(); ++i)
317 {
318 if (passedPreviousSegmentProximityCheck || !src || i_path.empty() || IsNodeIncludedInShortenedPath(i_path[i_path.size() - 1], nodes[i]))
319 {
320 if ((!src || (IsNodeIncludedInShortenedPath(start, nodes[i]) && i >= 2)) &&
321 (dst == taxi.size() - 1 || (IsNodeIncludedInShortenedPath(end, nodes[i]) && i < nodes.size() - 1)))
322 {
323 passedPreviousSegmentProximityCheck = true;
324 i_path.push_back(nodes[i]);
325 }
326 }
327 else
328 {
329 i_path.pop_back();
330 --_pointsForPathSwitch.back().PathIndex;
331 }
332 }
333 }
334
335 _pointsForPathSwitch.push_back({ uint32(i_path.size() - 1), int32(ceil(cost * discount)) });
336 }
337}
std::int32_t int32
Definition: Define.h:104
TaxiPathNodesByPath sTaxiPathNodesByPath
Definition: DBCStores.cpp:185
#define sObjectMgr
Definition: ObjectMgr.h:1640
bool IsNodeIncludedInShortenedPath(TaxiPathNodeEntry const *p1, TaxiPathNodeEntry const *p2)
Definition: WaypointMovementGenerator.cpp:291
std::vector< TaxiPathNodeEntry const * > TaxiPathNodeList
Definition: DBCStructure.h:2218
float GetReputationPriceDiscount(Creature const *creature) const
Definition: Player.cpp:12237
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 ( )
501{
502 // used to preload the final grid where the flightmaster is
503 Map* endMap = sMapMgr->FindBaseNonInstanceMap(_endMapId);
504
505 // Load the grid
506 if (endMap)
507 {
508 LOG_DEBUG("misc", "Preloading grid ({}, {}) for map %u at node index {}/{}", _endGridX, _endGridY, _endMapId, _preloadTargetNode, (uint32)(i_path.size() - 1));
509 endMap->LoadGrid(_endGridX, _endGridY);
510 }
511 else
512 {
513 LOG_DEBUG("misc", "Unable to determine map to preload flightmaster grid");
514 }
515}
#define sMapMgr
Definition: MapMgr.h:221
Definition: Map.h:312
void LoadGrid(float x, float y)
Definition: Map.cpp:494

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

Referenced by DoUpdate().

◆ SetCurrentNodeAfterTeleport()

void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport ( )
442{
443 if (i_path.empty() || i_currentNode >= i_path.size())
444 {
445 return;
446 }
447
448 uint32 map0 = i_path[i_currentNode]->mapid;
449 for (size_t i = i_currentNode + 1; i < i_path.size(); ++i)
450 {
451 if (i_path[i]->mapid != map0)
452 {
453 i_currentNode = i;
454 return;
455 }
456 }
457}

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