[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[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_DESTINATION_HOLDER_H |
---|
| 22 | #define TRINITY_DESTINATION_HOLDER_H |
---|
[2] | 23 | |
---|
| 24 | #include "Platform/Define.h" |
---|
| 25 | #include "Timer.h" |
---|
| 26 | |
---|
| 27 | class WorldObject; |
---|
| 28 | |
---|
| 29 | #define TRAVELLER_UPDATE_INTERVAL 300 |
---|
| 30 | |
---|
| 31 | template<typename TRAVELLER> |
---|
[44] | 32 | class TRINITY_DLL_DECL DestinationHolder |
---|
[2] | 33 | { |
---|
| 34 | TimeTrackerSmall i_tracker; |
---|
| 35 | uint32 i_totalTravelTime; |
---|
| 36 | uint32 i_timeElapsed; |
---|
| 37 | bool i_destSet; |
---|
| 38 | float i_fromX, i_fromY, i_fromZ; |
---|
| 39 | float i_destX, i_destY, i_destZ; |
---|
| 40 | |
---|
| 41 | public: |
---|
| 42 | DestinationHolder() : i_tracker(TRAVELLER_UPDATE_INTERVAL), i_totalTravelTime(0), i_timeElapsed(0), |
---|
| 43 | i_destSet(false), i_fromX(0), i_fromY(0), i_fromZ(0), i_destX(0), i_destY(0), i_destZ(0) {} |
---|
| 44 | |
---|
| 45 | uint32 SetDestination(TRAVELLER &traveller, float dest_x, float dest_y, float dest_z, bool sendMove = true); |
---|
| 46 | void GetDestination(float &x, float &y, float &z) const { x = i_destX; y = i_destY; z = i_destZ; } |
---|
| 47 | bool UpdateExpired(void) const { return i_tracker.Passed(); } |
---|
| 48 | void ResetUpdate(uint32 t = TRAVELLER_UPDATE_INTERVAL) { i_tracker.Reset(t); } |
---|
| 49 | uint32 GetTotalTravelTime(void) const { return i_totalTravelTime; } |
---|
| 50 | void IncreaseTravelTime(uint32 increment) { i_totalTravelTime += increment; } |
---|
| 51 | bool HasDestination(void) const { return i_destSet; } |
---|
| 52 | float GetDestinationDiff(float x, float y, float z) const; |
---|
| 53 | bool HasArrived(void) const { return (i_totalTravelTime == 0 || i_timeElapsed >= i_totalTravelTime); } |
---|
| 54 | bool UpdateTraveller(TRAVELLER &traveller, uint32 diff, bool force_update=false, bool micro_movement=false); |
---|
| 55 | uint32 StartTravel(TRAVELLER &traveller, bool sendMove = true); |
---|
| 56 | void GetLocationNow(uint32 mapid, float &x, float &y, float &z, bool is3D = false) const; |
---|
| 57 | void GetLocationNowNoMicroMovement(float &x, float &y, float &z) const; // For use without micro movement |
---|
| 58 | float GetDistance2dFromDestSq(const WorldObject &obj) const; |
---|
| 59 | |
---|
| 60 | private: |
---|
| 61 | void _findOffSetPoint(float x1, float y1, float x2, float y2, float offset, float &x, float &y); |
---|
| 62 | |
---|
| 63 | }; |
---|
| 64 | #endif |
---|