TrinityCore
Loading...
Searching...
No Matches
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>
35
37
38template<class T>
43
45
46template<class T>
48
49template<>
51{
52 // if we are ROOT/STUNNED/DISTRACTED even after aura clear, finalize on next update - otherwise we would get stuck in evade
54 {
56 return;
57 }
58
61
62 Position destination = owner->GetHomePosition();
63 Movement::MoveSplineInit init(owner);
64
65 /*
66 * TODO: maybe this never worked, who knows, top is always this generator, so this code calls GetResetPosition on itself
67 *
68 * if (owner->GetMotionMaster()->empty() || !owner->GetMotionMaster()->top()->GetResetPosition(owner, x, y, z))
69 * {
70 * owner->GetHomePosition(x, y, z, o);
71 * init.SetFacing(o);
72 * }
73 */
74
75 owner->UpdateAllowedPositionZ(destination.m_positionX, destination.m_positionY, destination.m_positionZ);
76 init.MoveTo(PositionToVector3(destination), true, true);
77 init.SetFacing(destination.GetOrientation());
78 init.SetWalk(false);
79 init.Launch();
80}
81
82template<class T>
84
85template<>
87{
90
91 owner->SetNoSearchAssistance(false);
92
93 SetTargetLocation(owner);
94 return true;
95}
96
97template<class T>
98bool HomeMovementGenerator<T>::DoReset(T*) { return false; }
99
100template<>
102{
104
105 return DoInitialize(owner);
106}
107
108template<class T>
110{
111 return false;
112}
113
114template<>
116{
118 {
120 return false;
121 }
122 return true;
123}
124
125template<class T>
127
128template<>
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->HasCanSwimFlagOutOfCombat())
149
150 owner->SetSpawnHealth();
151 owner->LoadCreaturesAddon();
152 if (owner->IsVehicle())
153 owner->GetVehicleKit()->Reset(true);
154 owner->AI()->JustReachedHome();
155 }
156}
uint32_t uint32
Definition Define.h:133
@ 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_FLAG_CAN_SWIM
@ UNIT_STATE_DISTRACTED
Definition Unit.h:232
@ UNIT_STATE_EVADE
Definition Unit.h:242
@ UNIT_STATE_ROAMING_MOVE
Definition Unit.h:243
@ UNIT_STATE_ROOT
Definition Unit.h:230
@ UNIT_STATE_ROAMING
Definition Unit.h:224
@ UNIT_STATE_ALL_ERASABLE
Definition Unit.h:267
@ UNIT_STATE_STUNNED
Definition Unit.h:223
virtual void JustReachedHome()
Definition CreatureAI.h:178
bool LoadCreaturesAddon()
void SetNoSearchAssistance(bool val)
Definition Creature.h:245
bool HasCanSwimFlagOutOfCombat() const
Definition Creature.h:363
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition Creature.h:295
void SetSpawnHealth()
CreatureAI * AI() const
Definition Creature.h:154
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)
bool Finalized() const
Definition MoveSpline.h:121
void ClearUnitState(uint32 f)
Definition Unit.h:877
bool IsVehicle() const
Definition Unit.h:887
Movement::MoveSpline * movespline
Definition Unit.h:1804
void AddUnitState(uint32 f)
Definition Unit.h:875
bool HasUnitState(const uint32 f) const
Definition Unit.h:876
Vehicle * GetVehicleKit() const
Definition Unit.h:1735
void RemoveUnitFlag(UnitFlags flags)
Definition Unit.h:955
void Reset(bool evading=false)
Reapplies immunities and reinstalls accessories. Only has effect for creatures.
Definition Vehicle.cpp:137
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition Object.cpp:1416
float m_positionZ
Definition Position.h:58
float m_positionX
Definition Position.h:56
float m_positionY
Definition Position.h:57
float GetOrientation() const
Definition Position.h:82