Files
WT-Offline/game-ai/ground/wto_ai_math_common.das
T
N0VAN0M4LY 975a28441a feat(ground-ai): implement modular zero-heap tank AI daScript layers
Add 14 modular daScript files under game-ai/ground covering per-vehicle
DataBlock specs, foliage-filtered terrain and cliff crest lookahead,
flat world snapshots, anti-clustering telemetry and active dispersion,
cap-insider-bounded macro scheduling, sticky 6-channel perception,
ridge snipe/reverse withdraw tactics, wide-projected NavMesh routing,
bidirectional forward/reverse DWA local planning, closed-loop
VehiclePhys chassis control, and settled ballistic fire control.
2026-12-03 12:12:17 +08:00

58 lines
1.5 KiB
Plaintext

// Pure zero-heap scalar, angle, and XZ plane math helpers for WTOffline's ground AI modules.
options indenting = 2
options no_global_heap = true
module wto_ai_math_common shared
require math
let public WTO_PI = 3.14159265
let public WTO_RAD_TO_DEG = 57.29577951
let public WTO_DEG_TO_RAD = 0.01745329
def public wto_sq(x : float) : float
return x * x
def public wto_is_finite(x : float) : bool
return x == x && x > -1.0e20 && x < 1.0e20
def public wto_is_finite3(v : float3) : bool
return wto_is_finite(v.x) && wto_is_finite(v.y) && wto_is_finite(v.z)
def public wto_xz_dist_sq(a, b : float3) : float
return wto_sq(a.x - b.x) + wto_sq(a.z - b.z)
def public wto_xz_len(v : float3) : float
return sqrt(v.x * v.x + v.z * v.z)
def public wto_xz_normalize(v, fallback : float3) : float3
let l = sqrt(v.x * v.x + v.z * v.z)
return l > 1.0e-4 ? float3(v.x / l, 0.0, v.z / l) : fallback
def public wto_wrap_rad(angle : float) : float
var a = angle
while a > WTO_PI
a -= 2.0 * WTO_PI
while a < -WTO_PI
a += 2.0 * WTO_PI
return a
def public wto_wrap_deg(angle : float) : float
var a = angle
while a > 180.0
a -= 360.0
while a < -180.0
a += 360.0
return a
def public wto_clamp_battle_xz(pos, center : float3; radius, margin : float) : float3
if radius <= margin + 10.0
return pos
let maxR = radius - margin
let dx = pos.x - center.x
let dz = pos.z - center.z
let dSq = dx * dx + dz * dz
if dSq <= maxR * maxR
return pos
let s = maxR / max(1.0, sqrt(dSq))
return float3(center.x + dx * s, pos.y, center.z + dz * s)