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 }),
};