TrinityCore
Loading...
Searching...
No Matches
WaypointMovementGenerator.h
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
18#ifndef TRINITY_WAYPOINTMOVEMENTGENERATOR_H
19#define TRINITY_WAYPOINTMOVEMENTGENERATOR_H
20
21#include "MovementGenerator.h"
22#include "PathMovementBase.h"
23#include "Timer.h"
24#include "WaypointDefines.h"
25#include <variant>
26
27class Unit;
28
29template <typename T>
30class WaypointMovementGenerator : public MovementGeneratorMedium<T, WaypointMovementGenerator<T>>,
31 public PathMovementBase<std::variant<WaypointPath const*, std::unique_ptr<WaypointPath>>>
32{
33 public:
34 explicit WaypointMovementGenerator(uint32 pathId, bool repeating, Optional<Milliseconds> duration = {}, Optional<float> speed = {},
36 Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd = {}, Optional<float> wanderDistanceAtPathEnds = {},
37 Optional<bool> followPathBackwardsFromEndToStart = {}, Optional<bool> exactSplinePath = {}, bool generatePath = true,
38 Optional<MovementFadeObject> fadeObject = {},
40 explicit WaypointMovementGenerator(WaypointPath const& path, bool repeating, Optional<Milliseconds> duration, Optional<float> speed,
41 MovementWalkRunSpeedSelectionMode speedSelectionMode,
42 Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd, Optional<float> wanderDistanceAtPathEnds,
43 Optional<bool> followPathBackwardsFromEndToStart, Optional<bool> exactSplinePath, bool generatePath,
47
49
51 void Pause(uint32 timer) override;
52 void Resume(uint32 overrideTimer) override;
53 bool GetResetPosition(Unit*, float& x, float& y, float& z) override;
54
55 void DoInitialize(T* owner);
56 void DoReset(T* owner);
57 bool DoUpdate(T* owner, uint32 diff);
58 void DoDeactivate(T* owner);
59 void DoFinalize(T* owner, bool active, bool movementInform);
60
61 WaypointPath const* GetPath() const { return std::visit([](auto&& path) -> WaypointPath const* { return std::addressof(*path); }, _path); }
62
63 std::string GetDebugInfo() const override;
64
65 private:
66 void MovementInform(T const* owner) const;
67 void OnArrived(T* owner);
68 void StartMove(T* owner, bool relaunch = false);
69 bool ComputeNextNode();
70 bool UpdateMoveTimer(uint32 diff) { return UpdateTimer(_moveTimer, diff); }
71 bool UpdateWaitTimer(uint32 diff) { return UpdateTimer(_nextMoveTime, diff); }
72 static bool UpdateTimer(TimeTracker& timer, uint32 diff)
73 {
74 timer.Update(Milliseconds(diff));
75 if (timer.Passed())
76 {
77 timer.Reset(0);
78 return true;
79 }
80 return false;
81 }
82
84 bool IsExactSplinePath() const;
85 bool IsCyclic() const;
86
87 bool IsLoadedFromDB() const { return std::holds_alternative<WaypointPath const*>(_path); }
88
99
105};
106
107#endif
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
MovementWalkRunSpeedSelectionMode
MovementGeneratorType
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
void AddFlag(uint16 const flag)
Definition Unit.h:635
void Resume(uint32 overrideTimer) override
MovementGeneratorType GetMovementGeneratorType() const override
static bool UpdateTimer(TimeTracker &timer, uint32 diff)
void MovementInform(T const *owner) const
WaypointPath const * GetPath() const
std::string GetDebugInfo() const override
void StartMove(T *owner, bool relaunch=false)
std::vector< int32 > _waypointTransitionSplinePoints
Optional< std::pair< Milliseconds, Milliseconds > > _waitTimeRangeAtPathEnd
void DoFinalize(T *owner, bool active, bool movementInform)
MovementWalkRunSpeedSelectionMode _speedSelectionMode
bool DoUpdate(T *owner, uint32 diff)
bool GetResetPosition(Unit *, float &x, float &y, float &z) override
Optional< TimeTracker > _duration
Optional< MovementFadeObject > _fadeObject
void Pause(uint32 timer) override
Optional< bool > _followPathBackwardsFromEndToStart
void Update(int32 diff)
Definition Timer.h:121
bool Passed() const
Definition Timer.h:131
void Reset(int32 expiry)
Definition Timer.h:136