feat(ground-ai): follow baked navmesh paths with sliced searches

Native engine (native/wto-nav):
- Path searches are queued per slot and advanced with Detour's sliced
  search inside a per-frame time budget (navEngine.pathBudgetMsPerFrame),
  so a 4 km search no longer stalls a frame. The synchronous find_path
  op is gone.
- The battle's pack is read on a background thread when the mission
  finishes loading (prefetch); load_map only takes the result.
- New mesh queries: probe (surface, flags, room to the mesh edge),
  raycast, nearest walkable point, and dynamic cost circles for wrecks,
  jams and fresh obstacles that later searches route around.

Ground AI scripts:
- route picks the mesh tier by vehicle width and the cost filter by
  tracked or wheeled, plans on goal change, drift off the corridor, a
  timer or reported obstacles, and falls back to the stock road mesh
  only when the battle decided on the fallback.
- follow steers at a speed-scaled lookahead point and brakes ahead of
  sharp corners, narrow passages and the destination.
- avoid casts rays from both front hull corners that drive through
  objects the bake marks crushable, follows slower traffic, steps aside
  or yields by size priority in narrow passages.
- unstick escalates deterministically: back up along the corridor, mark
  a jam and replan, then log the spot and hand the order back.
- Flank lanes are built through the queued searches; rallies are not
  released while their lanes are still being built.
- Removed the 9-arc forward probing, 7-arc reverse probing, 145 m
  straight shortcuts, 165 m snapping and random sideways detours.

Tuning: new pathFollow section, navEngine.goalSnapRadiusM and
pathBudgetMsPerFrame, navBake.crushableMaxRiExtraHp passed to the
scripts; retired navigation.cornerBrakeAccel, stuckWindowSec,
stuckMinMoveM and unstickReverseSec. Launcher fields and en/zh-CN labels
updated.

Checked: root and launcher typecheck, MSVC build with no warnings in
project code, check-patches for 2.61.0.58 and 2.61.0.60, offline engine
run on avg_poland (prefetch, sliced searches within budget, slot
replacement, dynamic costs), isolated game copy build. daScript
compilation and in-battle behaviour still need the in-game run.
This commit is contained in:
N0VAN0M4LY committed 2026-12-05 17:38:41 +08:00
1 parent e0a344708d
commit ba947fe5b6
34 files changed
+2810 -911

No files matched your search

+55 -4
View File
@@ -9,6 +9,7 @@ import {
type GroundAiDriveMode,
type GroundAiMode,
type GroundAiNavCosts,
type GroundAiPathFollow,
} from '@wto/patcher';
import type { TankLineupWeights } from '../battle/battle-ranks.ts';
import { tuningFiles } from './tuning-loader.ts';
@@ -48,6 +49,10 @@ export function readGroundAiTuning(reader: TuningReader): GroundAiTuning {
navEngine: readNavEngineSection(reader.object('navEngine')),
navCostsTracked: readNavCosts(reader.object('navCostsTracked')),
navCostsWheeled: readNavCosts(reader.object('navCostsWheeled')),
pathFollow: readPathFollowSection(reader.object('pathFollow')),
navBake: {
crushableMaxRiExtraHp: reader.object('navBake').number('crushableMaxRiExtraHp', { min: 0, max: 1000 }),
},
perception: readPerceptionSection(reader.object('perception')),
stateMachine: readStateMachineSection(reader.object('stateMachine')),
tactics: readTacticsSection(reader.object('tactics')),
@@ -182,6 +187,8 @@ function readNavEngineSection(engine: TuningReader): GroundAiTuning['navEngine']
enabled: engine.bool('enabled'),
allowFallback: engine.bool('allowFallback'),
snapRadiusM: engine.number('snapRadiusM', { min: 2, max: 40 }),
goalSnapRadiusM: engine.number('goalSnapRadiusM', { min: 5, max: 150 }),
pathBudgetMsPerFrame: engine.number('pathBudgetMsPerFrame', { min: 0.05, max: 5 }),
};
}
@@ -199,6 +206,54 @@ function readNavCosts(costs: TuningReader): GroundAiNavCosts {
};
}
function readPathFollowSection(pf: TuningReader): GroundAiPathFollow {
const n = (key: keyof GroundAiPathFollow, min: number, max: number) => pf.number(key, { min, max });
const lookahead = {
trackedLookaheadMinM: n('trackedLookaheadMinM', 2, 40),
trackedLookaheadMaxM: n('trackedLookaheadMaxM', 4, 60),
wheeledLookaheadMinM: n('wheeledLookaheadMinM', 2, 40),
wheeledLookaheadMaxM: n('wheeledLookaheadMaxM', 4, 60),
};
if (lookahead.trackedLookaheadMaxM < lookahead.trackedLookaheadMinM || lookahead.wheeledLookaheadMaxM < lookahead.wheeledLookaheadMinM) {
throw new TuningError('tuning file ground-ai.jsonc: pathFollow lookahead maximum must not be below its minimum');
}
return {
replanIntervalSec: n('replanIntervalSec', 1, 15),
replanGoalMoveM: n('replanGoalMoveM', 3, 80),
offCorridorReplanM: n('offCorridorReplanM', 3, 60),
lookaheadTimeSec: n('lookaheadTimeSec', 0.3, 5),
...lookahead,
cornerAngleDeg: n('cornerAngleDeg', 10, 120),
cornerLateralAccelMps2: n('cornerLateralAccelMps2', 0.5, 10),
cornerBrakeDecelMps2: n('cornerBrakeDecelMps2', 0.5, 10),
arriveRadiusM: n('arriveRadiusM', 1, 20),
arriveMinSpeedMps: n('arriveMinSpeedMps', 0.3, 6),
narrowWallMarginM: n('narrowWallMarginM', 0.2, 6),
narrowSpeedMps: n('narrowSpeedMps', 1, 15),
bumperRayM: n('bumperRayM', 2, 20),
bumperStopM: n('bumperStopM', 0.3, 6),
bumperBlockSec: n('bumperBlockSec', 0.2, 5),
trafficTtcSec: n('trafficTtcSec', 0.5, 8),
avoidShiftM: n('avoidShiftM', 0.5, 10),
yieldWaitMaxSec: n('yieldWaitMaxSec', 0.5, 15),
stuckWindowSec: n('stuckWindowSec', 1, 15),
stuckMinProgressM: n('stuckMinProgressM', 0.2, 10),
unstickReverseM: n('unstickReverseM', 2, 25),
unstickReverseSec: n('unstickReverseSec', 0.8, 10),
unstickRepeatSec: n('unstickRepeatSec', 2, 60),
unstickMaxAttempts: pf.int('unstickMaxAttempts', { min: 1, max: 10 }),
jamRadiusM: n('jamRadiusM', 2, 50),
jamCostMul: n('jamCostMul', 1, 50),
jamTtlSec: n('jamTtlSec', 5, 600),
rubbleRadiusM: n('rubbleRadiusM', 1, 40),
rubbleCostMul: n('rubbleCostMul', 1, 50),
rubbleTtlSec: n('rubbleTtlSec', 5, 600),
wreckRadiusM: n('wreckRadiusM', 1, 40),
wreckCostMul: n('wreckCostMul', 1, 50),
wreckTtlSec: n('wreckTtlSec', 5, 600),
};
}
function readNavigationSection(nav: TuningReader): GroundAiTuning['navigation'] {
const driveModeRaw = nav.string('driveMode');
const driveMode = GROUND_AI_DRIVE_MODES.find((candidate): candidate is GroundAiDriveMode => candidate === driveModeRaw);
@@ -215,12 +270,8 @@ function readNavigationSection(nav: TuningReader): GroundAiTuning['navigation']
steerSign,
deadEchoSec: nav.number('deadEchoSec', { min: 0.3, max: 10 }),
controlTimeoutSec: nav.number('controlTimeoutSec', { min: 0.3, max: 10 }),
cornerBrakeAccel: nav.number('cornerBrakeAccel', { min: 0.5, max: 8 }),
movingFireSpeedRampMps: nav.number('movingFireSpeedRampMps', { min: 0.2, max: 5 }),
pivotAngleDeg: nav.number('pivotAngleDeg', { min: 25, max: 150 }),
stuckWindowSec: nav.number('stuckWindowSec', { min: 1, max: 15 }),
stuckMinMoveM: nav.number('stuckMinMoveM', { min: 0.5, max: 10 }),
unstickReverseSec: nav.number('unstickReverseSec', { min: 0.8, max: 10 }),
tacticalReverseDistM: nav.number('tacticalReverseDistM', { min: 10, max: 90 }),
tacticalReverseMaxSec: nav.number('tacticalReverseMaxSec', { min: 2, max: 25 }),
};
+57 -5
View File
@@ -123,13 +123,9 @@
"steerSign": 1.0,
"deadEchoSec": 1.2,
"controlTimeoutSec": 1.0,
"cornerBrakeAccel": 1.75,
// Speed error at which the moving-fire controller applies full throttle or braking.
"movingFireSpeedRampMps": 1.0,
"pivotAngleDeg": 75.0,
"stuckWindowSec": 3.6,
"stuckMinMoveM": 2.0,
"unstickReverseSec": 3.0,
"tacticalReverseDistM": 34.0,
"tacticalReverseMaxSec": 9.5
},
@@ -142,7 +138,13 @@
// battle start, never in the middle of a battle.
"allowFallback": true,
// Farthest a path's start or goal may lie from the mesh.
"snapRadiusM": 12.0
"snapRadiusM": 12.0,
// A goal farther than snapRadiusM from the mesh (a position chosen by tactics inside a building
// or on a slope) is moved to the nearest walkable point within this distance; beyond it the
// goal counts as unreachable. Also used to find the way back onto the mesh.
"goalSnapRadiusM": 40.0,
// Path searches are spread over frames; this is the search time allowed per frame.
"pathBudgetMsPerFrame": 0.5
},
// Path cost multipliers per surface for tracked vehicles; chokepoint multiplies the surface cost
@@ -170,6 +172,56 @@
"chokepoint": 2.2
},
// Following the path, local avoidance and unstick (offline values).
"pathFollow": {
// Plan again after this long, when the goal moved this far, or when the bot is this far off its path.
"replanIntervalSec": 3.5,
"replanGoalMoveM": 15.0,
"offCorridorReplanM": 12.0,
// Steering point: speed times lookaheadTimeSec, kept within the range of the vehicle kind.
"lookaheadTimeSec": 1.4,
"trackedLookaheadMinM": 6.0,
"trackedLookaheadMaxM": 18.0,
"wheeledLookaheadMinM": 10.0,
"wheeledLookaheadMaxM": 24.0,
// Path corners sharper than cornerAngleDeg are taken at the speed the sideways acceleration
// allows; the vehicle brakes toward it (and toward its destination) at cornerBrakeDecelMps2.
"cornerAngleDeg": 35.0,
"cornerLateralAccelMps2": 2.8,
"cornerBrakeDecelMps2": 2.0,
"arriveRadiusM": 3.0,
"arriveMinSpeedMps": 1.5,
// The mesh already keeps the vehicle's half width from walls; less room than this beyond it,
// or a baked chokepoint, counts as a narrow passage.
"narrowWallMarginM": 1.5,
"narrowSpeedMps": 4.5,
// Rays from both front corners of the hull for obstacles the baked mesh does not know.
"bumperRayM": 7.0,
"bumperStopM": 1.5,
"bumperBlockSec": 0.6,
// Vehicles and wrecks that come within reach in trafficTtcSec: follow, step aside, or give way.
"trafficTtcSec": 2.5,
"avoidShiftM": 3.0,
"yieldWaitMaxSec": 3.0,
// Less progress than stuckMinProgressM within stuckWindowSec while wanting to move is stuck.
"stuckWindowSec": 3.0,
"stuckMinProgressM": 0.8,
"unstickReverseM": 6.5,
"unstickReverseSec": 3.0,
"unstickRepeatSec": 8.0,
"unstickMaxAttempts": 3,
// Temporary path costs: jams found by unstick, fresh obstacles hit by the front rays, wrecks.
"jamRadiusM": 10.0,
"jamCostMul": 4.0,
"jamTtlSec": 45.0,
"rubbleRadiusM": 6.0,
"rubbleCostMul": 8.0,
"rubbleTtlSec": 90.0,
"wreckRadiusM": 6.0,
"wreckCostMul": 6.0,
"wreckTtlSec": 120.0
},
// Exposure-based visual perception (offline values; foliageTransparency matches stock infantry AI).
"perception": {
"foliageTransparency": 0.01,