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.
129 lines
5.5 KiB
Plaintext
129 lines
5.5 KiB
Plaintext
// Anti-clustering telemetry & active dispersion solver: measures local friendly density around
|
|
// every tracked bot, updates match-wide crowd statistics for `.clog`, and computes drivable
|
|
// lateral/oblique dispersion anchors whenever allies bunch up.
|
|
options indenting = 2
|
|
options no_global_heap = true
|
|
module wto_ai_crowd_common shared
|
|
|
|
require ecs
|
|
require math
|
|
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_terrain_common
|
|
require %appGame.wtoai.wto_ai_world_common
|
|
|
|
[never_inline]
|
|
def public wto_crowd_point_penalty(world : WtoWorldSnap const&; army : int; selfEid : EntityId;
|
|
pt : float3) : float
|
|
let rad = max(12.0, WTO_AI_CROWD_CLUSTER_RADIUS_M)
|
|
let radSq = rad * rad
|
|
var pen = 0.0
|
|
for i in range(world.unitCount)
|
|
assume u = world.units[i]
|
|
if !u.isAlive || !u.isGround || u.army != army || u.eid == selfEid
|
|
continue
|
|
let dSq = wto_xz_dist_sq(pt, u.pos)
|
|
if dSq < radSq
|
|
let d = sqrt(dSq)
|
|
pen += (1.0 - d / rad) * 24.0
|
|
if d < WTO_AI_CROWD_PERSONAL_SPACE_M
|
|
pen += (WTO_AI_CROWD_PERSONAL_SPACE_M - d) * 4.5
|
|
return pen
|
|
|
|
[never_inline]
|
|
def private wto_eval_bot_crowd(world : WtoWorldSnap const&; myPos : float3; mySpeed : float;
|
|
slot : WtoBotSlot const&; var outInfo : WtoCrowdInfo&)
|
|
outInfo = WtoCrowdInfo()
|
|
let personalSq = wto_sq(WTO_AI_CROWD_PERSONAL_SPACE_M)
|
|
let clusterSq = wto_sq(WTO_AI_CROWD_CLUSTER_RADIUS_M)
|
|
var repulse = float3(0.0, 0.0, 0.0)
|
|
var nearestSpeed = 0.0
|
|
var higherPriorityAllies = 0
|
|
for i in range(world.unitCount)
|
|
assume u = world.units[i]
|
|
if !u.isAlive || !u.isGround || u.army != slot.army || u.eid == slot.eid
|
|
continue
|
|
let dSq = wto_xz_dist_sq(myPos, u.pos)
|
|
if dSq >= clusterSq
|
|
continue
|
|
let d = max(0.5, sqrt(dSq))
|
|
outInfo.clusterAllyCount++
|
|
if u.isHuman || uint(u.eid) < uint(slot.eid)
|
|
higherPriorityAllies++
|
|
if d < outInfo.nearestAllyDistM
|
|
outInfo.nearestAllyDistM = d
|
|
outInfo.nearestAllyEid = u.eid
|
|
nearestSpeed = wto_xz_len(u.vel)
|
|
if dSq <= personalSq
|
|
outInfo.nearPersonalCount++
|
|
let away = wto_xz_normalize(myPos - u.pos, float3(1.0, 0.0, 0.0))
|
|
let w = clamp((WTO_AI_CROWD_CLUSTER_RADIUS_M - d) / max(4.0, d), 0.15, 6.0)
|
|
repulse += away * w
|
|
let hashYaw = float(int(uint(slot.eid) % 7u) - 3) * 0.45
|
|
let fallbackDir = float3(cos(hashYaw), 0.0, sin(hashYaw))
|
|
outInfo.repulseDirXZ = wto_xz_normalize(repulse, fallbackDir)
|
|
// Trigger dispersion when personal space is violated (yielding to human or lower-eid leader,
|
|
// or whenever both tanks are nearly parked) OR when local cluster exceeds max allies.
|
|
let yieldPair = higherPriorityAllies > 0 || (mySpeed < 1.5 && nearestSpeed < 1.5)
|
|
if outInfo.nearPersonalCount > 0 && yieldPair
|
|
outInfo.isCrowded = true
|
|
elif outInfo.clusterAllyCount >= WTO_AI_CROWD_CLUSTER_MAX_ALLIES && higherPriorityAllies >= 1
|
|
outInfo.isCrowded = true
|
|
|
|
[never_inline]
|
|
def public wto_crowd_update_all(world : WtoWorldSnap const&; var bots : WtoBotSlot[64]&;
|
|
var summary : WtoCrowdSummary&)
|
|
summary.crowdedBotCount = 0
|
|
summary.maxClusterSize = 1
|
|
summary.minPairDistM = 999.0
|
|
for i in range(WTO_MAX_BOTS)
|
|
if !bots[i].used
|
|
continue
|
|
let uIdx = wto_world_find_unit(world, bots[i].eid)
|
|
if uIdx < 0
|
|
bots[i].crowd = WtoCrowdInfo()
|
|
continue
|
|
let myPos = world.units[uIdx].pos
|
|
let mySpd = wto_xz_len(world.units[uIdx].vel)
|
|
wto_eval_bot_crowd(world, myPos, mySpd, bots[i], bots[i].crowd)
|
|
if bots[i].crowd.isCrowded
|
|
summary.crowdedBotCount++
|
|
summary.maxClusterSize = max(summary.maxClusterSize, bots[i].crowd.clusterAllyCount + 1)
|
|
summary.minPairDistM = min(summary.minPairDistM, bots[i].crowd.nearestAllyDistM)
|
|
|
|
// Pick a drivable dispersion target 22..34m laterally/away from the cluster that maximizes
|
|
// spacing from teammates without stepping onto a cliff or into enemy spawn.
|
|
[never_inline]
|
|
def public wto_crowd_pick_disperse_pos(world : WtoWorldSnap const&; army : int; selfEid : EntityId;
|
|
myPos, threatDirXZ : float3; crowd : WtoCrowdInfo const&) : float3
|
|
let fwd = wto_xz_normalize(threatDirXZ, float3(1.0, 0.0, 0.0))
|
|
let lat = float3(-fwd.z, 0.0, fwd.x)
|
|
let rep = wto_xz_normalize(crowd.repulseDirXZ, lat)
|
|
let baseYaw = atan2(rep.z, rep.x)
|
|
let stepM = WTO_AI_CROWD_DISPERSE_STEP_M
|
|
let sideBias = (uint(selfEid) & 1u) == 0u ? 1.0 : -1.0
|
|
var bestPos = myPos + rep * stepM
|
|
var bestScore = -1.0e9
|
|
for k in range(8)
|
|
let angOff = float(k - 3) * 0.52 * sideBias
|
|
let candYaw = baseYaw + angOff
|
|
let dir = float3(cos(candYaw), 0.0, sin(candYaw))
|
|
var cand = float3(myPos.x + dir.x * stepM, myPos.y, myPos.z + dir.z * stepM)
|
|
cand = wto_clamp_battle_xz(cand, world.battleCenter, world.battleRadius, 35.0)
|
|
if !wto_terrain_point_valid(army, cand)
|
|
continue
|
|
if wto_terrain_has_cliff_ahead(myPos, dir, min(stepM, 18.0))
|
|
continue
|
|
if wto_terrain_hard_ray(myPos + float3(0.0, 1.3, 0.0), dir, min(stepM, 16.0)) < 9.0
|
|
continue
|
|
// Prefer lateral dispersion over pushing blindly forward into enemy guns.
|
|
let fwdProj = dot(dir, fwd)
|
|
let repAlign = dot(dir, rep) * 14.0
|
|
let latBonus = (1.0 - abs(fwdProj)) * 12.0 - max(0.0, fwdProj) * 8.0
|
|
let score = repAlign + latBonus - wto_crowd_point_penalty(world, army, selfEid, cand)
|
|
if score > bestScore
|
|
bestScore = score
|
|
bestPos = cand
|
|
return bestPos
|