TrinityCore
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 Creature;
28class Unit;
29
30template<class T>
32
33template<>
34class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium<Creature, WaypointMovementGenerator<Creature>>,
35 public PathMovementBase<Creature, std::variant<WaypointPath const*, std::unique_ptr<WaypointPath>>>
36{
37 public:
38 explicit WaypointMovementGenerator(uint32 pathId, bool repeating, Optional<Milliseconds> duration = {}, Optional<float> speed = {},
40 Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd = {}, Optional<float> wanderDistanceAtPathEnds = {},
41 Optional<bool> followPathBackwardsFromEndToStart = {}, bool generatePath = true);
42 explicit WaypointMovementGenerator(WaypointPath const& path, bool repeating, Optional<Milliseconds> duration, Optional<float> speed,
43 MovementWalkRunSpeedSelectionMode speedSelectionMode,
44 Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd, Optional<float> wanderDistanceAtPathEnds,
45 Optional<bool> followPathBackwardsFromEndToStart, bool generatePath);
47
48 MovementGeneratorType GetMovementGeneratorType() const override;
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(Creature*);
56 void DoReset(Creature*);
57 bool DoUpdate(Creature*, uint32);
58 void DoDeactivate(Creature*);
59 void DoFinalize(Creature*, bool, bool);
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(Creature*);
67 void OnArrived(Creature*);
68 void StartMove(Creature*, bool relaunch = false);
69 bool ComputeNextNode();
71 {
72 _nextMoveTime.Update(diff);
73 if (_nextMoveTime.Passed())
74 {
75 _nextMoveTime.Reset(0);
76 return true;
77 }
78 return false;
79 }
80
81 bool IsFollowingPathBackwardsFromEndToStart() const;
82
87
96};
97
98#endif
uint32_t uint32
Definition: Define.h:142
std::string GetDebugInfo()
Definition: Errors.cpp:157
MovementGeneratorType
MovementWalkRunSpeedSelectionMode
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Definition: Unit.h:627
MovementWalkRunSpeedSelectionMode _speedSelectionMode
Optional< std::pair< Milliseconds, Milliseconds > > _waitTimeRangeAtPathEnd