40{
42 return;
43
45 {
47 return;
48
54 init.SetWalk(true);
55 init.Launch();
58 return;
59 }
60
63 uint8 newPoint = *randomIter;
65
66
68 {
70 return;
71 }
72
74 if (finalPath.empty())
75 {
78
80 {
83 return;
84 }
85
89
90
93
94 else if (ground < levelZ)
95 {
97 {
100 return;
101 }
102 else
103 {
106 newZ = std::max<float>(ground, newZ);
107 }
108 }
109
110 else
111 {
112 if (levelZ <= INVALID_HEIGHT || !creature->
CanWalk())
113 {
116 return;
117 }
118 }
119
121
123 {
124
126 {
129 return;
130 }
131
133 finalPath.push_back(G3D::Vector3(x, y, newZ));
134 }
135 else
136 {
139 else
141
144 {
145
148 {
151 return;
152 }
153
155 Movement::PointsArray::iterator itr = finalPath.begin();
156 Movement::PointsArray::iterator itrNext = finalPath.begin() + 1;
157 float zDiff, distDiff;
158
159 for (; itrNext != finalPath.end(); ++itr, ++itrNext)
160 {
161 distDiff = std::sqrt(((*itr).x - (*itrNext).x) * ((*itr).x - (*itrNext).x) + ((*itr).y - (*itrNext).y) * ((*itr).y - (*itrNext).y));
162 zDiff = std::fabs((*itr).z - (*itrNext).z);
163
164
165 if (zDiff > 2.0f ||
166 (G3D::fuzzyNe(zDiff, 0.0f) && distDiff / zDiff < 2.15f))
167 {
170 return;
171 }
172
173 if (!map->
isInLineOfSight((*itr).x, (*itr).y, (*itr).z + 2.f, (*itrNext).x, (*itrNext).y, (*itrNext).z + 2.f, creature->
GetPhaseMask(),
175 {
178 return;
179 }
180 }
181
182
183 if (finalPath.size() < 2)
184 {
187 return;
188 }
189 }
190 else
191 {
194 return;
195 }
196 }
197 }
198
200 G3D::Vector3& finalPoint = finalPath[finalPath.size() - 1];
202
204 bool walk = true;
206 {
207 case CreatureRandomMovementType::CanRun:
209 break;
210 case CreatureRandomMovementType::AlwaysRun:
211 walk = false;
212 break;
213 default:
214 break;
215 }
216
218 init.MovebyPath(finalPath);
219 init.SetWalk(walk);
220 init.Launch();
221
224 {
227 }
230
231
234}
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
double rand_norm()
Definition: Random.cpp:77
bool roll_chance_i(int chance)
Definition: Random.h:59
std::int32_t int32
Definition: Define.h:103
std::uint16_t uint16
Definition: Define.h:108
@ LINEOFSIGHT_ALL_CHECKS
Definition: Map.h:198
#define INVALID_HEIGHT
Definition: Map.h:165
@ PATHFIND_NOPATH
Definition: PathGenerator.h:51
#define MAX_PATH_LENGHT_FACTOR
Definition: RandomMovementGenerator.h:28
@ CONFIG_DONT_CACHE_RANDOM_MOVEMENT_PATHS
Definition: IWorld.h:149
@ UNIT_STATE_ROAMING_MOVE
Definition: UnitDefines.h:171
@ MAP_OBJECT_CELL_MOVE_NONE
Definition: Object.h:382
#define sWorld
Definition: World.h:444
bool IsValidMapCoord(float c)
Definition: GridDefines.h:216
std::vector< Vector3 > PointsArray
Definition: MoveSplineInitArgs.h:28
void Reset(int32 interval)
Definition: Timer.h:249
bool CanFly() const override
Definition: Creature.h:84
CreatureGroup const * GetFormation() const
Definition: Creature.h:354
bool CanEnterWater() const override
Definition: Creature.cpp:3258
CreatureMovementData const & GetMovementTemplate() const
Definition: Creature.cpp:2975
CreatureRandomMovementType GetRandom() const
Definition: CreatureData.h:158
Creature * GetLeader() const
Definition: CreatureGroups.h:98
void LeaderMoveTo(float x, float y, float z, uint32 move_type)
Definition: CreatureGroups.cpp:345
MapObjectCellMoveState _moveState
Definition: Object.h:401
uint32 GetPhaseMask() const
Definition: Object.h:446
Map * GetMap() const
Definition: Object.h:531
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition: Object.cpp:1554
float GetMapWaterOrGroundLevel(float x, float y, float z, float *ground=nullptr) const
Definition: Object.cpp:3126
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition: Object.cpp:1326
float GetPositionZ() const
Definition: Position.h:119
float GetPositionX() const
Definition: Position.h:117
float GetPositionY() const
Definition: Position.h:118
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:170
void AddUnitState(uint32 f)
Definition: Unit.h:672
bool IsWalking() const
Definition: Unit.h:1695
bool isInLineOfSight(float x1, float y1, float z1, float x2, float y2, float z2, uint32 phasemask, LineOfSightChecks checks, VMAP::ModelIgnoreFlags ignoreFlags) const
Definition: Map.cpp:2438
Definition: PathGenerator.h:60
Movement::PointsArray const & GetPath() const
Definition: PathGenerator.h:91
float getPathLength() const
Definition: PathGenerator.h:98
PathType GetPathType() const
Definition: PathGenerator.h:93
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false)
Definition: PathGenerator.cpp:52
void Clear()
Definition: PathGenerator.h:125
std::map< uint16, Movement::PointsArray > _preComputedPaths
Definition: RandomMovementGenerator.h:68
Position _currDestPosition
Definition: RandomMovementGenerator.h:69
Definition: MoveSplineInit.h:71