37{
38 if (!creature)
39 return;
40
42 return;
43
45 {
47 return;
48
54
55 bool walk = true;
57 {
60 break;
62 walk = false;
63 break;
64 default:
65 break;
66 }
67
68 init.SetWalk(walk);
69 init.Launch();
72 return;
73 }
74
77 uint8 newPoint = *randomIter;
79
80
82 {
84 return;
85 }
86
88 if (finalPath.empty())
89 {
92
94 {
97 return;
98 }
99
103
104
107
108 else if (ground < levelZ)
109 {
111 {
114 return;
115 }
116 else
117 {
120 newZ = std::max<float>(ground, newZ);
121 }
122 }
123
124 else
125 {
126 if (levelZ <= INVALID_HEIGHT || !creature->
CanWalk())
127 {
130 return;
131 }
132 }
133
135
137 {
138
140 {
143 return;
144 }
145
147 finalPath.push_back(G3D::Vector3(x, y, newZ));
148 }
149 else
150 {
153 else
155
158 {
159
162 {
165 return;
166 }
167
169 Movement::PointsArray::iterator itr = finalPath.begin();
170 Movement::PointsArray::iterator itrNext = finalPath.begin() + 1;
171 float zDiff, distDiff;
172
173 for (; itrNext != finalPath.end(); ++itr, ++itrNext)
174 {
175 distDiff = std::sqrt(((*itr).x - (*itrNext).x) * ((*itr).x - (*itrNext).x) + ((*itr).y - (*itrNext).y) * ((*itr).y - (*itrNext).y));
176 zDiff = std::fabs((*itr).z - (*itrNext).z);
177
178
179 if (zDiff > 2.0f ||
180 (G3D::fuzzyNe(zDiff, 0.0f) && distDiff / zDiff < 2.15f))
181 {
184 return;
185 }
186
187 if (!map->
isInLineOfSight((*itr).x, (*itr).y, (*itr).z + 2.f, (*itrNext).x, (*itrNext).y, (*itrNext).z + 2.f, creature->
GetPhaseMask(),
189 {
192 return;
193 }
194 }
195
196
197 if (finalPath.size() < 2)
198 {
201 return;
202 }
203 }
204 else
205 {
208 return;
209 }
210 }
211 }
212
214 G3D::Vector3& finalPoint = finalPath[finalPath.size() - 1];
216
218 bool walk = true;
220 {
223 break;
225 walk = false;
226 break;
227 default:
228 break;
229 }
230
232 init.MovebyPath(finalPath);
233 init.SetWalk(walk);
234 init.Launch();
235
238 {
241 }
244
245
248}
std::int32_t int32
Definition Define.h:103
std::uint16_t uint16
Definition Define.h:108
#define INVALID_HEIGHT
Definition GridTerrainData.h:27
@ LINEOFSIGHT_ALL_CHECKS
Definition Map.h:110
@ MAP_OBJECT_CELL_MOVE_NONE
Definition Object.h:405
@ PATHFIND_NOPATH
Definition PathGenerator.h:50
#define MAX_PATH_LENGHT_FACTOR
Definition RandomMovementGenerator.h:29
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
double rand_norm()
Definition Random.cpp:85
bool roll_chance_i(int chance)
Definition Random.h:63
@ UNIT_STATE_ROAMING_MOVE
Definition UnitDefines.h:192
@ CONFIG_DONT_CACHE_RANDOM_MOVEMENT_PATHS
Definition WorldConfig.h:103
Creature * GetLeader() const
Definition CreatureGroups.h:99
void LeaderMoveTo(float x, float y, float z, uint32 move_type)
Definition CreatureGroups.cpp:347
bool CanFly() const override
Definition Creature.h:86
CreatureGroup const * GetFormation() const
Definition Creature.h:357
bool CanEnterWater() const override
Definition Creature.cpp:3303
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:2998
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:1539
MapObjectCellMoveState _moveState
Definition Object.h:425
Definition MoveSplineInit.h:71
std::map< uint16, Movement::PointsArray > _preComputedPaths
Definition RandomMovementGenerator.h:69
Position _currDestPosition
Definition RandomMovementGenerator.h:70
void AddUnitState(uint32 f)
Definition Unit.h:698
bool IsWalking() const
Definition Unit.h:1640
uint32 GetPhaseMask() const
Definition Object.h:513
Map * GetMap() const
Definition Object.h:621
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition Object.cpp:1583
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition Object.cpp:1355
float GetMapWaterOrGroundLevel(Position pos, float *ground=nullptr) const
Definition Object.h:700
#define sWorld
Definition World.h:316
bool IsValidMapCoord(float c)
Definition GridDefines.h:210
std::vector< Vector3 > PointsArray
Definition MoveSplineInitArgs.h:28
CreatureRandomMovementType GetRandom() const
Definition CreatureData.h:155
float GetPositionZ() const
Definition Position.h:123
float GetPositionX() const
Definition Position.h:121
float GetPositionY() const
Definition Position.h:122
float GetExactDistSq(float x, float y, float z) const
Definition Position.h:174
void Reset(int32 interval)
Definition Timer.h:249