[2] | 1 | /* |
---|
[44] | 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 3 | * |
---|
[44] | 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
| 5 | * |
---|
[2] | 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
[44] | 21 | #ifndef TRINITY_TRAVELLER_H |
---|
| 22 | #define TRINITY_TRAVELLER_H |
---|
[2] | 23 | |
---|
| 24 | #include "MapManager.h" |
---|
| 25 | #include "Creature.h" |
---|
| 26 | #include "Player.h" |
---|
| 27 | #include <cassert> |
---|
| 28 | |
---|
| 29 | /** Traveller is a wrapper for units (creatures or players) that |
---|
| 30 | * travel from point A to point B using the destination holder. |
---|
| 31 | */ |
---|
| 32 | #define PLAYER_FLIGHT_SPEED 32.0f |
---|
| 33 | |
---|
| 34 | template<class T> |
---|
[44] | 35 | struct TRINITY_DLL_DECL Traveller |
---|
[2] | 36 | { |
---|
| 37 | T &i_traveller; |
---|
| 38 | Traveller(T &t) : i_traveller(t) {} |
---|
| 39 | Traveller(const Traveller &obj) : i_traveller(obj) {} |
---|
| 40 | Traveller& operator=(const Traveller &obj) |
---|
| 41 | { |
---|
| 42 | this->~Traveller(); |
---|
| 43 | new (this) Traveller(obj); |
---|
| 44 | return *this; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | operator T&(void) { return i_traveller; } |
---|
| 48 | operator const T&(void) { return i_traveller; } |
---|
| 49 | inline float GetPositionX() const { return i_traveller.GetPositionX(); } |
---|
| 50 | inline float GetPositionY() const { return i_traveller.GetPositionY(); } |
---|
| 51 | inline float GetPositionZ() const { return i_traveller.GetPositionZ(); } |
---|
| 52 | inline T& GetTraveller(void) { return i_traveller; } |
---|
| 53 | |
---|
| 54 | float Speed(void) { assert(false); return 0.0f; } |
---|
| 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) {} |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | // specialization for creatures |
---|
| 61 | template<> |
---|
| 62 | inline float Traveller<Creature>::Speed() |
---|
| 63 | { |
---|
| 64 | return i_traveller.GetSpeed( i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | template<> |
---|
| 68 | inline void Traveller<Creature>::Relocation(float x, float y, float z, float orientation) |
---|
| 69 | { |
---|
| 70 | MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->CreatureRelocation(&i_traveller, x, y, z, orientation); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | template<> |
---|
| 74 | inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t) |
---|
| 75 | { |
---|
| 76 | i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetUnitMovementFlags(), 0); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | // specialization for players |
---|
| 80 | template<> |
---|
| 81 | inline float Traveller<Player>::Speed() |
---|
| 82 | { |
---|
| 83 | if (i_traveller.isInFlight()) |
---|
| 84 | return PLAYER_FLIGHT_SPEED; |
---|
| 85 | else |
---|
| 86 | return i_traveller.GetSpeed(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | template<> |
---|
| 90 | inline void Traveller<Player>::Relocation(float x, float y, float z, float orientation) |
---|
| 91 | { |
---|
| 92 | MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->PlayerRelocation(&i_traveller, x, y, z, orientation); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | template<> |
---|
| 96 | inline void Traveller<Player>::MoveTo(float x, float y, float z, uint32 t) |
---|
| 97 | { |
---|
| 98 | //Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags |
---|
| 99 | i_traveller.SendMonsterMove(x, y, z, 0, MOVEMENTFLAG_WALK_MODE, t); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | typedef Traveller<Creature> CreatureTraveller; |
---|
| 103 | typedef Traveller<Player> PlayerTraveller; |
---|
| 104 | #endif |
---|