[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / PointMovementGenerator.cpp
blobbcac405e3416eec57e4c01763dbd3814563351e3
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #include "PointMovementGenerator.h"
20 #include "Errors.h"
21 #include "Creature.h"
22 #include "CreatureAI.h"
23 #include "TemporarySummon.h"
24 #include "DestinationHolderImp.h"
25 #include "World.h"
27 //----- Point Movement Generator
28 template<class T>
29 void PointMovementGenerator<T>::Initialize(T &unit)
31 unit.StopMoving();
32 unit.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
33 Traveller<T> traveller(unit);
34 i_destinationHolder.SetDestination(traveller,i_x,i_y,i_z);
36 if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->canFly())
37 ((Creature&)unit).AddMonsterMoveFlag(MONSTER_MOVE_FLY);
40 template<class T>
41 void PointMovementGenerator<T>::Finalize(T &unit)
43 unit.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
46 template<class T>
47 void PointMovementGenerator<T>::Interrupt(T &unit)
49 unit.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
52 template<class T>
53 void PointMovementGenerator<T>::Reset(T &unit)
55 unit.StopMoving();
56 unit.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
60 template<class T>
61 bool PointMovementGenerator<T>::Update(T &unit, const uint32 &diff)
63 if(!&unit)
64 return false;
66 if(unit.hasUnitState(UNIT_STAT_CAN_NOT_MOVE))
68 unit.clearUnitState(UNIT_STAT_ROAMING_MOVE);
69 return true;
72 unit.addUnitState(UNIT_STAT_ROAMING_MOVE);
73 Traveller<T> traveller(unit);
74 i_destinationHolder.UpdateTraveller(traveller, diff, false);
76 if(i_destinationHolder.HasArrived())
78 unit.StopMoving();
79 MovementInform(unit);
80 return false;
83 return true;
86 template<>
87 void PointMovementGenerator<Player>::MovementInform(Player&)
91 template <>
92 void PointMovementGenerator<Creature>::MovementInform(Creature &unit)
94 if (unit.AI())
95 unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
97 if (unit.isTemporarySummon())
99 TemporarySummon* pSummon = (TemporarySummon*)(&unit);
100 if (IS_CREATURE_GUID(pSummon->GetSummonerGUID()))
101 if(Creature* pSummoner = unit.GetMap()->GetCreature(pSummon->GetSummonerGUID()))
102 if (pSummoner->AI())
103 pSummoner->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id);
107 template void PointMovementGenerator<Player>::Initialize(Player&);
108 template void PointMovementGenerator<Creature>::Initialize(Creature&);
109 template void PointMovementGenerator<Player>::Finalize(Player&);
110 template void PointMovementGenerator<Creature>::Finalize(Creature&);
111 template void PointMovementGenerator<Player>::Interrupt(Player&);
112 template void PointMovementGenerator<Creature>::Interrupt(Creature&);
113 template void PointMovementGenerator<Player>::Reset(Player&);
114 template void PointMovementGenerator<Creature>::Reset(Creature&);
115 template bool PointMovementGenerator<Player>::Update(Player &, const uint32 &diff);
116 template bool PointMovementGenerator<Creature>::Update(Creature&, const uint32 &diff);
118 void AssistanceMovementGenerator::Finalize(Unit &unit)
120 unit.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
122 ((Creature*)&unit)->SetNoCallAssistance(false);
123 ((Creature*)&unit)->CallAssistance();
124 if (unit.isAlive())
125 unit.GetMotionMaster()->MoveSeekAssistanceDistract(sWorld.getConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY));