[7333] Refactoring DestinationHolder/Traveler/Unit::SendMonsterMoveWithSpeed code. Author: VladimirMangos

* Move common code in appropriate functions.
    * Correct select speed and 2D/3D distance for creature/player walk/fly

--HG--
branch : trunk
This commit is contained in:
megamage
2009-02-26 20:35:40 -06:00
parent 0f9238ecb1
commit 85d5d94e71
9 changed files with 71 additions and 43 deletions

View File

@@ -47,6 +47,7 @@
#include "CellImpl.h"
#include "Path.h"
#include "CreatureGroups.h"
#include "Traveller.h"
#include <math.h>
@@ -276,28 +277,23 @@ void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player)
{
float x, y, z;
if(GetMotionMaster()->GetDestination(x, y, z))
SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player);
SendMonsterMoveWithSpeed(x, y, z, 0, player);
}
void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player)
void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime, Player* player)
{
if (!transitTime)
{
float dx = x - GetPositionX();
float dy = y - GetPositionY();
float dz = z - GetPositionZ();
float dist = ((dx*dx) + (dy*dy) + (dz*dz));
if(dist<0)
dist = 0;
if(GetTypeId()==TYPEID_PLAYER)
{
Traveller<Player> traveller(*(Player*)this);
transitTime = traveller.GetTotalTrevelTimeTo(x,y,z);
}
else
dist = sqrt(dist);
double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
if(speed<=0)
speed = 2.5f;
speed *= 0.001f;
transitTime = static_cast<uint32>(dist / speed + 0.5);
{
Traveller<Creature> traveller(*(Creature*)this);
transitTime = traveller.GetTotalTrevelTimeTo(x,y,z);
}
}
//float orientation = (float)atan2((double)dy, (double)dx);
SendMonsterMove(x, y, z, transitTime, player);