[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / Traveller.h
blob3daa558dac439f09bf575185e28533e7b6a65ab8
1 /*
2 * Copyright (C) 2005-2009 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
22 #include "MapManager.h"
23 #include "Creature.h"
24 #include "Player.h"
25 #include <cassert>
27 /** Traveller is a wrapper for units (creatures or players) that
28 * travel from point A to point B using the destination holder.
30 #define PLAYER_FLIGHT_SPEED 32.0f
32 template<class T>
33 struct MANGOS_DLL_DECL Traveller
35 T &i_traveller;
36 Traveller(T &t) : i_traveller(t) {}
37 Traveller(const Traveller &obj) : i_traveller(obj) {}
38 Traveller& operator=(const Traveller &obj)
40 ~Traveller();
41 new (this) Traveller(obj);
42 return *this;
45 operator T&(void) { return i_traveller; }
46 operator const T&(void) { return i_traveller; }
47 float GetPositionX() const { return i_traveller.GetPositionX(); }
48 float GetPositionY() const { return i_traveller.GetPositionY(); }
49 float GetPositionZ() const { return i_traveller.GetPositionZ(); }
50 T& GetTraveller(void) { return i_traveller; }
52 float Speed(void) { assert(false); return 0.0f; }
53 void Relocation(float x, float y, float z, float orientation) {}
54 void Relocation(float x, float y, float z) { Relocation(x, y, z, i_traveller.GetOrientation()); }
55 void MoveTo(float x, float y, float z, uint32 t) {}
58 // specialization for creatures
59 template<>
60 inline float Traveller<Creature>::Speed()
62 if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE))
63 return i_traveller.GetSpeed(MOVE_WALK);
64 else if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_FLYING2))
65 return i_traveller.GetSpeed(MOVE_FLIGHT);
66 else
67 return i_traveller.GetSpeed(MOVE_RUN);
70 template<>
71 inline void Traveller<Creature>::Relocation(float x, float y, float z, float orientation)
73 i_traveller.GetMap()->CreatureRelocation(&i_traveller, x, y, z, orientation);
76 template<>
77 inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
79 i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0);
82 // specialization for players
83 template<>
84 inline float Traveller<Player>::Speed()
86 if (i_traveller.isInFlight())
87 return PLAYER_FLIGHT_SPEED;
88 else
89 return i_traveller.GetSpeed(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
92 template<>
93 inline void Traveller<Player>::Relocation(float x, float y, float z, float orientation)
95 i_traveller.GetMap()->PlayerRelocation(&i_traveller, x, y, z, orientation);
98 template<>
99 inline void Traveller<Player>::MoveTo(float x, float y, float z, uint32 t)
101 //Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
102 i_traveller.SendMonsterMove(x, y, z, 0, MOVEMENTFLAG_WALK_MODE, t);
105 typedef Traveller<Creature> CreatureTraveller;
106 typedef Traveller<Player> PlayerTraveller;
107 #endif