mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[11709] Cleanup, simplify random and targeted movement generator code
This commit is contained in:
parent
6a597ae755
commit
fce6a5b7d3
4 changed files with 39 additions and 81 deletions
|
|
@ -91,23 +91,15 @@ RandomMovementGenerator<Creature>::_setRandomLocation(Creature &creature)
|
|||
}
|
||||
}
|
||||
|
||||
creature.AddSplineFlag(is_air_ok ? SPLINEFLAG_FLYING : SPLINEFLAG_WALKMODE);
|
||||
Traveller<Creature> traveller(creature);
|
||||
|
||||
creature.SetOrientation(creature.GetAngle(destX, destY));
|
||||
i_destinationHolder.SetDestination(traveller, destX, destY, destZ);
|
||||
creature.addUnitState(UNIT_STAT_ROAMING_MOVE);
|
||||
|
||||
if (is_air_ok)
|
||||
{
|
||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
||||
creature.AddSplineFlag(SPLINEFLAG_FLYING);
|
||||
}
|
||||
//else if (is_water_ok) // Swimming mode to be done with more than this check
|
||||
else
|
||||
{
|
||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime() + urand(500, 10000));
|
||||
creature.AddSplineFlag(SPLINEFLAG_WALKMODE);
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
@ -148,41 +140,22 @@ bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32
|
|||
{
|
||||
if (creature.hasUnitState(UNIT_STAT_NOT_MOVE))
|
||||
{
|
||||
i_nextMoveTime.Update(i_nextMoveTime.GetExpiry()); // Expire the timer
|
||||
i_nextMoveTime.Reset(0); // Expire the timer
|
||||
creature.clearUnitState(UNIT_STAT_ROAMING_MOVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
i_nextMoveTime.Update(diff);
|
||||
|
||||
if (i_destinationHolder.HasArrived() && !creature.IsStopped() && !creature.CanFly())
|
||||
creature.clearUnitState(UNIT_STAT_ROAMING_MOVE);
|
||||
|
||||
if (!i_destinationHolder.HasArrived() && creature.IsStopped())
|
||||
creature.addUnitState(UNIT_STAT_ROAMING_MOVE);
|
||||
|
||||
CreatureTraveller traveller(creature);
|
||||
|
||||
if (i_destinationHolder.UpdateTraveller(traveller, diff, false, true))
|
||||
{
|
||||
if (!IsActive(creature)) // force stop processing (movement can move out active zone with cleanup movegens list)
|
||||
return true; // not expire now, but already lost
|
||||
|
||||
if (i_nextMoveTime.Passed())
|
||||
{
|
||||
if (creature.CanFly())
|
||||
creature.AddSplineFlag(SPLINEFLAG_FLYING);
|
||||
else
|
||||
creature.AddSplineFlag(SPLINEFLAG_WALKMODE);
|
||||
|
||||
_setRandomLocation(creature);
|
||||
}
|
||||
else if (creature.IsPet() && creature.GetOwner() && !creature.IsWithinDist(creature.GetOwner(), PET_FOLLOW_DIST+2.5f))
|
||||
{
|
||||
creature.AddSplineFlag(SPLINEFLAG_WALKMODE);
|
||||
_setRandomLocation(creature);
|
||||
}
|
||||
}
|
||||
|
||||
i_nextMoveTime.Update(diff);
|
||||
if (i_nextMoveTime.Passed())
|
||||
_setRandomLocation(creature);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue