2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_TRAVELLER_H
20 #define MANGOS_TRAVELLER_H
26 /** Traveller is a wrapper for units (creatures or players) that
27 * travel from point A to point B using the destination holder.
29 #define PLAYER_FLIGHT_SPEED 32.0f
32 struct MANGOS_DLL_DECL Traveller
35 Traveller(T
&t
) : i_traveller(t
) {}
36 Traveller(const Traveller
&obj
) : i_traveller(obj
) {}
37 Traveller
& operator=(const Traveller
&obj
)
40 new (this) Traveller(obj
);
44 operator T
&(void) { return i_traveller
; }
45 operator const T
&(void) { return i_traveller
; }
46 float GetPositionX() const { return i_traveller
.GetPositionX(); }
47 float GetPositionY() const { return i_traveller
.GetPositionY(); }
48 float GetPositionZ() const { return i_traveller
.GetPositionZ(); }
49 T
& GetTraveller(void) { return i_traveller
; }
51 float Speed(void) { assert(false); return 0.0f
; }
52 float GetMoveDestinationTo(float x
, float y
, float z
);
53 uint32
GetTotalTrevelTimeTo(float x
, float y
, float z
);
55 void Relocation(float x
, float y
, float z
, float orientation
) {}
56 void Relocation(float x
, float y
, float z
) { Relocation(x
, y
, z
, i_traveller
.GetOrientation()); }
57 void MoveTo(float x
, float y
, float z
, uint32 t
) {}
61 inline uint32 Traveller
<T
>::GetTotalTrevelTimeTo(float x
, float y
, float z
)
63 float dist
= GetMoveDestinationTo(x
,y
,z
);
64 double speed
= Speed();
66 speed
*= 0.001f
; // speed is in seconds so convert from second to millisecond
67 return static_cast<uint32
>(dist
/speed
);
70 // specialization for creatures
72 inline float Traveller
<Creature
>::Speed()
74 if(i_traveller
.HasSplineFlag(SPLINEFLAG_WALKMODE
))
75 return i_traveller
.GetSpeed(MOVE_WALK
);
76 else if(i_traveller
.HasSplineFlag(SPLINEFLAG_UNKNOWN7
))
77 return i_traveller
.GetSpeed(MOVE_FLIGHT
);
79 return i_traveller
.GetSpeed(MOVE_RUN
);
83 inline void Traveller
<Creature
>::Relocation(float x
, float y
, float z
, float orientation
)
85 i_traveller
.GetMap()->CreatureRelocation(&i_traveller
, x
, y
, z
, orientation
);
89 inline float Traveller
<Creature
>::GetMoveDestinationTo(float x
, float y
, float z
)
91 float dx
= x
- GetPositionX();
92 float dy
= y
- GetPositionY();
93 float dz
= z
- GetPositionZ();
95 if(i_traveller
.hasUnitState(UNIT_STAT_IN_FLIGHT
))
96 return sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
));
97 else //Walking on the ground
98 return sqrt((dx
*dx
) + (dy
*dy
));
103 inline void Traveller
<Creature
>::MoveTo(float x
, float y
, float z
, uint32 t
)
105 i_traveller
.AI_SendMoveToPacket(x
, y
, z
, t
, i_traveller
.GetSplineFlags(), SPLINETYPE_NORMAL
);
108 // specialization for players
110 inline float Traveller
<Player
>::Speed()
112 if (i_traveller
.isInFlight())
113 return PLAYER_FLIGHT_SPEED
;
115 return i_traveller
.GetSpeed(i_traveller
.m_movementInfo
.HasMovementFlag(MOVEFLAG_WALK_MODE
) ? MOVE_WALK
: MOVE_RUN
);
119 inline float Traveller
<Player
>::GetMoveDestinationTo(float x
, float y
, float z
)
121 float dx
= x
- GetPositionX();
122 float dy
= y
- GetPositionY();
123 float dz
= z
- GetPositionZ();
125 if (i_traveller
.isInFlight())
126 return sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
));
127 else //Walking on the ground
128 return sqrt((dx
*dx
) + (dy
*dy
));
132 inline void Traveller
<Player
>::Relocation(float x
, float y
, float z
, float orientation
)
134 i_traveller
.GetMap()->PlayerRelocation(&i_traveller
, x
, y
, z
, orientation
);
138 inline void Traveller
<Player
>::MoveTo(float x
, float y
, float z
, uint32 t
)
140 //Only send SPLINEFLAG_WALKMODE, client has strange issues with other move flags
141 i_traveller
.SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, SPLINEFLAG_WALKMODE
, t
);
144 typedef Traveller
<Creature
> CreatureTraveller
;
145 typedef Traveller
<Player
> PlayerTraveller
;