OregonCore  revision 3611e8a-git
Your Favourite TBC server
PointMovementGenerator.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "PointMovementGenerator.h"
19 #include "Errors.h"
20 #include "Creature.h"
21 #include "CreatureAI.h"
22 #include "ScriptedInstance.h"
23 #include "TemporarySummon.h"
24 #include "MapManager.h"
25 #include "World.h"
26 #include "PathFinder.h"
27 #include "MoveSplineInit.h"
28 #include "MoveSpline.h"
29 
30 //----- Point Movement Generator
31 template<class T>
33 {
34  if (!unit.IsStopped())
35  unit.StopMoving();
36 
37  unit.AddUnitState(UNIT_STATE_ROAMING);
38  Movement::MoveSplineInit init(unit);
39  init.MoveTo(i_x, i_y, i_z, m_usePathfinding);
40  if (speed > 0.0f)
41  init.SetVelocity(speed);
42  init.Launch();
43 }
44 
45 template<class T>
47 {
48  if (unit.HasUnitState(UNIT_STATE_CHARGING))
49  unit.ClearUnitState(UNIT_STATE_CHARGING | UNIT_STATE_JUMPING);
50 
51  if (unit.movespline->Finalized())
52  MovementInform(unit);
53 }
54 
55 template<class T>
56 bool PointMovementGenerator<T>::Update(T& unit, const uint32& diff)
57 {
58  if (unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
59  {
60  if (unit.HasUnitState(UNIT_STATE_CHARGING))
61  return false;
62  else
63  return true;
64  }
65 
66  if (unit.movespline->Finalized())
67  {
68  unit.ClearUnitState(UNIT_STATE_MOVE);
69  return false;
70  }
71 
72  return true;
73 }
74 
75 template<class T>
77 {
78 }
79 
81 {
82  unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
83 
84  if (unit.IsSummon())
85  {
86  if (TempSummon* pSummon = (TempSummon*)(&unit))
87  {
88  if (Unit* pSummoner = pSummon->GetSummoner())
89  {
90  if (pSummoner->GetTypeId() == TYPEID_UNIT)
91  {
92  if (ScriptedInstance* pInstance = (ScriptedInstance*)pSummoner->GetInstanceData())
93  pInstance->MovementInform(&unit, POINT_MOTION_TYPE, id);
94 
95  if (pSummoner->ToCreature()->AI())
96  pSummoner->ToCreature()->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id);
97  }
98  }
99  }
100  }
101 }
102 
106 template bool PointMovementGenerator<Player>::Update(Player&, const uint32& diff);
108 
112 template bool PointMovementGenerator<Creature>::Update(Creature&, const uint32& diff);
113 
115 {
116  unit.ToCreature()->SetNoCallAssistance(false);
117  unit.ToCreature()->CallAssistance();
118  if (unit.IsAlive())
120 }
121 
123 {
124  return !unit.movespline->Finalized();
125 }
126 
128 {
129  if (unit.GetTypeId() != TYPEID_UNIT)
130  return;
131 
132  // Need restore previous movement since we have no proper states system
134  {
135  if (Unit* victim = unit.GetVictim())
136  unit.GetMotionMaster()->MoveChase(victim);
137  else
138  unit.GetMotionMaster()->Initialize();
139  }
140  else if (!unit.IsAlive())
141  {
142  unit.GetMotionMaster()->MoveIdle();
143  }
144 
145  if (unit.ToCreature()->AI())
147 }
void SetVelocity(float velocity)
void MoveIdle(MovementSlot slot=MOTION_SLOT_ACTIVE)
void SetNoCallAssistance(bool val)
Definition: Creature.h:697
void MoveSeekAssistanceDistract(uint32 timer)
void MoveChase(Unit *target, float dist=0.0f, float angle=0.0f)
Movement::MoveSpline * movespline
Definition: Unit.h:2018
MotionMaster * GetMotionMaster()
Definition: Unit.h:2001
bool Update(T &, const uint32 &diff)
void MoveTo(const Vector3 &destination, bool generatePath=false, bool forceDestination=false)
bool Update(Unit &, const uint32 &)
void CallAssistance()
Definition: Creature.cpp:1906
uint8 GetTypeId() const
Definition: Object.h:204
bool IsAlive() const
Definition: Unit.h:1433
Unit * GetVictim() const
Definition: Unit.h:985
CreatureAI * AI() const
Definition: Creature.h:548
bool Finalized() const
Definition: MoveSpline.h:117
Creature * ToCreature()
Definition: Object.h:389
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1002
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
void Initialize()
bool IsSummon() const
Definition: Unit.h:1018
Definition: Unit.h:884
Definition: Player.h:922
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:145