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.
This commit is contained in:
Karrz1
2026-10-23 18:55:33 +08:00
committed by GitHub
parent f8067cf820
commit ad9a00e49d
2 changed files with 35 additions and 2 deletions
+17
View File
@@ -5242,7 +5242,24 @@ private:
uint8 strikes = 0;
};
std::array<BadGoal, 6> 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_;
@@ -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