diff options
Diffstat (limited to 'src')
4 files changed, 35 insertions, 58 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index b9cfbdf024f..48f17a0d0c6 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -651,9 +651,9 @@ void MotionMaster::DelayedDelete(_Ty curr) bool MotionMaster::GetDestination(float &x, float &y, float &z) { if (_owner->movespline->Finalized()) - return false; + return false; - const G3D::Vector3& dest = _owner->movespline->FinalDestination(); + G3D::Vector3 const& dest = _owner->movespline->FinalDestination(); x = dest.x; y = dest.y; z = dest.z; diff --git a/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp index 4af5f7b4acb..a8b4d68c802 100755 --- a/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp @@ -33,16 +33,25 @@ template<class T> void ConfusedMovementGenerator<T>::Initialize(T* unit) { + unit->AddUnitState(UNIT_STATE_CONFUSED); + unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); unit->GetPosition(i_x, i_y, i_z); + + if (!unit->isAlive() || unit->IsStopped()) + return; + unit->StopMoving(); - unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); - unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE); + unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE); } template<class T> void ConfusedMovementGenerator<T>::Reset(T* unit) { i_nextMoveTime.Reset(0); + + if (!unit->isAlive() || unit->IsStopped()) + return; + unit->StopMoving(); unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE); } @@ -70,26 +79,18 @@ bool ConfusedMovementGenerator<T>::Update(T* unit, const uint32& diff) // start moving unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE); - float x = i_x + (4.0f * (float)rand_norm() - 2.0f); - float y = i_y + (4.0f * (float)rand_norm() - 2.0f); + float dest = 4.0f * (float)rand_norm() - 2.0f; - Trinity::NormalizeMapCoord(x); - Trinity::NormalizeMapCoord(y); - - float z = unit->GetBaseMap()->GetHeight(unit->GetPhaseMask(), x, y, 10.0f, true); - - if (z <= INVALID_HEIGHT || fabs(i_z - z) > 10.0f || !unit->IsWithinLOS(x, y, z)) - { - i_nextMoveTime.Reset(100); - return true; - } + Position pos; + pos.Relocate(i_x, i_y, i_z); + unit->MovePositionToFirstCollision(pos, dest, 0.0f); PathGenerator path(unit); - path.SetPathLengthLimit(20.0f); - bool result = path.CalculatePath(x, y, z); + path.SetPathLengthLimit(30.0f); + bool result = path.CalculatePath(pos.m_positionX, pos.m_positionY, pos.m_positionZ); if (!result || (path.GetPathType() & PATHFIND_NOPATH)) { - i_nextMoveTime.Reset(100); // short reset + i_nextMoveTime.Reset(100); return true; } diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp index 5cdbdb24341..578654ca162 100644 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp @@ -37,17 +37,13 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T* owner) if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) return; - float x, y, z; - if (!_getPoint(owner, x, y, z)) - { - i_nextCheckTime.Reset(100); - return; - } - owner->AddUnitState(UNIT_STATE_FLEEING_MOVE); + float x, y, z; + _getPoint(owner, x, y, z); + PathGenerator path(owner); - path.SetPathLengthLimit(20.0f); + path.SetPathLengthLimit(30.0f); bool result = path.CalculatePath(x, y, z); if (!result || (path.GetPathType() & PATHFIND_NOPATH)) { @@ -63,11 +59,8 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T* owner) } template<class T> -bool FleeingMovementGenerator<T>::_getPoint(T* owner, float &x, float &y, float &z) +void FleeingMovementGenerator<T>::_getPoint(T* owner, float &x, float &y, float &z) { - if (!owner) - return false; - float dist_from_caster, angle_to_caster; if (Unit* fright = ObjectAccessor::GetUnit(*owner, i_frightGUID)) { @@ -100,24 +93,11 @@ bool FleeingMovementGenerator<T>::_getPoint(T* owner, float &x, float &y, float angle = frand(0, 2*static_cast<float>(M_PI)); } - float curr_x, curr_y, curr_z; - owner->GetPosition(curr_x, curr_y, curr_z); - - x = curr_x + dist * std::cos(angle); - y = curr_y + dist * std::sin(angle); - - Trinity::NormalizeMapCoord(x); - Trinity::NormalizeMapCoord(y); - - z = owner->GetBaseMap()->GetHeight(owner->GetPhaseMask(), x, y, 10.0f, true); - - if (z <= INVALID_HEIGHT) - return false; - - if (fabs(curr_z - z) > 10.0f || !owner->IsWithinLOS(x, y, z)) - return false; - - return true; + Position pos; + owner->GetFirstCollisionPosition(pos, dist, angle); + x = pos.m_positionX; + y = pos.m_positionY; + z = pos.m_positionZ; } template<class T> @@ -127,11 +107,7 @@ void FleeingMovementGenerator<T>::Initialize(T* owner) return; owner->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); - owner->AddUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE); - - if (owner->GetTypeId() == TYPEID_UNIT) - return; - + owner->AddUnitState(UNIT_STATE_FLEEING | UNIT_STATE_FLEEING_MOVE); _setTargetLocation(owner); } @@ -171,7 +147,7 @@ bool FleeingMovementGenerator<T>::Update(T* owner, const uint32& time_diff) } i_nextCheckTime.Update(time_diff); - if (i_nextCheckTime.Passed()) + if (i_nextCheckTime.Passed() && owner->movespline->Finalized()) _setTargetLocation(owner); return true; @@ -179,8 +155,8 @@ bool FleeingMovementGenerator<T>::Update(T* owner, const uint32& time_diff) template void FleeingMovementGenerator<Player>::Initialize(Player*); template void FleeingMovementGenerator<Creature>::Initialize(Creature*); -template bool FleeingMovementGenerator<Player>::_getPoint(Player*, float&, float&, float&); -template bool FleeingMovementGenerator<Creature>::_getPoint(Creature*, float&, float&, float&); +template void FleeingMovementGenerator<Player>::_getPoint(Player*, float&, float&, float&); +template void FleeingMovementGenerator<Creature>::_getPoint(Creature*, float&, float&, float&); template void FleeingMovementGenerator<Player>::_setTargetLocation(Player*); template void FleeingMovementGenerator<Creature>::_setTargetLocation(Creature*); template void FleeingMovementGenerator<Player>::Reset(Player*); diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h index 88dedd31af6..ed1fe85a314 100755 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h @@ -36,7 +36,7 @@ class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovem private: void _setTargetLocation(T*); - bool _getPoint(T*, float &x, float &y, float &z); + void _getPoint(T*, float &x, float &y, float &z); uint64 i_frightGUID; TimeTracker i_nextCheckTime; |