| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.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 | #include "PointMovementGenerator.h" |
|---|
| 22 | #include "Errors.h" |
|---|
| 23 | #include "Creature.h" |
|---|
| 24 | #include "CreatureAI.h" |
|---|
| 25 | #include "MapManager.h" |
|---|
| 26 | #include "DestinationHolderImp.h" |
|---|
| 27 | |
|---|
| 28 | //----- Point Movement Generator |
|---|
| 29 | template<class T> |
|---|
| 30 | void PointMovementGenerator<T>::Initialize(T &unit) |
|---|
| 31 | { |
|---|
| 32 | unit.StopMoving(); |
|---|
| 33 | Traveller<T> traveller(unit); |
|---|
| 34 | i_destinationHolder.SetDestination(traveller,i_x,i_y,i_z); |
|---|
| 35 | |
|---|
| 36 | if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->canFly()) |
|---|
| 37 | unit.AddUnitMovementFlag(MOVEMENTFLAG_FLYING2); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | template<class T> |
|---|
| 41 | bool PointMovementGenerator<T>::Update(T &unit, const uint32 &diff) |
|---|
| 42 | { |
|---|
| 43 | if(!&unit) |
|---|
| 44 | return false; |
|---|
| 45 | |
|---|
| 46 | if(unit.hasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED)) |
|---|
| 47 | return true; |
|---|
| 48 | |
|---|
| 49 | Traveller<T> traveller(unit); |
|---|
| 50 | |
|---|
| 51 | i_destinationHolder.UpdateTraveller(traveller, diff, false); |
|---|
| 52 | |
|---|
| 53 | if(i_destinationHolder.HasArrived()) |
|---|
| 54 | { |
|---|
| 55 | unit.StopMoving(); |
|---|
| 56 | MovementInform(unit); |
|---|
| 57 | return false; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | return true; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | template<class T> |
|---|
| 64 | void PointMovementGenerator<T>::MovementInform(T &unit) |
|---|
| 65 | { |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | template <> void PointMovementGenerator<Creature>::MovementInform(Creature &unit) |
|---|
| 69 | { |
|---|
| 70 | unit.AI()->MovementInform(POINT_MOTION_TYPE, id); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | template void PointMovementGenerator<Player>::Initialize(Player&); |
|---|
| 74 | template bool PointMovementGenerator<Player>::Update(Player &, const uint32 &diff); |
|---|
| 75 | template void PointMovementGenerator<Player>::MovementInform(Player&); |
|---|
| 76 | |
|---|
| 77 | template void PointMovementGenerator<Creature>::Initialize(Creature&); |
|---|
| 78 | template bool PointMovementGenerator<Creature>::Update(Creature&, const uint32 &diff); |
|---|