Complete the team commander layer with validated flank routes, coordinated
rally launches, dynamic cap recall, and air-threat-responsive SPAA:
- Add flank, rally, and recall parameters to the commander section of
tuning/ground-ai.jsonc (flankMaxLengthRatio, flankMinSeparationM,
rallyProgressFrac, rallyWaitSec, rallyMinFrac, rallyRadiusM,
recallSafeHoldSec), validated in ground-ai-tuning.ts and compiled into
WTO_AI_CMD_* constants.
- Add wto_ai_lanes_common.das:
- Lazily build and cache per-(team, cap) center and left/right flank
lanes using two-segment navmesh find_path_ex; reject flanks exceeding
1.6x center path length or closer than 45 m to the center midpoint.
- Stage offensive groups at the 40% rally point along their lane and
launch once 2/3 of the group arrives or 25 s elapse, resetting on cap
ownership flips.
- Track enemy ground count and contested state on friendly caps,
holding recall active until safe for 15 s; track enemy aircraft
presence for team SPAA intel.
- Split mode planners and recall demand overrides into
wto_ai_commander_plans_common.das; pull (enemies + 1) nearest support
or reserve bots to defend contested friendly caps while always keeping
at least one offensive assault bot.
- Update wto_ai_commander_anchors_common.das so SPAA follows behind the
actual Assault group centroid and checks upward open-sky clearance when
enemy aircraft are active.
- Wire WtoTaskOrder lane/relay/rally fields into wto_ai_route_common.das
(replacing unvalidated wing relays and preserving corridor turning
corners), wto_ai_tactics_common.das (rally staging hold), and
wto_ai_runtime.das (1 s rally release check).
Verified root and launcher type checks, isolated 2.61.0.58 build (27
ground AI modules packed), and clean in-engine daScript compilation/load
(wto_ai_runtime.das loaded in 183 ms, 0 compile errors). Live battle
acceptance deferred until the full pipeline is wired.
198 lines
8.1 KiB
Plaintext
198 lines
8.1 KiB
Plaintext
// Whole-team commander (v1): mode-aware role quotas (Bttl / Conq / Dom), deterministic
|
|
// distance + vehicle-suitability matching, 20-second role hysteresis, separate total-assigned
|
|
// vs insider counters, and per-team assignment telemetry.
|
|
options indenting = 2
|
|
options no_global_heap = true
|
|
module wto_ai_commander_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_order_common
|
|
require %appGame.wtoai.wto_ai_types_common
|
|
require %appGame.wtoai.wto_ai_world_common
|
|
require %appGame.wtoai.wto_ai_lanes_common
|
|
require %appGame.wtoai.wto_ai_commander_anchors_common
|
|
require %appGame.wtoai.wto_ai_commander_plans_common
|
|
|
|
[never_inline]
|
|
def private wto_cmd_apply_order(world : WtoWorldSnap const&; army : int; now : float;
|
|
capIdx, cmdRole, urgency : int; lanes : WtoTeamLanes const&;
|
|
var capInsiders : int[8]&; var capAssigned : int[8]&;
|
|
var slot : WtoBotSlot&)
|
|
assume ord = slot.order
|
|
let sameTask = ord.valid && ord.role == cmdRole && ord.capIndex == capIdx
|
|
let insideCircle = cmdRole == WTO_CMD_ASSAULT && capInsiders[capIdx] < WTO_AI_MACRO_CAP_MAX_INSIDERS
|
|
if insideCircle
|
|
capInsiders[capIdx]++
|
|
capAssigned[capIdx]++
|
|
ord.role = cmdRole
|
|
ord.capIndex = capIdx
|
|
ord.urgency = urgency
|
|
ord.maxStopRangeM = wto_order_max_stop_range(cmdRole, urgency, WTO_AI_FC_MAX_RANGE_M)
|
|
ord.overwatchOutside = !insideCircle
|
|
ord.cautious = wto_cmd_death_zone_kills(world, army, world.caps[capIdx].center, now) >= WTO_AI_MACRO_DEATH_ZONE_MIN_KILLS
|
|
ord.goalPos = wto_cmd_pick_role_anchor(world, army, slot.eid, capIdx, cmdRole, insideCircle)
|
|
|
|
// Assign validated navmesh lane (center / left flank / right flank) and rally staging point.
|
|
let ck = wto_lanes_cap_key(army, capIdx)
|
|
ord.laneId = WTO_LANE_CENTER
|
|
ord.routeRelayValid = false
|
|
ord.rallyHold = false
|
|
if cmdRole == WTO_CMD_FLANK
|
|
let prefSide = int(uint(slot.eid) & 1u)
|
|
let altSide = 1 - prefSide
|
|
if lanes.flankValid[ck * 2 + prefSide]
|
|
ord.laneId = prefSide + 1
|
|
ord.routeRelayValid = true
|
|
ord.routeRelayPos = lanes.flankRelay[ck * 2 + prefSide]
|
|
elif lanes.flankValid[ck * 2 + altSide]
|
|
ord.laneId = altSide + 1
|
|
ord.routeRelayValid = true
|
|
ord.routeRelayPos = lanes.flankRelay[ck * 2 + altSide]
|
|
if wto_order_is_offensive(cmdRole)
|
|
let sk = wto_lanes_sub_key(army, capIdx, ord.laneId)
|
|
if !lanes.rallyReleased[sk] && length_sq(lanes.rallyPos[sk]) > 1.0
|
|
ord.rallyHold = true
|
|
ord.routeRelayValid = true
|
|
ord.routeRelayPos = lanes.rallyPos[sk]
|
|
|
|
if !sameTask
|
|
ord.assignedAt = now
|
|
ord.expiresAt = now + max(10.0, WTO_AI_CMD_ROLE_HOLD_SEC * 2.0)
|
|
ord.valid = true
|
|
|
|
[never_inline]
|
|
def private wto_cmd_match_and_log(world : WtoWorldSnap const&; army : int; now : float; forceRebalance : bool;
|
|
lanes : WtoTeamLanes const&;
|
|
candCount : int; cands : int[64]; candPos : float3[64];
|
|
dCount : int; dCap : int[64]; dRole : int[64]; dUrg : int[64];
|
|
spaaCount : int; var bots : WtoBotSlot[64]&)
|
|
var botUsed : bool[64]
|
|
var demUsed : bool[64]
|
|
for i in range(WTO_MAX_BOTS)
|
|
botUsed[i] = false
|
|
demUsed[i] = false
|
|
var capInsiders : int[8]
|
|
var capAssigned : int[8]
|
|
for c in range(WTO_MAX_CAPS)
|
|
capInsiders[c] = 0
|
|
capAssigned[c] = 0
|
|
if !forceRebalance
|
|
for ci in range(candCount)
|
|
let bIdx = cands[ci]
|
|
assume ord = bots[bIdx].order
|
|
if !ord.valid || (now - ord.assignedAt) >= WTO_AI_CMD_ROLE_HOLD_SEC || now >= ord.expiresAt
|
|
continue
|
|
for di in range(dCount)
|
|
if !demUsed[di] && dCap[di] == ord.capIndex && dRole[di] == ord.role
|
|
demUsed[di] = true
|
|
botUsed[ci] = true
|
|
wto_cmd_apply_order(world, army, now, dCap[di], dRole[di], dUrg[di], lanes, capInsiders, capAssigned, bots[bIdx])
|
|
break
|
|
for di in range(dCount)
|
|
if demUsed[di]
|
|
continue
|
|
var bestCi = -1
|
|
var bestScore = 1.0e12
|
|
var bestEid = 0xffffffffu
|
|
let tgtPos = world.caps[dCap[di]].center
|
|
for ci in range(candCount)
|
|
if botUsed[ci]
|
|
continue
|
|
let bIdx = cands[ci]
|
|
let dist = sqrt(wto_xz_dist_sq(candPos[ci], tgtPos))
|
|
let sc = dist + wto_cmd_vehicle_penalty(bots[bIdx].spec.role, dRole[di])
|
|
let eidU = uint(bots[bIdx].eid)
|
|
if sc < bestScore - 0.1 || (abs(sc - bestScore) <= 0.1 && eidU < bestEid)
|
|
bestScore = sc
|
|
bestEid = eidU
|
|
bestCi = ci
|
|
if bestCi >= 0
|
|
demUsed[di] = true
|
|
botUsed[bestCi] = true
|
|
wto_cmd_apply_order(world, army, now, dCap[di], dRole[di], dUrg[di], lanes, capInsiders, capAssigned, bots[cands[bestCi]])
|
|
wto_cmd_log_summary(world, army, now, candCount, cands, candPos, capAssigned, capInsiders, spaaCount, bots)
|
|
|
|
[never_inline]
|
|
def private wto_cmd_assign_army(world : WtoWorldSnap const&; army : int; now : float;
|
|
forceRebalance : bool; var lanes : WtoTeamLanes&;
|
|
var bots : WtoBotSlot[64]&)
|
|
var cands : int[64]
|
|
var candPos : float3[64]
|
|
var spaaIdx : int[64]
|
|
var spaaPos : float3[64]
|
|
var candCount = 0
|
|
var spaaCount = 0
|
|
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
|
|
if bots[i].spec.role == WTO_ROLE_SPAA
|
|
spaaIdx[spaaCount] = i
|
|
spaaPos[spaaCount] = world.units[uIdx].pos
|
|
spaaCount++
|
|
else
|
|
cands[candCount] = i
|
|
candPos[candCount] = world.units[uIdx].pos
|
|
candCount++
|
|
if world.capCount <= 0
|
|
for ci in range(candCount)
|
|
assume ord = bots[cands[ci]].order
|
|
ord.role = WTO_CMD_ASSAULT
|
|
ord.capIndex = -1
|
|
ord.laneId = WTO_LANE_CENTER
|
|
ord.routeRelayValid = false
|
|
ord.rallyHold = false
|
|
ord.goalPos = wto_cmd_clamp_away_enemy_spawn(world, army, world.battleCenter)
|
|
ord.urgency = WTO_URGENCY_MED
|
|
ord.maxStopRangeM = 300.0
|
|
ord.assignedAt = now
|
|
ord.expiresAt = now + 30.0
|
|
ord.valid = true
|
|
for si in range(spaaCount)
|
|
wto_cmd_assign_spaa(world, now, spaaPos[si], world.battleCenter, lanes.enemyAirActive[army], bots[spaaIdx[si]])
|
|
return
|
|
var enemiesInCap : int[8]
|
|
wto_lanes_update_recall(world, army, now, lanes, enemiesInCap)
|
|
for c in range(world.capCount)
|
|
wto_lanes_ensure_cap(world, army, c, lanes)
|
|
var dCap : int[64]
|
|
var dRole : int[64]
|
|
var dUrg : int[64]
|
|
var dCount = 0
|
|
var primaryCap = 0
|
|
if candCount > 0
|
|
if world.battleMode == WTO_MODE_BTTL
|
|
primaryCap = wto_cmd_plan_bttl(world, army, candCount, dCap, dRole, dUrg, dCount)
|
|
elif world.battleMode == WTO_MODE_CONQ || world.capCount == 1
|
|
primaryCap = wto_cmd_plan_conq(world, army, candCount, dCap, dRole, dUrg, dCount)
|
|
else
|
|
primaryCap = wto_cmd_plan_dom(world, army, candCount, dCap, dRole, dUrg, dCount)
|
|
wto_cmd_apply_recall_demands(world, army, candCount, lanes, enemiesInCap, dCap, dRole, dUrg, dCount)
|
|
wto_cmd_match_and_log(world, army, now, forceRebalance, lanes, candCount, cands, candPos, dCount, dCap, dRole, dUrg, spaaCount, bots)
|
|
var frontPt = world.caps[clamp(primaryCap, 0, world.capCount - 1)].center
|
|
var assaultSum = float3(0.0, 0.0, 0.0)
|
|
var assaultCnt = 0
|
|
for ci in range(candCount)
|
|
if bots[cands[ci]].order.role == WTO_CMD_ASSAULT
|
|
assaultSum += candPos[ci]
|
|
assaultCnt++
|
|
if assaultCnt > 0
|
|
frontPt = assaultSum / float(assaultCnt)
|
|
for si in range(spaaCount)
|
|
wto_cmd_assign_spaa(world, now, spaaPos[si], frontPt, lanes.enemyAirActive[army], bots[spaaIdx[si]])
|
|
|
|
[never_inline]
|
|
def public wto_commander_update_all(world : WtoWorldSnap const&; now : float;
|
|
forceRebalance : bool; var lanes : WtoTeamLanes&;
|
|
var bots : WtoBotSlot[64]&)
|
|
wto_lanes_update_team_intel(world, now, lanes)
|
|
wto_cmd_assign_army(world, 1, now, forceRebalance, lanes, bots)
|
|
wto_cmd_assign_army(world, 2, now, forceRebalance, lanes, bots)
|
|
wto_lanes_update_rallies(world, 1, now, lanes, bots)
|
|
wto_lanes_update_rallies(world, 2, now, lanes, bots)
|