AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ConfusedMovementGenerator< T > Class Template Reference

#include "ConfusedMovementGenerator.h"

Inheritance diagram for ConfusedMovementGenerator< T >:
MovementGeneratorMedium< T, ConfusedMovementGenerator< T > > MovementGenerator

Public Member Functions

 ConfusedMovementGenerator ()
 
void DoInitialize (T *)
 
void DoFinalize (T *)
 
void DoReset (T *)
 
bool DoUpdate (T *, uint32)
 
MovementGeneratorType GetMovementGeneratorType ()
 
void DoFinalize (Player *unit)
 
void DoFinalize (Creature *unit)
 
- Public Member Functions inherited from MovementGeneratorMedium< T, ConfusedMovementGenerator< T > >
void Initialize (Unit *u) override
 
void Finalize (Unit *u) override
 
void Reset (Unit *u) override
 
bool Update (Unit *u, uint32 time_diff) override
 
- Public Member Functions inherited from MovementGenerator
virtual ~MovementGenerator ()
 
virtual uint32 GetSplineId () const
 
virtual void unitSpeedChanged ()
 
virtual void Pause (uint32)
 
virtual void Resume (uint32)
 
virtual bool GetResetPosition (float &, float &, float &)
 

Private Member Functions

void _InitSpecific (T *, bool &, bool &)
 
void _InitSpecific (Creature *creature, bool &is_water_ok, bool &is_land_ok)
 
void _InitSpecific (Player *, bool &is_water_ok, bool &is_land_ok)
 

Private Attributes

TimeTracker i_nextMoveTime
 
float i_waypoints [MAX_CONF_WAYPOINTS+1][3]
 
uint32 i_nextMove
 

Detailed Description

template<class T>
class ConfusedMovementGenerator< T >

Constructor & Destructor Documentation

◆ ConfusedMovementGenerator()

template<class T >
ConfusedMovementGenerator< T >::ConfusedMovementGenerator ( )
inlineexplicit
30: i_nextMoveTime(1) {}
TimeTracker i_nextMoveTime
Definition ConfusedMovementGenerator.h:40

Member Function Documentation

◆ _InitSpecific() [1/3]

void ConfusedMovementGenerator< Creature >::_InitSpecific ( Creature creature,
bool &  is_water_ok,
bool &  is_land_ok 
)
private
96{
97 is_water_ok = creature->CanEnterWater();
98 is_land_ok = creature->CanWalk();
99}
bool CanWalk() const
Definition Creature.h:79
bool CanEnterWater() const override
Definition Creature.cpp:3288

References Creature::CanEnterWater(), and Creature::CanWalk().

◆ _InitSpecific() [2/3]

void ConfusedMovementGenerator< Player >::_InitSpecific ( Player ,
bool &  is_water_ok,
bool &  is_land_ok 
)
private
103{
104 is_water_ok = true;
105 is_land_ok = true;
106}

◆ _InitSpecific() [3/3]

template<class T >
void ConfusedMovementGenerator< T >::_InitSpecific ( T *  ,
bool &  ,
bool &   
)
private

◆ DoFinalize() [1/3]

void ConfusedMovementGenerator< Creature >::DoFinalize ( Creature unit)
166{
169 if (unit->GetVictim())
170 unit->SetTarget(unit->GetVictim()->GetGUID());
171}
@ UNIT_STATE_CONFUSED
Definition UnitDefines.h:181
@ UNIT_STATE_CONFUSED_MOVE
Definition UnitDefines.h:193
@ UNIT_FLAG_CONFUSED
Definition UnitDefines.h:272
void SetTarget(ObjectGuid guid=ObjectGuid::Empty) override
Definition Creature.cpp:3562
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:112
void ClearUnitState(uint32 f)
Definition Unit.h:708
Unit * GetVictim() const
Definition Unit.h:862
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:720

References Unit::ClearUnitState(), Object::GetGUID(), Unit::GetVictim(), Unit::RemoveUnitFlag(), Creature::SetTarget(), UNIT_FLAG_CONFUSED, UNIT_STATE_CONFUSED, and UNIT_STATE_CONFUSED_MOVE.

◆ DoFinalize() [2/3]

◆ DoFinalize() [3/3]

template<class T >
void ConfusedMovementGenerator< T >::DoFinalize ( T *  )

◆ DoInitialize()

template<class T >
template void ConfusedMovementGenerator< T >::DoInitialize ( T *  )

Cannot use coordinates outside our InhabitType. Use the current or previous position.

Trying to access path outside line of sight. Skip this by using the current or previous position.

Positions are fine - apply them to this waypoint

