Files
WT-Offline/game-ai/ground/wto_ai_specs_common.das
T
N0VAN0M4LY ac35c25851 feat(ground-ai): add ready-rack dual-ammo bot spawn loadouts and shell switching
Select realistic ready-rack dual-shell loadouts for AI tanks on the local
server, inject them natively on bot spawn, and switch between anti-armor
and soft-target shells in battle:

- Add the loadout section to tuning/ground-ai.jsonc (lowReadyRackThreshold,
  topUpAmmoCount, primaryAmmoPct, secondaryMinRounds,
  penetrationCompareDistM), validated in ground-ai-tuning.ts.
- Add the tank-bot-ammo v2 dataset (apps/server/src/game-data/datasets/
  tank-bot-ammo.ts) reading primary cannon weapon name, capacity,
  firstStage/autoLoad shell ready-rack counts (excluding separate charges),
  and selectable shell modifications (using Lanz-Odermatt kinetic fields,
  cumulativeDamage, armorpower, and transitive reqModification chains).
- Add selectBotTankLoadouts (apps/server/src/battle/bot-tank-loadouts.ts):
  carry ready-rack count when >= 15 (top up to 22 when smaller or absent,
  clamped to gun capacity), skip SPAA/belt autocannons, pick highest-tier
  APFSDS/anti-armor primary (~80%) plus HE/HESH/HEAT secondary (~20%, min
  3 rounds) when available, and attach required addModification entries and
  per-tank wtoAmmo_<unit> strings to customBots when mode != stock.
- Hook Unit::changeAircraft (already located dynamically on .37 and .58) in
  native/wto-net/src/local_mp_loadout.c to assign the 24-byte
  ChangeUnitReflection.bullets entries via bullet_vec_assign for LocalMP
  bot spawns (async == 0, non-local bot MPlayer), leaving player spawns
  untouched.
- Track soft-target vs anti-armor shell classes in wto_ai_specs_common.das
  and write gun.nextBulletType in wto_ai_fire_common.das to queue HE/HESH
  against light/narrow targets and APFSDS/AP against MBTs/heavy armor.

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, 12/12 LocalMP
module installation, clean daScript load (wto_ai_runtime.das loaded in
211 ms, 0 compile errors), and real 2.61.0.58 loadout selection on
cn_ztz_96a (18 APFSDS + 4 HE), germ_leopard_2a4 (12 DM23 + 3 HEATFS),
ussr_t_80bvm (22 3BM60 + 6 HE), us_m1a2_abrams (14 M829A2 + 4 HEAT-MP),
ussr_t_34_1941 (18 APHEBC + 4 HE), and ussr_zsu_23_4 (stock belt kept).
Live battle acceptance begins in Step 9.
2026-12-03 19:25:04 +08:00

203 lines
8.4 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
let bt = bBlk |> datablock_getStr("bulletType", "")
let isSoft = find(bt, "he_frag") >= 0 || find(bt, "hesh") >= 0
let isNonCombat = find(bt, "smoke") >= 0 || find(bt, "practice") >= 0 || find(bt, "shrapnel") >= 0
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.shells[idx].isSoftShell = isSoft
spec.shells[idx].isAntiArmor = !isSoft && !isNonCombat
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