From 58fde2030ca15330a78f64816b94cc9803be850a Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sat, 5 Dec 2026 22:12:37 +0800 Subject: [PATCH] fix(ground-ai): escalate repeated contacts with vehicles and wrecks A bot pressed against the same wreck or stopped vehicle backed off, planned the same path again and drove into it once more, every few seconds for minutes, because a contact reset the stuck watch and left no trace for path searches. A second contact within pathFollow.contactRepeatSec near the same place now marks the body for path searches and switches the passing side; after unstickMaxAttempts repeats the bot gives its order up and the place is avoided like any other unreachable spot. NAV_CONTACT logs the repeat count and the body position. --- .../src/renderer/src/i18n/locales/en.json | 1 + .../src/renderer/src/i18n/locales/zh-CN.json | 1 + .../src/pages/tuning/bot-tuning-fields.ts | 1 + apps/launcher/src/shared/schemas/tuning.ts | 1 + apps/server/src/tuning/ground-ai-tuning.ts | 1 + apps/server/tuning/ground-ai.jsonc | 3 ++ game-ai/ground/wto_ai_nav_common.das | 2 +- game-ai/ground/wto_ai_nav_types_common.das | 5 +++ game-ai/ground/wto_ai_traffic_common.das | 15 ++++--- game-ai/ground/wto_ai_unstick_common.das | 42 +++++++++++++++---- .../patcher/src/ground-ai/ground-ai-config.ts | 2 + 11 files changed, 61 insertions(+), 13 deletions(-) diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index 34e5f6a..e4f6b74 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -736,6 +736,7 @@ "blockTtlSec": "Blocked passage cost duration", "contactGapM": "Gap to an obstacle that counts as contact", "contactReverseSec": "Time in contact before backing off", + "contactRepeatSec": "Window in which a second contact counts as a repeat", "stuckWindowSec": "Stuck detection window", "stuckMinProgressM": "Min progress within the stuck window", "unstickReverseM": "Unstick reverse distance", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 2f0f6d2..5c6abf9 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -736,6 +736,7 @@ "blockTtlSec": "被堵路段代价持续时间", "contactGapM": "离障碍多近算作顶上", "contactReverseSec": "顶上多久后倒车", + "contactRepeatSec": "多久内在同一处再顶上算作反复顶上", "stuckWindowSec": "卡住检测窗口时长", "stuckMinProgressM": "检测窗口内的最小前进距离", "unstickReverseM": "脱困倒车距离", diff --git a/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts b/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts index b9325f5..1cc5ed8 100644 --- a/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts +++ b/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts @@ -318,6 +318,7 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [ num('pathFollow', 'blockTtlSec', 3, 120, 's'), num('pathFollow', 'contactGapM', 0.2, 3, 'm'), num('pathFollow', 'contactReverseSec', 0.3, 5, 's'), + num('pathFollow', 'contactRepeatSec', 3, 120, 's'), num('pathFollow', 'stuckWindowSec', 1, 15, 's'), num('pathFollow', 'stuckMinProgressM', 0.2, 10, 'm'), num('pathFollow', 'unstickReverseM', 2, 25, 'm'), diff --git a/apps/launcher/src/shared/schemas/tuning.ts b/apps/launcher/src/shared/schemas/tuning.ts index 94b4217..850e93c 100644 --- a/apps/launcher/src/shared/schemas/tuning.ts +++ b/apps/launcher/src/shared/schemas/tuning.ts @@ -148,6 +148,7 @@ const GroundAiPathFollowSchema = z.object({ blockTtlSec: z.number().min(3).max(120), contactGapM: z.number().min(0.2).max(3), contactReverseSec: z.number().min(0.3).max(5), + contactRepeatSec: z.number().min(3).max(120), stuckWindowSec: z.number().min(1).max(15), stuckMinProgressM: z.number().min(0.2).max(10), unstickReverseM: z.number().min(2).max(25), diff --git a/apps/server/src/tuning/ground-ai-tuning.ts b/apps/server/src/tuning/ground-ai-tuning.ts index 1d94c8c..f959970 100644 --- a/apps/server/src/tuning/ground-ai-tuning.ts +++ b/apps/server/src/tuning/ground-ai-tuning.ts @@ -246,6 +246,7 @@ function readPathFollowSection(pf: TuningReader): GroundAiPathFollow { blockTtlSec: n('blockTtlSec', 3, 120), contactGapM: n('contactGapM', 0.2, 3), contactReverseSec: n('contactReverseSec', 0.3, 5), + contactRepeatSec: n('contactRepeatSec', 3, 120), stuckWindowSec: n('stuckWindowSec', 1, 15), stuckMinProgressM: n('stuckMinProgressM', 0.2, 10), unstickReverseM: n('unstickReverseM', 2, 25), diff --git a/apps/server/tuning/ground-ai.jsonc b/apps/server/tuning/ground-ai.jsonc index f19fab9..23efc43 100644 --- a/apps/server/tuning/ground-ai.jsonc +++ b/apps/server/tuning/ground-ai.jsonc @@ -226,10 +226,13 @@ "passSpeedMps": 4.0, // No side free: stop short, and after blockWaitSec mark the obstacle for path searches for // blockTtlSec and plan again. A hull within contactGapM of it for contactReverseSec backs off. + // Pressed again within contactRepeatSec near the same place: mark the obstacle, try the other + // side, and after unstickMaxAttempts such repeats give the order up. "blockWaitSec": 2.0, "blockTtlSec": 15.0, "contactGapM": 0.8, "contactReverseSec": 1.0, + "contactRepeatSec": 20.0, // Less progress than stuckMinProgressM within stuckWindowSec while wanting to move is stuck. "stuckWindowSec": 3.0, "stuckMinProgressM": 0.8, diff --git a/game-ai/ground/wto_ai_nav_common.das b/game-ai/ground/wto_ai_nav_common.das index 10a34c8..bb58bde 100644 --- a/game-ai/ground/wto_ai_nav_common.das +++ b/game-ai/ground/wto_ai_nav_common.das @@ -157,7 +157,7 @@ def private wto_nav_follow(var world : WtoWorldSnap&; navState : int; now : floa let narrow = slot.nav.wallDistM < WTO_AI_PF_NARROW_WALL_M || slot.nav.chokepoint wto_traffic_update(world, navState, now, myPos, pathDir, speedNow, narrow, slot) if wto_traffic_in_contact(now, slot.nav) - wto_unstick_contact(navState, now, myPos, hullFwd, slot) + wto_unstick_contact(world, navState, now, myPos, hullFwd, slot) if !wto_unstick_reversing(now, myPos, slot) wto_nav_halt(myPos, hullFwd, slot) return diff --git a/game-ai/ground/wto_ai_nav_types_common.das b/game-ai/ground/wto_ai_nav_types_common.das index e0bd269..4791783 100644 --- a/game-ai/ground/wto_ai_nav_types_common.das +++ b/game-ai/ground/wto_ai_nav_types_common.das @@ -56,6 +56,11 @@ struct public WtoNavState avoidSpeedCap : float = 99.0 blockedSince : float = -100.0 contactSince : float = -100.0 + contactBodyPos : float3 = float3(0.0, 0.0, 0.0) + contactBodyRadiusM : float = 0.0 + lastContactAt : float = -100.0 + lastContactPos : float3 = float3(0.0, 0.0, 0.0) + contactRepeats : int = 0 stuckOrigin : float3 = float3(0.0, 0.0, 0.0) stuckCheckAt : float = -100.0 unstickAnchor : float3 = float3(0.0, 0.0, 0.0) diff --git a/game-ai/ground/wto_ai_traffic_common.das b/game-ai/ground/wto_ai_traffic_common.das index 9cc3bbf..dd27736 100644 --- a/game-ai/ground/wto_ai_traffic_common.das +++ b/game-ai/ground/wto_ai_traffic_common.das @@ -196,13 +196,18 @@ def private wto_traffic_yield(now : float; var nav : WtoNavState&) nav.yieldCooldownUntil = nav.yieldUntil + WTO_AI_PF_YIELD_WAIT_SEC nav.avoidSpeedCap = min(nav.avoidSpeedCap, now < nav.yieldUntil ? 0.0 : WTO_AI_PF_PASS_SPEED_MPS) -// Hull pressed against a standing body: when that started (cleared once there is room again). +// Hull pressed against a standing body: when that started (cleared once there is room again), +// and where the body is and how much room passing it takes, for marking it on repeats. [never_inline] -def private wto_traffic_contact(now, gap, speedMps : float; var nav : WtoNavState&) - if gap >= WTO_AI_PF_CONTACT_GAP_M || speedMps >= WTO_AI_PF_STATIONARY_MPS +def private wto_traffic_contact(now, speedMps : float; body : WtoTrafficBody const&; var slot : WtoBotSlot&) + assume nav = slot.nav + if wto_traffic_gap(body, slot.spec) >= WTO_AI_PF_CONTACT_GAP_M || speedMps >= WTO_AI_PF_STATIONARY_MPS nav.contactSince = -100.0 - elif nav.contactSince < -50.0 + return + if nav.contactSince < -50.0 nav.contactSince = now + nav.contactBodyPos = body.pos + nav.contactBodyRadiusM = wto_traffic_need(body, slot.spec) // True after contactReverseSec pressed against a vehicle or wreck: the caller backs off at once. [never_inline] @@ -222,7 +227,7 @@ def public wto_traffic_update(world : WtoWorldSnap const&; navState : int; now : var standing = WtoTrafficBody() let lookM = max(WTO_AI_PF_BUMPER_RAY_M, speedMps * WTO_AI_PF_TRAFFIC_TTC_SEC) if wto_traffic_find_standing(world, myPos, dir, lookM, slot, standing) - wto_traffic_contact(now, wto_traffic_gap(standing, slot.spec), speedMps, nav) + wto_traffic_contact(now, speedMps, standing, slot) if !wto_traffic_pass(navState, now, myPos, dir, standing, slot) wto_traffic_blocked(navState, now, standing, slot) return diff --git a/game-ai/ground/wto_ai_unstick_common.das b/game-ai/ground/wto_ai_unstick_common.das index 7f4b5bf..4e349ff 100644 --- a/game-ai/ground/wto_ai_unstick_common.das +++ b/game-ai/ground/wto_ai_unstick_common.das @@ -66,15 +66,43 @@ def private wto_unstick_give_up(var world : WtoWorldSnap&; navState : int; now : slot.nav.unstickAttempts = 0 slot.nav.unstickLevel = 0 -// Pressed against a vehicle or wreck: back up at once instead of waiting for the stuck window, -// and plan again so the next path or passing point accounts for it. +// Pressed against the same body again: mark it for path searches and try its other side; after +// unstickMaxAttempts repeats give the order up like a bot stuck for good. [never_inline] -def public wto_unstick_contact(navState : int; now : float; myPos, hullFwd : float3; var slot : WtoBotSlot&) - slot.nav.contactSince = -100.0 - slot.nav.contactEvents++ - slot.nav.stuckCheckAt = -100.0 +def private wto_unstick_contact_repeat(var world : WtoWorldSnap&; navState : int; now : float; myPos : float3; + var slot : WtoBotSlot&) + assume nav = slot.nav + nav.contactRepeats++ + if nav.contactRepeats >= WTO_AI_PF_UNSTICK_MAX_ATTEMPTS + nav.unstickAttempts = nav.contactRepeats + nav.contactRepeats = 0 + wto_unstick_give_up(world, navState, now, myPos, nav.contactBodyPos, slot) + return + if navState == WTO_NAVMESH_LOADED + wto_navq_add_dynamic(nav.contactBodyPos, nav.contactBodyRadiusM, WTO_AI_PF_RUBBLE_COST_MUL, now + WTO_AI_PF_BLOCK_TTL_SEC) + if nav.avoidSide != 0.0 + nav.avoidSide = -nav.avoidSide + nav.avoidSideUntil = now + WTO_AI_PF_UNSTICK_REV_SEC + WTO_AI_PF_BLOCK_WAIT_SEC + +// Pressed against a vehicle or wreck: back up at once instead of waiting for the stuck window, +// and plan again. Pressed again near the same place within contactRepeatSec escalates. +[never_inline] +def public wto_unstick_contact(var world : WtoWorldSnap&; navState : int; now : float; myPos, hullFwd : float3; + var slot : WtoBotSlot&) + assume nav = slot.nav + let again = (now - nav.lastContactAt <= WTO_AI_PF_CONTACT_REPEAT_SEC && + wto_xz_dist_sq(myPos, nav.lastContactPos) <= WTO_AI_PF_JAM_RADIUS_M * WTO_AI_PF_JAM_RADIUS_M) + nav.lastContactAt = now + nav.lastContactPos = myPos + nav.contactSince = -100.0 + nav.contactEvents++ + nav.stuckCheckAt = -100.0 slot.route.replanRequested = true - print("WTO_AI|NAV_CONTACT|eid={uint(slot.eid)}|pos={myPos}\n") + if again + wto_unstick_contact_repeat(world, navState, now, myPos, slot) + else + nav.contactRepeats = 0 + print("WTO_AI|NAV_CONTACT|eid={uint(slot.eid)}|repeat={nav.contactRepeats}|pos={myPos}|body={nav.contactBodyPos}\n") wto_unstick_start_reverse(navState, now, myPos, hullFwd, slot) // Backing up after being stuck; true while the manoeuvre runs (the drive command is set). diff --git a/packages/patcher/src/ground-ai/ground-ai-config.ts b/packages/patcher/src/ground-ai/ground-ai-config.ts index 17e2f18..11c101b 100644 --- a/packages/patcher/src/ground-ai/ground-ai-config.ts +++ b/packages/patcher/src/ground-ai/ground-ai-config.ts @@ -64,6 +64,7 @@ export interface GroundAiPathFollow { readonly blockTtlSec: number; readonly contactGapM: number; readonly contactReverseSec: number; + readonly contactRepeatSec: number; readonly stuckWindowSec: number; readonly stuckMinProgressM: number; readonly unstickReverseM: number; @@ -483,6 +484,7 @@ function pathFollowEntries(p: GroundAiPathFollow): readonly DasEntry[] { ['WTO_AI_PF_BLOCK_TTL_SEC', 'float', p.blockTtlSec], ['WTO_AI_PF_CONTACT_GAP_M', 'float', p.contactGapM], ['WTO_AI_PF_CONTACT_REVERSE_SEC', 'float', p.contactReverseSec], + ['WTO_AI_PF_CONTACT_REPEAT_SEC', 'float', p.contactRepeatSec], ['WTO_AI_PF_STUCK_WINDOW_SEC', 'float', p.stuckWindowSec], ['WTO_AI_PF_STUCK_MIN_PROGRESS_M', 'float', p.stuckMinProgressM], ['WTO_AI_PF_UNSTICK_REV_M', 'float', p.unstickReverseM],