Core/AreaTriggers: Implemented SpeedIsTime parameter for areatrigger splines and orbit

This commit is contained in:
Shauren
2025-09-12 00:58:27 +02:00
parent eade1ad6dc
commit c1b8daa639
5 changed files with 16 additions and 13 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE `areatrigger_create_properties` ADD `SpeedIsTime` tinyint(1) unsigned NOT NULL DEFAULT '0' AFTER `Speed`;

View File

@@ -252,10 +252,10 @@ bool AreaTrigger::Create(AreaTriggerCreatePropertiesId areaTriggerCreateProperti
else
orbit.Center = pos;
this->InitOrbit(orbit, GetCreateProperties()->Speed);
this->InitOrbit(orbit, {}, GetCreateProperties()->SpeedIsTime);
}
else if constexpr (std::is_same_v<MovementType, AreaTriggerCreateProperties::SplineInfo>)
this->InitSplineOffsets(movement);
this->InitSplineOffsets(movement, {}, GetCreateProperties()->SpeedIsTime);
else if constexpr (std::is_same_v<MovementType, std::monostate>)
this->SetUpdateFieldValue(areaTriggerData.ModifyValue(&UF::AreaTriggerData::PathType), int32(AreaTriggerPathType::None));
else
@@ -1195,7 +1195,7 @@ void AreaTrigger::UndoActions(Unit* unit)
}
}
void AreaTrigger::InitSplineOffsets(std::vector<Position> const& offsets, Optional<float> overrideSpeed)
void AreaTrigger::InitSplineOffsets(std::vector<Position> const& offsets, Optional<float> overrideSpeed /*= {}*/, bool speedIsTimeInSeconds /*= false*/)
{
float angleSin = std::sin(GetOrientation());
float angleCos = std::cos(GetOrientation());
@@ -1214,10 +1214,10 @@ void AreaTrigger::InitSplineOffsets(std::vector<Position> const& offsets, Option
rotatedPoints[i].z += offset.GetPositionZ();
}
InitSplines(rotatedPoints, overrideSpeed);
InitSplines(rotatedPoints, overrideSpeed, speedIsTimeInSeconds);
}
void AreaTrigger::InitSplines(std::vector<G3D::Vector3> const& splinePoints, Optional<float> overrideSpeed)
void AreaTrigger::InitSplines(std::vector<G3D::Vector3> const& splinePoints, Optional<float> overrideSpeed /*= {}*/, bool speedIsTimeInSeconds /*= false*/)
{
if (splinePoints.size() < 2)
return;
@@ -1230,7 +1230,7 @@ void AreaTrigger::InitSplines(std::vector<G3D::Vector3> const& splinePoints, Opt
if (speed <= 0.0f)
speed = 1.0f;
uint32 timeToTarget = spline->length() / speed * float(IN_MILLISECONDS);
uint32 timeToTarget = (speedIsTimeInSeconds ? speed : spline->length() / speed) * static_cast<float>(IN_MILLISECONDS);
auto areaTriggerData = m_values.ModifyValue(&AreaTrigger::m_areaTriggerData);
SetUpdateFieldValue(areaTriggerData.ModifyValue(&UF::AreaTriggerData::TimeToTarget), timeToTarget);
@@ -1256,7 +1256,7 @@ uint32 AreaTrigger::GetElapsedTimeForMovement() const
return 0;
}
void AreaTrigger::InitOrbit(AreaTriggerOrbitInfo const& orbit, Optional<float> overrideSpeed)
void AreaTrigger::InitOrbit(AreaTriggerOrbitInfo const& orbit, Optional<float> overrideSpeed /*= {}*/, bool speedIsTimeInSeconds /*= false*/)
{
// Circular movement requires either a center position or an attached unit
ASSERT(orbit.Center.has_value() || orbit.PathTarget.has_value());
@@ -1265,7 +1265,7 @@ void AreaTrigger::InitOrbit(AreaTriggerOrbitInfo const& orbit, Optional<float> o
if (speed <= 0.0f)
speed = 1.0f;
uint32 timeToTarget = static_cast<uint32>(orbit.Radius * 2.0f * static_cast<float>(M_PI) * static_cast<float>(IN_MILLISECONDS) / speed);
uint32 timeToTarget = (speedIsTimeInSeconds ? speed : static_cast<uint32>(orbit.Radius * 2.0f * static_cast<float>(M_PI) / speed)) * static_cast<float>(IN_MILLISECONDS);
auto areaTriggerData = m_values.ModifyValue(&AreaTrigger::m_areaTriggerData);
SetUpdateFieldValue(areaTriggerData.ModifyValue(&UF::AreaTriggerData::TimeToTarget), timeToTarget);

View File

@@ -180,13 +180,13 @@ class TC_GAME_API AreaTrigger final : public WorldObject, public GridObject<Area
void SetShape(AreaTriggerShapeInfo const& shape);
float GetMaxSearchRadius() const;
void InitSplineOffsets(std::vector<Position> const& offsets, Optional<float> overrideSpeed = {});
void InitSplines(std::vector<G3D::Vector3> const& splinePoints, Optional<float> overrideSpeed = {});
void InitSplineOffsets(std::vector<Position> const& offsets, Optional<float> overrideSpeed = {}, bool speedIsTimeInSeconds = false);
void InitSplines(std::vector<G3D::Vector3> const& splinePoints, Optional<float> overrideSpeed = {}, bool speedIsTimeInSeconds = false);
bool HasSplines() const { return _spline != nullptr; }
::Movement::Spline<float> const& GetSpline() const { return *_spline; }
uint32 GetElapsedTimeForMovement() const;
void InitOrbit(AreaTriggerOrbitInfo const& orbit, Optional<float> overrideSpeed = {});
void InitOrbit(AreaTriggerOrbitInfo const& orbit, Optional<float> overrideSpeed = {}, bool speedIsTimeInSeconds = false);
bool HasOrbit() const { return m_areaTriggerData->PathData.Is<UF::AreaTriggerOrbit>(); }
UF::AreaTriggerOrbit const& GetOrbit() const { return *m_areaTriggerData->PathData.Get<UF::AreaTriggerOrbit>(); }

View File

@@ -251,6 +251,7 @@ public:
AreaTriggerShapeInfo Shape;
float Speed = 1.0f;
bool SpeedIsTime = false;
using SplineInfo = std::vector<Position>;
std::variant<std::monostate, SplineInfo, AreaTriggerOrbitInfo> Movement;

View File

@@ -169,13 +169,13 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
}
if (QueryResult areatriggerCreateProperties = WorldDatabase.Query("SELECT Id, IsCustom, AreaTriggerId, IsAreatriggerCustom, Flags, "
"MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, SpellForVisuals, TimeToTargetScale, Speed, "
"MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, SpellForVisuals, TimeToTargetScale, Speed, SpeedIsTime, "
"Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ShapeData6, ShapeData7, ScriptName FROM `areatrigger_create_properties`"))
{
do
{
DEFINE_FIELD_ACCESSOR_CACHE_ANONYMOUS(ResultSet, (Id)(IsCustom)(AreaTriggerId)(IsAreatriggerCustom)(Flags)
(MoveCurveId)(ScaleCurveId)(MorphCurveId)(FacingCurveId)(AnimId)(AnimKitId)(DecalPropertiesId)(SpellForVisuals)(TimeToTargetScale)(Speed)
(MoveCurveId)(ScaleCurveId)(MorphCurveId)(FacingCurveId)(AnimId)(AnimKitId)(DecalPropertiesId)(SpellForVisuals)(TimeToTargetScale)(Speed)(SpeedIsTime)
(Shape)(ShapeData0)(ShapeData1)(ShapeData2)(ShapeData3)(ShapeData4)(ShapeData5)(ShapeData6)(ShapeData7)(ScriptName)
) fields { *areatriggerCreateProperties };
@@ -238,6 +238,7 @@ void AreaTriggerDataStore::LoadAreaTriggerTemplates()
createProperties.TimeToTargetScale = fields.TimeToTargetScale().GetUInt32();
createProperties.Speed = fields.Speed().GetFloat();
createProperties.SpeedIsTime = fields.SpeedIsTime().GetBool();
std::array<float, MAX_AREATRIGGER_ENTITY_DATA> shapeData =
{