Files
WT-Offline/game-ai/ground/wto_ai_specs_common.das
T
N0VAN0M4LY 9229045042 feat(ground-ai): add exposure perception and single ballistic fire gate
Replace the old foliage-ignoring LOS check and 45 m pre-fire ray with
separate vision/hard-occlusion queries, exposure-integrated spotting, and
a single fire-permission gate for every ground weapon:

- Add perception and fire-gate distance/ballistics/budget parameters to
  tuning/ground-ai.jsonc, validated in ground-ai-tuning.ts and compiled
  into wto_ai_config_common.das.
- Extract wto_ai_combat_types_common.das and add wto_ai_sight_common.das:
  visual checks use smoke occluders, ETF_ALL with aimRay material,
  traceTransparencyRayRIGenNormalized foliage transparency, and vehicle/
  wreck checks; hard-occlusion checks test terrain/structures plus both
  ETF_RI and ETF_RI_PHYS without skipping soft foliage, plus swept
  sphere_cast and wreck/vehicle bounds along the full shot distance.
- Rewrite wto_ai_perceive_common.das with per-target exposure integration
  (fast/normal/far fill times and occlusion decay), 4-point visibility
  sampling with continuous >=2-point LOS tracking for the 800 m 4-second
  window, frozen last-seen coordinates with zeroed velocity on LOS loss,
  and impact-time hit direction (no live offender lookup).
- Record per-shell ballistics profiles (speed, Cx, mass, ballisticCaliber)
  in wto_ai_specs_common.das and sync the currently loaded shell from
  gun.chosenBulletType / bulletSets at runtime.
- Add wto_ai_fire_gate_common.das as the sole ground trigger exit: checks
  visual lock, weapon readiness, distance-tier measured chassis speed
  limits (100/300/800 m), 800 m 4-second window, aim settle, per-frame
  check budget, straight muzzle hard-ray, drag-integrated ballistic arc
  sweep, predicted friendly corridor, and every barrel in the primary
  trigger group. Confirm real shot departure from loaded ammo/readiness,
  remove the pure-launcher stock bypass and add_unit_for_target leak, and
  log exact deny/shot reasons.

Verified root and launcher type checks, isolated 2.61.0.58 build (21
ground AI modules packed), and clean in-engine daScript compilation/load
(wto_ai_runtime.das loaded in 186 ms, 0 compile errors). Live battle
acceptance deferred until the full pipeline is wired.
2026-12-03 17:34:59 +08:00

198 lines
8.1 KiB
Plaintext

// Authoritative per-vehicle specification loader: reads unit & weapon DataBlocks once per
// spawned bot (`gamedata/units/<className>.blk`) to extract exact role, gun stabilizer,
// traverse limits, turret slew rates, shell muzzle velocity, and reverse speed capability.
options indenting = 2
options no_global_heap = true
module wto_ai_specs_common shared
require ecs
require app
require math
require strings
require DagorMath
require DagorDataBlock
require Unit
require IGroundModel
require HeavyVehicleModel
require Weapon
require %game.utils.utils_common
require %appGame.wtoai.wto_ai_math_common
require %appGame.wtoai.wto_ai_combat_types_common
require %appGame.wtoai.wto_ai_types_common
[never_inline]
def private wto_parse_role_strings(unitType : string; expClass : string; isLightTag : bool) : int
if unitType == "typeSPAA" || expClass == "exp_SPAA"
return WTO_ROLE_SPAA
if unitType == "typeTankDestroyer" || expClass == "exp_tank_destroyer"
return WTO_ROLE_TD
if unitType == "typeHeavyTank" || expClass == "exp_heavy_tank"
return WTO_ROLE_HEAVY
if unitType == "typeLightTank" || isLightTag
return WTO_ROLE_LIGHT
return WTO_ROLE_MEDIUM
[never_inline]
def private wto_parse_turret_limits(turretBlk : DataBlock const?; var spec : WtoVehicleSpec&)
if turretBlk == null
return
let lim1 = *turretBlk |> datablock_getPoint4("lim1", float4(0.0, 0.0, 0.0, 0.0))
let lim2 = *turretBlk |> datablock_getPoint4("lim2", float4(0.0, 0.0, 0.0, 0.0))
var maxAbsYaw = 0.0
var minPitch = 0.0
var maxPitch = 0.0
if abs(lim1.x) > 0.1 || abs(lim1.y) > 0.1
maxAbsYaw = max(maxAbsYaw, max(abs(lim1.x), abs(lim1.y)))
minPitch = min(minPitch, lim1.z)
maxPitch = max(maxPitch, lim1.w)
if abs(lim2.x) > 0.1 || abs(lim2.y) > 0.1
maxAbsYaw = max(maxAbsYaw, max(abs(lim2.x), abs(lim2.y)))
minPitch = min(minPitch, lim2.z)
maxPitch = max(maxPitch, lim2.w)
let limitsBlk = *turretBlk |> datablock_get_block_by_name("limits")
if limitsBlk != null
let yawRange = *limitsBlk |> datablock_getPoint2("yaw", float2(0.0, 0.0))
let pitchRange = *limitsBlk |> datablock_getPoint2("pitch", float2(0.0, 0.0))
if abs(yawRange.x) > 0.1 || abs(yawRange.y) > 0.1
maxAbsYaw = max(maxAbsYaw, max(abs(yawRange.x), abs(yawRange.y)))
if pitchRange.x < -0.1 || pitchRange.y > 0.1
minPitch = min(minPitch, pitchRange.x)
maxPitch = max(maxPitch, pitchRange.y)
if maxAbsYaw > 0.5
spec.yawLimitDeg = clamp(maxAbsYaw, 4.0, 180.0)
spec.isLimitedTraverse = spec.yawLimitDeg < 75.0
if minPitch < -0.5
spec.minPitchDeg = clamp(minPitch, -25.0, -2.0)
if maxPitch > 1.0
spec.maxPitchDeg = clamp(maxPitch, 8.0, 88.0)
[never_inline]
def private wto_record_shell_block(bBlk : DataBlock const&; var spec : WtoVehicleSpec&; isDefault : bool)
let spd = bBlk |> datablock_getReal("speed", 0.0)
if spd <= 80.0 || spd >= 2600.0
return
let cx = clamp(bBlk |> datablock_getReal("Cx", 0.35), 0.05, 1.5)
let mass = clamp(bBlk |> datablock_getReal("mass", 10.0), 0.05, 250.0)
let rawCal = bBlk |> datablock_getReal("ballisticCaliber", 0.0)
let cal = clamp(rawCal > 0.002 ? rawCal : bBlk |> datablock_getReal("caliber", 0.09), 0.005, 0.4)
if isDefault && spec.shellCount == 0
spec.muzzleSpeedMps = spd
spec.shellDragCx = cx
spec.shellMassKg = mass
spec.shellCaliberM = cal
let bName = bBlk |> datablock_getStr("bulletName", "")
if empty(bName) || spec.shellCount >= WTO_MAX_SHELL_PROFILES
return
let h = ecs_hash(bName)
for i in range(spec.shellCount)
if spec.shells[i].nameHash == h
return
let idx = spec.shellCount
spec.shells[idx].nameHash = h
spec.shells[idx].speedMps = spd
spec.shells[idx].dragCx = cx
spec.shells[idx].massKg = mass
spec.shells[idx].caliberM = cal
spec.shellCount = idx + 1
[never_inline]
def private wto_parse_weapon_blk(weapBlkPath : string; var spec : WtoVehicleSpec&)
if empty(weapBlkPath) || find(weapBlkPath, "dummy_weapon") >= 0
return
datablock_load_cached(weapBlkPath, DataBlockReadFlag.ROBUST) <| $(wBlk)
let isRocket = wBlk |> datablock_getBool("rocketGun", false)
let isCannon = wBlk |> datablock_getBool("cannon", false)
let isBelt = wBlk |> datablock_getBool("isBulletBelt", false)
if isRocket && !isCannon
return
spec.isAutocannonBelt = isBelt
spec.shellCount = 0
datablock_for_each_block(wBlk, "bullet") <| $(bBlk)
wto_record_shell_block(bBlk, spec, true)
datablock_for_each_block(wBlk) <| $(subBlk)
datablock_for_each_block(subBlk, "bullet") <| $(bBlk)
wto_record_shell_block(bBlk, spec, false)
[never_inline]
def private wto_parse_unit_blk(className : string; isLightTag : bool; var spec : WtoVehicleSpec&) : bool
if empty(className)
return false
let relPath = find(className, "/") >= 0 ? ("gamedata/units/" + className + ".blk") : ("gamedata/units/tankModels/" + className + ".blk")
var loaded = false
datablock_load_cached(relPath, DataBlockReadFlag.ROBUST) <| $(mBlk)
if mBlk.paramCount == 0u && mBlk.blockCount == 0u
return
loaded = true
let uType = mBlk |> datablock_getStr("type", "")
let expCls = mBlk |> datablock_getStr("expClass", "")
spec.role = wto_parse_role_strings(uType, expCls, isLightTag)
let fwdKmh = mBlk |> datablock_getReal("maxFwdSpeed", 0.0)
let revKmh = mBlk |> datablock_getReal("maxRevSpeed", 0.0)
if fwdKmh > 5.0
spec.vMaxFwd = clamp(fwdKmh / 3.6, 4.0, 28.0)
if revKmh > 1.0
spec.vMaxRev = clamp(revKmh / 3.6, 1.0, 16.0)
let commonBlk = mBlk |> datablock_get_block_by_name("commonWeapons")
if commonBlk == null
return
var primaryParsed = false
datablock_for_each_block(*commonBlk, "Weapon") <| $(weapBlk)
if primaryParsed
return
let trig = weapBlk |> datablock_getStr("triggerGroup", "primary")
let wPath = weapBlk |> datablock_getStr("blk", "")
if trig != "primary" || empty(wPath) || find(wPath, "dummy_weapon") >= 0 || find(wPath, "machinegun") >= 0
return
primaryParsed = true
let sy = weapBlk |> datablock_getReal("speedYaw", 24.0)
let sp = weapBlk |> datablock_getReal("speedPitch", 8.0)
spec.turretYawSpd = clamp(sy, 4.0, 120.0)
spec.turretPitchSpd = clamp(sp, 2.0, 90.0)
let stabBlk = weapBlk |> datablock_get_block_by_name("gunStabilizer")
if stabBlk != null
spec.hasVertStab = *stabBlk |> datablock_getBool("hasVertical", false)
wto_parse_turret_limits(weapBlk |> datablock_get_block_by_name("turret"), spec)
wto_parse_weapon_blk(wPath, spec)
return loaded
[never_inline]
def private wto_apply_runtime_fallbacks(unit : Unit const?; gm : IGroundModel const?;
isLightTag : bool; blkLoaded : bool; var spec : WtoVehicleSpec&)
if gm != null
let box = gm.bodyBoundingBox
spec.halfLen = max(2.0, max(abs(box.boxMin.x), abs(box.boxMax.x)) + 0.15)
spec.halfWid = max(1.0, max(abs(box.boxMin.z), abs(box.boxMax.z)) + 0.18)
let hv = unit != null ? as_hv(unit) : null
if hv != null && hv.getMaxSpeed > 1.5 && wto_is_finite(hv.getMaxSpeed)
spec.vMaxFwd = min(spec.vMaxFwd, hv.getMaxSpeed)
if unit == null || unit.weap == null
return
var gunCount = 0
var launcherCount = 0
foreach_primary_gun(unit.weap.Weapons) <| $(weapon)
if weapon == null || weapon.isDummyGun
return
if weapon.prop.launcher
launcherCount++
elif as_gun(weapon) != null
gunCount++
spec.isPureLauncher = gunCount == 0 && launcherCount > 0
if length(unit.weap.turret) == 0 && gunCount > 0
spec.isLimitedTraverse = true
spec.yawLimitDeg = min(spec.yawLimitDeg, 12.0)
if !blkLoaded
if spec.isLimitedTraverse
spec.role = WTO_ROLE_TD
elif isLightTag
spec.role = WTO_ROLE_LIGHT
elif spec.vMaxFwd <= 10.5 && spec.halfLen >= 3.3
spec.role = WTO_ROLE_HEAVY
[never_inline]
def public wto_specs_load(eid : EntityId; className : string; unit : Unit const?;
gm : IGroundModel const?; var spec : WtoVehicleSpec&)
let isLightTag = has(eid, "unit_tag__light_vehicle")
let blkLoaded = wto_parse_unit_blk(className, isLightTag, spec)
wto_apply_runtime_fallbacks(unit, gm, isLightTag, blkLoaded, spec)
spec.ready = true