Core/Movement: General improvements for confused/fleeing movement

This commit is contained in:
kaelima
2012-11-13 15:44:42 +01:00
parent 68291eed03
commit 94cca94017
4 changed files with 36 additions and 59 deletions

View File

@@ -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;

View File

@@ -33,16 +33,25 @@
template<class T>
void ConfusedMovementGenerator<T>::Initialize(T* unit)
{
unit->GetPosition(i_x, i_y, i_z);
unit->StopMoving();
unit->AddUnitState(UNIT_STATE_CONFUSED);
unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
unit->GetPosition(i_x, i_y, i_z);
if (!unit->isAlive() || unit->IsStopped())
return;
unit->StopMoving();
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;
}

View File

@@ -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*);

View File

@@ -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;