Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core/Movement: Added cyclic spline motion type #29923

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/server/game/AI/CreatureAIRegistry.cpp
Expand Up @@ -57,6 +57,7 @@ namespace AIRegistry
(new IdleMovementFactory())->RegisterSelf();
(new RandomMovementFactory())->RegisterSelf();
(new WaypointMovementFactory())->RegisterSelf();
(new CyclicMovementFactory())->RegisterSelf();

(void)sObjectMgr->GetScriptId("NullAreaTriggerAI", false);
}
Expand Down
18 changes: 14 additions & 4 deletions src/server/game/AI/SmartScripts/SmartAI.cpp
Expand Up @@ -526,12 +526,22 @@ void SmartAI::JustReachedHome()
CreatureGroup* formation = me->GetFormation();
if (!formation || formation->GetLeader() == me || !formation->IsFormed())
{
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType(MOTION_SLOT_DEFAULT) != WAYPOINT_MOTION_TYPE)
if (me->GetDefaultMovementType() == CYCLIC_SPLINE_MOTION_TYPE)
{
if (me->GetWaypointPathId())
me->GetMotionMaster()->MovePath(me->GetWaypointPathId(), true);
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType(MOTION_SLOT_DEFAULT) != CYCLIC_SPLINE_MOTION_TYPE)
{
if (me->GetWaypointPathId())
me->GetMotionMaster()->MoveCyclicPath(me->GetWaypointPathId());
}
}
else
{
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType(MOTION_SLOT_DEFAULT) != WAYPOINT_MOTION_TYPE)
{
if (me->GetWaypointPathId())
me->GetMotionMaster()->MovePath(me->GetWaypointPathId(), true);
}
}

me->ResumeMovement();
}
else if (formation->IsFormed())
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Unit/Unit.cpp
Expand Up @@ -571,7 +571,7 @@ void Unit::UpdateSplineMovement(uint32 t_diff)

WorldPackets::Movement::FlightSplineSync flightSplineSync;
flightSplineSync.Guid = GetGUID();
flightSplineSync.SplineDist = movespline->timePassed() / movespline->Duration();
flightSplineSync.SplineDist = (float)movespline->timePassed() / movespline->Duration();
SendMessageToSet(flightSplineSync.Write(), true);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/server/game/Movement/MotionMaster.cpp
Expand Up @@ -34,11 +34,13 @@
#include "ScriptSystem.h"
#include "Unit.h"
#include "WaypointDefines.h"
#include "WaypointManager.h"
#include <algorithm>
#include <iterator>

#include "ChaseMovementGenerator.h"
#include "ConfusedMovementGenerator.h"
#include "CyclicMovementGenerator.h"
#include "FleeingMovementGenerator.h"
#include "FlightPathMovementGenerator.h"
#include "FollowMovementGenerator.h"
Expand Down Expand Up @@ -990,6 +992,22 @@ void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool
Add(new GenericMovementGenerator(std::move(initializer), EFFECT_MOTION_TYPE, 0, { .Duration = duration, .ScriptResult = std::move(scriptResult) }));
}

void MotionMaster::MoveCyclicPath(uint32 pathId, bool enforceFly /*= false*/,
Optional<Milliseconds> duration /*= {}*/, Optional<float> speed /*= {}*/,
MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/)
{
WaypointPath const* path = sWaypointMgr->GetPath(pathId);
if (!path)
{
TC_LOG_ERROR("movement.motionmaster", "MotionMaster::MoveCyclePath: '{}' tried to use not existing path with id: {}", _owner->GetGUID(), pathId);
if (scriptResult)
scriptResult->SetResult(MovementStopReason::Interrupted);
return;
}
Add(new CyclicMovementGenerator<Creature>(path, enforceFly, duration, speed, speedSelectionMode, std::move(scriptResult)));
}

