fix(ground-ai): harden drive ownership, teardown and failure switch

Address two issues found in the first isolated 2.61.0.58 live runs and add
a test switch to disable silent fallback to stock movement:

- Add navigation.returnToStockOnFailure in tuning/ground-ai.jsonc (default
  true), compiled into WTO_AI_NAV_RETURN_TO_STOCK and written to wto_ws.cfg
  as ground_ai_return_to_stock=0 when disabled. When false, failed or
  timed-out bots keep stock movement paused, brake in place and log the
  failure once instead of silently handing control back to stock tankBot.
- Allow holdMs=0 release actions even after local_mp_is_host() flips false
  during mission unload, add eid=0 bulk release on wto_reset_runtime(), and
  match slots by eid rather than live owner lookup so match exit cleans up
  the native control table immediately.
- Stop releasing drive ownership when a vehicle is immobilized by damage or
  repair; brake in place and pause the echo watchdog instead, avoiding the
  1-second release/re-acquire flapping observed during combat. Log exact
  release reasons and back off for 1 second if MoveSystem.inactive is
  cleared externally.

Verified MSVC build of wto_ws.dll (0 warnings in project C sources), root
and launcher type checks, 14/14 check-patches on 2.61.0.58, and a temporary
2.61.0.58 game copy build confirming ground_ai_return_to_stock=0 in
wto_ws.cfg and 15 packed daScript modules. Live battle re-check pending.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 16:47:44 +08:00
1 parent 89242e91f0
commit 73bae4785f
11 files changed
+116 -27

No files matched your search

