Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
PointMovementGenerator.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
Creature.h
"
7
#include "
CreatureAI.h
"
8
#include "
CreatureGroups.h
"
9
#include "
Errors.h
"
10
#include "
MoveSpline.h
"
11
#include "
MoveSplineInit.h
"
12
#include "
Player.h
"
13
#include "
PointMovementGenerator.h
"
14
#include "
World.h
"
15
16
//----- Point Movement Generator
17
template
<
class
T>
18
void
PointMovementGenerator<T>::DoInitialize
(T* unit)
19
{
20
if
(!unit->IsStopped())
21
unit->StopMoving();
22
23
unit->AddUnitState(
UNIT_STATE_ROAMING
|
UNIT_STATE_ROAMING_MOVE
);
24
25
if
(
id
==
EVENT_CHARGE_PREPATH
)
26
return
;
27
28
Movement::MoveSplineInit
init(unit);
29
init.MoveTo(
i_x
,
i_y
,
i_z
,
m_generatePath
);
30
if
(
speed
> 0.0f)
31
init.SetVelocity(
speed
);
32
init.Launch();
33
34
// Call for creature group update
35
if
(
Creature
* creature = unit->
ToCreature
())
36
if
(creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
37
creature->GetFormation()->LeaderMoveTo(
i_x
,
i_y
,
i_z
);
38
}
39
40
template
<
class
T>
41
bool
PointMovementGenerator<T>::DoUpdate
(T* unit,
uint32
/*diff*/
)
42
{
43
if
(!unit)
44
return
false
;
45
46
if
(unit->HasUnitState(
UNIT_STATE_ROOT
|
UNIT_STATE_STUNNED
))
47
{
48
unit->ClearUnitState(
UNIT_STATE_ROAMING_MOVE
);
49
return
true
;
50
}
51
52
unit->AddUnitState(
UNIT_STATE_ROAMING_MOVE
);
53
54
if
(
id
!=
EVENT_CHARGE_PREPATH
&&
i_recalculateSpeed
&& !unit->movespline->Finalized())
55
{
56
i_recalculateSpeed
=
false
;
57
Movement::MoveSplineInit
init(unit);
58
init.
MoveTo
(
i_x
,
i_y
,
i_z
,
m_generatePath
);
59
if
(
speed
> 0.0f)
// Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
60
init.
SetVelocity
(
speed
);
61
init.
Launch
();
62
63
// Call for creature group update
64
if
(
Creature
* creature = unit->
ToCreature
())
65
if
(creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
66
creature->GetFormation()->LeaderMoveTo(
i_x
,
i_y
,
i_z
);
67
}
68
69
return
!unit->movespline->Finalized();
70
}
71
72
template
<
class
T>
73
void
PointMovementGenerator<T>::DoFinalize
(T* unit)
74
{
75
if
(unit->HasUnitState(
UNIT_STATE_CHARGING
))
76
unit->ClearUnitState(
UNIT_STATE_ROAMING
|
UNIT_STATE_ROAMING_MOVE
);
77
78
if
(unit->movespline->Finalized())
79
MovementInform
(unit);
80
}
81
82
template
<
class
T>
83
void
PointMovementGenerator<T>::DoReset
(T* unit)
84
{
85
if
(!unit->IsStopped())
86
unit->StopMoving();
87
88
unit->AddUnitState(
UNIT_STATE_ROAMING
|
UNIT_STATE_ROAMING_MOVE
);
89
}
90
91
template
<
class
T>
92
void
PointMovementGenerator<T>::MovementInform
(T*
/*unit*/
) { }
93
94
template
<>
void
PointMovementGenerator<Creature>::MovementInform
(
Creature
* unit)
95
{
96
if
(unit->
AI
())
97
unit->
AI
()->
MovementInform
(
POINT_MOTION_TYPE
,
id
);
98
}
99
100
template
void
PointMovementGenerator<Player>::DoInitialize
(
Player
*);
101
template
void
PointMovementGenerator<Creature>::DoInitialize
(
Creature
*);
102
template
void
PointMovementGenerator<Player>::DoFinalize
(
Player
*);
103
template
void
PointMovementGenerator<Creature>::DoFinalize
(
Creature
*);
104
template
void
PointMovementGenerator<Player>::DoReset
(
Player
*);
105
template
void
PointMovementGenerator<Creature>::DoReset
(
Creature
*);
106
template
bool
PointMovementGenerator<Player>::DoUpdate
(
Player
*,
uint32
);
107
template
bool
PointMovementGenerator<Creature>::DoUpdate
(
Creature
*,
uint32
);
108
109
void
AssistanceMovementGenerator::Finalize
(
Unit
* unit)
110
{
111
unit->
ToCreature
()->
SetNoCallAssistance
(
false
);
112
unit->
ToCreature
()->
CallAssistance
();
113
if
(unit->
IsAlive
())
114
unit->
GetMotionMaster
()->
MoveSeekAssistanceDistract
(
sWorld
->getIntConfig(
WorldIntConfigs::CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY
));
115
}
116
117
bool
EffectMovementGenerator::Update
(
Unit
* unit,
uint32
)
118
{
119
return
!unit->
movespline
->Finalized();
120
}
121
122
void
EffectMovementGenerator::Finalize
(
Unit
* unit)
123
{
124
if
(unit->
GetTypeId
() !=
TypeID::TYPEID_UNIT
)
125
return
;
126
127
// Need restore previous movement since we have no proper states system
128
if
(unit->
IsAlive
() && !unit->
HasUnitState
(
UNIT_STATE_CONFUSED
|
UNIT_STATE_FLEEING
))
129
{
130
if
(
Unit
* victim = unit->
GetVictim
())
131
unit->
GetMotionMaster
()->
MoveChase
(victim);
132
else
133
unit->
GetMotionMaster
()->
Initialize
();
134
}
135
136
if
(unit->
ToCreature
()->
AI
())
137
unit->
ToCreature
()->
AI
()->
MovementInform
(
EFFECT_MOTION_TYPE
,
m_Id
);
138
}
Creature.h
CreatureAI.h
CreatureGroups.h
uint32
std::uint32_t uint32
Definition
Define.h:77
Errors.h
POINT_MOTION_TYPE
@ POINT_MOTION_TYPE
Definition
MotionMaster.h:33
EFFECT_MOTION_TYPE
@ EFFECT_MOTION_TYPE
Definition
MotionMaster.h:41
MoveSpline.h
MoveSplineInit.h
TypeID::TYPEID_UNIT
@ TYPEID_UNIT
Definition
Object.h:54
Player.h
PointMovementGenerator.h
EVENT_CHARGE_PREPATH
@ EVENT_CHARGE_PREPATH
Definition
SharedDefines.h:3860
UNIT_STATE_ROAMING_MOVE
@ UNIT_STATE_ROAMING_MOVE
Definition
Unit.h:534
UNIT_STATE_CONFUSED
@ UNIT_STATE_CONFUSED
Definition
Unit.h:523
UNIT_STATE_ROOT
@ UNIT_STATE_ROOT
Definition
Unit.h:522
UNIT_STATE_CHARGING
@ UNIT_STATE_CHARGING
Definition
Unit.h:529
UNIT_STATE_ROAMING
@ UNIT_STATE_ROAMING
Definition
Unit.h:516
UNIT_STATE_FLEEING
@ UNIT_STATE_FLEEING
Definition
Unit.h:519
UNIT_STATE_STUNNED
@ UNIT_STATE_STUNNED
Definition
Unit.h:515
World.h
AssistanceMovementGenerator::Finalize
void Finalize(Unit *)
Definition
PointMovementGenerator.cpp:109
CreatureAI::MovementInform
virtual void MovementInform(uint32, uint32)
Definition
CreatureAI.h:118
Creature
Definition
Creature.h:427
Creature::SetNoCallAssistance
void SetNoCallAssistance(bool val)
Definition
Creature.h:583
Creature::CallAssistance
void CallAssistance()
Definition
Creature.cpp:1834
Creature::AI
CreatureAI * AI() const
Definition
Creature.h:483
EffectMovementGenerator::Update
bool Update(Unit *, uint32)
Definition
PointMovementGenerator.cpp:117
EffectMovementGenerator::m_Id
uint32 m_Id
Definition
PointMovementGenerator.h:60
EffectMovementGenerator::Finalize
void Finalize(Unit *)
Definition
PointMovementGenerator.cpp:122
MotionMaster::Initialize
void Initialize()
Definition
MotionMaster.cpp:27
MotionMaster::MoveChase
void MoveChase(Unit *target, float dist=0.0f, float angle=0.0f)
Definition
MotionMaster.cpp:225
MotionMaster::MoveSeekAssistanceDistract
void MoveSeekAssistanceDistract(uint32 timer)
Definition
MotionMaster.cpp:440
Movement::MoveSplineInit
Definition
MoveSplineInit.h:40
Movement::MoveSplineInit::Launch
int32 Launch()
Definition
MoveSplineInit.cpp:46
Movement::MoveSplineInit::SetVelocity
void SetVelocity(float velocity)
Definition
MoveSplineInit.h:151
Movement::MoveSplineInit::MoveTo
void MoveTo(const Vector3 &destination, bool generatePath=true, bool forceDestination=false)
Definition
MoveSplineInit.cpp:157
Object::GetTypeId
TypeID GetTypeId() const
Definition
Object.h:131
Object::ToCreature
Creature * ToCreature()
Definition
Object.h:207
Player
Definition
Player.h:1289
PointMovementGenerator< Creature >::i_z
float i_z
Definition
PointMovementGenerator.h:33
PointMovementGenerator::DoUpdate
bool DoUpdate(T *, uint32)
Definition
PointMovementGenerator.cpp:41
PointMovementGenerator::i_recalculateSpeed
bool i_recalculateSpeed
Definition
PointMovementGenerator.h:36
PointMovementGenerator< Creature >::m_generatePath
bool m_generatePath
Definition
PointMovementGenerator.h:35
PointMovementGenerator::MovementInform
void MovementInform(T *)
Definition
PointMovementGenerator.cpp:92
PointMovementGenerator::DoReset
void DoReset(T *)
Definition
PointMovementGenerator.cpp:83
PointMovementGenerator< Creature >::speed
float speed
Definition
PointMovementGenerator.h:34
PointMovementGenerator< Creature >::i_x
float i_x
Definition
PointMovementGenerator.h:33
PointMovementGenerator::DoFinalize
void DoFinalize(T *)
Definition
PointMovementGenerator.cpp:73
PointMovementGenerator< Creature >::i_y
float i_y
Definition
PointMovementGenerator.h:33
PointMovementGenerator::DoInitialize
void DoInitialize(T *)
Definition
PointMovementGenerator.cpp:18
Unit
Definition
Unit.h:1367
Unit::GetMotionMaster
MotionMaster * GetMotionMaster()
Definition
Unit.h:2605
Unit::IsAlive
bool IsAlive() const
Definition
Unit.h:2032
Unit::GetVictim
Unit * GetVictim() const
Definition
Unit.h:1468
Unit::HasUnitState
bool HasUnitState(const uint32 f) const
Definition
Unit.h:1485
Unit::movespline
std::unique_ptr< Movement::MoveSpline > movespline
Definition
Unit.h:2837
sWorld
#define sWorld
Definition
World.h:910
WorldIntConfigs::CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY
@ CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY
Definition
World.h:270
src
server
game
Movement
MovementGenerators
PointMovementGenerator.cpp
Generated on
for Project SkyFire Core by
1.17.0