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>
36
38
39template<class T>
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<>
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<>
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:154
@ 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:273
@ UNIT_STATE_EVADE
Definition Unit.h:283
@ UNIT_STATE_ROAMING_MOVE
Definition Unit.h:284
@ UNIT_STATE_ROOT
Definition Unit.h:271
@ UNIT_STATE_ROAMING
Definition Unit.h:265
@ UNIT_STATE_ALL_ERASABLE
Definition Unit.h:308
@ UNIT_STATE_STUNNED
Definition Unit.h:264
bool LoadCreaturesAddon()
void SetNoSearchAssistance(bool val)
Definition Creature.h:340
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition Creature.h:388
void InitializeMovementCapabilities()
bool IsStateRestoredOnEvade() const
Definition Creature.h:220
void LoadCreaturesSparringHealth(bool force=false)
void SetSpawnHealth()
CreatureAI * AI() const
Definition Creature.h:228
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:744
bool IsVehicle() const
Definition Unit.h:754
void AddUnitState(uint32 f)
Definition Unit.h:742
bool HasUnitState(const uint32 f) const
Definition Unit.h:743
std::unique_ptr< Movement::MoveSpline > movespline
Definition Unit.h:1838
Vehicle * GetVehicleKit() const
Definition Unit.h:1782
void Reset(bool evading=false)
Reapplies immunities and reinstalls accessories. Only has effect for creatures.
Definition Vehicle.cpp:150
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition Object.cpp:711
float m_positionZ
Definition Position.h:66
float m_positionX
Definition Position.h:64
float m_positionY
Definition Position.h:65
constexpr float GetOrientation() const
Definition Position.h:90