[2] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 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. |
---|
| 8 | * |
---|
| 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. |
---|
| 13 | * |
---|
| 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 |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef MANGOS_TRAVELLER_H |
---|
| 20 | #define MANGOS_TRAVELLER_H |
---|
| 21 | |
---|
| 22 | #include "MapManager.h" |
---|
| 23 | #include "Creature.h" |
---|
| 24 | #include "Player.h" |
---|
| 25 | #include <cassert> |
---|
| 26 | |
---|
| 27 | /** Traveller is a wrapper for units (creatures or players) that |
---|
| 28 | * travel from point A to point B using the destination holder. |
---|
| 29 | */ |
---|
| 30 | #define PLAYER_FLIGHT_SPEED 32.0f |
---|
| 31 | |
---|
| 32 | template<class T> |
---|
| 33 | struct MANGOS_DLL_DECL Traveller |
---|
| 34 | { |
---|
| 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) |
---|
| 39 | { |
---|
| 40 | this->~Traveller(); |
---|
| 41 | new (this) Traveller(obj); |
---|
| 42 | return *this; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | operator T&(void) { return i_traveller; } |
---|
| 46 | operator const T&(void) { return i_traveller; } |
---|
| 47 | inline float GetPositionX() const { return i_traveller.GetPositionX(); } |
---|
| 48 | inline float GetPositionY() const { return i_traveller.GetPositionY(); } |
---|
| 49 | inline float GetPositionZ() const { return i_traveller.GetPositionZ(); } |
---|
| 50 | inline T& GetTraveller(void) { return i_traveller; } |
---|
| 51 | |
---|
| 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) {} |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | // specialization for creatures |
---|
| 59 | template<> |
---|
| 60 | inline float Traveller<Creature>::Speed() |
---|
| 61 | { |
---|
| 62 | return i_traveller.GetSpeed( i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | template<> |
---|
| 66 | inline void Traveller<Creature>::Relocation(float x, float y, float z, float orientation) |
---|
| 67 | { |
---|
| 68 | MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->CreatureRelocation(&i_traveller, x, y, z, orientation); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | template<> |
---|
| 72 | inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t) |
---|
| 73 | { |
---|
| 74 | i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | // specialization for players |
---|
| 78 | template<> |
---|
| 79 | inline float Traveller<Player>::Speed() |
---|
| 80 | { |
---|
| 81 | if (i_traveller.isInFlight()) |
---|
| 82 | return PLAYER_FLIGHT_SPEED; |
---|
| 83 | else |
---|
| 84 | return i_traveller.GetSpeed(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | template<> |
---|
| 88 | inline void Traveller<Player>::Relocation(float x, float y, float z, float orientation) |
---|
| 89 | { |
---|
| 90 | MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->PlayerRelocation(&i_traveller, x, y, z, orientation); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | template<> |
---|
| 94 | inline void Traveller<Player>::MoveTo(float x, float y, float z, uint32 t) |
---|
| 95 | { |
---|
| 96 | //Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags |
---|
| 97 | i_traveller.SendMonsterMove(x, y, z, 0, MOVEMENTFLAG_WALK_MODE, t); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | typedef Traveller<Creature> CreatureTraveller; |
---|
| 101 | typedef Traveller<Player> PlayerTraveller; |
---|
| 102 | #endif |
---|