26{
27 unit->StopMoving();
28 float const wander_distance = 4;
29 float x = unit->GetPositionX();
30 float y = unit->GetPositionY();
31 float z = unit->GetPositionZ();
32
33 Map const* map = unit->GetMap();
34
35 bool is_water_ok, is_land_ok;
36 _InitSpecific(unit, is_water_ok, is_land_ok);
37
38 for (uint8 idx = 0; idx < MAX_CONF_WAYPOINTS + 1; ++idx)
39 {
40 float wanderX = x + (wander_distance * (float)rand_norm() - wander_distance / 2);
41 float wanderY = y + (wander_distance * (float)rand_norm() - wander_distance / 2);
42
43 // prevent invalid coordinates generation
46
47 float new_z = unit->GetMapHeight(wanderX, wanderY, z);
48 if (new_z <= INVALID_HEIGHT || std::fabs(z - new_z) > 3.0f) // pussywizard
49 {
50 i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
51 i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
52 i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
53 continue;
54 }
55 else if (unit->IsWithinLOS(wanderX, wanderY, z))
56 {
57 bool is_water = map->IsInWater(unit->GetPhaseMask(), wanderX, wanderY, z, unit->GetCollisionHeight());
58
59 if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
60 {
62 i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
63 i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
64 i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
65 continue;
66 }
67 }
68 else
69 {
71 i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
72 i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
73 i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
74 continue;
75 }
76
77 //unit->UpdateAllowedPositionZ(wanderX, wanderY, z);
78
80 i_waypoints[idx][0] = wanderX;
81 i_waypoints[idx][1] = wanderY;
82 i_waypoints[idx][2] = new_z;
83 }
84
85 // Xinef: Call movement immediately to broadcast movement packet
86 // Xinef: Initial timer is set to 1 so update with 1
88 DoUpdate(unit, 1);
89
90 unit->SetUnitFlag(UNIT_FLAG_CONFUSED);
92}
#define MAX_CONF_WAYPOINTS
Definition ConfusedMovementGenerator.h:24
std::uint8_t uint8
Definition Define.h:109
#define INVALID_HEIGHT
Definition GridTerrainData.h:27
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
double rand_norm()
Definition Random.cpp:77
float i_waypoints[MAX_CONF_WAYPOINTS+1][3]
Definition ConfusedMovementGenerator.h:41
bool DoUpdate(T *, uint32)
Definition ConfusedMovementGenerator.cpp:115
uint32 i_nextMove
Definition ConfusedMovementGenerator.h:42
void _InitSpecific(T *, bool &, bool &)
Definition Map.h:156
bool IsInWater(uint32 phaseMask, float x, float y, float z, float collisionHeight) const
Definition Map.cpp:1654
void NormalizeMapCoord(float &c)
Definition GridDefines.h:198

References INVALID_HEIGHT, Map::IsInWater(), MAX_CONF_WAYPOINTS, Acore::NormalizeMapCoord(), rand_norm(), UNIT_FLAG_CONFUSED, UNIT_STATE_CONFUSED, UNIT_STATE_CONFUSED_MOVE, and urand().

◆ DoReset()

template<class T >
template void ConfusedMovementGenerator< T >::DoReset ( T *  )
110{
111 DoInitialize(unit);
112}
void DoInitialize(T *)
Definition ConfusedMovementGenerator.cpp:25

◆ DoUpdate()

template<class T >
template bool ConfusedMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
116{
117 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE) || unit->IsMovementPreventedByCasting())
118 {
119 unit->StopMoving();
120 return true;
121 }
122
124 {
125 // currently moving, update location
126 unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
127
128 if (unit->movespline->Finalized())
129 {
131 i_nextMoveTime.Reset(urand(600, 1200)); // Guessed
132 }
133 }
134 else
135 {
136 // waiting for next move
139 {
140 // start moving
141 unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
142
144 float x = i_waypoints[i_nextMove][0];
145 float y = i_waypoints[i_nextMove][1];
146 float z = i_waypoints[i_nextMove][2];
147 Movement::MoveSplineInit init(unit);
148 init.MoveTo(x, y, z, true);
149 init.Launch();
150 }
151 }
152
153 return true;
154}
#define ASSERT
Definition Errors.h:68
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:218
Definition MoveSplineInit.h:71
void Update(time_t diff)
Definition Timer.h:207
void Reset(time_t interval)
Definition Timer.h:217
bool Passed() const
Definition Timer.h:212

References ASSERT, Movement::MoveSplineInit::Launch(), MAX_CONF_WAYPOINTS, Movement::MoveSplineInit::MoveTo(), UNIT_STATE_CONFUSED_MOVE, UNIT_STATE_NOT_MOVE, and urand().

◆ GetMovementGeneratorType()

template<class T >
MovementGeneratorType ConfusedMovementGenerator< T >::GetMovementGeneratorType ( )
inlinevirtual

Implements MovementGenerator.

37{ return CONFUSED_MOTION_TYPE; }
@ CONFUSED_MOTION_TYPE
Definition MotionMaster.h:44

References CONFUSED_MOTION_TYPE.

Member Data Documentation

◆ i_nextMove

template<class T >
uint32 ConfusedMovementGenerator< T >::i_nextMove
private

◆ i_nextMoveTime

template<class T >
TimeTracker ConfusedMovementGenerator< T >::i_nextMoveTime
private

◆ i_waypoints

template<class T >
float ConfusedMovementGenerator< T >::i_waypoints[MAX_CONF_WAYPOINTS+1][3]
private

The documentation for this class was generated from the following files: