fix(ground-ai): improve firing on the move
Share a distance-based speed cap between tactics and the fire gate. Brake toward it and try a short halt when speed or aim keeps blocking a ready shot. Measure tracking drift relative to the aim direction and use the close-range alignment window for quick shots. Expose the controls in the launcher and record measured and permitted speeds in diagnostics. Verified both TypeScript typechecks, 2.61.0.58 and 2.61.0.60 patch checks and builds, and daScript loading in the guarded 2.61.0.58 client.
This commit is contained in:
1 parent
0167c3ea7d
commit
688406bb76
17 files changed
+218
-114
No files matched your search
@@ -590,6 +590,7 @@
|
||||
},
|
||||
"stateMachine": {
|
||||
"preaimAngleDeg": "Moving pre-aim angle threshold",
|
||||
"movingShotWaitSec": "Time to attempt a moving shot before halting",
|
||||
"shortHaltMaxSec": "Short halt max duration",
|
||||
"shortHaltCooldownSec": "Short halt cooldown",
|
||||
"turnLaunchSpeedMps": "Turn launch target speed",
|
||||
@@ -645,11 +646,13 @@
|
||||
"longRangeM": "Long range band threshold",
|
||||
"midSlowSpeedRatio": "Mid-range fire-on-move speed ratio",
|
||||
"midSlowMaxMps": "Mid-range fire-on-move speed cap",
|
||||
"closeRangeMaxSpeedKmh": "Moving-fire speed cap at the close-range boundary",
|
||||
"pointBlankMaxSpeedKmh": "Moving-fire speed cap at point blank",
|
||||
"stopSpeedMaxMps": "Stopped speed threshold",
|
||||
"longRangeWindowSec": "Long-range clear LOS window",
|
||||
"baseAlignDeg": "Base gun alignment tolerance",
|
||||
"closeHitRadiusM": "Close-range hit acceptance radius",
|
||||
"barrelSettleDegSec": "Max barrel angular rate to settle",
|
||||
"barrelSettleDegSec": "Max aim error drift outside close range",
|
||||
"closeSettleHoldSec": "Close-range settle hold time",
|
||||
"settleHoldSec": "Standard settle hold time",
|
||||
"unstabilizedStopSpeedMps": "Unstabilized stop speed cap",
|
||||
@@ -666,6 +669,7 @@
|
||||
"deadEchoSec": "Dead-echo detection timeout",
|
||||
"controlTimeoutSec": "Native control release timeout",
|
||||
"cornerBrakeAccel": "Corner braking deceleration",
|
||||
"movingFireSpeedRampMps": "Speed error for full throttle or braking while firing on the move",
|
||||
"pivotAngleDeg": "Neutral pivot turn angle threshold",
|
||||
"stuckWindowSec": "Stuck detection window",
|
||||
"stuckMinMoveM": "Stuck min movement distance",
|
||||
|
||||
@@ -590,6 +590,7 @@
|
||||
},
|
||||
"stateMachine": {
|
||||
"preaimAngleDeg": "行进预瞄角度阈值",
|
||||
"movingShotWaitSec": "转入短停前尝试行进射击的时间",
|
||||
"shortHaltMaxSec": "单次短停最长时间",
|
||||
"shortHaltCooldownSec": "短停冷却时间",
|
||||
"turnLaunchSpeedMps": "甩弯起步目标车速",
|
||||
@@ -645,11 +646,13 @@
|
||||
"longRangeM": "远距交战分界距离",
|
||||
"midSlowSpeedRatio": "中距行进射击最高车速比",
|
||||
"midSlowMaxMps": "中距行进射击最高车速",
|
||||
"closeRangeMaxSpeedKmh": "近距分界处行进射击最高车速",
|
||||
"pointBlankMaxSpeedKmh": "贴身时行进射击最高车速",
|
||||
"stopSpeedMaxMps": "停稳判定最高车速",
|
||||
"longRangeWindowSec": "远距连续射界观察窗",
|
||||
"baseAlignDeg": "主炮对准允许角误差",
|
||||
"closeHitRadiusM": "近距命中判定半径",
|
||||
"barrelSettleDegSec": "炮管稳定最大角速度",
|
||||
"barrelSettleDegSec": "近距以外瞄准误差最大变化速度",
|
||||
"closeSettleHoldSec": "近距稳定保持时间",
|
||||
"settleHoldSec": "常规稳定保持时间",
|
||||
"unstabilizedStopSpeedMps": "无稳定器停稳车速上限",
|
||||
@@ -666,6 +669,7 @@
|
||||
"deadEchoSec": "无响应回声判定时长",
|
||||
"controlTimeoutSec": "原生控制超时归还时长",
|
||||
"cornerBrakeAccel": "弯道减速制动强度",
|
||||
"movingFireSpeedRampMps": "行进射击时全油门或全制动对应的速度差",
|
||||
"pivotAngleDeg": "原地中性转向角度阈值",
|
||||
"stuckWindowSec": "卡死检测窗口时长",
|
||||
"stuckMinMoveM": "卡死判定最小位移",
|
||||
|
||||
@@ -54,7 +54,7 @@ function hasValidCrossFieldRules(effective: GroundAiTuningValues, patch: TuningP
|
||||
if (est.watchMaxSec < est.watchMinSec || est.velStableSpanSec <= est.velSampleMinSpanSec) return false;
|
||||
const fc = mergeSection(effective.fireControl, patch.fireControl);
|
||||
if (fc.midRangeM <= fc.closeRangeM || fc.longRangeM <= fc.midRangeM) return false;
|
||||
return true;
|
||||
return fc.pointBlankMaxSpeedKmh >= fc.closeRangeMaxSpeedKmh;
|
||||
}
|
||||
|
||||
export function BotTuningPanel({ data, saving, onSave }: Props) {
|
||||
|
||||
@@ -156,6 +156,7 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [
|
||||
customOnly: true,
|
||||
fields: [
|
||||
num('stateMachine', 'preaimAngleDeg', 1, 30, '°'),
|
||||
num('stateMachine', 'movingShotWaitSec', 0.25, 5, 's'),
|
||||
num('stateMachine', 'shortHaltMaxSec', 0.5, 12, 's'),
|
||||
num('stateMachine', 'shortHaltCooldownSec', 0.5, 20, 's'),
|
||||
num('stateMachine', 'turnLaunchSpeedMps', 0.5, 6, 'm/s'),
|
||||
@@ -231,6 +232,8 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [
|
||||
num('fireControl', 'longRangeM', 300, 1500, 'm'),
|
||||
num('fireControl', 'midSlowSpeedRatio', 0.1, 1),
|
||||
num('fireControl', 'midSlowMaxMps', 1, 15, 'm/s'),
|
||||
num('fireControl', 'closeRangeMaxSpeedKmh', 3.6, 100, 'km/h'),
|
||||
num('fireControl', 'pointBlankMaxSpeedKmh', 3.6, 100, 'km/h'),
|
||||
num('fireControl', 'stopSpeedMaxMps', 0.1, 2, 'm/s'),
|
||||
num('fireControl', 'longRangeWindowSec', 1, 15, 's'),
|
||||
num('fireControl', 'baseAlignDeg', 0.1, 3, '°'),
|
||||
@@ -257,6 +260,7 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [
|
||||
num('navigation', 'deadEchoSec', 0.3, 10, 's'),
|
||||
num('navigation', 'controlTimeoutSec', 0.3, 10, 's'),
|
||||
num('navigation', 'cornerBrakeAccel', 0.5, 8),
|
||||
num('navigation', 'movingFireSpeedRampMps', 0.2, 5, 'm/s'),
|
||||
num('navigation', 'pivotAngleDeg', 25, 150, '°'),
|
||||
num('navigation', 'stuckWindowSec', 1, 15, 's'),
|
||||
num('navigation', 'stuckMinMoveM', 0.5, 10, 'm'),
|
||||
|
||||
@@ -91,6 +91,7 @@ const GroundAiNavigationSchema = z.object({
|
||||
deadEchoSec: z.number().min(0.3).max(10),
|
||||
controlTimeoutSec: z.number().min(0.3).max(10),
|
||||
cornerBrakeAccel: z.number().min(0.5).max(8),
|
||||
movingFireSpeedRampMps: z.number().min(0.2).max(5),
|
||||
pivotAngleDeg: z.number().min(25).max(150),
|
||||
stuckWindowSec: z.number().min(1).max(15),
|
||||
stuckMinMoveM: z.number().min(0.5).max(10),
|
||||
@@ -113,6 +114,7 @@ const GroundAiPerceptionSchema = z.object({
|
||||
|
||||
const GroundAiStateMachineSchema = z.object({
|
||||
preaimAngleDeg: z.number().min(1).max(30),
|
||||
movingShotWaitSec: z.number().min(0.25).max(5),
|
||||
shortHaltMaxSec: z.number().min(0.5).max(12),
|
||||
shortHaltCooldownSec: z.number().min(0.5).max(20),
|
||||
turnLaunchSpeedMps: z.number().min(0.5).max(6),
|
||||
@@ -160,6 +162,8 @@ const GroundAiFireControlSchema = z.object({
|
||||
longRangeM: z.number().min(300).max(1500),
|
||||
midSlowSpeedRatio: z.number().min(0.1).max(1),
|
||||
midSlowMaxMps: z.number().min(1).max(15),
|
||||
closeRangeMaxSpeedKmh: z.number().min(3.6).max(100),
|
||||
pointBlankMaxSpeedKmh: z.number().min(3.6).max(100),
|
||||
stopSpeedMaxMps: z.number().min(0.1).max(2),
|
||||
longRangeWindowSec: z.number().min(1).max(15),
|
||||
baseAlignDeg: z.number().min(0.1).max(3),
|
||||
|
||||
@@ -190,6 +190,7 @@ function readNavigationSection(nav: TuningReader): GroundAiTuning['navigation']
|
||||
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 }),
|
||||
@@ -221,6 +222,7 @@ function readStateMachineSection(sm: TuningReader): GroundAiTuning['stateMachine
|
||||
}
|
||||
return {
|
||||
preaimAngleDeg: sm.number('preaimAngleDeg', { min: 1.0, max: 30.0 }),
|
||||
movingShotWaitSec: sm.number('movingShotWaitSec', { min: 0.25, max: 5.0 }),
|
||||
shortHaltMaxSec: sm.number('shortHaltMaxSec', { min: 0.5, max: 12.0 }),
|
||||
shortHaltCooldownSec: sm.number('shortHaltCooldownSec', { min: 0.5, max: 20.0 }),
|
||||
turnLaunchSpeedMps: sm.number('turnLaunchSpeedMps', { min: 0.5, max: 6.0 }),
|
||||
@@ -283,6 +285,11 @@ function readFireControlSection(fc: TuningReader): GroundAiTuning['fireControl']
|
||||
if (midRangeM <= closeRangeM || longRangeM <= midRangeM) {
|
||||
throw new TuningError('tuning file ground-ai.jsonc: fireControl ranges must satisfy closeRangeM < midRangeM < longRangeM');
|
||||
}
|
||||
const closeRangeMaxSpeedKmh = fc.number('closeRangeMaxSpeedKmh', { min: 3.6, max: 100 });
|
||||
const pointBlankMaxSpeedKmh = fc.number('pointBlankMaxSpeedKmh', { min: 3.6, max: 100 });
|
||||
if (pointBlankMaxSpeedKmh < closeRangeMaxSpeedKmh) {
|
||||
throw new TuningError('tuning file ground-ai.jsonc: fireControl.pointBlankMaxSpeedKmh must be >= closeRangeMaxSpeedKmh');
|
||||
}
|
||||
return {
|
||||
maxEngageRangeM: fc.number('maxEngageRangeM', { min: 150, max: 3000 }),
|
||||
closeRangeM,
|
||||
@@ -290,6 +297,8 @@ function readFireControlSection(fc: TuningReader): GroundAiTuning['fireControl']
|
||||
longRangeM,
|
||||
midSlowSpeedRatio: fc.number('midSlowSpeedRatio', { min: 0.1, max: 1.0 }),
|
||||
midSlowMaxMps: fc.number('midSlowMaxMps', { min: 1.0, max: 15.0 }),
|
||||
closeRangeMaxSpeedKmh,
|
||||
pointBlankMaxSpeedKmh,
|
||||
stopSpeedMaxMps: fc.number('stopSpeedMaxMps', { min: 0.1, max: 2.0 }),
|
||||
longRangeWindowSec: fc.number('longRangeWindowSec', { min: 1.0, max: 15.0 }),
|
||||
baseAlignDeg: fc.number('baseAlignDeg', { min: 0.1, max: 3.0 }),
|
||||
|
||||
@@ -102,6 +102,8 @@
|
||||
"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,
|
||||
@@ -126,6 +128,8 @@
|
||||
// Per-bot hull state machine timings and thresholds (offline values).
|
||||
"stateMachine": {
|
||||
"preaimAngleDeg": 8.0,
|
||||
// Time a ready gun can be held up by speed or aim before attempting a short halt.
|
||||
"movingShotWaitSec": 1.0,
|
||||
"shortHaltMaxSec": 3.0,
|
||||
"shortHaltCooldownSec": 4.0,
|
||||
"turnLaunchSpeedMps": 2.1,
|
||||
@@ -174,10 +178,14 @@
|
||||
"longRangeM": 800.0,
|
||||
"midSlowSpeedRatio": 0.45,
|
||||
"midSlowMaxMps": 5.5,
|
||||
// Moving-fire speed rises from the mid-range limit through the close-range boundary to point blank.
|
||||
"closeRangeMaxSpeedKmh": 30.0,
|
||||
"pointBlankMaxSpeedKmh": 35.0,
|
||||
"stopSpeedMaxMps": 0.45,
|
||||
"longRangeWindowSec": 4.0,
|
||||
"baseAlignDeg": 0.42,
|
||||
"closeHitRadiusM": 0.85,
|
||||
// Outside close range, the rate at which barrel alignment drifts relative to the aim direction.
|
||||
"barrelSettleDegSec": 1.8,
|
||||
"closeSettleHoldSec": 0.08,
|
||||
"settleHoldSec": 0.20,
|
||||
|
||||
@@ -95,9 +95,10 @@ struct public WtoFireState
|
||||
curPitchDeg : float = 0.0
|
||||
prevPitchDeg : float = 0.0
|
||||
servoInit : bool = false
|
||||
prevBarrelDir : float3 = float3(1.0, 0.0, 0.0)
|
||||
prevBarrelAt : float = -100.0
|
||||
barrelOmegaDegSec : float = 0.0
|
||||
aimTargetEid : EntityId = INVALID_ENTITY_ID
|
||||
prevAimOffset : float3 = float3(0.0, 0.0, 0.0)
|
||||
prevAimAt : float = -100.0
|
||||
aimDriftDegSec : float = 0.0
|
||||
settleHoldSec : float = 0.0
|
||||
lastAligned : bool = false
|
||||
lastAimErrDeg : float = 0.0
|
||||
|
||||
@@ -16,7 +16,7 @@ def private wto_log_bot_and_cap_samples(world : WtoWorldSnap const&; bots : WtoB
|
||||
if !bots[i].used || sampled >= 2
|
||||
continue
|
||||
assume b = bots[i]
|
||||
print("WTO_AI|BOT_SAMPLE|eid={uint(b.eid)}|role={b.spec.role}|stab={b.spec.hasVertStab}|v0={b.fire.activeSpeedMps}|st={b.tactics.state}|allyD={b.crowd.nearestAllyDistM}|clust={b.crowd.clusterAllyCount}|ridge={b.tactics.onExposedRidge}|los={b.perceive.hasClearLos}|fc={b.fire.gunReady}/{b.fire.reloading}/{b.fire.lastAligned}|err={b.fire.lastAimErrDeg}|omB={b.fire.barrelOmegaDegSec}|mode={b.driveCmd.mode}|v={b.drive.lastVFwd}|clr={b.nav.frontClearM}/{b.nav.rearClearM}|wp={b.route.corridorIdx}/{b.route.corridorLen}|proj={b.route.lastStartOk}/{b.route.lastGoalOk}\n")
|
||||
print("WTO_AI|BOT_SAMPLE|eid={uint(b.eid)}|role={b.spec.role}|stab={b.spec.hasVertStab}|v0={b.fire.activeSpeedMps}|st={b.tactics.state}|allyD={b.crowd.nearestAllyDistM}|clust={b.crowd.clusterAllyCount}|ridge={b.tactics.onExposedRidge}|los={b.perceive.hasClearLos}|fc={b.fire.gunReady}/{b.fire.reloading}/{b.fire.lastAligned}|err={b.fire.lastAimErrDeg}|drift={b.fire.aimDriftDegSec}|mode={b.driveCmd.mode}|v={b.drive.lastVFwd}|clr={b.nav.frontClearM}/{b.nav.rearClearM}|wp={b.route.corridorIdx}/{b.route.corridorLen}|proj={b.route.lastStartOk}/{b.route.lastGoalOk}\n")
|
||||
sampled++
|
||||
for c in range(world.capCount)
|
||||
assume z = world.caps[c]
|
||||
|
||||
@@ -121,7 +121,7 @@ def private wto_compute_reverse_axes(cmd : WtoDriveCmd const&; spec : WtoVehicle
|
||||
|
||||
[never_inline]
|
||||
def private wto_compute_cruise_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleSpec const&;
|
||||
fwd, left : float3; vFwd, omega : float;
|
||||
fwd, left : float3; speedMps, omega : float; firingOnMove : bool;
|
||||
var outThr, outStr, outBrk : float&)
|
||||
let wish = wto_xz_normalize(cmd.desiredDir, fwd)
|
||||
let yawErr = atan2(dot(wish, left), dot(wish, fwd))
|
||||
@@ -133,7 +133,12 @@ def private wto_compute_cruise_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleS
|
||||
vLimit = min(vLimit, sqrt(WTO_AI_NAV_CORNER_BRAKE_ACCEL * radiusEst))
|
||||
if cmd.frontClearM < 12.0
|
||||
vLimit = min(vLimit, max(2.2, (cmd.frontClearM - 2.0) * 0.75))
|
||||
let vErr = vLimit - vFwd
|
||||
let vErr = vLimit - speedMps
|
||||
if firingOnMove
|
||||
let response = vErr / WTO_AI_NAV_MOVING_FIRE_SPEED_RAMP_MPS
|
||||
outThr = clamp(response, 0.0, 1.0)
|
||||
outBrk = clamp(-response, 0.0, 1.0)
|
||||
return
|
||||
if vErr < -1.5
|
||||
outThr = 0.0
|
||||
outBrk = clamp((-vErr - 1.2) * 0.35, 0.2, 1.0)
|
||||
@@ -176,6 +181,32 @@ def private wto_ensure_phys_owner(gm : IGroundModel const?; var actor : VehicleP
|
||||
st.routeBOwned = true
|
||||
return st.routeBOwned
|
||||
|
||||
[never_inline]
|
||||
def private wto_apply_drive_cmd(var actor : VehiclePhysActor&; fwd, left, velocity : float3;
|
||||
var slot : WtoBotSlot&)
|
||||
assume st = slot.drive
|
||||
assume cmd = slot.driveCmd
|
||||
let vFwd = st.lastVFwd
|
||||
var thr = 0.0
|
||||
var str = 0.0
|
||||
var brk = 0.0
|
||||
var hand = 0.0
|
||||
if cmd.mode == WTO_DRIVE_HALT || cmd.speedMps <= 0.05
|
||||
thr = abs(vFwd) > 0.35 ? (vFwd > 0.0 ? -1.0 : 1.0) : 0.0
|
||||
brk = 1.0
|
||||
hand = abs(vFwd) > 0.35 ? 0.0 : 1.0
|
||||
elif cmd.mode == WTO_DRIVE_PIVOT
|
||||
wto_compute_pivot_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk)
|
||||
elif cmd.mode == WTO_DRIVE_REVERSE
|
||||
wto_compute_reverse_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk, hand)
|
||||
else
|
||||
let firingOnMove = slot.tactics.state == WTO_STATE_RUN_AND_GUN
|
||||
let speed = firingOnMove ? length(velocity) : vFwd
|
||||
wto_compute_cruise_axes(cmd, slot.spec, fwd, left, speed, st.omegaYawRad, firingOnMove, thr, str, brk)
|
||||
st.prevThr = thr
|
||||
st.prevStr = str
|
||||
wto_set_phys_axes(actor, thr, str, brk, hand)
|
||||
|
||||
[never_inline]
|
||||
def public wto_drive_step_phys(var unit : Unit?; unitMissionName : string;
|
||||
gm : IGroundModel const?; var actor : VehiclePhysActor&;
|
||||
@@ -204,31 +235,12 @@ def public wto_drive_step_phys(var unit : Unit?; unitMissionName : string;
|
||||
slot.drive.failLogged = false
|
||||
vehicle_actor_set_allow_move_control(actor, true)
|
||||
assume st = slot.drive
|
||||
assume cmd = slot.driveCmd
|
||||
let fwd = wto_xz_normalize(unit.unitTm[0], float3(1.0, 0.0, 0.0))
|
||||
let left = float3(-fwd.z, 0.0, fwd.x)
|
||||
let curYaw = atan2(fwd.z, fwd.x)
|
||||
let vFwd = dot(vehicle_phys_getCurrentStateVelocity(actor.phys), fwd)
|
||||
st.lastVFwd = vFwd
|
||||
st.lastVFwd = dot(vehicle_phys_getCurrentStateVelocity(actor.phys), fwd)
|
||||
let age = now - st.prevYawAt
|
||||
st.omegaYawRad = (age > 1.0e-4 && age <= 0.25) ? lerp(clamp(wto_wrap_rad(curYaw - st.prevYaw) / age, -3.0, 3.0), st.omegaYawRad, 0.6) : 0.0
|
||||
st.prevYaw = curYaw
|
||||
st.prevYawAt = now
|
||||
|
||||
var thr = 0.0
|
||||
var str = 0.0
|
||||
var brk = 0.0
|
||||
var hand = 0.0
|
||||
if !cmd.valid || cmd.mode == WTO_DRIVE_HALT || cmd.speedMps <= 0.05
|
||||
thr = abs(vFwd) > 0.35 ? (vFwd > 0.0 ? -1.0 : 1.0) : 0.0
|
||||
brk = 1.0
|
||||
hand = abs(vFwd) > 0.35 ? 0.0 : 1.0
|
||||
elif cmd.mode == WTO_DRIVE_PIVOT
|
||||
wto_compute_pivot_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk)
|
||||
elif cmd.mode == WTO_DRIVE_REVERSE
|
||||
wto_compute_reverse_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk, hand)
|
||||
else
|
||||
wto_compute_cruise_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk)
|
||||
st.prevThr = thr
|
||||
st.prevStr = str
|
||||
wto_set_phys_axes(actor, thr, str, brk, hand)
|
||||
wto_apply_drive_cmd(actor, fwd, left, unit.vel, slot)
|
||||
@@ -197,7 +197,7 @@ def private wto_sample_turret_muzzle(unit : Unit const?; turretNo : int;
|
||||
return false
|
||||
|
||||
[never_inline]
|
||||
def private wto_drive_turret_and_sample_barrel(var unit : Unit?; dt, now : float;
|
||||
def private wto_drive_turret_and_sample_barrel(var unit : Unit?; dt : float;
|
||||
wishYawDeg, wishPitchDeg : float;
|
||||
var slot : WtoBotSlot&;
|
||||
var outMuzzlePos, outLiveDir : float3&)
|
||||
@@ -235,14 +235,13 @@ def private wto_drive_turret_and_sample_barrel(var unit : Unit?; dt, now : float
|
||||
updateWeaponAnims(*unit.weap, dtStep, 1.0, uPos)
|
||||
if !wto_sample_turret_muzzle(unit, fc.turretNo, outMuzzlePos, outLiveDir)
|
||||
outLiveDir = wto_hull_deg_to_world(fc.curYawDeg, fc.curPitchDeg, unit.unitTm[0], unit.unitTm[1], unit.unitTm[2])
|
||||
let bAge = now - fc.prevBarrelAt
|
||||
if bAge > 1.0e-4 && bAge <= 0.25
|
||||
let stepDeg = acos(clamp(dot(outLiveDir, fc.prevBarrelDir), -1.0, 1.0)) * WTO_RAD_TO_DEG
|
||||
fc.barrelOmegaDegSec = lerp(stepDeg / bAge, fc.barrelOmegaDegSec, 0.45)
|
||||
else
|
||||
fc.barrelOmegaDegSec = 0.0
|
||||
fc.prevBarrelDir = outLiveDir
|
||||
fc.prevBarrelAt = now
|
||||
|
||||
def private wto_clear_aim_tracking(var fc : WtoFireState&)
|
||||
fc.aimTargetEid = INVALID_ENTITY_ID
|
||||
fc.aimDriftDegSec = 0.0
|
||||
fc.settleHoldSec = 0.0
|
||||
fc.lastAligned = false
|
||||
fc.lastDenyReason = WTO_DENY_NO_TARGET
|
||||
|
||||
[never_inline]
|
||||
def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?;
|
||||
@@ -251,6 +250,7 @@ def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?;
|
||||
return
|
||||
// SPAA vs aircraft only delegates to stock air-target fire control (never ground targets).
|
||||
if slot.tactics.spaaYieldAir
|
||||
wto_clear_aim_tracking(slot.fire)
|
||||
var gm = as_gm(unit)
|
||||
if gm != null
|
||||
*gm |> set_check_visibility_target(true)
|
||||
@@ -287,10 +287,9 @@ def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?;
|
||||
var wishYaw = 0.0
|
||||
var wishPitch = 0.0
|
||||
wto_world_to_hull_deg(wishWorldDir, hFwd, unit.unitTm[1], unit.unitTm[2], wishYaw, wishPitch)
|
||||
wto_drive_turret_and_sample_barrel(unit, dt, now, wishYaw, wishPitch, slot, muzzlePos, liveBarrelDir)
|
||||
wto_drive_turret_and_sample_barrel(unit, dt, wishYaw, wishPitch, slot, muzzlePos, liveBarrelDir)
|
||||
if !engageValid || distToTgt > WTO_AI_FC_MAX_RANGE_M
|
||||
slot.fire.settleHoldSec = 0.0
|
||||
slot.fire.lastAligned = false
|
||||
wto_clear_aim_tracking(slot.fire)
|
||||
return
|
||||
let distXZ = sqrt(wto_xz_dist_sq(unit.pos, slot.perceive.knownPos))
|
||||
wto_fire_gate_try_shoot(world, unit, now, dt, distXZ, muzzlePos, aimPt, liveBarrelDir, wishWorldDir, slot, fireBudget)
|
||||
wto_fire_gate_try_shoot(world, unit, now, distXZ, muzzlePos, aimPt, liveBarrelDir, wishWorldDir, slot, fireBudget)
|
||||
@@ -16,6 +16,7 @@ require %game.utils.utils_common
|
||||
require %appGame.wtoai.wto_ai_config_common
|
||||
require %appGame.wtoai.wto_ai_math_common
|
||||
require %appGame.wtoai.wto_ai_combat_types_common
|
||||
require %appGame.wtoai.wto_ai_fire_speed_common
|
||||
require %appGame.wtoai.wto_ai_types_common
|
||||
require %appGame.wtoai.wto_ai_sight_common
|
||||
|
||||
@@ -126,74 +127,89 @@ def private wto_gate_check_all_primary_guns(world : WtoWorldSnap const&; unit :
|
||||
return WTO_DENY_OK
|
||||
|
||||
[never_inline]
|
||||
def private wto_gate_speed_allowed(distXZ, measuredSpeed : float; spec : WtoVehicleSpec const&) : bool
|
||||
if distXZ > WTO_AI_FC_MID_RANGE_M
|
||||
return measuredSpeed <= WTO_AI_FC_STOP_SPEED_MAX_MPS
|
||||
if distXZ > WTO_AI_FC_CLOSE_RANGE_M
|
||||
let slowCap = min(spec.vMaxFwd * WTO_AI_FC_MID_SLOW_RATIO, WTO_AI_FC_MID_SLOW_MAX_MPS)
|
||||
return measuredSpeed <= slowCap
|
||||
return true
|
||||
def private wto_gate_track_aim(now : float; offset : float3; target : EntityId;
|
||||
aligned, close : bool; var fc : WtoFireState&)
|
||||
let age = now - fc.prevAimAt
|
||||
let sameTrack = target == fc.aimTargetEid && age >= 0.0 && age <= WTO_AI_TACTICS_TICK_SEC
|
||||
if !sameTrack || age > 0.0
|
||||
// Compare offsets so steady tracking can pass while the turret is turning.
|
||||
fc.aimDriftDegSec = sameTrack && age > 0.0 ? length(offset - fc.prevAimOffset) * WTO_RAD_TO_DEG / age : 0.0
|
||||
fc.prevAimOffset = offset
|
||||
fc.prevAimAt = now
|
||||
fc.aimTargetEid = target
|
||||
let settled = sameTrack && aligned && (close || fc.aimDriftDegSec <= WTO_AI_FC_BARREL_SETTLE_DEG_SEC)
|
||||
fc.lastAligned = settled
|
||||
if !sameTrack
|
||||
fc.settleHoldSec = 0.0
|
||||
elif settled
|
||||
fc.settleHoldSec += age
|
||||
else
|
||||
fc.settleHoldSec = max(0.0, fc.settleHoldSec - age)
|
||||
|
||||
[never_inline]
|
||||
def private wto_gate_log_deny(now, distXZ, measuredSpeed : float; reason, blk : int; var slot : WtoBotSlot&)
|
||||
def private wto_gate_log_deny(now, distXZ, measuredSpeed, speedLimit : float; reason, blk : int; var slot : WtoBotSlot&)
|
||||
assume fc = slot.fire
|
||||
let changed = fc.lastDenyReason != reason || fc.lastDenyBlock != blk
|
||||
fc.lastDenyReason = reason
|
||||
fc.lastDenyBlock = blk
|
||||
if WTO_AI_DIAG_TELEMETRY && reason >= WTO_DENY_SPEED && (changed || (now - fc.lastDenyLogAt) >= 4.0)
|
||||
fc.lastDenyLogAt = now
|
||||
print("WTO_AI|DENY|eid={uint(slot.eid)}|reason={reason}|block={blk}|dist={distXZ}|spd={measuredSpeed}\n")
|
||||
print("WTO_AI|DENY|eid={uint(slot.eid)}|reason={reason}|block={blk}|dist={distXZ}|spd={measuredSpeed}|limit={speedLimit}|err={fc.lastAimErrDeg}|drift={fc.aimDriftDegSec}\n")
|
||||
|
||||
[never_inline]
|
||||
def public wto_fire_gate_try_shoot(world : WtoWorldSnap const&; var unit : Unit?;
|
||||
now, dt, distXZ : float; muzzlePos, aimPt, liveDir, wishDir : float3;
|
||||
var slot : WtoBotSlot&; var fireBudget : int&)
|
||||
def private wto_gate_request_primary_shot(var unit : Unit?; now, distXZ, measuredSpeed, speedLimit : float;
|
||||
var slot : WtoBotSlot&)
|
||||
assume fc = slot.fire
|
||||
let aimErrDeg = acos(clamp(dot(liveDir, wishDir), -1.0, 1.0)) * WTO_RAD_TO_DEG
|
||||
fc.lastAimErrDeg = aimErrDeg
|
||||
let measuredSpeed = length(unit.vel)
|
||||
let speedOk = wto_gate_speed_allowed(distXZ, measuredSpeed, slot.spec)
|
||||
let allowErrDeg = clamp(atan2(WTO_AI_FC_CLOSE_HIT_RADIUS_M, max(distXZ, 6.0)) * WTO_RAD_TO_DEG, WTO_AI_FC_BASE_ALIGN_DEG, 2.4)
|
||||
let settled = aimErrDeg <= allowErrDeg && fc.barrelOmegaDegSec <= WTO_AI_FC_BARREL_SETTLE_DEG_SEC && speedOk
|
||||
fc.lastAligned = settled
|
||||
fc.settleHoldSec = settled ? (fc.settleHoldSec + clamp(dt, 0.005, 0.10)) : max(0.0, fc.settleHoldSec - dt * 2.0)
|
||||
|
||||
let minCadence = slot.spec.isAutocannonBelt ? 0.12 : 0.65
|
||||
if !fc.gunReady || (now - fc.lastShotAt) < minCadence
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, WTO_DENY_NOT_READY, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
if !speedOk
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, WTO_DENY_SPEED, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
if distXZ > WTO_AI_FC_LONG_RANGE_M && (slot.perceive.goodLosSec < WTO_AI_FC_LONG_WINDOW_SEC || slot.perceive.visiblePointCount < 2)
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, WTO_DENY_LONG_WINDOW, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
if aimErrDeg > allowErrDeg
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, WTO_DENY_AIM_ERR, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
let reqHold = distXZ <= WTO_AI_FC_CLOSE_RANGE_M ? WTO_AI_FC_CLOSE_SETTLE_HOLD_SEC : WTO_AI_FC_SETTLE_HOLD_SEC
|
||||
if fc.settleHoldSec < reqHold
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, WTO_DENY_SETTLE, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
if fireBudget <= 0
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, WTO_DENY_BUDGET, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
fireBudget--
|
||||
var blk = WTO_BLOCK_NONE
|
||||
let gateRes = wto_gate_check_all_primary_guns(world, unit, slot, muzzlePos, liveDir, aimPt, blk)
|
||||
if gateRes != WTO_DENY_OK
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, gateRes, blk, slot)
|
||||
return
|
||||
|
||||
unit_single_shot(unit, int(WeaponTriggerGroups.TRIGGER_GROUP_PRIMARY))
|
||||
fc.lastShotAt = now
|
||||
fc.pendingShotConfirm = true
|
||||
fc.pendingShotAt = now
|
||||
fc.lastDenyReason = WTO_DENY_OK
|
||||
fc.lastDenyBlock = WTO_BLOCK_NONE
|
||||
fc.shotErrSumDeg += aimErrDeg
|
||||
fc.maxShotErrDeg = max(fc.maxShotErrDeg, aimErrDeg)
|
||||
fc.shotErrSumDeg += fc.lastAimErrDeg
|
||||
fc.maxShotErrDeg = max(fc.maxShotErrDeg, fc.lastAimErrDeg)
|
||||
if !slot.spec.isAutocannonBelt
|
||||
fc.settleHoldSec = 0.0
|
||||
if WTO_AI_DIAG_TELEMETRY
|
||||
print("WTO_AI|SHOT|eid={uint(slot.eid)}|tgt={uint(slot.perceive.targetEid)}|dist={distXZ}|spd={measuredSpeed}|v0={fc.activeSpeedMps}|err={aimErrDeg}\n")
|
||||
print("WTO_AI|SHOT|eid={uint(slot.eid)}|tgt={uint(slot.perceive.targetEid)}|dist={distXZ}|spd={measuredSpeed}|limit={speedLimit}|v0={fc.activeSpeedMps}|err={fc.lastAimErrDeg}\n")
|
||||
|
||||
[never_inline]
|
||||
def public wto_fire_gate_try_shoot(world : WtoWorldSnap const&; var unit : Unit?;
|
||||
now, distXZ : float; muzzlePos, aimPt, liveDir, wishDir : float3;
|
||||
var slot : WtoBotSlot&; var fireBudget : int&)
|
||||
assume fc = slot.fire
|
||||
let aimErrDeg = acos(clamp(dot(liveDir, wishDir), -1.0, 1.0)) * WTO_RAD_TO_DEG
|
||||
fc.lastAimErrDeg = aimErrDeg
|
||||
let measuredSpeed = length(unit.vel)
|
||||
let halting = slot.drive.routeBOwned && slot.tactics.state == WTO_STATE_SHORT_HALT
|
||||
let speedLimit = halting ? WTO_AI_FC_STOP_SPEED_MAX_MPS : wto_fire_speed_limit_mps(distXZ, slot.spec.vMaxFwd)
|
||||
let speedOk = measuredSpeed <= speedLimit
|
||||
let close = distXZ <= WTO_AI_FC_CLOSE_RANGE_M
|
||||
let allowErrDeg = clamp(atan2(WTO_AI_FC_CLOSE_HIT_RADIUS_M, max(distXZ, 6.0)) * WTO_RAD_TO_DEG, WTO_AI_FC_BASE_ALIGN_DEG, 2.4)
|
||||
wto_gate_track_aim(now, liveDir - wishDir, slot.perceive.targetEid, aimErrDeg <= allowErrDeg && speedOk, close, fc)
|
||||
|
||||
let minCadence = slot.spec.isAutocannonBelt ? 0.12 : 0.65
|
||||
let reqHold = close ? WTO_AI_FC_CLOSE_SETTLE_HOLD_SEC : WTO_AI_FC_SETTLE_HOLD_SEC
|
||||
var deny = WTO_DENY_OK
|
||||
if !fc.gunReady || (now - fc.lastShotAt) < minCadence
|
||||
deny = WTO_DENY_NOT_READY
|
||||
elif !speedOk
|
||||
deny = WTO_DENY_SPEED
|
||||
elif distXZ > WTO_AI_FC_LONG_RANGE_M && (slot.perceive.goodLosSec < WTO_AI_FC_LONG_WINDOW_SEC || slot.perceive.visiblePointCount < 2)
|
||||
deny = WTO_DENY_LONG_WINDOW
|
||||
elif aimErrDeg > allowErrDeg
|
||||
deny = WTO_DENY_AIM_ERR
|
||||
elif !fc.lastAligned || fc.settleHoldSec < reqHold
|
||||
deny = WTO_DENY_SETTLE
|
||||
elif fireBudget <= 0
|
||||
deny = WTO_DENY_BUDGET
|
||||
if deny != WTO_DENY_OK
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, speedLimit, deny, WTO_BLOCK_NONE, slot)
|
||||
return
|
||||
fireBudget--
|
||||
var blk = WTO_BLOCK_NONE
|
||||
let gateRes = wto_gate_check_all_primary_guns(world, unit, slot, muzzlePos, liveDir, aimPt, blk)
|
||||
if gateRes != WTO_DENY_OK
|
||||
wto_gate_log_deny(now, distXZ, measuredSpeed, speedLimit, gateRes, blk, slot)
|
||||
return
|
||||
wto_gate_request_primary_shot(unit, now, distXZ, measuredSpeed, speedLimit, slot)
|
||||
@@ -0,0 +1,19 @@
|
||||
// Shared speed limit for the movement command and the shot permission check.
|
||||
options indenting = 2
|
||||
options no_global_heap = true
|
||||
module wto_ai_fire_speed_common shared
|
||||
|
||||
require math
|
||||
require %appGame.wtoai.wto_ai_config_common
|
||||
|
||||
def public wto_fire_speed_limit_mps(distXZ, maxFwdMps : float) : float
|
||||
let stop = WTO_AI_FC_STOP_SPEED_MAX_MPS
|
||||
if distXZ > WTO_AI_FC_MID_RANGE_M
|
||||
return stop
|
||||
let close = max(stop, min(maxFwdMps, WTO_AI_FC_CLOSE_MAX_MPS))
|
||||
let mid = clamp(min(maxFwdMps * WTO_AI_FC_MID_SLOW_RATIO, WTO_AI_FC_MID_SLOW_MAX_MPS), stop, close)
|
||||
if distXZ <= WTO_AI_FC_CLOSE_RANGE_M
|
||||
let pointBlank = max(close, min(maxFwdMps, WTO_AI_FC_POINT_BLANK_MAX_MPS))
|
||||
return lerp(pointBlank, close, distXZ / WTO_AI_FC_CLOSE_RANGE_M)
|
||||
let frac = (distXZ - WTO_AI_FC_CLOSE_RANGE_M) / (WTO_AI_FC_MID_RANGE_M - WTO_AI_FC_CLOSE_RANGE_M)
|
||||
return lerp(close, mid, frac)
|
||||
@@ -27,6 +27,7 @@ def public wto_sm_set_state(now : float; newState : int; goalPos : float3; speed
|
||||
if newState == WTO_STATE_SHORT_HALT
|
||||
tac.haltEnterAt = now
|
||||
tac.haltStartShots = slot.fire.shotCount
|
||||
slot.nextNavAt = now
|
||||
tac.moveGoal = goalPos
|
||||
tac.desiredSpeedMps = speedMps
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ require %appGame.wtoai.wto_ai_config_common
|
||||
require %appGame.wtoai.wto_ai_math_common
|
||||
require %appGame.wtoai.wto_ai_order_common
|
||||
require %appGame.wtoai.wto_ai_combat_types_common
|
||||
require %appGame.wtoai.wto_ai_fire_speed_common
|
||||
require %appGame.wtoai.wto_ai_types_common
|
||||
require %appGame.wtoai.wto_ai_terrain_common
|
||||
require %appGame.wtoai.wto_ai_crowd_common
|
||||
@@ -23,6 +24,7 @@ def private wto_sm_sync_engagement_counters(dt : float; var slot : WtoBotSlot&)
|
||||
assume p = slot.perceive
|
||||
if p.hasClearLos && !!p.targetEid && !p.targetIsAir && tac.engageTargetEid != p.targetEid
|
||||
tac.engageTargetEid = p.targetEid
|
||||
tac.movingShotBlockedSince = -100.0
|
||||
tac.engageShotsNoEffect = 0
|
||||
tac.engageNoShotHalts = 0
|
||||
tac.engageTotalHaltSec = 0.0
|
||||
@@ -60,6 +62,14 @@ def private wto_sm_handle_ridge(world : WtoWorldSnap const&; now : float;
|
||||
return true
|
||||
return false
|
||||
|
||||
[never_inline]
|
||||
def private wto_sm_stop_range_allowed(distXZ : float; slot : WtoBotSlot const&) : bool
|
||||
let maxStop = slot.order.valid ? slot.order.maxStopRangeM : WTO_AI_FC_MAX_RANGE_M
|
||||
if distXZ > min(maxStop, WTO_AI_FC_MAX_RANGE_M)
|
||||
return false
|
||||
return (distXZ <= WTO_AI_FC_LONG_RANGE_M ||
|
||||
(slot.perceive.goodLosSec >= WTO_AI_FC_LONG_WINDOW_SEC && slot.perceive.visiblePointCount >= 2))
|
||||
|
||||
[never_inline]
|
||||
def private wto_sm_continue_short_halt(now : float; myPos : float3; hasGroundTgt : bool;
|
||||
distXZ : float; var slot : WtoBotSlot&) : bool
|
||||
@@ -71,12 +81,7 @@ def private wto_sm_continue_short_halt(now : float; myPos : float3; hasGroundTgt
|
||||
tac.engageShotsNoEffect += slot.fire.shotCount - tac.haltStartShots
|
||||
tac.haltStartShots = slot.fire.shotCount
|
||||
return false
|
||||
if !hasGroundTgt || distXZ > WTO_AI_FC_MAX_RANGE_M
|
||||
return false
|
||||
let maxStop = slot.order.valid ? slot.order.maxStopRangeM : WTO_AI_FC_MAX_RANGE_M
|
||||
if distXZ > maxStop
|
||||
return false
|
||||
if distXZ > WTO_AI_FC_LONG_RANGE_M && (slot.perceive.goodLosSec < WTO_AI_FC_LONG_WINDOW_SEC || slot.perceive.visiblePointCount < 2)
|
||||
if !hasGroundTgt || !wto_sm_stop_range_allowed(distXZ, slot)
|
||||
return false
|
||||
if (now - tac.haltEnterAt) >= WTO_AI_SM_SHORT_HALT_MAX_SEC
|
||||
tac.engageNoShotHalts++
|
||||
@@ -110,6 +115,18 @@ def private wto_sm_march_speed(slot : WtoBotSlot const&; distGoal : float) : flo
|
||||
let capScale = slot.order.cautious ? 0.78 : 0.98
|
||||
return distGoal < 24.0 ? min(slot.spec.vMaxFwd * 0.55, 6.0) : (slot.spec.vMaxFwd * capScale)
|
||||
|
||||
[never_inline]
|
||||
def private wto_sm_waited_for_moving_shot(now : float; aimReady : bool; var slot : WtoBotSlot&) : bool
|
||||
assume tac = slot.tactics
|
||||
let deny = slot.fire.lastDenyReason
|
||||
let blocked = deny == WTO_DENY_SPEED || deny == WTO_DENY_AIM_ERR || deny == WTO_DENY_SETTLE
|
||||
if tac.state != WTO_STATE_RUN_AND_GUN || !aimReady || !blocked
|
||||
tac.movingShotBlockedSince = -100.0
|
||||
return false
|
||||
if tac.movingShotBlockedSince < tac.stateEnteredAt
|
||||
tac.movingShotBlockedSince = now
|
||||
return now - tac.movingShotBlockedSince >= WTO_AI_SM_MOVING_SHOT_WAIT_SEC
|
||||
|
||||
[never_inline]
|
||||
def private wto_sm_handle_combat(world : WtoWorldSnap const&; now : float;
|
||||
myPos, hullFwd, threatPos, baseGoal : float3;
|
||||
@@ -119,23 +136,20 @@ def private wto_sm_handle_combat(world : WtoWorldSnap const&; now : float;
|
||||
let marchSpd = wto_sm_march_speed(slot, distGoal)
|
||||
if fc.reloading
|
||||
return wto_sm_start_reload_action(world, now, myPos, hullFwd, threatPos, baseGoal, distXZ, distGoal, slot)
|
||||
if distXZ <= WTO_AI_FC_CLOSE_RANGE_M
|
||||
let closeSpd = slot.spec.hasVertStab ? (slot.spec.vMaxFwd * 0.92) : min(slot.spec.vMaxFwd * 0.65, WTO_AI_FC_MID_SLOW_MAX_MPS)
|
||||
wto_sm_set_state(now, WTO_STATE_RUN_AND_GUN, baseGoal, max(2.5, closeSpd), "close_run_gun", distXZ, slot)
|
||||
return true
|
||||
let close = distXZ <= WTO_AI_FC_CLOSE_RANGE_M
|
||||
let urgentPush = slot.order.urgency == WTO_URGENCY_HIGH || distGoal > 130.0
|
||||
if distXZ <= WTO_AI_FC_MID_RANGE_M && urgentPush
|
||||
let slowCap = min(slot.spec.vMaxFwd * WTO_AI_FC_MID_SLOW_RATIO, WTO_AI_FC_MID_SLOW_MAX_MPS)
|
||||
wto_sm_set_state(now, WTO_STATE_RUN_AND_GUN, baseGoal, max(2.2, slowCap), "mid_slow_fire", distXZ, slot)
|
||||
let canHalt = now >= tac.shortHaltCooldownUntil && !tac.repositionActive && wto_sm_stop_range_allowed(distXZ, slot)
|
||||
let aimReady = (fc.gunReady && fc.aimTargetEid == slot.perceive.targetEid &&
|
||||
(fc.lastAimErrDeg <= WTO_AI_SM_PREAIM_DEG || slot.spec.isLimitedTraverse))
|
||||
if marchSpd > 0.0 && (close || (distXZ <= WTO_AI_FC_MID_RANGE_M && urgentPush))
|
||||
if wto_sm_waited_for_moving_shot(now, aimReady, slot) && canHalt
|
||||
wto_sm_set_state(now, WTO_STATE_SHORT_HALT, myPos, 0.0, "moving_shot_halt", distXZ, slot)
|
||||
else
|
||||
let speed = min(marchSpd, wto_fire_speed_limit_mps(distXZ, slot.spec.vMaxFwd))
|
||||
wto_sm_set_state(now, WTO_STATE_RUN_AND_GUN, baseGoal, speed, close ? "close_run_gun" : "mid_slow_fire", distXZ, slot)
|
||||
return true
|
||||
let maxStop = slot.order.valid ? slot.order.maxStopRangeM : WTO_AI_FC_MAX_RANGE_M
|
||||
if distXZ > maxStop || distXZ > WTO_AI_FC_MAX_RANGE_M || tac.repositionActive
|
||||
if !canHalt
|
||||
return false
|
||||
if distXZ > WTO_AI_FC_LONG_RANGE_M && (slot.perceive.goodLosSec < WTO_AI_FC_LONG_WINDOW_SEC || slot.perceive.visiblePointCount < 2)
|
||||
return false
|
||||
if now < tac.shortHaltCooldownUntil
|
||||
return false
|
||||
let aimReady = fc.gunReady && (fc.lastAimErrDeg <= WTO_AI_SM_PREAIM_DEG || slot.spec.isLimitedTraverse)
|
||||
if !aimReady
|
||||
wto_sm_set_state(now, WTO_STATE_PREAIM, baseGoal, marchSpd, "preaim_move", distXZ, slot)
|
||||
return true
|
||||
|
||||
@@ -169,6 +169,7 @@ struct public WtoTacticsState
|
||||
stateEnteredAt : float = -100.0
|
||||
moveGoal : float3 = float3(0.0, 0.0, 0.0)
|
||||
desiredSpeedMps : float = 10.0
|
||||
movingShotBlockedSince : float = -100.0
|
||||
haltEnterAt : float = -100.0
|
||||
haltStartShots : int = 0
|
||||
shortHaltCooldownUntil : float = -100.0
|
||||
|
||||
@@ -91,6 +91,7 @@ export interface GroundAiConfig {
|
||||
readonly deadEchoSec: number;
|
||||
readonly controlTimeoutSec: number;
|
||||
readonly cornerBrakeAccel: number;
|
||||
readonly movingFireSpeedRampMps: number;
|
||||
readonly pivotAngleDeg: number;
|
||||
readonly stuckWindowSec: number;
|
||||
readonly stuckMinMoveM: number;
|
||||
@@ -111,6 +112,7 @@ export interface GroundAiConfig {
|
||||
};
|
||||
readonly stateMachine: {
|
||||
readonly preaimAngleDeg: number;
|
||||
readonly movingShotWaitSec: number;
|
||||
readonly shortHaltMaxSec: number;
|
||||
readonly shortHaltCooldownSec: number;
|
||||
readonly turnLaunchSpeedMps: number;
|
||||
@@ -155,6 +157,8 @@ export interface GroundAiConfig {
|
||||
readonly longRangeM: number;
|
||||
readonly midSlowSpeedRatio: number;
|
||||
readonly midSlowMaxMps: number;
|
||||
readonly closeRangeMaxSpeedKmh: number;
|
||||
readonly pointBlankMaxSpeedKmh: number;
|
||||
readonly stopSpeedMaxMps: number;
|
||||
readonly longRangeWindowSec: number;
|
||||
readonly baseAlignDeg: number;
|
||||
@@ -271,6 +275,7 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] {
|
||||
['WTO_AI_NAV_DEAD_ECHO_SEC', 'float', c.navigation.deadEchoSec],
|
||||
['WTO_AI_NAV_CONTROL_TIMEOUT_SEC', 'float', c.navigation.controlTimeoutSec],
|
||||
['WTO_AI_NAV_CORNER_BRAKE_ACCEL', 'float', c.navigation.cornerBrakeAccel],
|
||||
['WTO_AI_NAV_MOVING_FIRE_SPEED_RAMP_MPS', 'float', c.navigation.movingFireSpeedRampMps],
|
||||
['WTO_AI_NAV_PIVOT_ANGLE_DEG', 'float', c.navigation.pivotAngleDeg],
|
||||
['WTO_AI_NAV_STUCK_WINDOW_SEC', 'float', c.navigation.stuckWindowSec],
|
||||
['WTO_AI_NAV_STUCK_MIN_MOVE_M', 'float', c.navigation.stuckMinMoveM],
|
||||
@@ -287,6 +292,7 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] {
|
||||
['WTO_AI_PERC_FRONT_CONE_DEG', 'float', c.perception.frontConeHalfDeg],
|
||||
['WTO_AI_PERC_PERIPH_CLOSE_M', 'float', c.perception.peripheralCloseM],
|
||||
['WTO_AI_SM_PREAIM_DEG', 'float', c.stateMachine.preaimAngleDeg],
|
||||
['WTO_AI_SM_MOVING_SHOT_WAIT_SEC', 'float', c.stateMachine.movingShotWaitSec],
|
||||
['WTO_AI_SM_SHORT_HALT_MAX_SEC', 'float', c.stateMachine.shortHaltMaxSec],
|
||||
['WTO_AI_SM_SHORT_HALT_COOLDOWN_SEC', 'float', c.stateMachine.shortHaltCooldownSec],
|
||||
['WTO_AI_SM_TURN_LAUNCH_MPS', 'float', c.stateMachine.turnLaunchSpeedMps],
|
||||
@@ -325,6 +331,8 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] {
|
||||
['WTO_AI_FC_LONG_RANGE_M', 'float', c.fireControl.longRangeM],
|
||||
['WTO_AI_FC_MID_SLOW_RATIO', 'float', c.fireControl.midSlowSpeedRatio],
|
||||
['WTO_AI_FC_MID_SLOW_MAX_MPS', 'float', c.fireControl.midSlowMaxMps],
|
||||
['WTO_AI_FC_CLOSE_MAX_MPS', 'float', c.fireControl.closeRangeMaxSpeedKmh / 3.6],
|
||||
['WTO_AI_FC_POINT_BLANK_MAX_MPS', 'float', c.fireControl.pointBlankMaxSpeedKmh / 3.6],
|
||||
['WTO_AI_FC_STOP_SPEED_MAX_MPS', 'float', c.fireControl.stopSpeedMaxMps],
|
||||
['WTO_AI_FC_LONG_WINDOW_SEC', 'float', c.fireControl.longRangeWindowSec],
|
||||
['WTO_AI_FC_BASE_ALIGN_DEG', 'float', c.fireControl.baseAlignDeg],
|
||||
|
||||
Reference in new issue
Block a user