2 * Copyright (C) 2005-2013 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"
22 #include "CreatureAI.h"
23 #include "TemporarySummon.h"
25 #include "movement/MoveSplineInit.h"
26 #include "movement/MoveSpline.h"
28 //----- Point Movement Generator
30 void PointMovementGenerator
<T
>::Initialize(T
& unit
)
32 if (!unit
.IsStopped())
35 unit
.addUnitState(UNIT_STAT_ROAMING
| UNIT_STAT_ROAMING_MOVE
);
36 Movement::MoveSplineInit
init(unit
);
37 init
.MoveTo(i_x
, i_y
, i_z
, m_generatePath
);
42 void PointMovementGenerator
<T
>::Finalize(T
& unit
)
44 unit
.clearUnitState(UNIT_STAT_ROAMING
| UNIT_STAT_ROAMING_MOVE
);
46 if (unit
.movespline
->Finalized())
51 void PointMovementGenerator
<T
>::Interrupt(T
& unit
)
53 unit
.clearUnitState(UNIT_STAT_ROAMING
| UNIT_STAT_ROAMING_MOVE
);
57 void PointMovementGenerator
<T
>::Reset(T
& unit
)
59 if (!unit
.IsStopped())
62 unit
.addUnitState(UNIT_STAT_ROAMING
| UNIT_STAT_ROAMING_MOVE
);
66 bool PointMovementGenerator
<T
>::Update(T
& unit
, const uint32
& diff
)
71 if (unit
.hasUnitState(UNIT_STAT_CAN_NOT_MOVE
))
73 unit
.clearUnitState(UNIT_STAT_ROAMING_MOVE
);
77 unit
.addUnitState(UNIT_STAT_ROAMING_MOVE
);
78 return !unit
.movespline
->Finalized();
82 void PointMovementGenerator
<Player
>::MovementInform(Player
&)
87 void PointMovementGenerator
<Creature
>::MovementInform(Creature
& unit
)
90 unit
.AI()->MovementInform(POINT_MOTION_TYPE
, id
);
92 if (unit
.IsTemporarySummon())
94 TemporarySummon
* pSummon
= (TemporarySummon
*)(&unit
);
95 if (pSummon
->GetSummonerGuid().IsCreatureOrVehicle())
96 if (Creature
* pSummoner
= unit
.GetMap()->GetCreature(pSummon
->GetSummonerGuid()))
98 pSummoner
->AI()->SummonedMovementInform(&unit
, POINT_MOTION_TYPE
, id
);
102 template void PointMovementGenerator
<Player
>::Initialize(Player
&);
103 template void PointMovementGenerator
<Creature
>::Initialize(Creature
&);
104 template void PointMovementGenerator
<Player
>::Finalize(Player
&);
105 template void PointMovementGenerator
<Creature
>::Finalize(Creature
&);
106 template void PointMovementGenerator
<Player
>::Interrupt(Player
&);
107 template void PointMovementGenerator
<Creature
>::Interrupt(Creature
&);
108 template void PointMovementGenerator
<Player
>::Reset(Player
&);
109 template void PointMovementGenerator
<Creature
>::Reset(Creature
&);
110 template bool PointMovementGenerator
<Player
>::Update(Player
&, const uint32
& diff
);
111 template bool PointMovementGenerator
<Creature
>::Update(Creature
&, const uint32
& diff
);
113 void AssistanceMovementGenerator::Finalize(Unit
& unit
)
115 unit
.clearUnitState(UNIT_STAT_ROAMING
| UNIT_STAT_ROAMING_MOVE
);
117 ((Creature
*)&unit
)->SetNoCallAssistance(false);
118 ((Creature
*)&unit
)->CallAssistance();
120 unit
.GetMotionMaster()->MoveSeekAssistanceDistract(sWorld
.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY
));
123 bool EffectMovementGenerator::Update(Unit
& unit
, const uint32
&)
125 return !unit
.movespline
->Finalized();
128 void EffectMovementGenerator::Finalize(Unit
& unit
)
130 if (unit
.GetTypeId() != TYPEID_UNIT
)
133 if (((Creature
&)unit
).AI() && unit
.movespline
->Finalized())
134 ((Creature
&)unit
).AI()->MovementInform(EFFECT_MOTION_TYPE
, m_Id
);
135 // Need restore previous movement since we have no proper states system
136 if (unit
.isAlive() && !unit
.hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_FLEEING
))
138 if (Unit
* victim
= unit
.getVictim())
139 unit
.GetMotionMaster()->MoveChase(victim
);
141 unit
.GetMotionMaster()->Initialize();