diff --git a/src/game/Path.h b/src/game/Path.h index 3440121b1..30a0c083d 100644 --- a/src/game/Path.h +++ b/src/game/Path.h @@ -20,11 +20,13 @@ #define MANGOSSERVER_PATH_H #include "Common.h" -#include +#include -struct SimplePathNode +struct PathNode { - float x,y,z; + PathNode(): x(0.0f), y(0.0f), z(0.0f) { } + PathNode(float _x, float _y, float _z): x(_x), y(_y), z(_z) { } + float x, y, z; }; template @@ -34,8 +36,22 @@ class Path size_t size() const { return i_nodes.size(); } bool empty() const { return i_nodes.empty(); } void resize(unsigned int sz) { i_nodes.resize(sz); } + void crop(unsigned int start, unsigned int end) + { + while(start && !i_nodes.empty()) + { + i_nodes.pop_front(); + --start; + } + + while(end && !i_nodes.empty()) + { + i_nodes.pop_back(); + --end; + } + } + void clear() { i_nodes.clear(); } - void erase(uint32 idx) { i_nodes.erase(i_nodes.begin()+idx); } float GetTotalLength(uint32 start, uint32 end) const { @@ -76,9 +92,9 @@ class Path void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; } protected: - std::vector i_nodes; + std::deque i_nodes; }; -typedef Path SimplePath; +typedef Path PointPath; #endif diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 99c6b00da..19ebb7917 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -8686,7 +8686,7 @@ void Spell::EffectCharge(SpellEffectIndex /*eff_idx*/) ((Creature *)unitTarget)->StopMoving(); // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags - m_caster->MonsterMoveWithSpeed(x, y, z, 24.f); + m_caster->MonsterMoveWithSpeed(x, y, z, 24.f, true, true); // not all charge effects used in negative spells if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id)) @@ -8711,7 +8711,7 @@ void Spell::EffectCharge2(SpellEffectIndex /*eff_idx*/) return; // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags - m_caster->MonsterMoveWithSpeed(x, y, z, 24.f); + m_caster->MonsterMoveWithSpeed(x, y, z, 24.f, true, true); // not all charge effects used in negative spells if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id)) diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 94ff330fa..621c25713 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -10522,10 +10522,10 @@ void Unit::NearTeleportTo( float x, float y, float z, float orientation, bool ca } } -void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed) +void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath, bool forceDestination) { Movement::MoveSplineInit init(*this); - init.MoveTo(x,y,z); + init.MoveTo(x,y,z, generatePath, forceDestination); init.SetVelocity(speed); init.Launch(); } diff --git a/src/game/Unit.h b/src/game/Unit.h index ab93021cc..06591900e 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1412,7 +1412,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo); void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false); - void MonsterMoveWithSpeed(float x, float y, float z, float speed); + void MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath = false, bool forceDestination = false); // recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens // if used additional args in ... part then floats must explicitly casted to double void SendHeartBeat(); diff --git a/src/game/movement/MoveSpline.h b/src/game/movement/MoveSpline.h index ce8652ea1..d8c0a3a89 100644 --- a/src/game/movement/MoveSpline.h +++ b/src/game/movement/MoveSpline.h @@ -78,7 +78,6 @@ namespace Movement UpdateResult _updateState(int32& ms_time_diff); int32 next_timestamp() const { return spline.length(point_Idx+1);} int32 segment_time_elapsed() const { return next_timestamp()-time_passed;} - int32 Duration() const { return spline.length();} int32 timeElapsed() const { return Duration() - time_passed;} int32 timePassed() const { return time_passed;} @@ -121,6 +120,8 @@ namespace Movement const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3();} int32 currentPathIdx() const; + int32 Duration() const { return spline.length();} + std::string ToString() const; }; } diff --git a/src/game/movement/MoveSplineInit.cpp b/src/game/movement/MoveSplineInit.cpp index 14524a62b..eccef0ccd 100644 --- a/src/game/movement/MoveSplineInit.cpp +++ b/src/game/movement/MoveSplineInit.cpp @@ -50,7 +50,7 @@ namespace Movement return MOVE_RUN; } - void MoveSplineInit::Launch() + int32 MoveSplineInit::Launch() { MoveSpline& move_spline = *unit.movespline; @@ -82,7 +82,7 @@ namespace Movement args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags)); if (!args.Validate()) - return; + return 0; unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags); move_spline.Initialize(args); @@ -91,6 +91,8 @@ namespace Movement data << unit.GetPackGUID(); PacketBuilder::WriteMonsterMove(move_spline, data); unit.SendMessageToSet(&data,true); + + return move_spline.Duration(); } MoveSplineInit::MoveSplineInit(Unit& m) : unit(m) diff --git a/src/game/movement/MoveSplineInit.h b/src/game/movement/MoveSplineInit.h index dcb785290..0149c7b3a 100644 --- a/src/game/movement/MoveSplineInit.h +++ b/src/game/movement/MoveSplineInit.h @@ -20,6 +20,7 @@ #define MANGOSSERVER_MOVESPLINEINIT_H #include "MoveSplineInitArgs.h" +#include "../PathFinder.h" class Unit; @@ -41,9 +42,10 @@ namespace Movement explicit MoveSplineInit(Unit& m); - /* Final pass of initialization that launches spline movement. + /* Final pass of initialization that launches spline movement. + * @return duration - estimated travel time */ - void Launch(); + int32 Launch(); /* Adds movement by parabolic trajectory * @param amplitude - the maximum height of parabola, value could be negative and positive @@ -72,8 +74,8 @@ namespace Movement /* Initializes simple A to B mition, A is current unit's position, B is destination */ - void MoveTo(const Vector3& destination); - void MoveTo(float x, float y, float z); + void MoveTo(const Vector3& destination, bool generatePath = false, bool forceDestination = false); + void MoveTo(float x, float y, float z, bool generatePath = false, bool forceDestination = false); /* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done * Needed for waypoint movement where path splitten into parts @@ -133,17 +135,26 @@ namespace Movement args.path.assign(controls.begin(),controls.end()); } - inline void MoveSplineInit::MoveTo(float x, float y, float z) + inline void MoveSplineInit::MoveTo(float x, float y, float z, bool generatePath, bool forceDestination) { Vector3 v(x,y,z); - MoveTo(v); + MoveTo(v, generatePath, forceDestination); } - inline void MoveSplineInit::MoveTo(const Vector3& dest) + inline void MoveSplineInit::MoveTo(const Vector3& dest, bool generatePath, bool forceDestination) { - args.path_Idx_offset = 0; - args.path.resize(2); - args.path[1] = dest; + if(generatePath) + { + PathFinder path(&unit); + path.calculate(dest.x, dest.y, dest.z, forceDestination); + MovebyPath(path.getPath()); + } + else + { + args.path_Idx_offset = 0; + args.path.resize(2); + args.path[1] = dest; + } } inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 61ddf9d1a..080d5d15d 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11910" + #define REVISION_NR "11911" #endif // __REVISION_NR_H__