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
103{
104 is_water_ok = creature->CanEnterWater();
105 is_land_ok = creature->CanWalk();
106}
bool CanWalk() const
Definition: Creature.h:81
bool CanEnterWater() const override
Definition: Creature.cpp:3258

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

◆ _InitSpecific() [2/3]

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

◆ _InitSpecific() [3/3]

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

◆ DoFinalize() [1/3]

void ConfusedMovementGenerator< Creature >::DoFinalize ( Creature unit)
173{
176 if (unit->GetVictim())
177 unit->SetTarget(unit->GetVictim()->GetGUID());
178}
@ 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:3532
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
void ClearUnitState(uint32 f)
Definition: Unit.h:674
Unit * GetVictim() const
Definition: Unit.h:789
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition: Unit.h:684

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

33{
34 unit->StopMoving();
35 float const wander_distance = 4;
36 float x = unit->GetPositionX();
37 float y = unit->GetPositionY();
38 float z = unit->GetPositionZ();
39
40 Map const* map = unit->GetMap();
41
42 bool is_water_ok, is_land_ok;
43 _InitSpecific(unit, is_water_ok, is_land_ok);
44
45 for (uint8 idx = 0; idx < MAX_CONF_WAYPOINTS + 1; ++idx)
46 {
47 float wanderX = x + (wander_distance * (float)rand_norm() - wander_distance / 2);
48 float wanderY = y + (wander_distance * (float)rand_norm() - wander_distance / 2);
49
50 // prevent invalid coordinates generation
53
54 float new_z = unit->GetMapHeight(wanderX, wanderY, z);
55 if (new_z <= INVALID_HEIGHT || std::fabs(z - new_z) > 3.0f) // pussywizard
56 {
57 i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
58 i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
59 i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
60 continue;
61 }
62 else if (unit->IsWithinLOS(wanderX, wanderY, z))
63 {
64 bool is_water = map->IsInWater(unit->GetPhaseMask(), wanderX, wanderY, z, unit->GetCollisionHeight());
65
66 if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
67 {
69 i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
70 i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
71 i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
72 continue;
73 }
74 }
75 else
76 {
78 i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
79 i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
80 i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
81 continue;
82 }
83
84 //unit->UpdateAllowedPositionZ(wanderX, wanderY, z);
85
87 i_waypoints[idx][0] = wanderX;
88 i_waypoints[idx][1] = wanderY;
89 i_waypoints[idx][2] = new_z;
90 }
91
92 // Xinef: Call movement immediately to broadcast movement packet
93 // Xinef: Initial timer is set to 1 so update with 1
95 DoUpdate(unit, 1);
96
97 unit->SetUnitFlag(UNIT_FLAG_CONFUSED);
99}
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:165
#define MAX_CONF_WAYPOINTS
Definition: ConfusedMovementGenerator.h:24
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:208
Definition: Map.h:313
bool IsInWater(uint32 phaseMask, float x, float y, float z, float collisionHeight) const
Definition: Map.cpp:2500
float i_waypoints[MAX_CONF_WAYPOINTS+1][3]
Definition: ConfusedMovementGenerator.h:41
bool DoUpdate(T *, uint32)
Definition: ConfusedMovementGenerator.cpp:122
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 *  )
117{
118 DoInitialize(unit);
119}
void DoInitialize(T *)
Definition: ConfusedMovementGenerator.cpp:32

◆ DoUpdate()

template<class T >
template bool ConfusedMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
123{
124 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE) || unit->IsMovementPreventedByCasting())
125 {
126 unit->StopMoving();
127 return true;
128 }
129
131 {
132 // currently moving, update location
133 unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
134
135 if (unit->movespline->Finalized())
136 {
138 i_nextMoveTime.Reset(urand(600, 1200)); // Guessed
139 }
140 }
141 else
142 {
143 // waiting for next move
146 {
147 // start moving
148 unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
149
151 float x = i_waypoints[i_nextMove][0];
152 float y = i_waypoints[i_nextMove][1];
153 float z = i_waypoints[i_nextMove][2];
154 Movement::MoveSplineInit init(unit);
155 init.MoveTo(x, y, z, true);
156 init.Launch();
157 }
158 }
159
160 return true;
161}
#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:42

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