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 void Initialize (Unit *)=0
 
virtual void Finalize (Unit *)=0
 
virtual void Reset (Unit *)=0
 
virtual bool Update (Unit *, uint32 time_diff)=0
 
virtual MovementGeneratorType GetMovementGeneratorType ()=0
 
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
101{
102 is_water_ok = creature->CanEnterWater();
103 is_land_ok = creature->CanWalk();
104}
bool CanWalk() const
Definition: Creature.h:78
bool CanEnterWater() const override
Definition: Creature.cpp:3271

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

◆ _InitSpecific() [2/3]

void ConfusedMovementGenerator< Player >::_InitSpecific ( Player ,
bool &  is_water_ok,
bool &  is_land_ok 
)
private
108{
109 is_water_ok = true;
110 is_land_ok = true;
111}

◆ _InitSpecific() [3/3]

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

◆ DoFinalize() [1/3]

void ConfusedMovementGenerator< Creature >::DoFinalize ( Creature unit)
171{
174 if (unit->GetVictim())
175 unit->SetTarget(unit->GetVictim()->GetGUID());
176}
@ UNIT_STATE_CONFUSED
Definition: UnitDefines.h:160
@ UNIT_STATE_CONFUSED_MOVE
Definition: UnitDefines.h:172
@ UNIT_FLAG_CONFUSED
Definition: UnitDefines.h:251
void SetTarget(ObjectGuid guid=ObjectGuid::Empty) override
Definition: Creature.cpp:3545
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
void ClearUnitState(uint32 f)
Definition: Unit.h:702
Unit * GetVictim() const
Definition: Unit.h:853
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition: Unit.h:714

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

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

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 *  )
115{
116 DoInitialize(unit);
117}
void DoInitialize(T *)
Definition: ConfusedMovementGenerator.cpp:30

◆ DoUpdate()

template<class T >
template bool ConfusedMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
121{
122 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE) || unit->IsMovementPreventedByCasting())
123 {
124 unit->StopMoving();
125 return true;
126 }
127
129 {
130 // currently moving, update location
131 unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
132
133 if (unit->movespline->Finalized())
134 {
136 i_nextMoveTime.Reset(urand(600, 1200)); // Guessed
137 }
138 }
139 else
140 {
141 // waiting for next move
144 {
145 // start moving
146 unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
147
149 float x = i_waypoints[i_nextMove][0];
150 float y = i_waypoints[i_nextMove][1];
151 float z = i_waypoints[i_nextMove][2];
152 Movement::MoveSplineInit init(unit);
153 init.MoveTo(x, y, z, true);
154 init.Launch();
155 }
156 }
157
158 return true;
159}
#define ASSERT
Definition: Errors.h:68
@ UNIT_STATE_NOT_MOVE
Definition: UnitDefines.h:197
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
Definition: MoveSplineInit.h:71

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