TrinityCore
HomeMovementGenerator.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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
19#include "Creature.h"
20#include "CreatureAI.h"
21#include "G3DPosition.hpp"
22#include "MotionMaster.h"
23#include "MovementDefines.h"
24#include "MoveSpline.h"
25#include "MoveSplineInit.h"
26#include "Vehicle.h"
27
28template<class T>
30{
31 this->Mode = MOTION_MODE_DEFAULT;
32 this->Priority = MOTION_PRIORITY_NORMAL;
34 this->BaseUnitState = UNIT_STATE_ROAMING;
35}
36
38
39template<class T>
41{
42 return HOME_MOTION_TYPE;
43}
44
46
47template<class T>
49
50template<>
52{
53 // if we are ROOT/STUNNED/DISTRACTED even after aura clear, finalize on next update - otherwise we would get stuck in evade
55 {
57 return;
58 }
59
62
63 Position destination = owner->GetHomePosition();
64 Movement::MoveSplineInit init(owner);
65
66 /*
67 * TODO: maybe this never worked, who knows, top is always this generator, so this code calls GetResetPosition on itself
68 *
69 * if (owner->GetMotionMaster()->empty() || !owner->GetMotionMaster()->top()->GetResetPosition(owner, x, y, z))
70 * {
71 * owner->GetHomePosition(x, y, z, o);
72 * init.SetFacing(o);
73 * }
74 */
75
76 owner->UpdateAllowedPositionZ(destination.m_positionX, destination.m_positionY, destination.m_positionZ);
77 init.MoveTo(PositionToVector3(destination));
78 init.SetFacing(destination.GetOrientation());
79 init.SetWalk(false);
80 init.Launch();
81}
82
83template<class T>
85
86template<>
88{
91
92 owner->SetNoSearchAssistance(false);
93
94 SetTargetLocation(owner);
95}
96
97template<class T>
99
100template<>
102{
104
105 DoInitialize(owner);
106}
107
108template<class T>
110{
111 return false;
112}
113
114template<>
116{
117 if (HasFlag(MOVEMENTGENERATOR_FLAG_INTERRUPTED) || owner->movespline->Finalized())
118 {
120 return false;
121 }
122 return true;
123}
124
125template<class T>
127
128template<>
130{
133}
134
135template<class T>
137
138template<>
139void HomeMovementGenerator<Creature>::DoFinalize(Creature* owner, bool active, bool movementInform)
140{
142 if (active)
144
145 if (movementInform && HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED))
146 {
147 if (owner->IsStateRestoredOnEvade())
148 {
150 owner->SetSpawnHealth();
151 owner->LoadCreaturesAddon();
153 if (owner->IsVehicle())
154 owner->GetVehicleKit()->Reset(true);
155 }
156 if (CreatureAI* ai = owner->AI())
157 ai->JustReachedHome();
158 }
159}
uint32_t uint32
Definition: Define.h:142
@ MOTION_MODE_DEFAULT
@ MOTION_PRIORITY_NORMAL
MovementGeneratorType
@ HOME_MOTION_TYPE
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_INTERRUPTED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ UNIT_STATE_DISTRACTED
Definition: Unit.h:267
@ UNIT_STATE_EVADE
Definition: Unit.h:277
@ UNIT_STATE_ROAMING_MOVE
Definition: Unit.h:278
@ UNIT_STATE_ROOT
Definition: Unit.h:265
@ UNIT_STATE_ROAMING
Definition: Unit.h:259
@ UNIT_STATE_ALL_ERASABLE
Definition: Unit.h:302
@ UNIT_STATE_STUNNED
Definition: Unit.h:258
bool LoadCreaturesAddon()
Definition: Creature.cpp:2749
void SetNoSearchAssistance(bool val)
Definition: Creature.h:318
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:373
void InitializeMovementCapabilities()
Definition: Creature.cpp:2906
bool IsStateRestoredOnEvade() const
Definition: Creature.h:206
void LoadCreaturesSparringHealth(bool force=false)
Definition: Creature.cpp:2806
void SetSpawnHealth()
Definition: Creature.cpp:1969
CreatureAI * AI() const
Definition: Creature.h:214
MovementGeneratorType GetMovementGeneratorType() const override
void DoFinalize(T *, bool, bool)
void MoveTo(Vector3 const &destination, bool generatePath=true, bool forceDestination=false)
void SetWalk(bool enable)
void SetFacing(float angle)
void ClearUnitState(uint32 f)
Definition: Unit.h:733
bool IsVehicle() const
Definition: Unit.h:743
void AddUnitState(uint32 f)
Definition: Unit.h:731
bool HasUnitState(const uint32 f) const
Definition: Unit.h:732
std::unique_ptr< Movement::MoveSpline > movespline
Definition: Unit.h:1766
Vehicle * GetVehicleKit() const
Definition: Unit.h:1711
void Reset(bool evading=false)
Reapplies immunities and reinstalls accessories. Only has effect for creatures.
Definition: Vehicle.cpp:138
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition: Object.cpp:1371
float m_positionZ
Definition: Position.h:55
float m_positionX
Definition: Position.h:53
float m_positionY
Definition: Position.h:54
constexpr float GetOrientation() const
Definition: Position.h:79