From ad9a00e49d34db79269679ff8ef4e77d302becb5 Mon Sep 17 00:00:00 2001 From: Karrz1 <127596890+Karrz1@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:55:33 +0100 Subject: [PATCH] Bots: a formation follower tracks a walking owner with the follow generator (#99) Reason: in a formation the bots walked to the slot as it stood at the last issue, so a circle trailed far behind a walking owner, and a follower waited for the full recall slack (13 to 15 yd for a caster) before it started. Why: the slot was re-issued at most every 500 ms and only after it had moved 2 y, so by the time a bot got there the owner had left the point. Fix: while the owner is on the move (BotAI::anchor_moving, seen from successive ticks) the follow generator keeps the bot at its slot's distance and angle, and a plain follower starts at its follow distance plus 1.5 yd instead of the full slack. The slot walk still settles the bots when the owner stops. --- src/modules/PlayerbotV2/Bot/BotAI.h | 17 ++++++++++++++++ .../PlayerbotV2/Bot/States/State_InGroup.cpp | 20 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/modules/PlayerbotV2/Bot/BotAI.h b/src/modules/PlayerbotV2/Bot/BotAI.h index d76f8e801c..2a684b7ded 100644 --- a/src/modules/PlayerbotV2/Bot/BotAI.h +++ b/src/modules/PlayerbotV2/Bot/BotAI.h @@ -5242,7 +5242,24 @@ private: uint8 strikes = 0; }; std::array bad_goals_{}; + uint32 anchor_seen_ms_ = 0, anchor_move_ms_ = 0; + float anchor_x_ = 0.f, anchor_y_ = 0.f; public: + // Whether the follow anchor (leader or owner) has moved in the last second, seen from successive ticks. A follower that waits for the + // full recall slack (13-15 yd for a caster) before it starts runs 2-4 s behind a leader who sets off; while he moves it starts at the + // follow distance instead. + bool anchor_moving(float x, float y, uint32 now_ms) + { + if (anchor_seen_ms_ == 0 || now_ms - anchor_seen_ms_ > 3000u) + { + anchor_x_ = x; anchor_y_ = y; anchor_seen_ms_ = now_ms; anchor_move_ms_ = 0; + return false; + } + const float dx = x - anchor_x_, dy = y - anchor_y_; + if (dx * dx + dy * dy > 1.0f) { anchor_move_ms_ = now_ms; anchor_x_ = x; anchor_y_ = y; } + anchor_seen_ms_ = now_ms; + return anchor_move_ms_ != 0 && now_ms - anchor_move_ms_ < 1000u; + } void note_path_blocked(uint32 now_ms) { ++path_blocked_count_; diff --git a/src/modules/PlayerbotV2/Bot/States/State_InGroup.cpp b/src/modules/PlayerbotV2/Bot/States/State_InGroup.cpp index 007ad8e31c..3e95713788 100644 --- a/src/modules/PlayerbotV2/Bot/States/State_InGroup.cpp +++ b/src/modules/PlayerbotV2/Bot/States/State_InGroup.cpp @@ -1,4 +1,4 @@ -// State_InGroup - Cross-cutting layer that runs alongside the primary state +// State_InGroup - Cross-cutting layer that runs alongside the primary state // whenever the bot is grouped. Today: keep within follow distance of the // leader when idle. Future: ready-checks, raid mark targeting, role hand-off. @@ -1257,6 +1257,9 @@ void DispatchInGroup(BotAI& ai, // re-issued when the slot has moved more than 2 y from the last one (500 ms apart at most), a bot stops within // 1.5 y of the slot and restarts only beyond 2.5 y (no jitter), and a bot that makes no progress for 3 s falls // back to the plain follow behind the owner for 8 s. + // While the anchor is on the move a follower starts at its follow distance (+1.5 yd), not at the full recall slack; a standing + // anchor keeps the wide slack, so nobody shuffles about at a halt. + const bool anchor_on_the_move = ai.anchor_moving(anchor->x, anchor->y, snapshot.published_at_ms()); if (formation_slot_active) { auto& ft = ai.formation_track(); @@ -1289,6 +1292,18 @@ void DispatchInGroup(BotAI& ai, ai.set_last_rule_fired("ingroup:formation_fallback"); action = 3; } + else if (anchor_on_the_move) + { + // The owner is walking: the follow generator keeps the bot at its slot's distance and angle and re-aims every update, which + // starts the moment the owner does. Walking to the slot as it stood at the last issue (a point the owner has left by + // the time the bot gets there, re-issued at most every 500 ms and only after the slot moved 2 y) left the circle trailing + // far behind a walking owner. The slot walk settles the bots once the owner halts. + ft.dest_valid = false; + ft.last_progress_ms = formation_now_ms; + emit.follow(anchor->guid, formation_offset.distance, formation_offset.angle_radians); + ai.set_last_rule_fired("ingroup:formation_follow"); + action = 1; + } else { action = 1; @@ -1341,8 +1356,9 @@ void DispatchInGroup(BotAI& ai, else if (!formation_fallback && ai.formation_track().dest_valid) ai.formation_track().dest_valid = false; + const float recall_now = anchor_on_the_move ? std::min(kRecallSlack, std::max(kFollowDistance + 1.5f, 5.0f)) : kRecallSlack; if (!formation_slot_active && !movement_owned_elsewhere && - (dist > kRecallSlack || (refollow && dist > 1.5f))) + (dist > recall_now || (refollow && dist > 1.5f))) { // Follow uses MotionMaster MoveFollow, which silently re-emits forever // when the leader is unreachable (across a gap / closed door) — and