+51 -14
View File
@@ -25,6 +25,13 @@ def public wto_drive_request_control(eid : EntityId; holdMs : int)
add(blk, "holdMs", "{holdMs}")
call_mission_action("wtoGroundAiDriveControl", blk)
[never_inline]
def public wto_drive_release_all()
using() <| $(var blk : DataBlock)
add(blk, "eid", "0")
add(blk, "holdMs", "0")
call_mission_action("wtoGroundAiDriveControl", blk)
[never_inline]
def private wto_set_phys_axes(var actor : VehiclePhysActor&; thr, str, brk, handBrk : float)
actor.phys.producedCT |> ground_control_state_setAutomaticTransmission(true)
@@ -49,8 +56,7 @@ def private wto_check_echo_watchdog(unitMissionName : string; var actor : Vehicl
if !throttleEchoed || !steeringEchoed
st.deadEchoSec += clamp(dt, 0.0, 0.15)
if st.deadEchoSec >= WTO_AI_NAV_DEAD_ECHO_SEC
st.routeAFallback = true
print("WTO_AI|PHYS_FALLBACK|actor={unitMissionName}|eid={uint(slot.eid)}\n")
print("WTO_AI|PHYS_FALLBACK|actor={unitMissionName}|eid={uint(slot.eid)}|autoReturn={WTO_AI_NAV_RETURN_TO_STOCK}\n")
return false
else
st.deadEchoSec = 0.0
@@ -127,10 +133,11 @@ def private wto_compute_cruise_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleS
[never_inline]
def private wto_release_phys_owner(gm : IGroundModel const?; var actor : VehiclePhysActor&;
var slot : WtoBotSlot&)
var slot : WtoBotSlot&; reason : string)
assume st = slot.drive
if !st.routeBOwned
return
print("WTO_AI|DRIVE_RELEASE|eid={uint(slot.eid)}|reason={reason}\n")
if gm != null && gm.moveSys != null && gm.moveSys.inactive
wto_set_phys_axes(actor, 0.0, 0.0, 0.0, 0.0)
wto_drive_request_control(slot.eid, 0)
@@ -139,22 +146,39 @@ def private wto_release_phys_owner(gm : IGroundModel const?; var actor : Vehicle
st.prevStr = 0.0
st.deadEchoSec = 0.0
[never_inline]
def private wto_drive_is_immobilized(actor : VehiclePhysActor const&) : bool
assume dmg = actor.phys.currentState.damageState
return (!dmg.allowMoveControl || dmg.engineReadyness <= 0.0 ||
dmg.driverReadyness <= 0.0 || (dmg.trackLBroken && dmg.trackRBroken))
[never_inline]
def private wto_drive_handle_failure(gm : IGroundModel const?; var actor : VehiclePhysActor&;
var slot : WtoBotSlot&; reason : string; permanent : bool)
assume st = slot.drive
if WTO_AI_NAV_RETURN_TO_STOCK
if permanent
st.routeAFallback = true
wto_release_phys_owner(gm, actor, slot, reason)
return
if !st.failLogged
st.failLogged = true
print("WTO_AI|DRIVE_FAIL|eid={uint(slot.eid)}|reason={reason}|autoReturn=false\n")
st.prevThr = 0.0
st.prevStr = 0.0
st.deadEchoSec = 0.0
wto_set_phys_axes(actor, 0.0, 0.0, 1.0, 1.0)
[never_inline]
def private wto_prepare_phys_owner(gm : IGroundModel const?; var actor : VehiclePhysActor&;
now : float; var slot : WtoBotSlot&) : bool
assume st = slot.drive
if gm == null || gm.moveSys == null
wto_release_phys_owner(gm, actor, slot)
return false
assume dmg = actor.phys.currentState.damageState
if (!slot.driveCmd.valid || (!slot.macro.valid && !WTO_AI_LAYER_TACTICS) ||
now > slot.nextNavAt + WTO_AI_NAV_TICK_SEC ||
!dmg.allowMoveControl || dmg.engineReadyness <= 0.0 || dmg.driverReadyness <= 0.0 ||
(dmg.trackLBroken && dmg.trackRBroken))
wto_release_phys_owner(gm, actor, slot)
wto_release_phys_owner(gm, actor, slot, "missing_movesys")
return false
if st.routeBOwned && !gm.moveSys.inactive
wto_release_phys_owner(gm, actor, slot)
wto_release_phys_owner(gm, actor, slot, "external_inactive_reset")
st.nextControlRequestAt = now + 1.0
return false
if now >= st.nextControlRequestAt
if !st.routeBOwned && gm.moveSys.inactive
@@ -178,9 +202,22 @@ def public wto_drive_step_phys(var unit : Unit?; unitMissionName : string;
return
if !wto_prepare_phys_owner(gm, actor, now, slot)
return
if !wto_check_echo_watchdog(unitMissionName, actor, dt, slot)
wto_release_phys_owner(gm, actor, slot)
if !slot.driveCmd.valid || (!slot.macro.valid && !WTO_AI_LAYER_TACTICS)
wto_drive_handle_failure(gm, actor, slot, "invalid_drive_cmd", false)
return
if now > slot.nextNavAt + WTO_AI_NAV_TICK_SEC
wto_drive_handle_failure(gm, actor, slot, "stale_nav_tick", false)
return
if wto_drive_is_immobilized(actor)
slot.drive.prevThr = 0.0
slot.drive.prevStr = 0.0
slot.drive.deadEchoSec = 0.0
wto_set_phys_axes(actor, 0.0, 0.0, 1.0, 1.0)
return
if !wto_check_echo_watchdog(unitMissionName, actor, dt, slot)
wto_drive_handle_failure(gm, actor, slot, "dead_echo", true)
return
slot.drive.failLogged = false
vehicle_actor_set_allow_move_control(actor, true)
assume st = slot.drive
assume cmd = slot.driveCmd
+1
View File
@@ -52,6 +52,7 @@ def private wto_reset_runtime()
if g_bots[i].drive.routeBOwned
wto_drive_request_control(g_bots[i].eid, 0)
g_bots[i] = WtoBotSlot()
wto_drive_release_all()
[never_inline]
def private wto_find_slot(eid : EntityId) : int
+1
View File
@@ -242,6 +242,7 @@ struct public WtoDriveCmd
struct public WtoDriveState
routeBOwned : bool = false
routeAFallback : bool = false
failLogged : bool = false
nextControlRequestAt : float = -1.0
deadEchoSec : float = 0.0
prevYaw : float = 0.0