[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
+43
View File
@@ -53,11 +53,27 @@ struct TRINITY_DLL_DECL Traveller
T& GetTraveller(void) { return i_traveller; }
float Speed(void) { assert(false); return 0.0f; }
float GetMoveDestinationTo(float x, float y, float z);
uint32 GetTotalTrevelTimeTo(float x, float y, float z);
void Relocation(float x, float y, float z, float orientation) {}
void Relocation(float x, float y, float z) { Relocation(x, y, z, i_traveller.GetOrientation()); }
void MoveTo(float x, float y, float z, uint32 t) {}
};
template<class T>
inline uint32 Traveller<T>::GetTotalTrevelTimeTo(float x, float y, float z)
{
float dist = GetMoveDestinationTo(x,y,z);
float speed = 0.001f;
if(GetTraveller().hasUnitState(UNIT_STAT_CHARGING))
speed *= SPEED_CHARGE;
else
speed *= Speed(); // speed is in seconds so convert from second to millisecond
return static_cast<uint32>(dist/speed);
}
// specialization for creatures
template<>
inline float Traveller<Creature>::Speed()
@@ -76,6 +92,20 @@ inline void Traveller<Creature>::Relocation(float x, float y, float z, float ori
MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->CreatureRelocation(&i_traveller, x, y, z, orientation);
}
template<>
inline float Traveller<Creature>::GetMoveDestinationTo(float x, float y, float z)
{
float dx = x - GetPositionX();
float dy = y - GetPositionY();
float dz = z - GetPositionZ();
if(i_traveller.hasUnitState(UNIT_STAT_IN_FLIGHT))
return sqrt((dx*dx) + (dy*dy) + (dz*dz));
else //Walking on the ground
return sqrt((dx*dx) + (dy*dy));
}
template<>
inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
{
@@ -97,6 +127,19 @@ inline float Traveller<Player>::Speed()
return i_traveller.GetSpeed(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
}
template<>
inline float Traveller<Player>::GetMoveDestinationTo(float x, float y, float z)
{
float dx = x - GetPositionX();
float dy = y - GetPositionY();
float dz = z - GetPositionZ();
if (i_traveller.isInFlight())
return sqrt((dx*dx) + (dy*dy) + (dz*dz));
else //Walking on the ground
return sqrt((dx*dx) + (dy*dy));
}
template<>
inline void Traveller<Player>::Relocation(float x, float y, float z, float orientation)
{