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.
182 lines
8.1 KiB
Plaintext
182 lines
8.1 KiB
Plaintext
// Team-level macro objective scheduler: monotone opening lateral lane split, capture-circle
|
|
// insider cap (`capMaxInsiders`) with dispersed flank overwatch anchors outside the circle,
|
|
// bounded recapture response, death-zone caution, SPAA rear anchor, and enemy spawn avoidance.
|
|
options indenting = 2
|
|
options no_global_heap = true
|
|
module wto_ai_macro_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 private wto_death_zone_kills(world : WtoWorldSnap const&; army : int; pos : float3; now : float) : int
|
|
let radSq = wto_sq(WTO_AI_MACRO_DEATH_ZONE_RAD_M)
|
|
var kills = 0
|
|
for i in range(WTO_MAX_DEATHS)
|
|
assume d = world.deaths[i]
|
|
if d.army == army && (now - d.at) <= WTO_AI_MACRO_DEATH_ZONE_TTL_SEC && wto_xz_dist_sq(pos, d.pos) <= radSq
|
|
kills++
|
|
return kills
|
|
|
|
[never_inline]
|
|
def private wto_clamp_away_enemy_spawn(world : WtoWorldSnap const&; army : int; pos : float3) : float3
|
|
let enemyArmy = army == 1 ? 2 : 1
|
|
if enemyArmy < 1 || enemyArmy > 2 || !world.teamSpawnValid[enemyArmy]
|
|
return pos
|
|
let eSpawn = world.teamSpawnCenter[enemyArmy]
|
|
let minDist = WTO_AI_MACRO_ENEMY_SPAWN_AVOID_M
|
|
let dSq = wto_xz_dist_sq(pos, eSpawn)
|
|
if dSq >= minDist * minDist
|
|
return pos
|
|
let away = wto_xz_normalize(pos - eSpawn, float3(1.0, 0.0, 0.0))
|
|
return float3(eSpawn.x + away.x * minDist, pos.y, eSpawn.z + away.z * minDist)
|
|
|
|
[never_inline]
|
|
def private wto_pick_cap_anchor(world : WtoWorldSnap const&; army : int; eid : EntityId;
|
|
capIdx : int; outsideOverwatch : bool) : float3
|
|
assume cap = world.caps[capIdx]
|
|
let h = uint(eid)
|
|
let friendlySpawn = world.teamSpawnValid[army] ? world.teamSpawnCenter[army] : world.battleCenter
|
|
let toCap = wto_xz_normalize(cap.center - friendlySpawn, float3(1.0, 0.0, 0.0))
|
|
let lat = float3(-toCap.z, 0.0, toCap.x)
|
|
if !outsideOverwatch
|
|
let slotAng = float(h % 5u) * (2.0 * WTO_PI / 5.0) + float(capIdx) * 0.7
|
|
let inRad = clamp(cap.radius * 0.52, 7.0, max(8.0, cap.radius - 4.5))
|
|
var insidePt = float3(cap.center.x + cos(slotAng) * inRad, cap.center.y, cap.center.z + sin(slotAng) * inRad)
|
|
if wto_terrain_point_valid(army, insidePt)
|
|
return insidePt
|
|
return cap.center
|
|
// Cap already has enough insiders -> fan remaining bots onto flank overwatch 24..48m outside!
|
|
let fanIdx = int(h % 6u)
|
|
let sideSign = (fanIdx % 2) == 0 ? 1.0 : -1.0
|
|
let tier = float(fanIdx / 2 + 1)
|
|
let latOff = sideSign * (cap.radius + 18.0 + tier * 12.0)
|
|
let depthOff = -8.0 + float(int((h / 6u) % 3u) - 1) * 14.0
|
|
for attempt in range(4)
|
|
let scale = attempt == 0 ? 1.0 : (attempt == 1 ? -1.0 : (attempt == 2 ? 0.65 : -0.65))
|
|
var cand = cap.center + lat * (latOff * scale) + toCap * depthOff
|
|
if cap.ownerArmy == army
|
|
cand = wto_clamp_away_enemy_spawn(world, army, cand)
|
|
cand = wto_clamp_battle_xz(cand, world.battleCenter, world.battleRadius, 40.0)
|
|
if wto_terrain_point_valid(army, cand)
|
|
return cand
|
|
return cap.center - toCap * (cap.radius + 22.0)
|
|
|
|
[never_inline]
|
|
def private wto_assign_spaa_order(world : WtoWorldSnap const&; now : float; myPos : float3;
|
|
var slot : WtoBotSlot&)
|
|
let army = slot.army
|
|
let needNew = !slot.macro.spaaAnchorValid || (slot.fire.lastShotAt > slot.macro.spaaRelocateAt && (now - slot.fire.lastShotAt) > 3.0)
|
|
if !needNew
|
|
slot.macro.goalPos = slot.macro.spaaAnchorPos
|
|
slot.macro.capIndex = -1
|
|
slot.macro.valid = true
|
|
return
|
|
let spawnPt = world.teamSpawnValid[army] ? world.teamSpawnCenter[army] : myPos
|
|
let frontPt = world.capCount > 0 ? world.caps[0].center : world.battleCenter
|
|
let toFront = wto_xz_normalize(frontPt - spawnPt, float3(1.0, 0.0, 0.0))
|
|
let lat = float3(-toFront.z, 0.0, toFront.x)
|
|
let base = frontPt - toFront * WTO_AI_MACRO_SPAA_REAR_OFFSET_M
|
|
let tickIdx = max(0, int(now / max(5.0, WTO_AI_MACRO_SPAA_RELOCATE_SEC)))
|
|
let phase = int((uint(slot.eid) + uint(tickIdx)) % 5u)
|
|
let side = float(phase - 2) * 42.0
|
|
var cand = wto_clamp_battle_xz(base + lat * side, world.battleCenter, world.battleRadius, 45.0)
|
|
if !wto_terrain_point_valid(army, cand)
|
|
cand = myPos
|
|
slot.macro.spaaAnchorPos = cand
|
|
slot.macro.spaaAnchorValid = true
|
|
slot.macro.spaaRelocateAt = now + WTO_AI_MACRO_SPAA_RELOCATE_SEC
|
|
slot.macro.goalPos = cand
|
|
slot.macro.capIndex = -1
|
|
slot.macro.valid = true
|
|
|
|
[never_inline]
|
|
def private wto_count_cap_insiders(world : WtoWorldSnap const&; army : int; var counts : int[8]&)
|
|
for k in range(WTO_MAX_CAPS)
|
|
counts[k] = 0
|
|
for c in range(world.capCount)
|
|
let rSq = wto_sq(world.caps[c].radius + 14.0)
|
|
for u in range(world.unitCount)
|
|
assume uSnap = world.units[u]
|
|
if uSnap.isAlive && uSnap.isGround && uSnap.army == army && wto_xz_dist_sq(uSnap.pos, world.caps[c].center) <= rSq
|
|
counts[c]++
|
|
|
|
[never_inline]
|
|
def private wto_pick_best_cap_idx(world : WtoWorldSnap const&; army : int; now : float;
|
|
openingSplit : bool; myPos, axisLat : float3;
|
|
prevCapIdx : int; capAssigned : int[8]) : int
|
|
var bestCap = 0
|
|
var bestCost = 1.0e9
|
|
let myLat = dot(myPos - world.battleCenter, axisLat)
|
|
for c in range(world.capCount)
|
|
assume cap = world.caps[c]
|
|
var cost = sqrt(wto_xz_dist_sq(myPos, cap.center))
|
|
if cap.ownerArmy != army
|
|
if capAssigned[c] < WTO_AI_MACRO_RECAP_MIN_BOTS
|
|
cost -= 240.0
|
|
elif capAssigned[c] >= WTO_AI_MACRO_RECAP_MAX_BOTS && world.capCount > 1
|
|
cost += 220.0
|
|
else
|
|
cost -= 95.0
|
|
else
|
|
cost += 120.0 + float(capAssigned[c]) * 65.0
|
|
if prevCapIdx == c
|
|
cost -= WTO_AI_MACRO_CAP_STICKY_BONUS_M
|
|
if openingSplit && world.capCount > 1
|
|
cost += abs(myLat - dot(cap.center - world.battleCenter, axisLat)) * 0.85
|
|
let kills = wto_death_zone_kills(world, army, cap.center, now)
|
|
if kills >= WTO_AI_MACRO_DEATH_ZONE_MIN_KILLS
|
|
cost += float(kills) * 85.0
|
|
if cost < bestCost
|
|
bestCost = cost
|
|
bestCap = c
|
|
return bestCap
|
|
|
|
[never_inline]
|
|
def private wto_assign_army_caps(world : WtoWorldSnap const&; army : int; now : float;
|
|
var bots : WtoBotSlot[64]&)
|
|
var capInsiders : int[8]
|
|
var capAssigned : int[8]
|
|
wto_count_cap_insiders(world, army, capInsiders)
|
|
for c in range(WTO_MAX_CAPS)
|
|
capAssigned[c] = capInsiders[c]
|
|
let openingSplit = (now - world.matchStartAt) <= WTO_AI_MACRO_OPENING_SPLIT_SEC
|
|
let spawnPt = world.teamSpawnValid[army] ? world.teamSpawnCenter[army] : world.battleCenter
|
|
let axisFwd = wto_xz_normalize(world.battleCenter - spawnPt, float3(1.0, 0.0, 0.0))
|
|
let axisLat = float3(-axisFwd.z, 0.0, axisFwd.x)
|
|
|
|
for i in range(WTO_MAX_BOTS)
|
|
if !bots[i].used || bots[i].army != army
|
|
continue
|
|
let uIdx = wto_world_find_unit(world, bots[i].eid)
|
|
if uIdx < 0
|
|
continue
|
|
let myPos = world.units[uIdx].pos
|
|
if bots[i].spec.role == WTO_ROLE_SPAA
|
|
wto_assign_spaa_order(world, now, myPos, bots[i])
|
|
continue
|
|
if world.capCount <= 0
|
|
bots[i].macro.goalPos = wto_clamp_away_enemy_spawn(world, army, world.battleCenter + axisLat * float(int(uint(bots[i].eid) % 5u) - 2) * 55.0)
|
|
bots[i].macro.capIndex = -1
|
|
bots[i].macro.valid = true
|
|
continue
|
|
let bestCap = wto_pick_best_cap_idx(world, army, now, openingSplit, myPos, axisLat, bots[i].macro.capIndex, capAssigned)
|
|
let overwatchOut = capAssigned[bestCap] >= WTO_AI_MACRO_CAP_MAX_INSIDERS || bots[i].spec.role == WTO_ROLE_TD
|
|
if !overwatchOut
|
|
capAssigned[bestCap]++
|
|
bots[i].macro.capIndex = bestCap
|
|
bots[i].macro.overwatchOutside = overwatchOut
|
|
bots[i].macro.cautious = wto_death_zone_kills(world, army, world.caps[bestCap].center, now) >= WTO_AI_MACRO_DEATH_ZONE_MIN_KILLS
|
|
bots[i].macro.goalPos = wto_pick_cap_anchor(world, army, bots[i].eid, bestCap, overwatchOut)
|
|
bots[i].macro.valid = true
|
|
|
|
[never_inline]
|
|
def public wto_macro_update_all(world : WtoWorldSnap const&; now : float; var bots : WtoBotSlot[64]&)
|
|
wto_assign_army_caps(world, 1, now, bots)
|
|
wto_assign_army_caps(world, 2, now, bots)
|