From f32f38a91c609f24f6dc6d5d01c575028d31eec1 Mon Sep 17 00:00:00 2001 From: ccrs Date: Thu, 6 Oct 2016 17:53:35 +0200 Subject: Core/MotionMaster: cleanup, reordering and renaming --- src/server/game/Movement/MotionMaster.cpp | 646 ++++++++++++++++-------------- src/server/game/Movement/MotionMaster.h | 174 +++----- 2 files changed, 402 insertions(+), 418 deletions(-) (limited to 'src') diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 4ad2a314111..79510f9312b 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -20,7 +20,6 @@ #include "CreatureAISelector.h" #include "Creature.h" #include "ScriptSystem.h" - #include "ConfusedMovementGenerator.h" #include "FleeingMovementGenerator.h" #include "HomeMovementGenerator.h" @@ -33,9 +32,18 @@ #include "MoveSpline.h" #include "MoveSplineInit.h" -inline bool isStatic(MovementGenerator *mv) +inline bool IsStatic(MovementGenerator *mv) { return (mv == &si_idleMovement); } + +MotionMaster::~MotionMaster() { - return (mv == &si_idleMovement); + // clear ALL movement generators (including default) + while (!empty()) + { + MovementGenerator *curr = top(); + Pop(); + if (curr && !IsStatic(curr)) + delete curr; // Skip finalizing on delete, it might launch new movement + } } void MotionMaster::Initialize() @@ -44,7 +52,7 @@ void MotionMaster::Initialize() while (!empty()) { MovementGenerator *curr = top(); - pop(); + Pop(); if (curr) DirectDelete(curr); } @@ -55,9 +63,9 @@ void MotionMaster::Initialize() // set new default movement generator void MotionMaster::InitDefault() { - if (_owner->GetTypeId() == TYPEID_UNIT) + if (m_owner->GetTypeId() == TYPEID_UNIT) { - MovementGenerator* movement = FactorySelector::selectMovementGenerator(_owner->ToCreature()); + MovementGenerator* movement = FactorySelector::selectMovementGenerator(m_owner->ToCreature()); Mutate(movement == NULL ? &si_idleMovement : movement, MOTION_SLOT_IDLE); } else @@ -66,153 +74,141 @@ void MotionMaster::InitDefault() } } -MotionMaster::~MotionMaster() -{ - // clear ALL movement generators (including default) - while (!empty()) - { - MovementGenerator *curr = top(); - pop(); - if (curr && !isStatic(curr)) - delete curr; // Skip finalizing on delete, it might launch new movement - } -} - void MotionMaster::UpdateMotion(uint32 diff) { - if (!_owner) + if (!m_owner) return; - if (_owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) // what about UNIT_STATE_DISTRACTED? Why is this not included? + if (m_owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) // what about UNIT_STATE_DISTRACTED? Why is this not included? return; ASSERT(!empty()); - _cleanFlag |= MMCF_UPDATE; - if (!top()->Update(_owner, diff)) + m_cleanFlag |= MMCF_UPDATE; + if (!top()->Update(m_owner, diff)) { - _cleanFlag &= ~MMCF_UPDATE; + m_cleanFlag &= ~MMCF_UPDATE; MovementExpired(); } else - _cleanFlag &= ~MMCF_UPDATE; + m_cleanFlag &= ~MMCF_UPDATE; - if (_expList) + if (m_expireList) { - for (size_t i = 0; i < _expList->size(); ++i) + for (size_t i = 0; i < m_expireList->size(); ++i) { - MovementGenerator* mg = (*_expList)[i]; + MovementGenerator* mg = (*m_expireList)[i]; DirectDelete(mg); } - delete _expList; - _expList = NULL; + delete m_expireList; + m_expireList = nullptr; if (empty()) Initialize(); - else if (needInitTop()) + else if (NeedInitTop()) InitTop(); - else if (_cleanFlag & MMCF_RESET) - top()->Reset(_owner); + else if (m_cleanFlag & MMCF_RESET) + top()->Reset(m_owner); - _cleanFlag &= ~MMCF_RESET; + m_cleanFlag &= ~MMCF_RESET; } // probably not the best place to pu this but im not really sure where else to put it. - _owner->UpdateUnderwaterState(_owner->GetMap(), _owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); + m_owner->UpdateUnderwaterState(m_owner->GetMap(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ()); } -void MotionMaster::DirectClean(bool reset) +void MotionMaster::Clear(bool reset = true) { - while (size() > 1) + if (m_cleanFlag & MMCF_UPDATE) { - MovementGenerator *curr = top(); - pop(); - if (curr) DirectDelete(curr); + if (reset) + m_cleanFlag |= MMCF_RESET; + else + m_cleanFlag &= ~MMCF_RESET; + DelayedClean(); } - - if (empty()) - return; - - if (needInitTop()) - InitTop(); - else if (reset) - top()->Reset(_owner); + else + DirectClean(reset); } -void MotionMaster::DelayedClean() +void MotionMaster::MovementExpired(bool reset = true) { - while (size() > 1) + if (m_cleanFlag & MMCF_UPDATE) { - MovementGenerator *curr = top(); - pop(); - if (curr) - DelayedDelete(curr); + if (reset) + m_cleanFlag |= MMCF_RESET; + else + m_cleanFlag &= ~MMCF_RESET; + DelayedExpire(); } + else + DirectExpire(reset); } -void MotionMaster::DirectExpire(bool reset) +MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const { - if (size() > 1) - { - MovementGenerator *curr = top(); - pop(); - DirectDelete(curr); - } + if (empty()) + return IDLE_MOTION_TYPE; - while (!empty() && !top()) - --_top; + return top()->GetMovementGeneratorType(); +} - if (empty()) - Initialize(); - else if (needInitTop()) - InitTop(); - else if (reset) - top()->Reset(_owner); +MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const +{ + if (!m_slot[slot]) + return NULL_MOTION_TYPE; + else + return m_slot[slot]->GetMovementGeneratorType(); } -void MotionMaster::DelayedExpire() +MovementGenerator* MotionMaster::GetMotionSlot(int slot) const { - if (size() > 1) + ASSERT(slot >= 0); + return m_slot[slot]; +} + +void MotionMaster::propagateSpeedChange() +{ + for (int i = 0; i <= m_top; ++i) { - MovementGenerator *curr = top(); - pop(); - DelayedDelete(curr); + if (m_slot[i]) + m_slot[i]->unitSpeedChanged(); } +} - while (!empty() && !top()) - --_top; +bool MotionMaster::GetDestination(float &x, float &y, float &z) +{ + if (m_owner->movespline->Finalized()) + return false; + + G3D::Vector3 const& dest = m_owner->movespline->FinalDestination(); + x = dest.x; + y = dest.y; + z = dest.z; + return true; } void MotionMaster::MoveIdle() { //! Should be preceded by MovementExpired or Clear if there's an overlying movementgenerator active - if (empty() || !isStatic(top())) + if (empty() || !IsStatic(top())) Mutate(&si_idleMovement, MOTION_SLOT_IDLE); } -void MotionMaster::MoveRandom(float spawndist) -{ - if (_owner->GetTypeId() == TYPEID_UNIT) - { - TC_LOG_DEBUG("misc", "Creature (GUID: %u) started random movement.", _owner->GetGUID().GetCounter()); - Mutate(new RandomMovementGenerator(spawndist), MOTION_SLOT_IDLE); - } -} - void MotionMaster::MoveTargetedHome() { Clear(false); - if (_owner->GetTypeId() == TYPEID_UNIT && !_owner->ToCreature()->GetCharmerOrOwnerGUID()) + if (m_owner->GetTypeId() == TYPEID_UNIT && !m_owner->ToCreature()->GetCharmerOrOwnerGUID()) { - TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) targeted home.", _owner->GetEntry(), _owner->GetGUID().GetCounter()); + TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) targeted home.", m_owner->GetEntry(), m_owner->GetGUID().GetCounter()); Mutate(new HomeMovementGenerator(), MOTION_SLOT_ACTIVE); } - else if (_owner->GetTypeId() == TYPEID_UNIT && _owner->ToCreature()->GetCharmerOrOwnerGUID()) + else if (m_owner->GetTypeId() == TYPEID_UNIT && m_owner->ToCreature()->GetCharmerOrOwnerGUID()) { - TC_LOG_DEBUG("misc", "Pet or controlled creature (Entry: %u GUID: %u) is targeting home.", _owner->GetEntry(), _owner->GetGUID().GetCounter()); - Unit* target = _owner->ToCreature()->GetCharmerOrOwner(); + TC_LOG_DEBUG("misc", "Pet or controlled creature (Entry: %u GUID: %u) is targeting home.", m_owner->GetEntry(), m_owner->GetGUID().GetCounter()); + Unit* target = m_owner->ToCreature()->GetCharmerOrOwner(); if (target) { TC_LOG_DEBUG("misc", "Following %s (GUID: %u).", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : ((Creature*)target)->GetSpawnId()); @@ -221,36 +217,54 @@ void MotionMaster::MoveTargetedHome() } else { - TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to move towards target home.", _owner->GetGUID().GetCounter()); + TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to move towards target home.", m_owner->GetGUID().GetCounter()); } } -void MotionMaster::MoveConfused() +void MotionMaster::MoveRandom(float spawndist) { - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_UNIT) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) move confused", _owner->GetGUID().GetCounter()); - Mutate(new ConfusedMovementGenerator(), MOTION_SLOT_CONTROLLED); + TC_LOG_DEBUG("misc", "Creature (GUID: %u) started random movement.", m_owner->GetGUID().GetCounter()); + Mutate(new RandomMovementGenerator(spawndist), MOTION_SLOT_IDLE); + } +} + +void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlot slot) +{ + // ignore movement request if target not exist + if (!target || target == m_owner) + return; + + //m_owner->AddUnitState(UNIT_STATE_FOLLOW); + if (m_owner->GetTypeId() == TYPEID_PLAYER) + { + TC_LOG_DEBUG("misc", "Player (GUID: %u) follows %s (GUID: %u).", m_owner->GetGUID().GetCounter(), + target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", + target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); + Mutate(new FollowMovementGenerator(target, dist, angle), slot); } else { - TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) move confused", - _owner->GetEntry(), _owner->GetGUID().GetCounter()); - Mutate(new ConfusedMovementGenerator(), MOTION_SLOT_CONTROLLED); + TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) follows %s (GUID: %u).", + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), + target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", + target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); + Mutate(new FollowMovementGenerator(target, dist, angle), slot); } } void MotionMaster::MoveChase(Unit* target, float dist, float angle) { // ignore movement request if target not exist - if (!target || target == _owner) + if (!target || target == m_owner) return; - //_owner->ClearUnitState(UNIT_STATE_FOLLOW); - if (_owner->GetTypeId() == TYPEID_PLAYER) + //m_owner->ClearUnitState(UNIT_STATE_FOLLOW); + if (m_owner->GetTypeId() == TYPEID_PLAYER) { TC_LOG_DEBUG("misc", "Player (GUID: %u) chase to %s (GUID: %u)", - _owner->GetGUID().GetCounter(), + m_owner->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); Mutate(new ChaseMovementGenerator(target, dist, angle), MOTION_SLOT_ACTIVE); @@ -258,67 +272,84 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle) else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) chase to %s (GUID: %u)", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); Mutate(new ChaseMovementGenerator(target, dist, angle), MOTION_SLOT_ACTIVE); } } -void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlot slot) +void MotionMaster::MoveConfused() { - // ignore movement request if target not exist - if (!target || target == _owner) + if (m_owner->GetTypeId() == TYPEID_PLAYER) + { + TC_LOG_DEBUG("misc", "Player (GUID: %u) move confused", m_owner->GetGUID().GetCounter()); + Mutate(new ConfusedMovementGenerator(), MOTION_SLOT_CONTROLLED); + } + else + { + TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) move confused", + m_owner->GetEntry(), m_owner->GetGUID().GetCounter()); + Mutate(new ConfusedMovementGenerator(), MOTION_SLOT_CONTROLLED); + } +} + +void MotionMaster::MoveFleeing(Unit* enemy, uint32 time) +{ + if (!enemy) return; - //_owner->AddUnitState(UNIT_STATE_FOLLOW); - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) follows %s (GUID: %u).", _owner->GetGUID().GetCounter(), - target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", - target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); - Mutate(new FollowMovementGenerator(target, dist, angle), slot); + TC_LOG_DEBUG("misc", "Player (GUID: %u) flees from %s (GUID: %u).", m_owner->GetGUID().GetCounter(), + enemy->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", + enemy->GetTypeId() == TYPEID_PLAYER ? enemy->GetGUID().GetCounter() : enemy->ToCreature()->GetSpawnId()); + Mutate(new FleeingMovementGenerator(enemy->GetGUID()), MOTION_SLOT_CONTROLLED); } else { - TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) follows %s (GUID: %u).", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), - target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", - target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); - Mutate(new FollowMovementGenerator(target, dist, angle), slot); + TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) flees from %s (GUID: %u)%s.", + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), + enemy->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", + enemy->GetTypeId() == TYPEID_PLAYER ? enemy->GetGUID().GetCounter() : enemy->ToCreature()->GetSpawnId(), + time ? " for a limited time" : ""); + if (time) + Mutate(new TimedFleeingMovementGenerator(enemy->GetGUID(), time), MOTION_SLOT_CONTROLLED); + else + Mutate(new FleeingMovementGenerator(enemy->GetGUID()), MOTION_SLOT_CONTROLLED); } } void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generatePath) { - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) targeted point (Id: %u X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), id, x, y, z); + TC_LOG_DEBUG("misc", "Player (GUID: %u) targeted point (Id: %u X: %f Y: %f Z: %f).", m_owner->GetGUID().GetCounter(), id, x, y, z); Mutate(new PointMovementGenerator(id, x, y, z, generatePath), MOTION_SLOT_ACTIVE); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) targeted point (ID: %u X: %f Y: %f Z: %f).", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), id, x, y, z); + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), id, x, y, z); Mutate(new PointMovementGenerator(id, x, y, z, generatePath), MOTION_SLOT_ACTIVE); } } void MotionMaster::MoveCloserAndStop(uint32 id, Unit* target, float distance) { - float distanceToTravel = _owner->GetExactDist2d(target) - distance; + float distanceToTravel = m_owner->GetExactDist2d(target) - distance; if (distanceToTravel > 0.0f) { - float angle = _owner->GetAngle(target); - float destx = _owner->GetPositionX() + distanceToTravel * std::cos(angle); - float desty = _owner->GetPositionY() + distanceToTravel * std::sin(angle); + float angle = m_owner->GetAngle(target); + float destx = m_owner->GetPositionX() + distanceToTravel * std::cos(angle); + float desty = m_owner->GetPositionY() + distanceToTravel * std::sin(angle); MovePoint(id, destx, desty, target->GetPositionZ()); } else { // we are already close enough. We just need to turn toward the target without changing position. - Movement::MoveSplineInit init(_owner); - init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZMinusOffset()); + Movement::MoveSplineInit init(m_owner); + init.MoveTo(m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZMinusOffset()); init.SetFacing(target); init.Launch(); Mutate(new EffectMovementGenerator(id), MOTION_SLOT_ACTIVE); @@ -330,9 +361,9 @@ void MotionMaster::MoveLand(uint32 id, Position const& pos) float x, y, z; pos.GetPosition(x, y, z); - TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", _owner->GetEntry(), id, x, y, z); + TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", m_owner->GetEntry(), id, x, y, z); - Movement::MoveSplineInit init(_owner); + Movement::MoveSplineInit init(m_owner); init.MoveTo(x, y, z); init.SetAnimation(Movement::ToGround); init.Launch(); @@ -344,19 +375,50 @@ void MotionMaster::MoveTakeoff(uint32 id, Position const& pos) float x, y, z; pos.GetPosition(x, y, z); - TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", _owner->GetEntry(), id, x, y, z); + TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", m_owner->GetEntry(), id, x, y, z); - Movement::MoveSplineInit init(_owner); + Movement::MoveSplineInit init(m_owner); init.MoveTo(x, y, z); init.SetAnimation(Movement::ToFly); init.Launch(); Mutate(new EffectMovementGenerator(id), MOTION_SLOT_ACTIVE); } +void MotionMaster::MoveCharge(float x, float y, float z, float speed /*= SPEED_CHARGE*/, uint32 id /*= EVENT_CHARGE*/, bool generatePath /*= false*/) +{ + if (m_slot[MOTION_SLOT_CONTROLLED] && m_slot[MOTION_SLOT_CONTROLLED]->GetMovementGeneratorType() != DISTRACT_MOTION_TYPE) + return; + + if (m_owner->GetTypeId() == TYPEID_PLAYER) + { + TC_LOG_DEBUG("misc", "Player (GUID: %u) charged point (X: %f Y: %f Z: %f).", m_owner->GetGUID().GetCounter(), x, y, z); + Mutate(new PointMovementGenerator(id, x, y, z, generatePath, speed), MOTION_SLOT_CONTROLLED); + } + else + { + TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) charged point (X: %f Y: %f Z: %f).", + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), x, y, z); + Mutate(new PointMovementGenerator(id, x, y, z, generatePath, speed), MOTION_SLOT_CONTROLLED); + } +} + +void MotionMaster::MoveCharge(PathGenerator const& path, float speed /*= SPEED_CHARGE*/) +{ + G3D::Vector3 dest = path.GetActualEndPosition(); + + MoveCharge(dest.x, dest.y, dest.z, speed, EVENT_CHARGE_PREPATH); + + // Charge movement is not started when using EVENT_CHARGE_PREPATH + Movement::MoveSplineInit init(m_owner); + init.MovebyPath(path.GetPath()); + init.SetVelocity(speed); + init.Launch(); +} + void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ) { //this function may make players fall below map - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) return; if (speedXY <= 0.1f) @@ -367,9 +429,9 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa float dist = 2 * moveTimeHalf * speedXY; float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -speedZ); - _owner->GetNearPoint(_owner, x, y, z, _owner->GetObjectSize(), dist, _owner->GetAngle(srcX, srcY) + float(M_PI)); + m_owner->GetNearPoint(m_owner, x, y, z, m_owner->GetObjectSize(), dist, m_owner->GetAngle(srcX, srcY) + float(M_PI)); - Movement::MoveSplineInit init(_owner); + Movement::MoveSplineInit init(m_owner); init.MoveTo(x, y, z); init.SetParabolic(max_height, 0); init.SetOrientationFixed(true); @@ -381,27 +443,27 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa void MotionMaster::MoveJumpTo(float angle, float speedXY, float speedZ) { //this function may make players fall below map - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) return; float x, y, z; float moveTimeHalf = speedZ / Movement::gravity; float dist = 2 * moveTimeHalf * speedXY; - _owner->GetClosePoint(x, y, z, _owner->GetObjectSize(), dist, angle); + m_owner->GetClosePoint(x, y, z, m_owner->GetObjectSize(), dist, angle); MoveJump(x, y, z, 0.0f, speedXY, speedZ); } void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id, bool hasOrientation /* = false*/) { - TC_LOG_DEBUG("misc", "Unit (GUID: %u) jumps to point (X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), x, y, z); + TC_LOG_DEBUG("misc", "Unit (GUID: %u) jumps to point (X: %f Y: %f Z: %f).", m_owner->GetGUID().GetCounter(), x, y, z); if (speedXY <= 0.1f) return; float moveTimeHalf = speedZ / Movement::gravity; float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -speedZ); - Movement::MoveSplineInit init(_owner); + Movement::MoveSplineInit init(m_owner); init.MoveTo(x, y, z, false); init.SetParabolic(max_height, 0); init.SetVelocity(speedXY); @@ -415,9 +477,9 @@ void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool { float step = 2 * float(M_PI) / stepCount * (clockwise ? -1.0f : 1.0f); Position const& pos = { x, y, z, 0.0f }; - float angle = pos.GetAngle(_owner->GetPositionX(), _owner->GetPositionY()); + float angle = pos.GetAngle(m_owner->GetPositionX(), m_owner->GetPositionY()); - Movement::MoveSplineInit init(_owner); + Movement::MoveSplineInit init(m_owner); for (uint8 i = 0; i < stepCount; angle += step, ++i) { @@ -425,15 +487,15 @@ void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool point.x = x + radius * cosf(angle); point.y = y + radius * sinf(angle); - if (_owner->IsFlying()) + if (m_owner->IsFlying()) point.z = z; else - point.z = _owner->GetMap()->GetHeight(_owner->GetPhaseMask(), point.x, point.y, z); + point.z = m_owner->GetMap()->GetHeight(m_owner->GetPhaseMask(), point.x, point.y, z); init.Path().push_back(point); } - if (_owner->IsFlying()) + if (m_owner->IsFlying()) { init.SetFly(); init.SetCyclic(); @@ -456,7 +518,7 @@ void MotionMaster::MoveSmoothPath(uint32 pointId, G3D::Vector3 const* pathPoints void MotionMaster::MoveSmoothPath(uint32 pointId, Movement::PointsArray const& path, bool walk) { - Movement::MoveSplineInit init(_owner); + Movement::MoveSplineInit init(m_owner); init.MovebyPath(path); init.SetSmooth(); init.SetWalk(walk); @@ -472,10 +534,10 @@ void MotionMaster::MoveSmoothPath(uint32 pointId, Movement::PointsArray const& p void MotionMaster::MoveAlongSplineChain(uint32 pointId, uint16 dbChainId, bool walk) { - Creature* owner = _owner->ToCreature(); + Creature* owner = m_owner->ToCreature(); if (!owner) { - TC_LOG_ERROR("misc", "MotionMaster::MoveAlongSplineChain: non-creature %s tried to walk along DB spline chain. Ignoring.", _owner->GetGUID().ToString().c_str()); + TC_LOG_ERROR("misc", "MotionMaster::MoveAlongSplineChain: non-creature %s tried to walk along DB spline chain. Ignoring.", m_owner->GetGUID().ToString().c_str()); return; } SplineChain const* chain = sScriptSystemMgr->GetSplineChain(owner, dbChainId); @@ -496,7 +558,7 @@ void MotionMaster::ResumeSplineChain(SplineChainResumeInfo const& info) { if (info.Empty()) { - TC_LOG_ERROR("misc", "MotionMaster::ResumeSplineChain: unit with entry %u tried to resume a spline chain from empty info.", _owner->GetEntry()); + TC_LOG_ERROR("misc", "MotionMaster::ResumeSplineChain: unit with entry %u tried to resume a spline chain from empty info.", m_owner->GetEntry()); return; } Mutate(new SplineChainMovementGenerator(info), MOTION_SLOT_ACTIVE); @@ -505,282 +567,252 @@ void MotionMaster::ResumeSplineChain(SplineChainResumeInfo const& info) void MotionMaster::MoveFall(uint32 id /*=0*/) { // use larger distance for vmap height search than in most other cases - float tz = _owner->GetMap()->GetHeight(_owner->GetPhaseMask(), _owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ(), true, MAX_FALL_DISTANCE); + float tz = m_owner->GetMap()->GetHeight(m_owner->GetPhaseMask(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ(), true, MAX_FALL_DISTANCE); if (tz <= INVALID_HEIGHT) { TC_LOG_DEBUG("misc", "MotionMaster::MoveFall: unable to retrieve a proper height at map %u (x: %f, y: %f, z: %f).", - _owner->GetMap()->GetId(), _owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); + m_owner->GetMap()->GetId(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ()); return; } // Abort too if the ground is very near - if (std::fabs(_owner->GetPositionZ() - tz) < 0.1f) + if (std::fabs(m_owner->GetPositionZ() - tz) < 0.1f) return; - _owner->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); - _owner->m_movementInfo.SetFallTime(0); + m_owner->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); + m_owner->m_movementInfo.SetFallTime(0); // don't run spline movement for players - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) return; - Movement::MoveSplineInit init(_owner); - init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz, false); + Movement::MoveSplineInit init(m_owner); + init.MoveTo(m_owner->GetPositionX(), m_owner->GetPositionY(), tz, false); init.SetFall(); init.Launch(); Mutate(new EffectMovementGenerator(id), MOTION_SLOT_CONTROLLED); } -void MotionMaster::MoveCharge(float x, float y, float z, float speed /*= SPEED_CHARGE*/, uint32 id /*= EVENT_CHARGE*/, bool generatePath /*= false*/) -{ - if (Impl[MOTION_SLOT_CONTROLLED] && Impl[MOTION_SLOT_CONTROLLED]->GetMovementGeneratorType() != DISTRACT_MOTION_TYPE) - return; - - if (_owner->GetTypeId() == TYPEID_PLAYER) - { - TC_LOG_DEBUG("misc", "Player (GUID: %u) charged point (X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), x, y, z); - Mutate(new PointMovementGenerator(id, x, y, z, generatePath, speed), MOTION_SLOT_CONTROLLED); - } - else - { - TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) charged point (X: %f Y: %f Z: %f).", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), x, y, z); - Mutate(new PointMovementGenerator(id, x, y, z, generatePath, speed), MOTION_SLOT_CONTROLLED); - } -} - -void MotionMaster::MoveCharge(PathGenerator const& path, float speed /*= SPEED_CHARGE*/) -{ - G3D::Vector3 dest = path.GetActualEndPosition(); - - MoveCharge(dest.x, dest.y, dest.z, speed, EVENT_CHARGE_PREPATH); - - // Charge movement is not started when using EVENT_CHARGE_PREPATH - Movement::MoveSplineInit init(_owner); - init.MovebyPath(path.GetPath()); - init.SetVelocity(speed); - init.Launch(); -} - void MotionMaster::MoveSeekAssistance(float x, float y, float z) { - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to seek assistance.", _owner->GetGUID().GetCounter()); + TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to seek assistance.", m_owner->GetGUID().GetCounter()); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) seek assistance (X: %f Y: %f Z: %f)", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), x, y, z); - _owner->AttackStop(); - _owner->CastStop(); - _owner->ToCreature()->SetReactState(REACT_PASSIVE); + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), x, y, z); + m_owner->AttackStop(); + m_owner->CastStop(); + m_owner->ToCreature()->SetReactState(REACT_PASSIVE); Mutate(new AssistanceMovementGenerator(x, y, z), MOTION_SLOT_ACTIVE); } } void MotionMaster::MoveSeekAssistanceDistract(uint32 time) { - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to call distract assistance.", _owner->GetGUID().GetCounter()); + TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to call distract assistance.", m_owner->GetGUID().GetCounter()); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) is distracted after assistance call (Time: %u).", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), time); + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), time); Mutate(new AssistanceDistractMovementGenerator(time), MOTION_SLOT_ACTIVE); } } -void MotionMaster::MoveFleeing(Unit* enemy, uint32 time) -{ - if (!enemy) - return; - - if (_owner->GetTypeId() == TYPEID_PLAYER) - { - TC_LOG_DEBUG("misc", "Player (GUID: %u) flees from %s (GUID: %u).", _owner->GetGUID().GetCounter(), - enemy->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", - enemy->GetTypeId() == TYPEID_PLAYER ? enemy->GetGUID().GetCounter() : enemy->ToCreature()->GetSpawnId()); - Mutate(new FleeingMovementGenerator(enemy->GetGUID()), MOTION_SLOT_CONTROLLED); - } - else - { - TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) flees from %s (GUID: %u)%s.", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), - enemy->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", - enemy->GetTypeId() == TYPEID_PLAYER ? enemy->GetGUID().GetCounter() : enemy->ToCreature()->GetSpawnId(), - time ? " for a limited time" : ""); - if (time) - Mutate(new TimedFleeingMovementGenerator(enemy->GetGUID(), time), MOTION_SLOT_CONTROLLED); - else - Mutate(new FleeingMovementGenerator(enemy->GetGUID()), MOTION_SLOT_CONTROLLED); - } -} - void MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode) { - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) { if (path < sTaxiPathNodesByPath.size()) { - TC_LOG_DEBUG("misc", "%s taxi to (Path %u node %u).", _owner->GetName().c_str(), path, pathnode); + TC_LOG_DEBUG("misc", "%s taxi to (Path %u node %u).", m_owner->GetName().c_str(), path, pathnode); FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(pathnode); - mgen->LoadPath(_owner->ToPlayer()); + mgen->LoadPath(m_owner->ToPlayer()); Mutate(mgen, MOTION_SLOT_CONTROLLED); } else { TC_LOG_ERROR("misc", "%s attempted taxi to (non-existing Path %u node %u).", - _owner->GetName().c_str(), path, pathnode); + m_owner->GetName().c_str(), path, pathnode); } } else { TC_LOG_ERROR("misc", "Creature (Entry: %u GUID: %u) attempted taxi to (Path %u node %u).", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), path, pathnode); + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), path, pathnode); } } void MotionMaster::MoveDistract(uint32 timer) { - if (Impl[MOTION_SLOT_CONTROLLED]) + if (m_slot[MOTION_SLOT_CONTROLLED]) return; - if (_owner->GetTypeId() == TYPEID_PLAYER) + if (m_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) distracted (timer: %u).", _owner->GetGUID().GetCounter(), timer); + TC_LOG_DEBUG("misc", "Player (GUID: %u) distracted (timer: %u).", m_owner->GetGUID().GetCounter(), timer); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) distracted (timer: %u)", - _owner->GetEntry(), _owner->GetGUID().GetCounter(), timer); + m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), timer); } DistractMovementGenerator* mgen = new DistractMovementGenerator(timer); Mutate(mgen, MOTION_SLOT_CONTROLLED); } +void MotionMaster::MovePath(uint32 path_id, bool repeatable) +{ + if (!path_id) + return; + + Mutate(new WaypointMovementGenerator(path_id, repeatable), MOTION_SLOT_IDLE); + + TC_LOG_DEBUG("misc", "%s (GUID: %u) starts moving over path(Id:%u, repeatable: %s).", + m_owner->GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature", + m_owner->GetGUID().GetCounter(), path_id, repeatable ? "YES" : "NO"); +} + +void MotionMaster::MoveRotate(uint32 time, RotateDirection direction) +{ + if (!time) + return; + + Mutate(new RotateMovementGenerator(time, direction), MOTION_SLOT_ACTIVE); +} + +/******************** Private methods ********************/ + +bool MotionMaster::NeedInitTop() const +{ + if (empty()) + return false; + return m_initialize[m_top]; +} + +void MotionMaster::InitTop() +{ + top()->Initialize(m_owner); + m_initialize[m_top] = false; +} + +void MotionMaster::Pop() +{ + if (empty()) + return; + + m_slot[m_top] = NULL; + while (!empty() && !top()) + --m_top; +} + void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot) { - if (MovementGenerator *curr = Impl[slot]) + if (MovementGenerator *curr = m_slot[slot]) { - Impl[slot] = NULL; // in case a new one is generated in this slot during directdelete - if (_top == slot && (_cleanFlag & MMCF_UPDATE)) + m_slot[slot] = NULL; // in case a new one is generated in this slot during directdelete + if (m_top == slot && (m_cleanFlag & MMCF_UPDATE)) DelayedDelete(curr); else DirectDelete(curr); } - else if (_top < slot) + else if (m_top < slot) { - _top = slot; + m_top = slot; } - Impl[slot] = m; - if (_top > slot) - _needInit[slot] = true; + m_slot[slot] = m; + if (m_top > slot) + m_initialize[slot] = true; else { - _needInit[slot] = false; - m->Initialize(_owner); + m_initialize[slot] = false; + m->Initialize(m_owner); } } -void MotionMaster::MovePath(uint32 path_id, bool repeatable) +void MotionMaster::DirectClean(bool reset) { - if (!path_id) - return; - //We set waypoint movement as new default movement generator - // clear ALL movement generators (including default) - /*while (!empty()) + while (size() > 1) { MovementGenerator *curr = top(); - curr->Finalize(*_owner); - pop(); - if (!isStatic(curr)) - delete curr; - }*/ - - //_owner->GetTypeId() == TYPEID_PLAYER ? - //Mutate(new WaypointMovementGenerator(path_id, repeatable)): - Mutate(new WaypointMovementGenerator(path_id, repeatable), MOTION_SLOT_IDLE); - - TC_LOG_DEBUG("misc", "%s (GUID: %u) starts moving over path(Id:%u, repeatable: %s).", - _owner->GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature", - _owner->GetGUID().GetCounter(), path_id, repeatable ? "YES" : "NO"); -} + Pop(); + if (curr) DirectDelete(curr); + } -void MotionMaster::MoveRotate(uint32 time, RotateDirection direction) -{ - if (!time) + if (empty()) return; - Mutate(new RotateMovementGenerator(time, direction), MOTION_SLOT_ACTIVE); + if (NeedInitTop()) + InitTop(); + else if (reset) + top()->Reset(m_owner); } -void MotionMaster::propagateSpeedChange() +void MotionMaster::DelayedClean() { - /*Impl::container_type::iterator it = Impl::c.begin(); - for (; it != end(); ++it) - { - (*it)->unitSpeedChanged(); - }*/ - for (int i = 0; i <= _top; ++i) + while (size() > 1) { - if (Impl[i]) - Impl[i]->unitSpeedChanged(); + MovementGenerator *curr = top(); + Pop(); + if (curr) + DelayedDelete(curr); } } -MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const +void MotionMaster::DirectExpire(bool reset) { - if (empty()) - return IDLE_MOTION_TYPE; + if (size() > 1) + { + MovementGenerator *curr = top(); + Pop(); + DirectDelete(curr); + } - return top()->GetMovementGeneratorType(); -} + while (!empty() && !top()) + --m_top; -MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const -{ - if (!Impl[slot]) - return NULL_MOTION_TYPE; - else - return Impl[slot]->GetMovementGeneratorType(); + if (empty()) + Initialize(); + else if (NeedInitTop()) + InitTop(); + else if (reset) + top()->Reset(m_owner); } -void MotionMaster::InitTop() +void MotionMaster::DelayedExpire() { - top()->Initialize(_owner); - _needInit[_top] = false; + if (size() > 1) + { + MovementGenerator *curr = top(); + Pop(); + DelayedDelete(curr); + } + + while (!empty() && !top()) + --m_top; } -void MotionMaster::DirectDelete(_Ty curr) +void MotionMaster::DirectDelete(MovementGenerator* curr) { - if (isStatic(curr)) + if (IsStatic(curr)) return; - curr->Finalize(_owner); + curr->Finalize(m_owner); delete curr; } -void MotionMaster::DelayedDelete(_Ty curr) +void MotionMaster::DelayedDelete(MovementGenerator* curr) { - TC_LOG_FATAL("misc", "Unit (Entry %u) is trying to delete its updating Movement Generator (Type %u)!", _owner->GetEntry(), curr->GetMovementGeneratorType()); - if (isStatic(curr)) + TC_LOG_FATAL("misc", "Unit (Entry %u) is trying to delete its updating Movement Generator (Type %u)!", m_owner->GetEntry(), curr->GetMovementGeneratorType()); + if (IsStatic(curr)) return; - if (!_expList) - _expList = new ExpireList(); - _expList->push_back(curr); -} - -bool MotionMaster::GetDestination(float &x, float &y, float &z) -{ - if (_owner->movespline->Finalized()) - return false; - - G3D::Vector3 const& dest = _owner->movespline->FinalDestination(); - x = dest.x; - y = dest.y; - z = dest.z; - return true; + if (!m_expireList) + m_expireList = new ExpireList(); + m_expireList->push_back(curr); } diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index d376f6aa58f..ccc9d8b4e5a 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -16,8 +16,8 @@ * with this program. If not, see . */ -#ifndef TRINITY_MOTIONMASTER_H -#define TRINITY_MOTIONMASTER_H +#ifndef MOTIONMASTER_H +#define MOTIONMASTER_H #include "Common.h" #include @@ -32,31 +32,32 @@ class PathGenerator; // Creature Entry ID used for waypoints show, visible only for GMs #define VISUAL_WAYPOINT 1 +// assume it is 25 yard per 0.6 second +#define SPEED_CHARGE 42.0f -// values 0 ... MAX_DB_MOTION_TYPE-1 used in DB enum MovementGeneratorType { - IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h - RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h - WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h - MAX_DB_MOTION_TYPE = 3, // *** this and below motion types can't be set in DB. - ANIMAL_RANDOM_MOTION_TYPE = MAX_DB_MOTION_TYPE, // AnimalRandomMovementGenerator.h - CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h - CHASE_MOTION_TYPE = 5, // TargetedMovementGenerator.h - HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h - FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h - POINT_MOTION_TYPE = 8, // PointMovementGenerator.h - FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h - DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h - ASSISTANCE_MOTION_TYPE= 11, // PointMovementGenerator.h (first part of flee for assistance) - ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance) - TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance) - FOLLOW_MOTION_TYPE = 14, - ROTATE_MOTION_TYPE = 15, - EFFECT_MOTION_TYPE = 16, - NULL_MOTION_TYPE = 17, - SPLINE_CHAIN_MOTION_TYPE = 18, // SplineChainMovementGenerator.h - MAX_MOTION_TYPE // limit + IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h + RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h + WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h + MAX_DB_MOTION_TYPE = 3, // Below motion types can't be set in DB. + ANIMAL_RANDOM_MOTION_TYPE = MAX_DB_MOTION_TYPE, // AnimalRandomMovementGenerator.h + CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h + CHASE_MOTION_TYPE = 5, // TargetedMovementGenerator.h + HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h + FLIGHT_MOTION_TYPE = 7, // WaypointMovementGenerator.h + POINT_MOTION_TYPE = 8, // PointMovementGenerator.h + FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h + DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h + ASSISTANCE_MOTION_TYPE = 11, // PointMovementGenerator.h (first part of flee for assistance) + ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance) + TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance) + FOLLOW_MOTION_TYPE = 14, + ROTATE_MOTION_TYPE = 15, + EFFECT_MOTION_TYPE = 16, + NULL_MOTION_TYPE = 17, + SPLINE_CHAIN_MOTION_TYPE = 18, // SplineChainMovementGenerator.h + MAX_MOTION_TYPE // limit }; enum MovementSlot @@ -80,91 +81,41 @@ enum RotateDirection ROTATE_DIRECTION_RIGHT }; -// assume it is 25 yard per 0.6 second -#define SPEED_CHARGE 42.0f - -class TC_GAME_API MotionMaster //: private std::stack +class TC_GAME_API MotionMaster { private: - //typedef std::stack Impl; - typedef MovementGenerator* _Ty; - - void pop() - { - if (empty()) - return; - - Impl[_top] = NULL; - while (!empty() && !top()) - --_top; - } - void push(_Ty _Val) { ++_top; Impl[_top] = _Val; } + typedef std::vector ExpireList; - bool needInitTop() const - { - if (empty()) - return false; - return _needInit[_top]; - } - void InitTop(); public: - - explicit MotionMaster(Unit* unit) : _expList(NULL), _top(-1), _owner(unit), _cleanFlag(MMCF_NONE) + explicit MotionMaster(Unit* unit) : m_expireList(nullptr), m_top(-1), m_owner(unit), m_cleanFlag(MMCF_NONE) { for (uint8 i = 0; i < MAX_MOTION_SLOT; ++i) { - Impl[i] = NULL; - _needInit[i] = true; + m_slot[i] = NULL; + m_initialize[i] = true; } } ~MotionMaster(); + bool empty() const { return (m_top < 0); } + int size() const { return m_top + 1; } + MovementGenerator* top() const { ASSERT(!empty()); return m_slot[m_top]; } + void Initialize(); void InitDefault(); - bool empty() const { return (_top < 0); } - int size() const { return _top + 1; } - _Ty top() const - { - ASSERT(!empty()); - return Impl[_top]; - } - _Ty GetMotionSlot(int slot) const - { - ASSERT(slot >= 0); - return Impl[slot]; - } + void UpdateMotion(uint32 diff); - void DirectDelete(_Ty curr); - void DelayedDelete(_Ty curr); + void Clear(bool reset = true); + void MovementExpired(bool reset = true); - void UpdateMotion(uint32 diff); - void Clear(bool reset = true) - { - if (_cleanFlag & MMCF_UPDATE) - { - if (reset) - _cleanFlag |= MMCF_RESET; - else - _cleanFlag &= ~MMCF_RESET; - DelayedClean(); - } - else - DirectClean(reset); - } - void MovementExpired(bool reset = true) - { - if (_cleanFlag & MMCF_UPDATE) - { - if (reset) - _cleanFlag |= MMCF_RESET; - else - _cleanFlag &= ~MMCF_RESET; - DelayedExpire(); - } - else - DirectExpire(reset); - } + MovementGeneratorType GetCurrentMovementGeneratorType() const; + MovementGeneratorType GetMotionSlotType(int slot) const; + MovementGenerator* GetMotionSlot(int slot) const; + + void propagateSpeedChange(); + + bool GetDestination(float &x, float &y, float &z); void MoveIdle(); void MoveTargetedHome(); @@ -174,7 +125,9 @@ class TC_GAME_API MotionMaster //: private std::stack void MoveConfused(); void MoveFleeing(Unit* enemy, uint32 time = 0); void MovePoint(uint32 id, Position const& pos, bool generatePath = true) - { MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath); } + { + MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath); + } void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true); /* Makes the unit move toward the target until it is at a certain distance from it. The unit then stops. @@ -212,27 +165,26 @@ class TC_GAME_API MotionMaster //: private std::stack void MovePath(uint32 path_id, bool repeatable); void MoveRotate(uint32 time, RotateDirection direction); - MovementGeneratorType GetCurrentMovementGeneratorType() const; - MovementGeneratorType GetMotionSlotType(int slot) const; - - void propagateSpeedChange(); - - bool GetDestination(float &x, float &y, float &z); private: - void Mutate(MovementGenerator *m, MovementSlot slot); // use Move* functions instead + bool NeedInitTop() const; + void InitTop(); + void Pop(); + + void Mutate(MovementGenerator *m, MovementSlot slot); void DirectClean(bool reset); void DelayedClean(); - void DirectExpire(bool reset); void DelayedExpire(); - - typedef std::vector<_Ty> ExpireList; - ExpireList* _expList; - _Ty Impl[MAX_MOTION_SLOT]; - int _top; - Unit* _owner; - bool _needInit[MAX_MOTION_SLOT]; - uint8 _cleanFlag; + void DirectDelete(MovementGenerator* curr); + void DelayedDelete(MovementGenerator* curr); + + ExpireList* m_expireList; + MovementGenerator* m_slot[MAX_MOTION_SLOT]; + int m_top; + Unit* m_owner; + bool m_initialize[MAX_MOTION_SLOT]; + uint8 m_cleanFlag; }; -#endif + +#endif // MOTIONMASTER_H -- cgit v1.2.3 From 46b099e727702979fe0b47cebd13b4c757f50ded Mon Sep 17 00:00:00 2001 From: ccrs Date: Thu, 6 Oct 2016 18:17:52 +0200 Subject: fix build --- src/server/game/Movement/MotionMaster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 79510f9312b..f6ac9587c51 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -118,7 +118,7 @@ void MotionMaster::UpdateMotion(uint32 diff) m_owner->UpdateUnderwaterState(m_owner->GetMap(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ()); } -void MotionMaster::Clear(bool reset = true) +void MotionMaster::Clear(bool reset /*= true*/) { if (m_cleanFlag & MMCF_UPDATE) { @@ -132,7 +132,7 @@ void MotionMaster::Clear(bool reset = true) DirectClean(reset); } -void MotionMaster::MovementExpired(bool reset = true) +void MotionMaster::MovementExpired(bool reset /*= true*/) { if (m_cleanFlag & MMCF_UPDATE) { -- cgit v1.2.3 From 960f75ff4ba489cc239abd89418e299759b9c45b Mon Sep 17 00:00:00 2001 From: ccrs Date: Thu, 6 Oct 2016 22:04:37 +0200 Subject: rerename --- src/server/game/Movement/MotionMaster.cpp | 282 +++++++++++++++--------------- src/server/game/Movement/MotionMaster.h | 24 +-- 2 files changed, 153 insertions(+), 153 deletions(-) (limited to 'src') diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index f6ac9587c51..d4240fa8435 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -63,9 +63,9 @@ void MotionMaster::Initialize() // set new default movement generator void MotionMaster::InitDefault() { - if (m_owner->GetTypeId() == TYPEID_UNIT) + if (_owner->GetTypeId() == TYPEID_UNIT) { - MovementGenerator* movement = FactorySelector::selectMovementGenerator(m_owner->ToCreature()); + MovementGenerator* movement = FactorySelector::selectMovementGenerator(_owner->ToCreature()); Mutate(movement == NULL ? &si_idleMovement : movement, MOTION_SLOT_IDLE); } else @@ -76,56 +76,56 @@ void MotionMaster::InitDefault() void MotionMaster::UpdateMotion(uint32 diff) { - if (!m_owner) + if (!_owner) return; - if (m_owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) // what about UNIT_STATE_DISTRACTED? Why is this not included? + if (_owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) // what about UNIT_STATE_DISTRACTED? Why is this not included? return; ASSERT(!empty()); - m_cleanFlag |= MMCF_UPDATE; - if (!top()->Update(m_owner, diff)) + _cleanFlag |= MMCF_UPDATE; + if (!top()->Update(_owner, diff)) { - m_cleanFlag &= ~MMCF_UPDATE; + _cleanFlag &= ~MMCF_UPDATE; MovementExpired(); } else - m_cleanFlag &= ~MMCF_UPDATE; + _cleanFlag &= ~MMCF_UPDATE; - if (m_expireList) + if (_expireList) { - for (size_t i = 0; i < m_expireList->size(); ++i) + for (size_t i = 0; i < _expireList->size(); ++i) { - MovementGenerator* mg = (*m_expireList)[i]; + MovementGenerator* mg = (*_expireList)[i]; DirectDelete(mg); } - delete m_expireList; - m_expireList = nullptr; + delete _expireList; + _expireList = nullptr; if (empty()) Initialize(); else if (NeedInitTop()) InitTop(); - else if (m_cleanFlag & MMCF_RESET) - top()->Reset(m_owner); + else if (_cleanFlag & MMCF_RESET) + top()->Reset(_owner); - m_cleanFlag &= ~MMCF_RESET; + _cleanFlag &= ~MMCF_RESET; } // probably not the best place to pu this but im not really sure where else to put it. - m_owner->UpdateUnderwaterState(m_owner->GetMap(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ()); + _owner->UpdateUnderwaterState(_owner->GetMap(), _owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); } void MotionMaster::Clear(bool reset /*= true*/) { - if (m_cleanFlag & MMCF_UPDATE) + if (_cleanFlag & MMCF_UPDATE) { if (reset) - m_cleanFlag |= MMCF_RESET; + _cleanFlag |= MMCF_RESET; else - m_cleanFlag &= ~MMCF_RESET; + _cleanFlag &= ~MMCF_RESET; DelayedClean(); } else @@ -134,12 +134,12 @@ void MotionMaster::Clear(bool reset /*= true*/) void MotionMaster::MovementExpired(bool reset /*= true*/) { - if (m_cleanFlag & MMCF_UPDATE) + if (_cleanFlag & MMCF_UPDATE) { if (reset) - m_cleanFlag |= MMCF_RESET; + _cleanFlag |= MMCF_RESET; else - m_cleanFlag &= ~MMCF_RESET; + _cleanFlag &= ~MMCF_RESET; DelayedExpire(); } else @@ -156,33 +156,33 @@ MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const { - if (!m_slot[slot]) + if (!_slot[slot]) return NULL_MOTION_TYPE; else - return m_slot[slot]->GetMovementGeneratorType(); + return _slot[slot]->GetMovementGeneratorType(); } MovementGenerator* MotionMaster::GetMotionSlot(int slot) const { ASSERT(slot >= 0); - return m_slot[slot]; + return _slot[slot]; } void MotionMaster::propagateSpeedChange() { - for (int i = 0; i <= m_top; ++i) + for (int i = 0; i <= _top; ++i) { - if (m_slot[i]) - m_slot[i]->unitSpeedChanged(); + if (_slot[i]) + _slot[i]->unitSpeedChanged(); } } bool MotionMaster::GetDestination(float &x, float &y, float &z) { - if (m_owner->movespline->Finalized()) + if (_owner->movespline->Finalized()) return false; - G3D::Vector3 const& dest = m_owner->movespline->FinalDestination(); + G3D::Vector3 const& dest = _owner->movespline->FinalDestination(); x = dest.x; y = dest.y; z = dest.z; @@ -200,15 +200,15 @@ void MotionMaster::MoveTargetedHome() { Clear(false); - if (m_owner->GetTypeId() == TYPEID_UNIT && !m_owner->ToCreature()->GetCharmerOrOwnerGUID()) + if (_owner->GetTypeId() == TYPEID_UNIT && !_owner->ToCreature()->GetCharmerOrOwnerGUID()) { - TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) targeted home.", m_owner->GetEntry(), m_owner->GetGUID().GetCounter()); + TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) targeted home.", _owner->GetEntry(), _owner->GetGUID().GetCounter()); Mutate(new HomeMovementGenerator(), MOTION_SLOT_ACTIVE); } - else if (m_owner->GetTypeId() == TYPEID_UNIT && m_owner->ToCreature()->GetCharmerOrOwnerGUID()) + else if (_owner->GetTypeId() == TYPEID_UNIT && _owner->ToCreature()->GetCharmerOrOwnerGUID()) { - TC_LOG_DEBUG("misc", "Pet or controlled creature (Entry: %u GUID: %u) is targeting home.", m_owner->GetEntry(), m_owner->GetGUID().GetCounter()); - Unit* target = m_owner->ToCreature()->GetCharmerOrOwner(); + TC_LOG_DEBUG("misc", "Pet or controlled creature (Entry: %u GUID: %u) is targeting home.", _owner->GetEntry(), _owner->GetGUID().GetCounter()); + Unit* target = _owner->ToCreature()->GetCharmerOrOwner(); if (target) { TC_LOG_DEBUG("misc", "Following %s (GUID: %u).", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : ((Creature*)target)->GetSpawnId()); @@ -217,15 +217,15 @@ void MotionMaster::MoveTargetedHome() } else { - TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to move towards target home.", m_owner->GetGUID().GetCounter()); + TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to move towards target home.", _owner->GetGUID().GetCounter()); } } void MotionMaster::MoveRandom(float spawndist) { - if (m_owner->GetTypeId() == TYPEID_UNIT) + if (_owner->GetTypeId() == TYPEID_UNIT) { - TC_LOG_DEBUG("misc", "Creature (GUID: %u) started random movement.", m_owner->GetGUID().GetCounter()); + TC_LOG_DEBUG("misc", "Creature (GUID: %u) started random movement.", _owner->GetGUID().GetCounter()); Mutate(new RandomMovementGenerator(spawndist), MOTION_SLOT_IDLE); } } @@ -233,13 +233,13 @@ void MotionMaster::MoveRandom(float spawndist) void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlot slot) { // ignore movement request if target not exist - if (!target || target == m_owner) + if (!target || target == _owner) return; - //m_owner->AddUnitState(UNIT_STATE_FOLLOW); - if (m_owner->GetTypeId() == TYPEID_PLAYER) + //_owner->AddUnitState(UNIT_STATE_FOLLOW); + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) follows %s (GUID: %u).", m_owner->GetGUID().GetCounter(), + TC_LOG_DEBUG("misc", "Player (GUID: %u) follows %s (GUID: %u).", _owner->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); Mutate(new FollowMovementGenerator(target, dist, angle), slot); @@ -247,7 +247,7 @@ void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlo else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) follows %s (GUID: %u).", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), + _owner->GetEntry(), _owner->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); Mutate(new FollowMovementGenerator(target, dist, angle), slot); @@ -257,14 +257,14 @@ void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlo void MotionMaster::MoveChase(Unit* target, float dist, float angle) { // ignore movement request if target not exist - if (!target || target == m_owner) + if (!target || target == _owner) return; - //m_owner->ClearUnitState(UNIT_STATE_FOLLOW); - if (m_owner->GetTypeId() == TYPEID_PLAYER) + //_owner->ClearUnitState(UNIT_STATE_FOLLOW); + if (_owner->GetTypeId() == TYPEID_PLAYER) { TC_LOG_DEBUG("misc", "Player (GUID: %u) chase to %s (GUID: %u)", - m_owner->GetGUID().GetCounter(), + _owner->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); Mutate(new ChaseMovementGenerator(target, dist, angle), MOTION_SLOT_ACTIVE); @@ -272,7 +272,7 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle) else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) chase to %s (GUID: %u)", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), + _owner->GetEntry(), _owner->GetGUID().GetCounter(), target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUID().GetCounter() : target->ToCreature()->GetSpawnId()); Mutate(new ChaseMovementGenerator(target, dist, angle), MOTION_SLOT_ACTIVE); @@ -281,15 +281,15 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle) void MotionMaster::MoveConfused() { - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) move confused", m_owner->GetGUID().GetCounter()); + TC_LOG_DEBUG("misc", "Player (GUID: %u) move confused", _owner->GetGUID().GetCounter()); Mutate(new ConfusedMovementGenerator(), MOTION_SLOT_CONTROLLED); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) move confused", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter()); + _owner->GetEntry(), _owner->GetGUID().GetCounter()); Mutate(new ConfusedMovementGenerator(), MOTION_SLOT_CONTROLLED); } } @@ -299,9 +299,9 @@ void MotionMaster::MoveFleeing(Unit* enemy, uint32 time) if (!enemy) return; - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) flees from %s (GUID: %u).", m_owner->GetGUID().GetCounter(), + TC_LOG_DEBUG("misc", "Player (GUID: %u) flees from %s (GUID: %u).", _owner->GetGUID().GetCounter(), enemy->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", enemy->GetTypeId() == TYPEID_PLAYER ? enemy->GetGUID().GetCounter() : enemy->ToCreature()->GetSpawnId()); Mutate(new FleeingMovementGenerator(enemy->GetGUID()), MOTION_SLOT_CONTROLLED); @@ -309,7 +309,7 @@ void MotionMaster::MoveFleeing(Unit* enemy, uint32 time) else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) flees from %s (GUID: %u)%s.", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), + _owner->GetEntry(), _owner->GetGUID().GetCounter(), enemy->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", enemy->GetTypeId() == TYPEID_PLAYER ? enemy->GetGUID().GetCounter() : enemy->ToCreature()->GetSpawnId(), time ? " for a limited time" : ""); @@ -322,34 +322,34 @@ void MotionMaster::MoveFleeing(Unit* enemy, uint32 time) void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generatePath) { - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) targeted point (Id: %u X: %f Y: %f Z: %f).", m_owner->GetGUID().GetCounter(), id, x, y, z); + TC_LOG_DEBUG("misc", "Player (GUID: %u) targeted point (Id: %u X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), id, x, y, z); Mutate(new PointMovementGenerator(id, x, y, z, generatePath), MOTION_SLOT_ACTIVE); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) targeted point (ID: %u X: %f Y: %f Z: %f).", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), id, x, y, z); + _owner->GetEntry(), _owner->GetGUID().GetCounter(), id, x, y, z); Mutate(new PointMovementGenerator(id, x, y, z, generatePath), MOTION_SLOT_ACTIVE); } } void MotionMaster::MoveCloserAndStop(uint32 id, Unit* target, float distance) { - float distanceToTravel = m_owner->GetExactDist2d(target) - distance; + float distanceToTravel = _owner->GetExactDist2d(target) - distance; if (distanceToTravel > 0.0f) { - float angle = m_owner->GetAngle(target); - float destx = m_owner->GetPositionX() + distanceToTravel * std::cos(angle); - float desty = m_owner->GetPositionY() + distanceToTravel * std::sin(angle); + float angle = _owner->GetAngle(target); + float destx = _owner->GetPositionX() + distanceToTravel * std::cos(angle); + float desty = _owner->GetPositionY() + distanceToTravel * std::sin(angle); MovePoint(id, destx, desty, target->GetPositionZ()); } else { // we are already close enough. We just need to turn toward the target without changing position. - Movement::MoveSplineInit init(m_owner); - init.MoveTo(m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZMinusOffset()); + Movement::MoveSplineInit init(_owner); + init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZMinusOffset()); init.SetFacing(target); init.Launch(); Mutate(new EffectMovementGenerator(id), MOTION_SLOT_ACTIVE); @@ -361,9 +361,9 @@ void MotionMaster::MoveLand(uint32 id, Position const& pos) float x, y, z; pos.GetPosition(x, y, z); - TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", m_owner->GetEntry(), id, x, y, z); + TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", _owner->GetEntry(), id, x, y, z); - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); init.MoveTo(x, y, z); init.SetAnimation(Movement::ToGround); init.Launch(); @@ -375,9 +375,9 @@ void MotionMaster::MoveTakeoff(uint32 id, Position const& pos) float x, y, z; pos.GetPosition(x, y, z); - TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", m_owner->GetEntry(), id, x, y, z); + TC_LOG_DEBUG("misc", "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f).", _owner->GetEntry(), id, x, y, z); - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); init.MoveTo(x, y, z); init.SetAnimation(Movement::ToFly); init.Launch(); @@ -386,18 +386,18 @@ void MotionMaster::MoveTakeoff(uint32 id, Position const& pos) void MotionMaster::MoveCharge(float x, float y, float z, float speed /*= SPEED_CHARGE*/, uint32 id /*= EVENT_CHARGE*/, bool generatePath /*= false*/) { - if (m_slot[MOTION_SLOT_CONTROLLED] && m_slot[MOTION_SLOT_CONTROLLED]->GetMovementGeneratorType() != DISTRACT_MOTION_TYPE) + if (_slot[MOTION_SLOT_CONTROLLED] && _slot[MOTION_SLOT_CONTROLLED]->GetMovementGeneratorType() != DISTRACT_MOTION_TYPE) return; - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) charged point (X: %f Y: %f Z: %f).", m_owner->GetGUID().GetCounter(), x, y, z); + TC_LOG_DEBUG("misc", "Player (GUID: %u) charged point (X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), x, y, z); Mutate(new PointMovementGenerator(id, x, y, z, generatePath, speed), MOTION_SLOT_CONTROLLED); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) charged point (X: %f Y: %f Z: %f).", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), x, y, z); + _owner->GetEntry(), _owner->GetGUID().GetCounter(), x, y, z); Mutate(new PointMovementGenerator(id, x, y, z, generatePath, speed), MOTION_SLOT_CONTROLLED); } } @@ -409,7 +409,7 @@ void MotionMaster::MoveCharge(PathGenerator const& path, float speed /*= SPEED_C MoveCharge(dest.x, dest.y, dest.z, speed, EVENT_CHARGE_PREPATH); // Charge movement is not started when using EVENT_CHARGE_PREPATH - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); init.MovebyPath(path.GetPath()); init.SetVelocity(speed); init.Launch(); @@ -418,7 +418,7 @@ void MotionMaster::MoveCharge(PathGenerator const& path, float speed /*= SPEED_C void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ) { //this function may make players fall below map - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) return; if (speedXY <= 0.1f) @@ -429,9 +429,9 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa float dist = 2 * moveTimeHalf * speedXY; float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -speedZ); - m_owner->GetNearPoint(m_owner, x, y, z, m_owner->GetObjectSize(), dist, m_owner->GetAngle(srcX, srcY) + float(M_PI)); + _owner->GetNearPoint(_owner, x, y, z, _owner->GetObjectSize(), dist, _owner->GetAngle(srcX, srcY) + float(M_PI)); - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); init.MoveTo(x, y, z); init.SetParabolic(max_height, 0); init.SetOrientationFixed(true); @@ -443,27 +443,27 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa void MotionMaster::MoveJumpTo(float angle, float speedXY, float speedZ) { //this function may make players fall below map - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) return; float x, y, z; float moveTimeHalf = speedZ / Movement::gravity; float dist = 2 * moveTimeHalf * speedXY; - m_owner->GetClosePoint(x, y, z, m_owner->GetObjectSize(), dist, angle); + _owner->GetClosePoint(x, y, z, _owner->GetObjectSize(), dist, angle); MoveJump(x, y, z, 0.0f, speedXY, speedZ); } void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id, bool hasOrientation /* = false*/) { - TC_LOG_DEBUG("misc", "Unit (GUID: %u) jumps to point (X: %f Y: %f Z: %f).", m_owner->GetGUID().GetCounter(), x, y, z); + TC_LOG_DEBUG("misc", "Unit (GUID: %u) jumps to point (X: %f Y: %f Z: %f).", _owner->GetGUID().GetCounter(), x, y, z); if (speedXY <= 0.1f) return; float moveTimeHalf = speedZ / Movement::gravity; float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -speedZ); - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); init.MoveTo(x, y, z, false); init.SetParabolic(max_height, 0); init.SetVelocity(speedXY); @@ -477,9 +477,9 @@ void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool { float step = 2 * float(M_PI) / stepCount * (clockwise ? -1.0f : 1.0f); Position const& pos = { x, y, z, 0.0f }; - float angle = pos.GetAngle(m_owner->GetPositionX(), m_owner->GetPositionY()); + float angle = pos.GetAngle(_owner->GetPositionX(), _owner->GetPositionY()); - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); for (uint8 i = 0; i < stepCount; angle += step, ++i) { @@ -487,15 +487,15 @@ void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool point.x = x + radius * cosf(angle); point.y = y + radius * sinf(angle); - if (m_owner->IsFlying()) + if (_owner->IsFlying()) point.z = z; else - point.z = m_owner->GetMap()->GetHeight(m_owner->GetPhaseMask(), point.x, point.y, z); + point.z = _owner->GetMap()->GetHeight(_owner->GetPhaseMask(), point.x, point.y, z); init.Path().push_back(point); } - if (m_owner->IsFlying()) + if (_owner->IsFlying()) { init.SetFly(); init.SetCyclic(); @@ -518,7 +518,7 @@ void MotionMaster::MoveSmoothPath(uint32 pointId, G3D::Vector3 const* pathPoints void MotionMaster::MoveSmoothPath(uint32 pointId, Movement::PointsArray const& path, bool walk) { - Movement::MoveSplineInit init(m_owner); + Movement::MoveSplineInit init(_owner); init.MovebyPath(path); init.SetSmooth(); init.SetWalk(walk); @@ -534,10 +534,10 @@ void MotionMaster::MoveSmoothPath(uint32 pointId, Movement::PointsArray const& p void MotionMaster::MoveAlongSplineChain(uint32 pointId, uint16 dbChainId, bool walk) { - Creature* owner = m_owner->ToCreature(); + Creature* owner = _owner->ToCreature(); if (!owner) { - TC_LOG_ERROR("misc", "MotionMaster::MoveAlongSplineChain: non-creature %s tried to walk along DB spline chain. Ignoring.", m_owner->GetGUID().ToString().c_str()); + TC_LOG_ERROR("misc", "MotionMaster::MoveAlongSplineChain: non-creature %s tried to walk along DB spline chain. Ignoring.", _owner->GetGUID().ToString().c_str()); return; } SplineChain const* chain = sScriptSystemMgr->GetSplineChain(owner, dbChainId); @@ -558,7 +558,7 @@ void MotionMaster::ResumeSplineChain(SplineChainResumeInfo const& info) { if (info.Empty()) { - TC_LOG_ERROR("misc", "MotionMaster::ResumeSplineChain: unit with entry %u tried to resume a spline chain from empty info.", m_owner->GetEntry()); + TC_LOG_ERROR("misc", "MotionMaster::ResumeSplineChain: unit with entry %u tried to resume a spline chain from empty info.", _owner->GetEntry()); return; } Mutate(new SplineChainMovementGenerator(info), MOTION_SLOT_ACTIVE); @@ -567,27 +567,27 @@ void MotionMaster::ResumeSplineChain(SplineChainResumeInfo const& info) void MotionMaster::MoveFall(uint32 id /*=0*/) { // use larger distance for vmap height search than in most other cases - float tz = m_owner->GetMap()->GetHeight(m_owner->GetPhaseMask(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ(), true, MAX_FALL_DISTANCE); + float tz = _owner->GetMap()->GetHeight(_owner->GetPhaseMask(), _owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ(), true, MAX_FALL_DISTANCE); if (tz <= INVALID_HEIGHT) { TC_LOG_DEBUG("misc", "MotionMaster::MoveFall: unable to retrieve a proper height at map %u (x: %f, y: %f, z: %f).", - m_owner->GetMap()->GetId(), m_owner->GetPositionX(), m_owner->GetPositionY(), m_owner->GetPositionZ()); + _owner->GetMap()->GetId(), _owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); return; } // Abort too if the ground is very near - if (std::fabs(m_owner->GetPositionZ() - tz) < 0.1f) + if (std::fabs(_owner->GetPositionZ() - tz) < 0.1f) return; - m_owner->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); - m_owner->m_movementInfo.SetFallTime(0); + _owner->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); + _owner->m_movementInfo.SetFallTime(0); // don't run spline movement for players - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) return; - Movement::MoveSplineInit init(m_owner); - init.MoveTo(m_owner->GetPositionX(), m_owner->GetPositionY(), tz, false); + Movement::MoveSplineInit init(_owner); + init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz, false); init.SetFall(); init.Launch(); Mutate(new EffectMovementGenerator(id), MOTION_SLOT_CONTROLLED); @@ -595,72 +595,72 @@ void MotionMaster::MoveFall(uint32 id /*=0*/) void MotionMaster::MoveSeekAssistance(float x, float y, float z) { - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to seek assistance.", m_owner->GetGUID().GetCounter()); + TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to seek assistance.", _owner->GetGUID().GetCounter()); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) seek assistance (X: %f Y: %f Z: %f)", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), x, y, z); - m_owner->AttackStop(); - m_owner->CastStop(); - m_owner->ToCreature()->SetReactState(REACT_PASSIVE); + _owner->GetEntry(), _owner->GetGUID().GetCounter(), x, y, z); + _owner->AttackStop(); + _owner->CastStop(); + _owner->ToCreature()->SetReactState(REACT_PASSIVE); Mutate(new AssistanceMovementGenerator(x, y, z), MOTION_SLOT_ACTIVE); } } void MotionMaster::MoveSeekAssistanceDistract(uint32 time) { - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to call distract assistance.", m_owner->GetGUID().GetCounter()); + TC_LOG_ERROR("misc", "Player (GUID: %u) attempted to call distract assistance.", _owner->GetGUID().GetCounter()); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) is distracted after assistance call (Time: %u).", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), time); + _owner->GetEntry(), _owner->GetGUID().GetCounter(), time); Mutate(new AssistanceDistractMovementGenerator(time), MOTION_SLOT_ACTIVE); } } void MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode) { - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { if (path < sTaxiPathNodesByPath.size()) { - TC_LOG_DEBUG("misc", "%s taxi to (Path %u node %u).", m_owner->GetName().c_str(), path, pathnode); + TC_LOG_DEBUG("misc", "%s taxi to (Path %u node %u).", _owner->GetName().c_str(), path, pathnode); FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(pathnode); - mgen->LoadPath(m_owner->ToPlayer()); + mgen->LoadPath(_owner->ToPlayer()); Mutate(mgen, MOTION_SLOT_CONTROLLED); } else { TC_LOG_ERROR("misc", "%s attempted taxi to (non-existing Path %u node %u).", - m_owner->GetName().c_str(), path, pathnode); + _owner->GetName().c_str(), path, pathnode); } } else { TC_LOG_ERROR("misc", "Creature (Entry: %u GUID: %u) attempted taxi to (Path %u node %u).", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), path, pathnode); + _owner->GetEntry(), _owner->GetGUID().GetCounter(), path, pathnode); } } void MotionMaster::MoveDistract(uint32 timer) { - if (m_slot[MOTION_SLOT_CONTROLLED]) + if (_slot[MOTION_SLOT_CONTROLLED]) return; - if (m_owner->GetTypeId() == TYPEID_PLAYER) + if (_owner->GetTypeId() == TYPEID_PLAYER) { - TC_LOG_DEBUG("misc", "Player (GUID: %u) distracted (timer: %u).", m_owner->GetGUID().GetCounter(), timer); + TC_LOG_DEBUG("misc", "Player (GUID: %u) distracted (timer: %u).", _owner->GetGUID().GetCounter(), timer); } else { TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) distracted (timer: %u)", - m_owner->GetEntry(), m_owner->GetGUID().GetCounter(), timer); + _owner->GetEntry(), _owner->GetGUID().GetCounter(), timer); } DistractMovementGenerator* mgen = new DistractMovementGenerator(timer); @@ -675,8 +675,8 @@ void MotionMaster::MovePath(uint32 path_id, bool repeatable) Mutate(new WaypointMovementGenerator(path_id, repeatable), MOTION_SLOT_IDLE); TC_LOG_DEBUG("misc", "%s (GUID: %u) starts moving over path(Id:%u, repeatable: %s).", - m_owner->GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature", - m_owner->GetGUID().GetCounter(), path_id, repeatable ? "YES" : "NO"); + _owner->GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature", + _owner->GetGUID().GetCounter(), path_id, repeatable ? "YES" : "NO"); } void MotionMaster::MoveRotate(uint32 time, RotateDirection direction) @@ -693,13 +693,13 @@ bool MotionMaster::NeedInitTop() const { if (empty()) return false; - return m_initialize[m_top]; + return _initialize[_top]; } void MotionMaster::InitTop() { - top()->Initialize(m_owner); - m_initialize[m_top] = false; + top()->Initialize(_owner); + _initialize[_top] = false; } void MotionMaster::Pop() @@ -707,33 +707,33 @@ void MotionMaster::Pop() if (empty()) return; - m_slot[m_top] = NULL; + _slot[_top] = NULL; while (!empty() && !top()) - --m_top; + --_top; } void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot) { - if (MovementGenerator *curr = m_slot[slot]) + if (MovementGenerator *curr = _slot[slot]) { - m_slot[slot] = NULL; // in case a new one is generated in this slot during directdelete - if (m_top == slot && (m_cleanFlag & MMCF_UPDATE)) + _slot[slot] = NULL; // in case a new one is generated in this slot during directdelete + if (_top == slot && (_cleanFlag & MMCF_UPDATE)) DelayedDelete(curr); else DirectDelete(curr); } - else if (m_top < slot) + else if (_top < slot) { - m_top = slot; + _top = slot; } - m_slot[slot] = m; - if (m_top > slot) - m_initialize[slot] = true; + _slot[slot] = m; + if (_top > slot) + _initialize[slot] = true; else { - m_initialize[slot] = false; - m->Initialize(m_owner); + _initialize[slot] = false; + m->Initialize(_owner); } } @@ -752,7 +752,7 @@ void MotionMaster::DirectClean(bool reset) if (NeedInitTop()) InitTop(); else if (reset) - top()->Reset(m_owner); + top()->Reset(_owner); } void MotionMaster::DelayedClean() @@ -776,14 +776,14 @@ void MotionMaster::DirectExpire(bool reset) } while (!empty() && !top()) - --m_top; + --_top; if (empty()) Initialize(); else if (NeedInitTop()) InitTop(); else if (reset) - top()->Reset(m_owner); + top()->Reset(_owner); } void MotionMaster::DelayedExpire() @@ -796,23 +796,23 @@ void MotionMaster::DelayedExpire() } while (!empty() && !top()) - --m_top; + --_top; } void MotionMaster::DirectDelete(MovementGenerator* curr) { if (IsStatic(curr)) return; - curr->Finalize(m_owner); + curr->Finalize(_owner); delete curr; } void MotionMaster::DelayedDelete(MovementGenerator* curr) { - TC_LOG_FATAL("misc", "Unit (Entry %u) is trying to delete its updating Movement Generator (Type %u)!", m_owner->GetEntry(), curr->GetMovementGeneratorType()); + TC_LOG_FATAL("misc", "Unit (Entry %u) is trying to delete its updating Movement Generator (Type %u)!", _owner->GetEntry(), curr->GetMovementGeneratorType()); if (IsStatic(curr)) return; - if (!m_expireList) - m_expireList = new ExpireList(); - m_expireList->push_back(curr); + if (!_expireList) + _expireList = new ExpireList(); + _expireList->push_back(curr); } diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index ccc9d8b4e5a..7c215fb2ab4 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -87,19 +87,19 @@ class TC_GAME_API MotionMaster typedef std::vector ExpireList; public: - explicit MotionMaster(Unit* unit) : m_expireList(nullptr), m_top(-1), m_owner(unit), m_cleanFlag(MMCF_NONE) + explicit MotionMaster(Unit* unit) : _expireList(nullptr), _top(-1), _owner(unit), _cleanFlag(MMCF_NONE) { for (uint8 i = 0; i < MAX_MOTION_SLOT; ++i) { - m_slot[i] = NULL; - m_initialize[i] = true; + _slot[i] = nullptr; + _initialize[i] = true; } } ~MotionMaster(); - bool empty() const { return (m_top < 0); } - int size() const { return m_top + 1; } - MovementGenerator* top() const { ASSERT(!empty()); return m_slot[m_top]; } + bool empty() const { return (_top < 0); } + int size() const { return _top + 1; } + MovementGenerator* top() const { ASSERT(!empty()); return _slot[_top]; } void Initialize(); void InitDefault(); @@ -179,12 +179,12 @@ class TC_GAME_API MotionMaster void DirectDelete(MovementGenerator* curr); void DelayedDelete(MovementGenerator* curr); - ExpireList* m_expireList; - MovementGenerator* m_slot[MAX_MOTION_SLOT]; - int m_top; - Unit* m_owner; - bool m_initialize[MAX_MOTION_SLOT]; - uint8 m_cleanFlag; + ExpireList* _expireList; + MovementGenerator* _slot[MAX_MOTION_SLOT]; + int _top; + Unit* _owner; + bool _initialize[MAX_MOTION_SLOT]; + uint8 _cleanFlag; }; #endif // MOTIONMASTER_H -- cgit v1.2.3 From 91d7c1805b3cd492ed28615105f141be3bfff116 Mon Sep 17 00:00:00 2001 From: ccrs Date: Fri, 7 Oct 2016 12:07:56 +0200 Subject: whatever --- src/server/game/Movement/MotionMaster.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index d4240fa8435..f5090854ad4 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -32,7 +32,10 @@ #include "MoveSpline.h" #include "MoveSplineInit.h" -inline bool IsStatic(MovementGenerator *mv) { return (mv == &si_idleMovement); } +inline bool IsStatic(MovementGenerator* movement) +{ + return (movement == &si_idleMovement); +} MotionMaster::~MotionMaster() { -- cgit v1.2.3 From c2592506adc5683e18e769a918c474c1231a69ce Mon Sep 17 00:00:00 2001 From: ccrs Date: Fri, 7 Oct 2016 14:25:58 +0200 Subject: rerenaming --- src/server/game/Movement/MotionMaster.cpp | 34 +++++++++++++++---------------- src/server/game/Movement/MotionMaster.h | 3 ++- 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index f5090854ad4..105b4245ff3 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -43,7 +43,7 @@ MotionMaster::~MotionMaster() while (!empty()) { MovementGenerator *curr = top(); - Pop(); + pop(); if (curr && !IsStatic(curr)) delete curr; // Skip finalizing on delete, it might launch new movement } @@ -55,7 +55,7 @@ void MotionMaster::Initialize() while (!empty()) { MovementGenerator *curr = top(); - Pop(); + pop(); if (curr) DirectDelete(curr); } @@ -692,6 +692,16 @@ void MotionMaster::MoveRotate(uint32 time, RotateDirection direction) /******************** Private methods ********************/ +void MotionMaster::pop() +{ + if (empty()) + return; + + _slot[_top] = nullptr; + while (!empty() && !top()) + --_top; +} + bool MotionMaster::NeedInitTop() const { if (empty()) @@ -705,21 +715,11 @@ void MotionMaster::InitTop() _initialize[_top] = false; } -void MotionMaster::Pop() -{ - if (empty()) - return; - - _slot[_top] = NULL; - while (!empty() && !top()) - --_top; -} - void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot) { if (MovementGenerator *curr = _slot[slot]) { - _slot[slot] = NULL; // in case a new one is generated in this slot during directdelete + _slot[slot] = nullptr; // in case a new one is generated in this slot during directdelete if (_top == slot && (_cleanFlag & MMCF_UPDATE)) DelayedDelete(curr); else @@ -745,7 +745,7 @@ void MotionMaster::DirectClean(bool reset) while (size() > 1) { MovementGenerator *curr = top(); - Pop(); + pop(); if (curr) DirectDelete(curr); } @@ -763,7 +763,7 @@ void MotionMaster::DelayedClean() while (size() > 1) { MovementGenerator *curr = top(); - Pop(); + pop(); if (curr) DelayedDelete(curr); } @@ -774,7 +774,7 @@ void MotionMaster::DirectExpire(bool reset) if (size() > 1) { MovementGenerator *curr = top(); - Pop(); + pop(); DirectDelete(curr); } @@ -794,7 +794,7 @@ void MotionMaster::DelayedExpire() if (size() > 1) { MovementGenerator *curr = top(); - Pop(); + pop(); DelayedDelete(curr); } diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index 7c215fb2ab4..0f46f42e08e 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -166,9 +166,10 @@ class TC_GAME_API MotionMaster void MoveRotate(uint32 time, RotateDirection direction); private: + void pop(); + bool NeedInitTop() const; void InitTop(); - void Pop(); void Mutate(MovementGenerator *m, MovementSlot slot); -- cgit v1.2.3