*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
This commit is contained in:
@@ -17,15 +17,19 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_TRAVELLER_H
|
||||
#define TRINITY_TRAVELLER_H
|
||||
|
||||
#include "Creature.h"
|
||||
#include "Player.h"
|
||||
#include <cassert>
|
||||
|
||||
/** Traveller is a wrapper for units (creatures or players) that
|
||||
* travel from point A to point B using the destination holder.
|
||||
*/
|
||||
#define PLAYER_FLIGHT_SPEED 32.0f
|
||||
|
||||
template<class T>
|
||||
struct TRINITY_DLL_DECL Traveller
|
||||
{
|
||||
@@ -38,19 +42,23 @@ struct TRINITY_DLL_DECL Traveller
|
||||
new (this) Traveller(obj);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T&(void) { return i_traveller; }
|
||||
operator const T&(void) { return i_traveller; }
|
||||
float GetPositionX() const { return i_traveller.GetPositionX(); }
|
||||
float GetPositionY() const { return i_traveller.GetPositionY(); }
|
||||
float GetPositionZ() const { return i_traveller.GetPositionZ(); }
|
||||
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)
|
||||
{
|
||||
@@ -62,6 +70,7 @@ inline uint32 Traveller<T>::GetTotalTrevelTimeTo(float x, float y, float z)
|
||||
speed *= 0.001f; // 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()
|
||||
@@ -75,29 +84,34 @@ inline float Traveller<Creature>::Speed()
|
||||
else
|
||||
return i_traveller.GetSpeed(MOVE_RUN);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Traveller<Creature>::Relocation(float x, float y, float z, float orientation)
|
||||
{
|
||||
i_traveller.GetMap()->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.HasUnitMovementFlag(MOVEMENTFLAG_FLYING))
|
||||
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)
|
||||
{
|
||||
//i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0);
|
||||
i_traveller.SendMonsterMove(x, y, z, t);
|
||||
}
|
||||
|
||||
// specialization for players
|
||||
template<>
|
||||
inline float Traveller<Player>::Speed()
|
||||
@@ -109,28 +123,33 @@ inline float Traveller<Player>::Speed()
|
||||
else
|
||||
return i_traveller.GetSpeed(i_traveller.m_movementInfo.HasMovementFlag(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)
|
||||
{
|
||||
i_traveller.GetMap()->PlayerRelocation(&i_traveller, x, y, z, orientation);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Traveller<Player>::MoveTo(float x, float y, float z, uint32 t)
|
||||
{
|
||||
//Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
|
||||
i_traveller.SendMonsterMove(x, y, z, t);
|
||||
}
|
||||
|
||||
typedef Traveller<Creature> CreatureTraveller;
|
||||
typedef Traveller<Player> PlayerTraveller;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user