diff options
| author | ccrs <ccrs@users.noreply.github.com> | 2018-06-03 10:06:57 -0700 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-09-28 00:15:13 +0200 |
| commit | 426f9f2f92b26fbb68e7cda9290ccbd586c6af4e (patch) | |
| tree | ede70b7865c2edb58964c7aa668eb1250a5816ab /src/server/game/Entities | |
| parent | 3e0af19b7767d6e71a7467874fdad566cea5ee87 (diff) | |
Core/Movement: MotionMaster reimplementation (#21888)
Internal structure and handling changes, nothing behavioural (or thats the intention at least).
(cherry picked from commit 982643cd96790ffc54e7a3e507469649f3b074d2)
Diffstat (limited to 'src/server/game/Entities')
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 13 | ||||
| -rw-r--r-- | src/server/game/Entities/Creature/CreatureGroups.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 21 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.h | 3 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 36 | ||||
| -rw-r--r-- | src/server/game/Entities/Vehicle/Vehicle.cpp | 2 |
6 files changed, 39 insertions, 44 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 08b57f37fed..162fd6fc1f0 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -371,7 +371,7 @@ void Creature::DisappearAndDie() bool Creature::IsReturningHome() const { - if (GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_ACTIVE) == HOME_MOTION_TYPE) + if (GetMotionMaster()->GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE) return true; return false; @@ -817,8 +817,7 @@ void Creature::Update(uint32 diff) IsAIEnabled = true; if (!IsInEvadeMode() && !LastCharmerGUID.IsEmpty()) if (Unit* charmer = ObjectAccessor::GetUnit(*this, LastCharmerGUID)) - if (CanStartAttack(charmer, true)) - i_AI->AttackStart(charmer); + EngageWithTarget(charmer); LastCharmerGUID.Clear(); } @@ -1020,7 +1019,6 @@ void Creature::DoFleeToGetAssistance() UpdateSpeed(MOVE_RUN); if (!creature) - //SetFeared(true, EnsureVictim()->GetGUID(), 0, sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_FLEE_DELAY)); /// @todo use 31365 SetControlled(true, UNIT_STATE_FLEEING); else @@ -1089,7 +1087,7 @@ void Creature::Motion_Initialize() m_formation->FormationReset(false); else if (m_formation->IsFormed()) { - GetMotionMaster()->MoveIdle(); //wait the order of leader + GetMotionMaster()->MoveIdle(); // wait the order of leader return; } } @@ -2230,8 +2228,9 @@ void Creature::Respawn(bool force) SetNativeDisplayId(display.CreatureDisplayID, display.DisplayScale); } - GetMotionMaster()->InitDefault(); - //Re-initialize reactstate that could be altered by movementgenerators + GetMotionMaster()->InitializeDefault(); + + // Re-initialize reactstate that could be altered by movementgenerators InitializeReactState(); if (IsAIEnabled) // reset the AI to be sure no dirty or uninitialized values will be used till next tick diff --git a/src/server/game/Entities/Creature/CreatureGroups.cpp b/src/server/game/Entities/Creature/CreatureGroups.cpp index 8e285f3e931..e54e3f33ec6 100644 --- a/src/server/game/Entities/Creature/CreatureGroups.cpp +++ b/src/server/game/Entities/Creature/CreatureGroups.cpp @@ -268,7 +268,7 @@ void CreatureGroup::FormationReset(bool dismiss) pair.first->GetMotionMaster()->Initialize(); else pair.first->GetMotionMaster()->MoveIdle(); - TC_LOG_DEBUG("entities.unit", "Set %s movement for member: %s", dismiss ? "default" : "idle", pair.first->GetGUID().ToString().c_str()); + TC_LOG_DEBUG("entities.unit", "CreatureGroup::FormationReset: Set %s movement for member %s", dismiss ? "default" : "idle", pair.first->GetGUID().ToString().c_str()); } } @@ -316,16 +316,16 @@ void CreatureGroup::LeaderMoveTo(Position const& destination, uint32 id /*= 0*/, if (!member->IsFlying()) member->UpdateGroundPositionZ(dx, dy, dz); - Position point(dx, dy, dz, destination.GetOrientation()); + member->SetHomePosition(dx, dy, dz, pathangle); + Position point(dx, dy, dz, destination.GetOrientation()); member->GetMotionMaster()->MoveFormation(id, point, moveType, !member->IsWithinDist(_leader, dist + MAX_DESYNC), orientation); - member->SetHomePosition(dx, dy, dz, pathangle); } } bool CreatureGroup::CanLeaderStartMoving() const { - for (auto const& pair : _members) + for (std::unordered_map<Creature*, FormationInfo*>::value_type const& pair : _members) { if (pair.first != _leader && pair.first->IsAlive()) { diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index f8eedbe9752..0350d2b3833 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -22735,9 +22735,18 @@ bool Player::ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid /*= 0*/) return ActivateTaxiPathTo(nodes, nullptr, spellid); } +void Player::FinishTaxiFlight() +{ + if (!IsInFlight()) + return; + + GetMotionMaster()->Remove(FLIGHT_MOTION_TYPE); + m_taxi.ClearTaxiDestinations(); // not destinations, clear source node +} + void Player::CleanupAfterTaxiFlight() { - m_taxi.ClearTaxiDestinations(); // not destinations, clear source node + m_taxi.ClearTaxiDestinations(); // not destinations, clear source node Dismount(); RemoveUnitFlag(UnitFlags(UNIT_FLAG_REMOVE_CLIENT_CONTROL | UNIT_FLAG_TAXI_FLIGHT)); } @@ -25153,11 +25162,7 @@ void Player::SummonIfPossible(bool agree) return; // stop taxi flight at summon - if (IsInFlight()) - { - GetMotionMaster()->MovementExpired(); - CleanupAfterTaxiFlight(); - } + FinishTaxiFlight(); // drop flag at summon // this code can be reached only when GM is summoning player who carries flag, because player should be immune to summoning spells when he carries flag @@ -25554,13 +25559,9 @@ void Player::SetClientControl(Unit* target, bool allowMove) void Player::SetMover(Unit* target) { m_unitMovedByMe->m_playerMovingMe = nullptr; - if (m_unitMovedByMe->GetTypeId() == TYPEID_UNIT) - m_unitMovedByMe->GetMotionMaster()->Initialize(); m_unitMovedByMe = target; m_unitMovedByMe->m_playerMovingMe = this; - if (m_unitMovedByMe->GetTypeId() == TYPEID_UNIT) - m_unitMovedByMe->GetMotionMaster()->Initialize(); WorldPackets::Movement::MoveSetActiveMover packet; packet.MoverGUID = target->GetGUID(); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index f6ee48328ad..4695eb8d21a 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1120,9 +1120,10 @@ class TC_GAME_API Player : public Unit, public GridObject<Player> void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(getRace(), getClass(), getLevel()); } bool ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc = nullptr, uint32 spellid = 0, uint32 preferredMountDisplay = 0); bool ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid = 0); + void FinishTaxiFlight(); void CleanupAfterTaxiFlight(); void ContinueTaxiFlight() const; - // mount_id can be used in scripting calls + bool isAcceptWhispers() const { return (m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS) != 0; } void SetAcceptWhispers(bool on) { if (on) m_ExtraFlags |= PLAYER_EXTRA_ACCEPT_WHISPERS; else m_ExtraFlags &= ~PLAYER_EXTRA_ACCEPT_WHISPERS; } bool IsGameMaster() const { return (m_ExtraFlags & PLAYER_EXTRA_GM_ON) != 0; } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index a6d6b8b0bde..a1b85a33ff1 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -473,7 +473,7 @@ void Unit::Update(uint32 p_time) } UpdateSplineMovement(p_time); - i_motionMaster->UpdateMotion(p_time); + i_motionMaster->Update(p_time); } bool Unit::haveOffhandWeapon() const @@ -489,7 +489,7 @@ void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed, bool gen Movement::MoveSplineInit init(this); init.MoveTo(x, y, z, generatePath, forceDestination); init.SetVelocity(speed); - GetMotionMaster()->LaunchMoveSpline(std::move(init), 0, MOTION_SLOT_ACTIVE, POINT_MOTION_TYPE); + GetMotionMaster()->LaunchMoveSpline(std::move(init), 0, MOTION_PRIORITY_NORMAL, POINT_MOTION_TYPE); } void Unit::UpdateSplineMovement(uint32 t_diff) @@ -8065,7 +8065,7 @@ void Unit::UpdateSpeed(UnitMoveType mtype) { if (GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE) { - Unit* followed = ASSERT_NOTNULL(dynamic_cast<AbstractFollower*>(GetMotionMaster()->top()))->GetTarget(); + Unit* followed = ASSERT_NOTNULL(dynamic_cast<AbstractFollower*>(GetMotionMaster()->GetCurrentMovementGenerator()))->GetTarget(); if (followed && followed->GetGUID() == GetOwnerGUID() && !followed->IsInCombat()) { float ownerSpeed = followed->GetSpeedRate(mtype); @@ -8206,7 +8206,7 @@ void Unit::setDeathState(DeathState s) // * Using 'call pet' on dead pets // * Using 'call stabled pet' // * Logging in with dead pets - GetMotionMaster()->Clear(false); + GetMotionMaster()->Clear(); GetMotionMaster()->MoveIdle(); } StopMoving(); @@ -9787,10 +9787,10 @@ void Unit::PauseMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/, bool forced/* if (IsInvalidMovementSlot(slot)) return; - if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MovementSlot(slot))) + if (MovementGenerator* movementGenerator = GetMotionMaster()->GetCurrentMovementGenerator(MovementSlot(slot))) movementGenerator->Pause(timer); - if (forced) + if (forced && GetMotionMaster()->GetCurrentSlot() == MovementSlot(slot)) StopMoving(); } @@ -9799,7 +9799,7 @@ void Unit::ResumeMovement(uint32 timer/* = 0*/, uint8 slot/* = 0*/) if (IsInvalidMovementSlot(slot)) return; - if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MovementSlot(slot))) + if (MovementGenerator* movementGenerator = GetMotionMaster()->GetCurrentMovementGenerator(MovementSlot(slot))) movementGenerator->Resume(timer); } @@ -10775,8 +10775,7 @@ void Unit::SetFeared(bool apply) { if (IsAlive()) { - if (GetMotionMaster()->GetCurrentMovementGeneratorType() == FLEEING_MOTION_TYPE) - GetMotionMaster()->MovementExpired(); + GetMotionMaster()->Remove(FLEEING_MOTION_TYPE); if (GetVictim()) SetTarget(EnsureVictim()->GetGUID()); } @@ -10801,8 +10800,7 @@ void Unit::SetConfused(bool apply) { if (IsAlive()) { - if (GetMotionMaster()->GetCurrentMovementGeneratorType() == CONFUSED_MOTION_TYPE) - GetMotionMaster()->MovementExpired(); + GetMotionMaster()->Remove(CONFUSED_MOTION_TYPE); if (GetVictim()) SetTarget(EnsureVictim()->GetGUID()); } @@ -10894,10 +10892,8 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au if (GetTypeId() == TYPEID_UNIT) { - if (MovementGenerator* movementGenerator = GetMotionMaster()->GetMotionSlot(MOTION_SLOT_IDLE)) - movementGenerator->Pause(0); - - GetMotionMaster()->Clear(MOTION_SLOT_ACTIVE); + PauseMovement(0, 0, false); + GetMotionMaster()->Clear(MOTION_PRIORITY_NORMAL); StopMoving(); @@ -11016,7 +11012,7 @@ void Unit::RemoveCharmedBy(Unit* charmer) RestoreFaction(); ///@todo Handle SLOT_IDLE motion resume - GetMotionMaster()->InitDefault(); + GetMotionMaster()->InitializeDefault(); if (Creature* creature = ToCreature()) { @@ -11085,8 +11081,6 @@ void Unit::RemoveCharmedBy(Unit* charmer) player->SetClientControl(this, true); } - EngageWithTarget(charmer); - // a guardian should always have charminfo if (playerCharmer && this != charmer->GetFirstControlled()) playerCharmer->SendRemoveControlBar(); @@ -11939,7 +11933,7 @@ void Unit::_ExitVehicle(Position const* exitPosition) init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), height, false); init.SetFacing(GetOrientation()); init.SetTransportExit(); - GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_VEHICLE_EXIT, MOTION_SLOT_CONTROLLED); + GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_VEHICLE_EXIT, MOTION_PRIORITY_HIGHEST); if (player) player->ResummonPetTemporaryUnSummonedIfAny(); @@ -12300,7 +12294,7 @@ void Unit::SetFacingTo(float ori, bool force) init.DisableTransportPathTransformations(); // It makes no sense to target global orientation init.SetFacing(ori); - //GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_SLOT_CONTROLLED); + //GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_PRIORITY_HIGHEST); init.Launch(); } @@ -12315,7 +12309,7 @@ void Unit::SetFacingToObject(WorldObject const* object, bool force) init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZ(), false); init.SetFacing(GetAbsoluteAngle(object)); // when on transport, GetAbsoluteAngle will still return global coordinates (and angle) that needs transforming - //GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_SLOT_CONTROLLED); + //GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_PRIORITY_HIGHEST); init.Launch(); } diff --git a/src/server/game/Entities/Vehicle/Vehicle.cpp b/src/server/game/Entities/Vehicle/Vehicle.cpp index 6025d5f8692..152751c91ad 100644 --- a/src/server/game/Entities/Vehicle/Vehicle.cpp +++ b/src/server/game/Entities/Vehicle/Vehicle.cpp @@ -847,7 +847,7 @@ bool VehicleJoinEvent::Execute(uint64, uint32) init.MoveTo(veSeat->AttachmentOffset.X, veSeat->AttachmentOffset.Y, veSeat->AttachmentOffset.Z, false, true); init.SetFacing(0.0f); init.SetTransportEnter(); - Passenger->GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_VEHICLE_BOARD, MOTION_SLOT_CONTROLLED); + Passenger->GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_VEHICLE_BOARD, MOTION_PRIORITY_HIGHEST); if (Creature* creature = Target->GetBase()->ToCreature()) { |