void MotionMaster::MoveSmoothPath(uint32 pointId, Position const* pathPoints, size_t pathSize, bool walk, bool fly)
{
Movement::PointsArray path;
Expand Down
4 changes: 4 additions & 0 deletions src/server/game/Movement/MotionMaster.h
Expand Up @@ -201,6 +201,10 @@ class TC_GAME_API MotionMaster
Optional<Milliseconds> duration = {}, Optional<float> speed = {},
MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});
void MoveCyclicPath(uint32 pathId, bool enforceFly = false,
Optional<Milliseconds> duration = {}, Optional<float> speed = {},
MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});
void MoveSmoothPath(uint32 pointId, Position const* pathPoints, size_t pathSize, bool walk = false, bool fly = false);
// Walk along spline chain stored in DB (script_spline_chain_meta and script_spline_chain_waypoints)
void MoveAlongSplineChain(uint32 pointId, uint16 dbChainId, bool walk);
Expand Down
42 changes: 22 additions & 20 deletions src/server/game/Movement/MovementDefines.h
Expand Up @@ -27,26 +27,28 @@
// EnumUtils: DESCRIBE THIS
enum MovementGeneratorType : uint8
{
IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
MAX_DB_MOTION_TYPE = 3, // Below motion types can't be set in DB.
CONFUSED_MOTION_TYPE = 4, // ConfusedMovementGenerator.h
CHASE_MOTION_TYPE = 5, // ChaseMovementGenerator.h
HOME_MOTION_TYPE = 6, // HomeMovementGenerator.h
FLIGHT_MOTION_TYPE = 7, // FlightPathMovementGenerator.h
POINT_MOTION_TYPE = 8, // PointMovementGenerator.h
FLEEING_MOTION_TYPE = 9, // FleeingMovementGenerator.h
DISTRACT_MOTION_TYPE = 10, // IdleMovementGenerator.h
ASSISTANCE_MOTION_TYPE = 11, // PointMovementGenerator.h
ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h
TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h
FOLLOW_MOTION_TYPE = 14, // FollowMovementGenerator.h
ROTATE_MOTION_TYPE = 15, // IdleMovementGenerator.h
EFFECT_MOTION_TYPE = 16,
SPLINE_CHAIN_MOTION_TYPE = 17, // SplineChainMovementGenerator.h
FORMATION_MOTION_TYPE = 18, // FormationMovementGenerator.h
MAX_MOTION_TYPE // SKIP
IDLE_MOTION_TYPE = 0, // IdleMovementGenerator.h
RANDOM_MOTION_TYPE = 1, // RandomMovementGenerator.h
WAYPOINT_MOTION_TYPE = 2, // WaypointMovementGenerator.h
CYCLIC_SPLINE_MOTION_TYPE = 3, // CyclicMovementGenerator.h
MAX_DB_MOTION_TYPE, // Below motion types can't be set in DB.

CONFUSED_MOTION_TYPE, // ConfusedMovementGenerator.h
CHASE_MOTION_TYPE, // ChaseMovementGenerator.h
HOME_MOTION_TYPE, // HomeMovementGenerator.h
FLIGHT_MOTION_TYPE, // FlightPathMovementGenerator.h
POINT_MOTION_TYPE, // PointMovementGenerator.h
FLEEING_MOTION_TYPE, // FleeingMovementGenerator.h
DISTRACT_MOTION_TYPE, // IdleMovementGenerator.h
ASSISTANCE_MOTION_TYPE, // PointMovementGenerator.h
ASSISTANCE_DISTRACT_MOTION_TYPE, // IdleMovementGenerator.h
TIMED_FLEEING_MOTION_TYPE, // FleeingMovementGenerator.h
FOLLOW_MOTION_TYPE, // FollowMovementGenerator.h
ROTATE_MOTION_TYPE, // IdleMovementGenerator.h
EFFECT_MOTION_TYPE,
SPLINE_CHAIN_MOTION_TYPE, // SplineChainMovementGenerator.h
FORMATION_MOTION_TYPE, // FormationMovementGenerator.h
MAX_MOTION_TYPE // SKIP
};

enum MovementGeneratorMode : uint8
Expand Down
8 changes: 8 additions & 0 deletions src/server/game/Movement/MovementGenerator.cpp
Expand Up @@ -17,6 +17,7 @@

#include "MovementGenerator.h"
#include "Creature.h"
#include "CyclicMovementGenerator.h"
#include "IdleMovementGenerator.h"
#include "MovementDefines.h"
#include "PathGenerator.h"
Expand Down Expand Up @@ -72,3 +73,10 @@ MovementGenerator* WaypointMovementFactory::Create(Unit* /*object*/) const
{
return new WaypointMovementGenerator<Creature>(0, true);
}

CyclicMovementFactory::CyclicMovementFactory() : MovementGeneratorCreator(CYCLIC_SPLINE_MOTION_TYPE) { }

MovementGenerator* CyclicMovementFactory::Create(Unit* /*object*/) const
{
return new CyclicMovementGenerator<Creature>(nullptr);
}
7 changes: 7 additions & 0 deletions src/server/game/Movement/MovementGenerator.h
Expand Up @@ -157,6 +157,13 @@ struct WaypointMovementFactory : public MovementGeneratorCreator
MovementGenerator* Create(Unit* object) const override;
};

struct CyclicMovementFactory : public MovementGeneratorCreator
{
CyclicMovementFactory();

MovementGenerator* Create(Unit* object) const override;
};

typedef MovementGeneratorCreator::FactoryHolderRegistry MovementGeneratorRegistry;

#define sMovementGeneratorRegistry MovementGeneratorRegistry::instance()
Expand Down