root/trunk/src/game/Traveller.h @ 102

Revision 102, 3.6 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
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
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef TRINITY_TRAVELLER_H
22#define TRINITY_TRAVELLER_H
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
34template<class T>
35struct TRINITY_DLL_DECL Traveller
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
61template<>
62inline float Traveller<Creature>::Speed()
63{
64    return i_traveller.GetSpeed( i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
65}
66
67template<>
68inline 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
73template<>
74inline 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
80template<>
81inline 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
89template<>
90inline 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
95template<>
96inline 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
102typedef Traveller<Creature> CreatureTraveller;
103typedef Traveller<Player> PlayerTraveller;
104#endif
Note: See TracBrowser for help on using the browser.