Core/Movement: Some improvements to script interfaces for SplineChainMovementGenerator

(cherry picked from commit e63e0cb6fc)
This commit is contained in:
Treeston
2018-08-29 17:15:22 +02:00
committed by Shauren
parent d57e74b3b5
commit 852164132c
2 changed files with 7 additions and 11 deletions

View File

@@ -211,23 +211,18 @@ SplineChainResumeInfo SplineChainMovementGenerator::GetResumeInfo(Unit const* ow
return SplineChainResumeInfo(_id, &_chain, _walk, uint8(_nextIndex - 1), uint8(owner->movespline->_currentSplineIdx()), _msToNext);
}
/* static */ void SplineChainMovementGenerator::GetResumeInfo(Unit const* owner, uint32 id, SplineChainResumeInfo& info)
/* static */ void SplineChainMovementGenerator::GetResumeInfo(SplineChainResumeInfo& info, Unit const* owner, Optional<uint32> id)
{
std::function<bool(MovementGenerator const*)> criteria = [id](MovementGenerator const* movement) -> bool
{
if (movement->GetMovementGeneratorType() == SPLINE_CHAIN_MOTION_TYPE)
{
SplineChainMovementGenerator const* splineChainMovement = dynamic_cast<SplineChainMovementGenerator const*>(movement);
return splineChainMovement && splineChainMovement->GetId() == id;
}
return (!id || static_cast<SplineChainMovementGenerator const*>(movement)->GetId() == *id);
return false;
};
if (MovementGenerator const* activeGenerator = owner->GetMotionMaster()->GetMovementGenerator(criteria))
{
if (activeGenerator->GetMovementGeneratorType() == SPLINE_CHAIN_MOTION_TYPE)
info = reinterpret_cast<SplineChainMovementGenerator const*>(activeGenerator)->GetResumeInfo(owner);
}
info = static_cast<SplineChainMovementGenerator const*>(activeGenerator)->GetResumeInfo(owner);
else
info.Chain = nullptr;
info.Clear();
}

View File

@@ -20,6 +20,7 @@
#include "SplineChain.h"
#include "MovementGenerator.h"
#include "Optional.h"
#include <vector>
class Unit;
@@ -38,7 +39,7 @@ class TC_GAME_API SplineChainMovementGenerator : public MovementGenerator
MovementGeneratorType GetMovementGeneratorType() const override;
// Builds info that can later be used to resume this spline chain movement at the current position
static void GetResumeInfo(Unit const* owner, uint32 id, SplineChainResumeInfo& info);
static void GetResumeInfo(SplineChainResumeInfo& info, Unit const* owner, Optional<uint32> id = {});
// Leaving the object method public for people that know what they're doing to use
// But really, 99% of the time you should be using the static one instead
SplineChainResumeInfo GetResumeInfo(Unit const* owner) const;