mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(ai): FollowTarget with radius, speed and keepFollowing; AI value setters
MovementAIComponent::FollowTarget(target, radius, speed, keepFollowing) halts within the radius and walks after the target again once it is out of it; without keepFollowing the follow ends on arrival. The old overload is FollowTarget(target, 0, 1, true) and behaves as before. Setters for the wander settings (radius, speed, chance, delay range) and the combat ones (hard tether radius, attack radius, pursuit speed) that the Lua AI's Set table overrides. BaseCombatAIComponent's proximity entities start as null, so one whose constructor returns before making them no longer frees garbage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -210,6 +210,16 @@ public:
|
||||
*/
|
||||
void SetAggroRadius(float value);
|
||||
|
||||
// The combat settings a script overrides (the Lua AI's Set table): tetherRadius is how far it chases from
|
||||
// home, AggroDist how far from its target it stops to attack, and the pursuit speed the multiple of its base
|
||||
// speed it chases at
|
||||
void SetHardTetherRadius(const float value) { m_HardTetherRadius = value; }
|
||||
float GetHardTetherRadius() const { return m_HardTetherRadius; }
|
||||
void SetAttackRadius(const float value) { m_AttackRadius = value; }
|
||||
float GetAttackRadius() const { return m_AttackRadius; }
|
||||
void SetPursuitSpeed(const float value) { m_PursuitSpeed = value; }
|
||||
float GetPursuitSpeed() const { return m_PursuitSpeed; }
|
||||
|
||||
/**
|
||||
* Makes the entity look at a certain point in space
|
||||
* @param point the point to look at
|
||||
@@ -295,8 +305,8 @@ private:
|
||||
/**
|
||||
* The aggro physics volumes of this entity
|
||||
*/
|
||||
dpEntity* m_dpEntity;
|
||||
dpEntity* m_dpEntityEnemy;
|
||||
dpEntity* m_dpEntity{ nullptr };
|
||||
dpEntity* m_dpEntityEnemy{ nullptr };
|
||||
|
||||
/**
|
||||
* The max radius of this entity to an enemy allowing it to be chased
|
||||
|
||||
@@ -194,6 +194,13 @@ void MovementAIComponent::Run(const float deltaTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
// A follow with a radius halts short of the target: it walks after it again once it is out of the radius, or the
|
||||
// follow ends there without keepFollowing
|
||||
if (m_FollowedTarget != LWOOBJID_EMPTY && m_FollowRadius > 0.0f && AtFinalWaypoint()) {
|
||||
if (m_KeepFollowing) ResumeFollow();
|
||||
else m_FollowedTarget = LWOOBJID_EMPTY;
|
||||
}
|
||||
|
||||
// Are we done?
|
||||
if (AtFinalWaypoint()) return;
|
||||
|
||||
@@ -298,7 +305,10 @@ bool MovementAIComponent::ContinuePath() {
|
||||
}
|
||||
} else {
|
||||
Stop();
|
||||
if (m_FollowedTarget != LWOOBJID_EMPTY) {
|
||||
if (m_FollowedTarget != LWOOBJID_EMPTY && !m_KeepFollowing) {
|
||||
// It arrived: a follow that does not keep following ends here
|
||||
m_FollowedTarget = LWOOBJID_EMPTY;
|
||||
} else if (m_FollowedTarget != LWOOBJID_EMPTY && m_FollowRadius <= 0.0f) {
|
||||
GameMessages::GetPosition getPos;
|
||||
if (!getPos.Send(m_FollowedTarget)) {
|
||||
LOG("Target %llu does not exist anymore to follow", m_FollowedTarget);
|
||||
@@ -723,6 +733,15 @@ bool MovementAIComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInf
|
||||
}
|
||||
|
||||
void MovementAIComponent::FollowTarget(const LWOOBJID target) {
|
||||
FollowTarget(target, 0.0f, 1.0f, true);
|
||||
}
|
||||
|
||||
void MovementAIComponent::FollowTarget(const LWOOBJID target, const float radius, const float speed, const bool keepFollowing) {
|
||||
// The halt distance of an earlier follow with a radius goes with it
|
||||
if (m_FollowRadius > 0.0f && radius <= 0.0f) SetHaltDistance(0.0f);
|
||||
m_FollowRadius = radius;
|
||||
m_FollowSpeed = speed;
|
||||
m_KeepFollowing = keepFollowing;
|
||||
if (target == LWOOBJID_EMPTY) {
|
||||
m_FollowedTarget = target;
|
||||
return;
|
||||
@@ -735,8 +754,24 @@ void MovementAIComponent::FollowTarget(const LWOOBJID target) {
|
||||
}
|
||||
|
||||
m_FollowedTarget = target;
|
||||
SetMaxSpeed(1.0f);
|
||||
m_CurrentSpeed = 1.0f;
|
||||
if (radius > 0.0f) SetHaltDistance(radius);
|
||||
SetMaxSpeed(speed);
|
||||
m_CurrentSpeed = speed;
|
||||
SetDestination(getPos.pos);
|
||||
}
|
||||
|
||||
void MovementAIComponent::ResumeFollow() {
|
||||
GameMessages::GetPosition getPos;
|
||||
if (!getPos.Send(m_FollowedTarget)) {
|
||||
LOG("Target %llu does not exist anymore to follow", m_FollowedTarget);
|
||||
m_FollowedTarget = LWOOBJID_EMPTY;
|
||||
return;
|
||||
}
|
||||
if (Vector3::DistanceSquared(m_Parent->GetPosition(), getPos.pos) <= m_FollowRadius * m_FollowRadius) return;
|
||||
|
||||
SetHaltDistance(m_FollowRadius);
|
||||
SetMaxSpeed(m_FollowSpeed);
|
||||
m_CurrentSpeed = m_FollowSpeed;
|
||||
SetDestination(getPos.pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,13 @@ public:
|
||||
*/
|
||||
const MovementAIInfo& GetInfo() const;
|
||||
|
||||
// The wander settings a script overrides (the Lua AI's Set table: wanderRadius, WanderSpeed, WanderChance,
|
||||
// WanderDelayMin and WanderDelayMax), used as given
|
||||
void SetWanderRadius(const float value) { m_Info.wanderRadius = value; }
|
||||
void SetWanderSpeed(const float value) { m_Info.wanderSpeed = value; }
|
||||
void SetWanderChance(const float value) { m_Info.wanderChance = value; }
|
||||
void SetWanderDelay(const float min, const float max) { m_Info.wanderDelayMin = min; m_Info.wanderDelayMax = max; }
|
||||
|
||||
/**
|
||||
* Set a destination point for the entity to move towards
|
||||
* @param value the destination point to move towards
|
||||
@@ -242,8 +249,21 @@ public:
|
||||
|
||||
bool HasPath() const { return m_Path != nullptr; }
|
||||
|
||||
// Follows the target at speed 1 until told otherwise, walking up to it (FollowTarget(target, 0, 1, true))
|
||||
void FollowTarget(const LWOOBJID target);
|
||||
|
||||
/**
|
||||
* The FollowTarget game message: walks to the target at the speed (a multiple of the base speed) and stops
|
||||
* within the radius of it; keepFollowing walks after it again each time it gets further than the radius,
|
||||
* otherwise it stops following once it arrives.
|
||||
*/
|
||||
void FollowTarget(const LWOOBJID target, const float radius, const float speed, const bool keepFollowing);
|
||||
|
||||
LWOOBJID GetFollowedTarget() const { return m_FollowedTarget; }
|
||||
float GetFollowRadius() const { return m_FollowRadius; }
|
||||
float GetFollowSpeed() const { return m_FollowSpeed; }
|
||||
bool GetKeepFollowing() const { return m_KeepFollowing; }
|
||||
|
||||
/**
|
||||
* Knocks this entity back the way the client knocks back the character it controls (the Knockback game
|
||||
* message): a vector longer than dpKnockback::MIN_LAUNCH_SPEED throws it in an arc under the zone's gravity
|
||||
@@ -409,6 +429,12 @@ private:
|
||||
std::vector<std::function<void(uint32_t)>> m_WaypointReachedCallbacks;
|
||||
|
||||
LWOOBJID m_FollowedTarget{ LWOOBJID_EMPTY };
|
||||
float m_FollowRadius{ 0.0f };
|
||||
float m_FollowSpeed{ 1.0f };
|
||||
bool m_KeepFollowing{ true };
|
||||
|
||||
// Walks after the followed target again when it is further away than the follow radius
|
||||
void ResumeFollow();
|
||||
|
||||
/**
|
||||
* The knockback this entity is flying through, if any
|
||||
|
||||
Reference in New Issue
Block a user