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

* Move common code in appropriate functions.
* Correct select speed and 2D/3D distance for creature/player walk/fly
This commit is contained in:
VladimirMangos 2009-02-25 06:58:43 +03:00
parent 3c87af93e6
commit 1349d36270
6 changed files with 57 additions and 39 deletions

View file

@ -43,6 +43,7 @@
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
#include "Path.h"
#include "Traveller.h"
#include <math.h>
@ -232,31 +233,26 @@ 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, 0, MovementFlags, transitTime, player);
SendMonsterMove(x, y, z, 0, GetUnitMovementFlags(), transitTime, player);
}
void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player)