fix(ground-ai): respect mounted gun traverse limits

Read the selected gun mount limits from the vehicle data and constrain its aiming commands. Send out-of-traverse aim requests to the chassis driver and require alignment before firing.

Verified type checks, executable patch checks and builds on 2.61.0.37 and 2.61.0.64, and guarded daScript initialization on 2.61.0.64. In-battle acceptance remains pending.
This commit is contained in:
N0VAN0M4LY committed 2026-12-05 18:36:19 +08:00
1 parent 39a77c04cb
commit 0843fde6ff
10 files changed
+303 -157

No files matched your search

+13 -2
View File
@@ -29,6 +29,7 @@ let public WTO_DENY_MUZZLE_HARD = 8
let public WTO_DENY_ARC_HARD = 9 let public WTO_DENY_ARC_HARD = 9
let public WTO_DENY_FRIENDLY = 10 let public WTO_DENY_FRIENDLY = 10
let public WTO_DENY_MULTI_GUN = 11 let public WTO_DENY_MULTI_GUN = 11
let public WTO_DENY_TRAVERSE = 12
[safe_when_uninitialized] [safe_when_uninitialized]
struct public WtoShellProfile struct public WtoShellProfile
@@ -76,9 +77,21 @@ struct public WtoPerceiveState
expScore : float[8] expScore : float[8]
expGoodLosSec : float[8] expGoodLosSec : float[8]
[safe_when_uninitialized]
struct public WtoGunTraverse
known : bool = false
yaw : float2 = float2(0.0, 0.0)
pitch : float2 = float2(1.0, 0.0)
hasPitchTable : bool = false
pitchSector : float4 = float4(1.0, 0.0, 1.0, 0.0)
[safe_when_uninitialized] [safe_when_uninitialized]
struct public WtoFireState struct public WtoFireState
turretNo : int = -1 turretNo : int = -1
traverseTurretNo : int = -1
traverse : WtoGunTraverse = WtoGunTraverse()
hullAimTarget : EntityId = INVALID_ENTITY_ID
hullAimDir : float3 = float3(0.0, 0.0, 0.0)
gunReady : bool = false gunReady : bool = false
reloading : bool = false reloading : bool = false
gunDamaged : bool = false gunDamaged : bool = false
@@ -89,8 +102,6 @@ struct public WtoFireState
activeCaliberM : float = 0.09 activeCaliberM : float = 0.09
pitchBlocked : bool = false pitchBlocked : bool = false
pitchClampSec : float = 0.0 pitchClampSec : float = 0.0
cmdYawDeg : float = 0.0
cmdPitchDeg : float = 0.0
curYawDeg : float = 0.0 curYawDeg : float = 0.0
curPitchDeg : float = 0.0 curPitchDeg : float = 0.0
prevPitchDeg : float = 0.0 prevPitchDeg : float = 0.0
+21 -9
View File
@@ -70,6 +70,15 @@ def private wto_check_echo_watchdog(unitMissionName : string; var actor : Vehicl
st.deadEchoSec = 0.0 st.deadEchoSec = 0.0
return true return true
def public wto_pivot_drive_mode(spec : WtoVehicleSpec const&; frontClearM, rearClearM : float; preferNeutral : bool) : int
let openFront = frontClearM >= spec.halfLen + 3.5
let neutralTurn = spec.canPivot && frontClearM >= spec.halfLen + 1.2 && rearClearM >= spec.halfLen + 1.0
if neutralTurn && (preferNeutral || !openFront)
return WTO_DRIVE_PIVOT
if openFront
return WTO_DRIVE_CRUISE
return rearClearM >= spec.halfLen + WTO_AI_TERRAIN_MARGIN_M ? WTO_DRIVE_REVERSE : WTO_DRIVE_HALT
[never_inline] [never_inline]
def private wto_compute_pivot_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleSpec const&; def private wto_compute_pivot_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleSpec const&;
fwd, left : float3; vFwd, omega : float; fwd, left : float3; vFwd, omega : float;
@@ -82,15 +91,18 @@ def private wto_compute_pivot_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleSp
outBrk = 1.0 outBrk = 1.0
outStr = turnSign * WTO_AI_NAV_STEER_SIGN outStr = turnSign * WTO_AI_NAV_STEER_SIGN
return return
let openFront = cmd.frontClearM >= spec.halfLen + 3.5 let mode = wto_pivot_drive_mode(spec, cmd.frontClearM, cmd.rearClearM, cmd.speedMps <= 0.0)
if openFront if mode == WTO_DRIVE_PIVOT
let response = errRad / (WTO_AI_NAV_PIVOT_ANGLE_DEG * WTO_DEG_TO_RAD)
outStr = clamp(response - omega * 0.35, -1.0, 1.0) * WTO_AI_NAV_STEER_SIGN
return
if mode == WTO_DRIVE_CRUISE
// Two-beat turn micro: launch straight to 2nd gear before applying full steering. // Two-beat turn micro: launch straight to 2nd gear before applying full steering.
outThr = 1.0 outThr = 1.0
outStr = abs(vFwd) < WTO_AI_SM_TURN_LAUNCH_MPS ? 0.0 : (turnSign * WTO_AI_NAV_STEER_SIGN) outStr = abs(vFwd) < WTO_AI_SM_TURN_LAUNCH_MPS ? 0.0 : (turnSign * WTO_AI_NAV_STEER_SIGN)
return return
if spec.canPivot && cmd.frontClearM >= spec.halfLen + 1.2 && cmd.rearClearM >= spec.halfLen + 1.0 if mode == WTO_DRIVE_HALT
outThr = 0.0 outBrk = 1.0
outStr = clamp(turnSign - omega * 0.35, -1.0, 1.0) * WTO_AI_NAV_STEER_SIGN
return return
// Tight front obstacle: execute clean 3-point reverse turn instead of ramming the wall. // Tight front obstacle: execute clean 3-point reverse turn instead of ramming the wall.
outThr = vFwd > -WTO_AI_SM_TURN_LAUNCH_MPS ? -1.0 : -0.6 outThr = vFwd > -WTO_AI_SM_TURN_LAUNCH_MPS ? -1.0 : -0.6
@@ -177,7 +189,7 @@ def private wto_ensure_phys_owner(gm : IGroundModel const?; var actor : VehicleP
return false return false
if !st.routeBOwned if !st.routeBOwned
slot.spec.isTracked = actor.phys.trackWidth > 0.01 slot.spec.isTracked = actor.phys.trackWidth > 0.01
slot.spec.canPivot = slot.spec.isTracked && actor.phys.haveSeparateBrakes slot.spec.canPivot = slot.spec.canPivot && slot.spec.isTracked && actor.phys.haveSeparateBrakes
st.routeBOwned = true st.routeBOwned = true
return st.routeBOwned return st.routeBOwned
@@ -191,12 +203,12 @@ def private wto_apply_drive_cmd(var actor : VehiclePhysActor&; fwd, left, veloci
var str = 0.0 var str = 0.0
var brk = 0.0 var brk = 0.0
var hand = 0.0 var hand = 0.0
if cmd.mode == WTO_DRIVE_HALT || cmd.speedMps <= 0.05 if 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_HALT || cmd.speedMps <= 0.05
thr = abs(vFwd) > 0.35 ? (vFwd > 0.0 ? -1.0 : 1.0) : 0.0 thr = abs(vFwd) > 0.35 ? (vFwd > 0.0 ? -1.0 : 1.0) : 0.0
brk = 1.0 brk = 1.0
hand = abs(vFwd) > 0.35 ? 0.0 : 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 elif cmd.mode == WTO_DRIVE_REVERSE
wto_compute_reverse_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk, hand) wto_compute_reverse_axes(cmd, slot.spec, fwd, left, vFwd, st.omegaYawRad, thr, str, brk, hand)
else else
+34 -84
View File
@@ -22,31 +22,7 @@ require %appGame.wtoai.wto_ai_types_common
require %appGame.wtoai.wto_ai_world_common require %appGame.wtoai.wto_ai_world_common
require %appGame.wtoai.wto_ai_estimate_common require %appGame.wtoai.wto_ai_estimate_common
require %appGame.wtoai.wto_ai_fire_gate_common require %appGame.wtoai.wto_ai_fire_gate_common
require %appGame.wtoai.wto_ai_traverse_common
[never_inline]
def private wto_world_to_hull_deg(worldDir, hullFwd, hullUp, hullLeft : float3;
var outYawDeg, outPitchDeg : float&)
let len = length(worldDir)
if len < 1.0e-5
outYawDeg = 0.0
outPitchDeg = 0.0
return
let d = worldDir / len
let f = dot(d, hullFwd)
let u = dot(d, hullUp)
let l = dot(d, hullLeft)
let horiz = sqrt(f * f + l * l)
outYawDeg = horiz > 1.0e-5 ? (-atan2(l, f) * WTO_RAD_TO_DEG) : 0.0
outPitchDeg = clamp(atan2(u, max(1.0e-5, horiz)) * WTO_RAD_TO_DEG, -24.0, 65.0)
[never_inline]
def private wto_hull_deg_to_world(yawDeg, pitchDeg : float; hullFwd, hullUp, hullLeft : float3) : float3
let yr = yawDeg * WTO_DEG_TO_RAD
let pr = pitchDeg * WTO_DEG_TO_RAD
let cp = cos(pr)
let dir = hullFwd * (cp * cos(yr)) - hullLeft * (cp * sin(yr)) + hullUp * sin(pr)
let l = length(dir)
return l > 1.0e-5 ? (dir / l) : hullFwd
[never_inline] [never_inline]
def private wto_sync_active_shell(gun : WTGun const?; spec : WtoVehicleSpec const&; var fc : WtoFireState&) def private wto_sync_active_shell(gun : WTGun const?; spec : WtoVehicleSpec const&; var fc : WtoFireState&)
@@ -111,18 +87,23 @@ def private wto_select_next_shell(var gun : WTGun?; spec : WtoVehicleSpec const&
[never_inline] [never_inline]
def private wto_inspect_primary_weapon(var unit : Unit?; now : float; def private wto_inspect_primary_weapon(var unit : Unit?; now : float;
spec : WtoVehicleSpec const&; wantSoftShell : bool; spec : WtoVehicleSpec const&; wantSoftShell : bool;
var fc : WtoFireState&) var fc : WtoFireState&) : int
let previousTurret = fc.turretNo
fc.turretNo = -1 fc.turretNo = -1
fc.gunReady = false fc.gunReady = false
fc.reloading = false fc.reloading = false
fc.gunDamaged = false fc.gunDamaged = false
if unit == null || unit.weap == null if unit == null || unit.weap == null
return return -1
var selected = -1
var nextIndex = 0
var anyGun = false var anyGun = false
var anyAlive = false var anyAlive = false
var anyReserve = false var anyReserve = false
var totalLoaded = 0 var totalLoaded = 0
foreach_primary_gun(unit.weap.Weapons) <| $(var weapon) foreach_primary_gun(unit.weap.Weapons) <| $(var weapon)
let index = nextIndex
nextIndex++
if weapon == null || weapon.isDummyGun if weapon == null || weapon.isDummyGun
return return
var gun = as_gun(weapon) var gun = as_gun(weapon)
@@ -131,7 +112,8 @@ def private wto_inspect_primary_weapon(var unit : Unit?; now : float;
anyGun = true anyGun = true
anyAlive = true anyAlive = true
anyReserve = true anyReserve = true
if fc.turretNo < 0 if selected < 0
selected = index
fc.turretNo = weapon.turretNo fc.turretNo = weapon.turretNo
fc.gunReady = true fc.gunReady = true
totalLoaded += weapon.countBullets totalLoaded += weapon.countBullets
@@ -140,8 +122,11 @@ def private wto_inspect_primary_weapon(var unit : Unit?; now : float;
if gun.isInoperable if gun.isInoperable
return return
anyAlive = true anyAlive = true
if fc.turretNo < 0 if selected < 0
selected = index
fc.turretNo = weapon.turretNo fc.turretNo = weapon.turretNo
if fc.turretNo != previousTurret
fc.loadedBulletIdx = -1
wto_select_next_shell(gun, spec, wantSoftShell) wto_select_next_shell(gun, spec, wantSoftShell)
wto_sync_active_shell(gun, spec, fc) wto_sync_active_shell(gun, spec, fc)
if gun.isReadyToShoot if gun.isReadyToShoot
@@ -158,6 +143,7 @@ def private wto_inspect_primary_weapon(var unit : Unit?; now : float;
elif (now - fc.pendingShotAt) > 0.35 elif (now - fc.pendingShotAt) > 0.35
fc.pendingShotConfirm = false fc.pendingShotConfirm = false
fc.prevLoadedAmmo = totalLoaded fc.prevLoadedAmmo = totalLoaded
return selected
[never_inline] [never_inline]
def private wto_solve_ballistic_aim(muzzlePos, myVel : float3; var slot : WtoBotSlot&; def private wto_solve_ballistic_aim(muzzlePos, myVel : float3; var slot : WtoBotSlot&;
@@ -178,63 +164,24 @@ def private wto_solve_ballistic_aim(muzzlePos, myVel : float3; var slot : WtoBot
return rawDist return rawDist
[never_inline] [never_inline]
def private wto_sample_turret_muzzle(unit : Unit const?; turretNo : int; def private wto_sample_muzzle(unit : Unit const?; primaryIndex : int;
var outPos, outDir : float3&) : bool var outPos, outDir : float3&) : bool
if unit == null || unit.weap == null if unit == null || unit.weap == null || primaryIndex < 0
return false return false
for tIdx, turret in iter_range(unit.weap.turret), unit.weap.turret var sampled = false
if (turretNo >= 0 && tIdx != turretNo) || (turretNo < 0 && int(turret.triggerGroupNo) != int(WeaponTriggerGroups.TRIGGER_GROUP_PRIMARY)) get_weapons_by_trigger_group(unit.weap.Weapons, WeaponTriggerGroups.TRIGGER_GROUP_PRIMARY) <| $(weapons : array<Weapon const? const> const#)
continue if primaryIndex >= length(weapons)
let weapon = get_weapon(unit.weap.Weapons, int(turret.triggerNo), int(turret.weaponIndex)) return
assume weapon = weapons[primaryIndex]
if weapon == null if weapon == null
continue return
var gunTm : float3x4 var gunTm : float3x4
weapon_calcShootTm(weapon, unit.unitTm, gunTm) weapon_calcShootTm(weapon, unit.unitTm, gunTm)
if length_sq(gunTm[0]) > 0.25 if length_sq(gunTm[0]) > 0.25
outPos = gunTm[3] outPos = gunTm[3]
outDir = normalize(gunTm[0]) outDir = normalize(gunTm[0])
return true sampled = true
return false return sampled
[never_inline]
def private wto_drive_turret_and_sample_barrel(var unit : Unit?; dt : float;
wishYawDeg, wishPitchDeg : float;
var slot : WtoBotSlot&;
var outMuzzlePos, outLiveDir : float3&)
assume fc = slot.fire
let dtStep = clamp(dt, 0.005, 0.12)
for tIdx, turret in iter_range(unit.weap.turret), unit.weap.turret
if (fc.turretNo >= 0 && tIdx != fc.turretNo) || (fc.turretNo < 0 && int(turret.triggerGroupNo) != int(WeaponTriggerGroups.TRIGGER_GROUP_PRIMARY))
continue
fc.curYawDeg = turret.currentState.yaw
fc.curPitchDeg = turret.currentState.pitch
if !fc.servoInit
fc.cmdYawDeg = fc.curYawDeg
fc.cmdPitchDeg = fc.curPitchDeg
fc.prevPitchDeg = fc.curPitchDeg
fc.servoInit = true
let pitchSpd = abs(fc.curPitchDeg - fc.prevPitchDeg) / dtStep
fc.prevPitchDeg = fc.curPitchDeg
if slot.perceive.hasClearLos && wishPitchDeg < fc.curPitchDeg - 2.3 && pitchSpd < 0.8
fc.pitchClampSec = min(2.0, fc.pitchClampSec + dtStep)
fc.pitchBlocked = fc.pitchClampSec >= 0.75
else
fc.pitchClampSec = max(0.0, fc.pitchClampSec - dtStep * 2.5)
if fc.pitchClampSec <= 0.05
fc.pitchBlocked = false
let maxYawStep = max(24.0, slot.spec.turretYawSpd * 1.1) * dtStep
let maxPitchStep = max(10.0, slot.spec.turretPitchSpd * 1.1) * dtStep
let yawDelta = clamp(wto_wrap_deg(wishYawDeg - fc.curYawDeg), -maxYawStep, maxYawStep)
let pitchDelta = clamp(wishPitchDeg - fc.curPitchDeg, -maxPitchStep, maxPitchStep)
fc.cmdYawDeg = wto_wrap_deg(fc.curYawDeg + yawDelta)
fc.cmdPitchDeg = clamp(fc.curPitchDeg + pitchDelta, slot.spec.minPitchDeg - 2.0, slot.spec.maxPitchDeg + 2.0)
turret.yawLim = fc.cmdYawDeg
turret.pitchLim = fc.cmdPitchDeg
break
var uPos = unit.pos
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])
def private wto_clear_aim_tracking(var fc : WtoFireState&) def private wto_clear_aim_tracking(var fc : WtoFireState&)
fc.aimTargetEid = INVALID_ENTITY_ID fc.aimTargetEid = INVALID_ENTITY_ID
@@ -244,12 +191,13 @@ def private wto_clear_aim_tracking(var fc : WtoFireState&)
fc.lastDenyReason = WTO_DENY_NO_TARGET fc.lastDenyReason = WTO_DENY_NO_TARGET
[never_inline] [never_inline]
def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?; def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?; className : string;
now, dt : float; var slot : WtoBotSlot&; var fireBudget : int&) now, dt : float; var slot : WtoBotSlot&; var fireBudget : int&)
if !WTO_AI_LAYER_FIRE_CONTROL || unit == null || unit.weap == null if !WTO_AI_LAYER_FIRE_CONTROL || unit == null || unit.weap == null
return return
// SPAA vs aircraft only delegates to stock air-target fire control (never ground targets). // SPAA vs aircraft only delegates to stock air-target fire control (never ground targets).
if slot.tactics.spaaYieldAir if slot.tactics.spaaYieldAir
wto_set_hull_aim(unit, false, 0.0, unit.unitTm[0], slot)
wto_clear_aim_tracking(slot.fire) wto_clear_aim_tracking(slot.fire)
var gm = as_gm(unit) var gm = as_gm(unit)
if gm != null if gm != null
@@ -263,10 +211,10 @@ def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?;
let tgtIdx = wto_world_find_unit(world, slot.perceive.targetEid) let tgtIdx = wto_world_find_unit(world, slot.perceive.targetEid)
if tgtIdx >= 0 if tgtIdx >= 0
wantSoftShell = world.units[tgtIdx].isLightTag || world.units[tgtIdx].halfWid < 1.35 wantSoftShell = world.units[tgtIdx].isLightTag || world.units[tgtIdx].halfWid < 1.35
wto_inspect_primary_weapon(unit, now, slot.spec, wantSoftShell, slot.fire) let primaryIndex = wto_inspect_primary_weapon(unit, now, slot.spec, wantSoftShell, slot.fire)
var muzzlePos = unit.pos + float3(0.0, 1.95, 0.0) var muzzlePos = unit.pos + float3(0.0, 1.95, 0.0)
var liveBarrelDir = unit.unitTm[0] var liveBarrelDir = unit.unitTm[0]
let _preSample = wto_sample_turret_muzzle(unit, slot.fire.turretNo, muzzlePos, liveBarrelDir) let _preSample = wto_sample_muzzle(unit, primaryIndex, muzzlePos, liveBarrelDir)
let hFwd = unit.unitTm[0] let hFwd = unit.unitTm[0]
var wishWorldDir = hFwd var wishWorldDir = hFwd
@@ -287,8 +235,10 @@ def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?;
var wishYaw = 0.0 var wishYaw = 0.0
var wishPitch = 0.0 var wishPitch = 0.0
wto_world_to_hull_deg(wishWorldDir, hFwd, unit.unitTm[1], unit.unitTm[2], wishYaw, wishPitch) wto_world_to_hull_deg(wishWorldDir, hFwd, unit.unitTm[1], unit.unitTm[2], wishYaw, wishPitch)
wto_drive_turret_and_sample_barrel(unit, dt, wishYaw, wishPitch, slot, muzzlePos, liveBarrelDir) wto_drive_mounted_gun(unit, className, dt, wishYaw, wishPitch, slot)
if !engageValid || distToTgt > WTO_AI_FC_MAX_RANGE_M let canEngage = engageValid && distToTgt <= WTO_AI_FC_MAX_RANGE_M && wto_sample_muzzle(unit, primaryIndex, muzzlePos, liveBarrelDir)
wto_set_hull_aim(unit, canEngage, wishYaw, liveBarrelDir, slot)
if !canEngage
wto_clear_aim_tracking(slot.fire) wto_clear_aim_tracking(slot.fire)
return return
let distXZ = sqrt(wto_xz_dist_sq(unit.pos, slot.perceive.knownPos)) let distXZ = sqrt(wto_xz_dist_sq(unit.pos, slot.perceive.knownPos))
+5 -2
View File
@@ -186,12 +186,15 @@ def public wto_fire_gate_try_shoot(world : WtoWorldSnap const&; var unit : Unit?
let speedOk = measuredSpeed <= speedLimit let speedOk = measuredSpeed <= speedLimit
let close = distXZ <= WTO_AI_FC_CLOSE_RANGE_M 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) 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 withinTraverse = fc.hullAimTarget == INVALID_ENTITY_ID
wto_gate_track_aim(now, liveDir - wishDir, slot.perceive.targetEid, withinTraverse && aimErrDeg <= allowErrDeg && speedOk, close, fc)
let minCadence = slot.spec.isAutocannonBelt ? 0.12 : 0.65 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 let reqHold = close ? WTO_AI_FC_CLOSE_SETTLE_HOLD_SEC : WTO_AI_FC_SETTLE_HOLD_SEC
var deny = WTO_DENY_OK var deny = WTO_DENY_OK
if !fc.gunReady || (now - fc.lastShotAt) < minCadence if !withinTraverse
deny = WTO_DENY_TRAVERSE
elif !fc.gunReady || (now - fc.lastShotAt) < minCadence
deny = WTO_DENY_NOT_READY deny = WTO_DENY_NOT_READY
elif !speedOk elif !speedOk
deny = WTO_DENY_SPEED deny = WTO_DENY_SPEED
+16 -11
View File
@@ -12,6 +12,7 @@ require math
require %appGame.wtoai.wto_ai_config_common require %appGame.wtoai.wto_ai_config_common
require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_math_common
require %appGame.wtoai.wto_ai_types_common require %appGame.wtoai.wto_ai_types_common
require %appGame.wtoai.wto_ai_drive_common
require %appGame.wtoai.wto_ai_terrain_common require %appGame.wtoai.wto_ai_terrain_common
require %appGame.wtoai.wto_ai_world_common require %appGame.wtoai.wto_ai_world_common
require %appGame.wtoai.wto_ai_crowd_common require %appGame.wtoai.wto_ai_crowd_common
@@ -155,16 +156,17 @@ def private wto_set_drive_cmd(var cmd : WtoDriveCmd&; mode : int; targetPos, des
cmd.rearClearM = rearClr cmd.rearClearM = rearClr
[never_inline] [never_inline]
def private wto_handle_stationary_engage(myPos, hullFwd : float3; var slot : WtoBotSlot&) def private wto_try_hull_aim(myPos, hullFwd : float3; var slot : WtoBotSlot&) : bool
// Casemate / limited-traverse TDs rotate hull ONLY while target is outside 78% of gun arc. let state = slot.tactics.state
if slot.spec.isLimitedTraverse && !!slot.perceive.targetEid if state != WTO_STATE_MARCH && state != WTO_STATE_RUN_AND_GUN && state != WTO_STATE_PREAIM && state != WTO_STATE_SHORT_HALT
let toTgt = wto_xz_normalize(slot.perceive.knownPos - myPos, hullFwd) return false
let angDeg = acos(clamp(dot(toTgt, hullFwd), -1.0, 1.0)) * WTO_RAD_TO_DEG if !slot.fire.hullAimTarget || slot.fire.hullAimTarget != slot.perceive.targetEid || slot.tactics.immobilized
if angDeg > slot.spec.yawLimitDeg * 0.78 return false
wto_set_drive_cmd(slot.driveCmd, WTO_DRIVE_PIVOT, myPos + toTgt * 18.0, toTgt, 2.0, slot.nav.frontClearM, slot.nav.rearClearM) if wto_pivot_drive_mode(slot.spec, slot.nav.frontClearM, slot.nav.rearClearM, true) == WTO_DRIVE_HALT
return return false
// Turreted tanks (and aligned TDs) hold chassis completely still so barrel settles cleanly! let direction = wto_xz_normalize(slot.fire.hullAimDir, hullFwd)
wto_set_drive_cmd(slot.driveCmd, WTO_DRIVE_HALT, myPos, hullFwd, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) wto_set_drive_cmd(slot.driveCmd, WTO_DRIVE_PIVOT, myPos, direction, 0.0, slot.nav.frontClearM, slot.nav.rearClearM)
return true
[never_inline] [never_inline]
def private wto_check_stuck_watchdog(var world : WtoWorldSnap&; now : float; def private wto_check_stuck_watchdog(var world : WtoWorldSnap&; now : float;
@@ -230,9 +232,12 @@ def public wto_nav_update(var world : WtoWorldSnap&; now : float;
else else
wto_set_drive_cmd(slot.driveCmd, WTO_DRIVE_HALT, myPos, hullFwd, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) wto_set_drive_cmd(slot.driveCmd, WTO_DRIVE_HALT, myPos, hullFwd, 0.0, slot.nav.frontClearM, slot.nav.rearClearM)
return return
if wto_try_hull_aim(myPos, hullFwd, slot)
slot.nav.stuckCheckAt = now + WTO_AI_NAV_STUCK_WINDOW_SEC
return
if slot.tactics.state == WTO_STATE_SHORT_HALT || slot.tactics.state == WTO_STATE_COVER_RELOAD || slot.tactics.desiredSpeedMps <= 0.05 if slot.tactics.state == WTO_STATE_SHORT_HALT || slot.tactics.state == WTO_STATE_COVER_RELOAD || slot.tactics.desiredSpeedMps <= 0.05
slot.nav.stuckCheckAt = now + WTO_AI_NAV_STUCK_WINDOW_SEC slot.nav.stuckCheckAt = now + WTO_AI_NAV_STUCK_WINDOW_SEC
wto_handle_stationary_engage(myPos, hullFwd, slot) wto_set_drive_cmd(slot.driveCmd, WTO_DRIVE_HALT, myPos, hullFwd, 0.0, slot.nav.frontClearM, slot.nav.rearClearM)
return return
if wto_try_reverse_drive(world, now, myPos, hullFwd, slot) if wto_try_reverse_drive(world, now, myPos, hullFwd, slot)
return return
+1 -1
View File
@@ -268,10 +268,10 @@ def wto_ai_pipeline_es(act : UpdateStageInfoAct; eid : EntityId; var unit__ref :
if WTO_AI_LAYER_TACTICS || WTO_AI_LAYER_FIRE_CONTROL if WTO_AI_LAYER_TACTICS || WTO_AI_LAYER_FIRE_CONTROL
wto_perceive_update(g_world, now, WTO_AI_TACTICS_TICK_SEC, unit.pos, unit.unitTm[0], slot) wto_perceive_update(g_world, now, WTO_AI_TACTICS_TICK_SEC, unit.pos, unit.unitTm[0], slot)
wto_tactics_update(g_world, now, WTO_AI_TACTICS_TICK_SEC, unit.pos, unit.unitTm[0], unit.isBurn, repair_system_remaining_repair_time, slot, g_crowd) wto_tactics_update(g_world, now, WTO_AI_TACTICS_TICK_SEC, unit.pos, unit.unitTm[0], unit.isBurn, repair_system_remaining_repair_time, slot, g_crowd)
wto_fire_update(g_world, unit, unit__className, now, act.dt, slot, g_fire_budget)
if now >= slot.nextNavAt if now >= slot.nextNavAt
slot.nextNavAt = now + WTO_AI_NAV_TICK_SEC slot.nextNavAt = now + WTO_AI_NAV_TICK_SEC
wto_nav_update(g_world, now, unit.pos, unit.unitTm[0], slot) wto_nav_update(g_world, now, unit.pos, unit.unitTm[0], slot)
wto_fire_update(g_world, unit, now, act.dt, slot, g_fire_budget)
[es(tag=server, after=wto_ai_pipeline_es)] [es(tag=server, after=wto_ai_pipeline_es)]
def wto_ai_phys_tick_es(act : UpdateStageInfoAct; eid : EntityId; var unit__ref : UnitRef&; def wto_ai_phys_tick_es(act : UpdateStageInfoAct; eid : EntityId; var unit__ref : UnitRef&;
+10 -42
View File
@@ -1,6 +1,6 @@
// Authoritative per-vehicle specification loader: reads unit & weapon DataBlocks once per // Authoritative per-vehicle specification loader: reads unit & weapon DataBlocks once per
// spawned bot (`gamedata/units/<className>.blk`) to extract exact role, gun stabilizer, // spawned bot (`gamedata/units/<className>.blk`) to extract role, gun stabilizer,
// traverse limits, turret slew rates, shell muzzle velocity, and reverse speed capability. // turret slew rates, shell muzzle velocity, and chassis capabilities.
options indenting = 2 options indenting = 2
options no_global_heap = true options no_global_heap = true
module wto_ai_specs_common shared module wto_ai_specs_common shared
@@ -19,6 +19,7 @@ require %game.utils.utils_common
require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_math_common
require %appGame.wtoai.wto_ai_combat_types_common require %appGame.wtoai.wto_ai_combat_types_common
require %appGame.wtoai.wto_ai_types_common require %appGame.wtoai.wto_ai_types_common
require %appGame.wtoai.wto_ai_traverse_common
[never_inline] [never_inline]
def private wto_parse_role_strings(unitType : string; expClass : string; isLightTag : bool) : int def private wto_parse_role_strings(unitType : string; expClass : string; isLightTag : bool) : int
@@ -32,40 +33,6 @@ def private wto_parse_role_strings(unitType : string; expClass : string; isLight
return WTO_ROLE_LIGHT return WTO_ROLE_LIGHT
return WTO_ROLE_MEDIUM 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] [never_inline]
def private wto_record_shell_block(bBlk : DataBlock const&; var spec : WtoVehicleSpec&; isDefault : bool) def private wto_record_shell_block(bBlk : DataBlock const&; var spec : WtoVehicleSpec&; isDefault : bool)
let spd = bBlk |> datablock_getReal("speed", 0.0) let spd = bBlk |> datablock_getReal("speed", 0.0)
@@ -122,7 +89,7 @@ def private wto_parse_weapon_blk(weapBlkPath : string; var spec : WtoVehicleSpec
def private wto_parse_unit_blk(className : string; isLightTag : bool; var spec : WtoVehicleSpec&) : bool def private wto_parse_unit_blk(className : string; isLightTag : bool; var spec : WtoVehicleSpec&) : bool
if empty(className) if empty(className)
return false return false
let relPath = find(className, "/") >= 0 ? ("gamedata/units/" + className + ".blk") : ("gamedata/units/tankModels/" + className + ".blk") let relPath = wto_unit_model_path(className)
var loaded = false var loaded = false
datablock_load_cached(relPath, DataBlockReadFlag.ROBUST) <| $(mBlk) datablock_load_cached(relPath, DataBlockReadFlag.ROBUST) <| $(mBlk)
if mBlk.paramCount == 0u && mBlk.blockCount == 0u if mBlk.paramCount == 0u && mBlk.blockCount == 0u
@@ -137,6 +104,11 @@ def private wto_parse_unit_blk(className : string; isLightTag : bool; var spec :
spec.vMaxFwd = clamp(fwdKmh / 3.6, 4.0, 28.0) spec.vMaxFwd = clamp(fwdKmh / 3.6, 4.0, 28.0)
if revKmh > 1.0 if revKmh > 1.0
spec.vMaxRev = clamp(revKmh / 3.6, 1.0, 16.0) spec.vMaxRev = clamp(revKmh / 3.6, 1.0, 16.0)
let physBlk = mBlk |> datablock_get_block_by_name("VehiclePhys")
if physBlk != null
let mechanics = *physBlk |> datablock_get_block_by_name("mechanics")
if mechanics != null
spec.canPivot = (*mechanics |> datablock_getReal("neutralGearRatio", 0.0)) > 0.0
let commonBlk = mBlk |> datablock_get_block_by_name("commonWeapons") let commonBlk = mBlk |> datablock_get_block_by_name("commonWeapons")
if commonBlk == null if commonBlk == null
return return
@@ -156,7 +128,6 @@ def private wto_parse_unit_blk(className : string; isLightTag : bool; var spec :
let stabBlk = weapBlk |> datablock_get_block_by_name("gunStabilizer") let stabBlk = weapBlk |> datablock_get_block_by_name("gunStabilizer")
if stabBlk != null if stabBlk != null
spec.hasVertStab = *stabBlk |> datablock_getBool("hasVertical", false) 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) wto_parse_weapon_blk(wPath, spec)
return loaded return loaded
@@ -182,11 +153,8 @@ def private wto_apply_runtime_fallbacks(unit : Unit const?; gm : IGroundModel co
elif as_gun(weapon) != null elif as_gun(weapon) != null
gunCount++ gunCount++
spec.isPureLauncher = gunCount == 0 && launcherCount > 0 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 !blkLoaded
if spec.isLimitedTraverse if length(unit.weap.turret) == 0 && gunCount > 0
spec.role = WTO_ROLE_TD spec.role = WTO_ROLE_TD
elif isLightTag elif isLightTag
spec.role = WTO_ROLE_LIGHT spec.role = WTO_ROLE_LIGHT
+1 -2
View File
@@ -139,8 +139,7 @@ def private wto_sm_handle_combat(world : WtoWorldSnap const&; now : float;
let close = distXZ <= WTO_AI_FC_CLOSE_RANGE_M let close = distXZ <= WTO_AI_FC_CLOSE_RANGE_M
let urgentPush = slot.order.urgency == WTO_URGENCY_HIGH || distGoal > 130.0 let urgentPush = slot.order.urgency == WTO_URGENCY_HIGH || distGoal > 130.0
let canHalt = now >= tac.shortHaltCooldownUntil && !tac.repositionActive && wto_sm_stop_range_allowed(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 && let aimReady = (fc.gunReady && fc.aimTargetEid == slot.perceive.targetEid && fc.lastAimErrDeg <= WTO_AI_SM_PREAIM_DEG)
(fc.lastAimErrDeg <= WTO_AI_SM_PREAIM_DEG || slot.spec.isLimitedTraverse))
if marchSpd > 0.0 && (close || (distXZ <= WTO_AI_FC_MID_RANGE_M && urgentPush)) if marchSpd > 0.0 && (close || (distXZ <= WTO_AI_FC_MID_RANGE_M && urgentPush))
if wto_sm_waited_for_moving_shot(now, aimReady, slot) && canHalt 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) wto_sm_set_state(now, WTO_STATE_SHORT_HALT, myPos, 0.0, "moving_shot_halt", distXZ, slot)
+202
View File
@@ -0,0 +1,202 @@
// Mechanical angles of the selected ground weapon, read from the original mount definition.
options indenting = 2
options no_global_heap = true
module wto_ai_traverse_common shared
require ecs
require app
require math
require strings
require DagorMath
require DagorDataBlock
require Unit
require Weapon
require %game.utils.utils_common
require %appGame.wtoai.wto_ai_config_common
require %appGame.wtoai.wto_ai_math_common
require %appGame.wtoai.wto_ai_types_common
require %appGame.wtoai.wto_ai_combat_types_common
// The engine's weapon trigger parser maps "gunnerN" to N + 0x13.
let private WTO_FIRST_GUNNER_TRIGGER = int(0x13)
def public wto_unit_model_path(className : string) : string
return find(className, "/") >= 0 ? ("gamedata/units/" + className + ".blk") : ("gamedata/units/tankModels/" + className + ".blk")
def private wto_valid_angle_range(angles : float2) : bool
return wto_is_finite(angles.x) && wto_is_finite(angles.y) && angles.x <= angles.y
[never_inline]
def private wto_read_gunner_mount(className : string; triggerNo, weaponIndex : int;
readMount : block<(mount : DataBlock) : void>)
if empty(className) || triggerNo < WTO_FIRST_GUNNER_TRIGGER || weaponIndex < 0
return
let trigger = "gunner{triggerNo - WTO_FIRST_GUNNER_TRIGGER}"
datablock_load_cached(wto_unit_model_path(className), DataBlockReadFlag.ROBUST) <| $(unitBlk)
let common = unitBlk |> datablock_get_block_by_name("commonWeapons")
if common == null
return
var index = 0
datablock_for_each_block(*common, "Weapon") <| $(mount)
if (mount |> datablock_getStr("trigger", "")) != trigger
return
if index == weaponIndex && (mount |> datablock_getStr("triggerGroup", "primary")) == "primary"
invoke(readMount, mount)
index++
[never_inline]
def private wto_load_gun_traverse(className : string; triggerNo, weaponIndex : int; var traverse : WtoGunTraverse&)
traverse = WtoGunTraverse()
wto_read_gunner_mount(className, triggerNo, weaponIndex) <| $(mount)
let limits = mount |> datablock_get_block_by_name("limits")
if limits == null
return
let yaw = *limits |> datablock_getPoint2("yaw", float2(1.0, 0.0))
if !wto_valid_angle_range(yaw) || abs(yaw.x) > 360.0 || abs(yaw.y) > 360.0
return
traverse.known = true
traverse.yaw = yaw
let pitch = *limits |> datablock_getPoint2("pitch", float2(1.0, 0.0))
if wto_valid_angle_range(pitch)
traverse.pitch = pitch
let sectors = mount |> datablock_get_block_by_name("limitsTable")
traverse.hasPitchTable = sectors != null && sectors.paramCount > 0u
def private wto_full_gun_traverse(yaw : float2) : bool
return yaw.y - yaw.x >= 360.0
def private wto_yaw_in_mount_coordinates(yaw : float; arc : float2) : float
let center = (arc.x + arc.y) * 0.5
return center + wto_wrap_deg(yaw - center)
[never_inline]
def private wto_gun_pitch_at_yaw(className : string; triggerNo, weaponIndex : int; yaw : float;
var traverse : WtoGunTraverse&) : float2
if !traverse.hasPitchTable
return traverse.pitch
if yaw >= traverse.pitchSector.x && yaw < traverse.pitchSector.y
return float2(traverse.pitchSector.z, traverse.pitchSector.w)
var sector = float4(traverse.yaw.x, traverse.yaw.y, traverse.pitch.x, traverse.pitch.y)
wto_read_gunner_mount(className, triggerNo, weaponIndex) <| $(mount)
let sectors = mount |> datablock_get_block_by_name("limitsTable")
if sectors == null
return
// A DataBlock can repeat a parameter name. Read each sector by its original index.
for index in 0u..sectors.paramCount
if (*sectors |> datablock_getParamType(index)) != int(DataBlockParamType.TYPE_POINT4)
continue
let entry = *sectors |> datablock_getPoint4(int(index))
if !wto_valid_angle_range(float2(entry.x, entry.y)) || !wto_valid_angle_range(float2(entry.z, entry.w))
continue
if yaw < entry.x
sector.y = min(sector.y, entry.x)
elif yaw > entry.y
sector.x = max(sector.x, entry.y)
else
sector = entry
break
traverse.pitchSector = sector
return float2(sector.z, sector.w)
[never_inline]
def public wto_world_to_hull_deg(worldDir, hullFwd, hullUp, hullLeft : float3;
var outYawDeg, outPitchDeg : float&)
let len = length(worldDir)
if !wto_is_finite3(worldDir) || len < 1.0e-5
outYawDeg = 0.0
outPitchDeg = 0.0
return
let d = worldDir / len
let f = dot(d, hullFwd)
let u = dot(d, hullUp)
let l = dot(d, hullLeft)
let horiz = sqrt(f * f + l * l)
outYawDeg = horiz > 1.0e-5 ? (-atan2(l, f) * WTO_RAD_TO_DEG) : 0.0
outPitchDeg = atan2(u, max(1.0e-5, horiz)) * WTO_RAD_TO_DEG
[never_inline]
def private wto_hull_deg_to_world(yawDeg, pitchDeg : float; hullFwd, hullUp, hullLeft : float3) : float3
let yr = yawDeg * WTO_DEG_TO_RAD
let pr = pitchDeg * WTO_DEG_TO_RAD
let cp = cos(pr)
let dir = hullFwd * (cp * cos(yr)) - hullLeft * (cp * sin(yr)) + hullUp * sin(pr)
let l = length(dir)
return l > 1.0e-5 ? (dir / l) : hullFwd
def private wto_step_mounted_yaw(current, desired, step : float; arc : float2) : float
if wto_full_gun_traverse(arc)
return wto_wrap_deg(current + clamp(wto_wrap_deg(desired - current), -step, step))
let clampedCurrent = clamp(wto_yaw_in_mount_coordinates(current, arc), arc.x, arc.y)
let clampedTarget = clamp(wto_yaw_in_mount_coordinates(desired, arc), arc.x, arc.y)
return clamp(clampedCurrent + clamp(clampedTarget - clampedCurrent, -step, step), arc.x, arc.y)
def private wto_track_blocked_pitch(wishPitchDeg, dtStep : float; var slot : WtoBotSlot&)
assume fc = slot.fire
let pitchSpd = abs(fc.curPitchDeg - fc.prevPitchDeg) / dtStep
fc.prevPitchDeg = fc.curPitchDeg
if slot.perceive.hasClearLos && wishPitchDeg < fc.curPitchDeg - 2.3 && pitchSpd < 0.8
fc.pitchClampSec = min(2.0, fc.pitchClampSec + dtStep)
fc.pitchBlocked = fc.pitchClampSec >= 0.75
else
fc.pitchClampSec = max(0.0, fc.pitchClampSec - dtStep * 2.5)
if fc.pitchClampSec <= 0.05
fc.pitchBlocked = false
[never_inline]
def public wto_drive_mounted_gun(var unit : Unit?; className : string; dt : float;
wishYawDeg, wishPitchDeg : float; var slot : WtoBotSlot&)
assume fc = slot.fire
let dtStep = clamp(dt, 0.005, 0.12)
if fc.traverseTurretNo != fc.turretNo
fc.traverseTurretNo = fc.turretNo
fc.traverse = WtoGunTraverse()
fc.servoInit = false
fc.pitchBlocked = false
fc.pitchClampSec = 0.0
for tIdx, turret in iter_range(unit.weap.turret), unit.weap.turret
if tIdx != fc.turretNo
continue
let triggerNo = int(turret.triggerNo)
let weaponIndex = int(turret.weaponIndex)
if !fc.servoInit
wto_load_gun_traverse(className, triggerNo, weaponIndex, fc.traverse)
fc.prevPitchDeg = turret.currentState.pitch
fc.servoInit = true
fc.curYawDeg = turret.currentState.yaw
fc.curPitchDeg = turret.currentState.pitch
if !fc.traverse.known
return
wto_track_blocked_pitch(wishPitchDeg, dtStep, slot)
let yaw = fc.traverse.yaw
let maxYawStep = max(24.0, slot.spec.turretYawSpd * 1.1) * dtStep
let cmdYaw = wto_step_mounted_yaw(fc.curYawDeg, wishYawDeg, maxYawStep, yaw)
let maxPitchStep = max(10.0, slot.spec.turretPitchSpd * 1.1) * dtStep
let pitch = wto_gun_pitch_at_yaw(className, triggerNo, weaponIndex, cmdYaw, fc.traverse)
turret.yawLim = cmdYaw
if pitch.x <= pitch.y
let pitchDelta = clamp(wishPitchDeg - fc.curPitchDeg, -maxPitchStep, maxPitchStep)
turret.pitchLim = clamp(fc.curPitchDeg + pitchDelta, pitch.x, pitch.y)
break
if fc.traverse.known
var uPos = unit.pos
updateWeaponAnims(*unit.weap, dtStep, 1.0, uPos)
def public wto_set_hull_aim(unit : Unit const?; active : bool; wishYaw : float; liveBarrelDir : float3;
var slot : WtoBotSlot&)
assume fc = slot.fire
var target = INVALID_ENTITY_ID
if active
var arc = fc.traverse.yaw
if !fc.traverse.known
var fixedYaw, pitch : float
wto_world_to_hull_deg(liveBarrelDir, unit.unitTm[0], unit.unitTm[1], unit.unitTm[2], fixedYaw, pitch)
arc = float2(fixedYaw, fixedYaw)
let aimYaw = wto_yaw_in_mount_coordinates(wishYaw, arc)
let tolerance = arc.x == arc.y ? WTO_AI_FC_BASE_ALIGN_DEG : 0.0
if !wto_full_gun_traverse(arc) && (aimYaw < arc.x - tolerance || aimYaw > arc.y + tolerance)
target = slot.perceive.targetEid
let yawToTurn = wto_wrap_deg(wishYaw - (arc.x + arc.y) * 0.5)
fc.hullAimDir = wto_hull_deg_to_world(yawToTurn, 0.0, unit.unitTm[0], unit.unitTm[1], unit.unitTm[2])
if target != fc.hullAimTarget
slot.nextNavAt = 0.0
fc.hullAimTarget = target
-4
View File
@@ -45,10 +45,6 @@ struct public WtoVehicleSpec
ready : bool = false ready : bool = false
role : int = 0 role : int = 0
hasVertStab : bool = false hasVertStab : bool = false
isLimitedTraverse : bool = false
yawLimitDeg : float = 180.0
minPitchDeg : float = -8.0
maxPitchDeg : float = 22.0
turretYawSpd : float = 24.0 turretYawSpd : float = 24.0
turretPitchSpd : float = 8.0 turretPitchSpd : float = 8.0
muzzleSpeedMps : float = 880.0 muzzleSpeedMps : float = 880.0