Files
WT-Offline/game-ai/ground/wto_ai_commander_plans_common.das
T
N0VAN0M4LY d5008baeff feat(ground-ai): add navmesh flank lanes, rally staging, recall, and air-aware SPAA
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.
2026-12-03 18:46:53 +08:00

169 lines
7.4 KiB
Plaintext

// Mode-aware team quota planners (Bttl / Conq / Dom) and dynamic recall demand overrides.
options indenting = 2
options no_global_heap = true
module wto_ai_commander_plans_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_lanes_common
[never_inline]
def private wto_cmd_push_demands(capIdx, role, urgency, count : int;
var dCap : int[64]&; var dRole : int[64]&; var dUrg : int[64]&;
var dCount : int&)
for _k in range(count)
if dCount >= WTO_MAX_BOTS
return
dCap[dCount] = capIdx
dRole[dCount] = role
dUrg[dCount] = urgency
dCount++
[never_inline]
def public wto_cmd_plan_bttl(world : WtoWorldSnap const&; army, n : int;
var dCap : int[64]&; var dRole : int[64]&; var dUrg : int[64]&;
var dCount : int&) : int
let spawnPt = world.teamSpawnValid[army] ? world.teamSpawnCenter[army] : world.battleCenter
var enemyCap = -1
var friendlyCap = -1
var bestEnemyD = 1.0e12
var bestFriendD = 1.0e12
for c in range(world.capCount)
let dSq = wto_xz_dist_sq(spawnPt, world.caps[c].center)
if world.caps[c].ownerArmy != army && dSq < bestEnemyD
bestEnemyD = dSq
enemyCap = c
elif world.caps[c].ownerArmy == army && dSq < bestFriendD
bestFriendD = dSq
friendlyCap = c
if enemyCap < 0
enemyCap = friendlyCap >= 0 ? (world.capCount > 1 ? (1 - friendlyCap) : friendlyCap) : 0
if friendlyCap < 0
friendlyCap = enemyCap
let nAssault = clamp((n * WTO_AI_CMD_BTTL_ASSAULT_PCT + 50) / 100, 1, n)
let rem1 = max(0, n - nAssault)
let nFlank = min(rem1, (n * WTO_AI_CMD_BTTL_FLANK_PCT + 50) / 100)
let rem2 = max(0, rem1 - nFlank)
let nOverwatch = min(rem2, (n * WTO_AI_CMD_BTTL_OVERWATCH_PCT + 50) / 100)
let nDefend = max(0, rem2 - nOverwatch)
let defUrg = world.caps[friendlyCap].contested ? WTO_URGENCY_HIGH : WTO_URGENCY_LOW
wto_cmd_push_demands(enemyCap, WTO_CMD_ASSAULT, WTO_URGENCY_HIGH, nAssault, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(enemyCap, WTO_CMD_FLANK, WTO_URGENCY_HIGH, nFlank, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(enemyCap, WTO_CMD_OVERWATCH, WTO_URGENCY_MED, nOverwatch, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(friendlyCap, WTO_CMD_DEFEND, defUrg, nDefend, dCap, dRole, dUrg, dCount)
return enemyCap
[never_inline]
def public wto_cmd_plan_conq(world : WtoWorldSnap const&; army, n : int;
var dCap : int[64]&; var dRole : int[64]&; var dUrg : int[64]&;
var dCount : int&) : int
if world.caps[0].ownerArmy != army
let nAssault = clamp((n * WTO_AI_CMD_CONQ_ASSAULT_PCT + 50) / 100, 1, n)
let rem1 = max(0, n - nAssault)
let nFlank = min(rem1, (n * WTO_AI_CMD_CONQ_FLANK_PCT + 50) / 100)
let nOverwatch = max(0, rem1 - nFlank)
wto_cmd_push_demands(0, WTO_CMD_ASSAULT, WTO_URGENCY_HIGH, nAssault, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(0, WTO_CMD_FLANK, WTO_URGENCY_HIGH, nFlank, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(0, WTO_CMD_OVERWATCH, WTO_URGENCY_MED, nOverwatch, dCap, dRole, dUrg, dCount)
else
let nDefend = min(n, (n * WTO_AI_CMD_CONQ_HOLD_DEFEND_PCT + 50) / 100)
let rem1 = max(0, n - nDefend)
let nOverwatch = min(rem1, (n * WTO_AI_CMD_CONQ_HOLD_OVERWATCH_PCT + 50) / 100)
let nFlank = max(0, rem1 - nOverwatch)
let defUrg = world.caps[0].contested ? WTO_URGENCY_HIGH : WTO_URGENCY_LOW
wto_cmd_push_demands(0, WTO_CMD_DEFEND, defUrg, nDefend, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(0, WTO_CMD_OVERWATCH, WTO_URGENCY_MED, nOverwatch, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(0, WTO_CMD_FLANK, WTO_URGENCY_MED, nFlank, dCap, dRole, dUrg, dCount)
return 0
[never_inline]
def public wto_cmd_plan_dom(world : WtoWorldSnap const&; army, n : int;
var dCap : int[64]&; var dRole : int[64]&; var dUrg : int[64]&;
var dCount : int&) : int
let spawnPt = world.teamSpawnValid[army] ? world.teamSpawnCenter[army] : world.battleCenter
var prio : int[2]
prio[0] = -1
prio[1] = -1
var prioCnt = 0
var bestMidScore = 1.0e12
for c in range(world.capCount)
if world.caps[c].ownerArmy != army
let sc = wto_xz_dist_sq(world.caps[c].center, world.battleCenter)
if sc < bestMidScore
bestMidScore = sc
prio[0] = c
if prio[0] >= 0
prioCnt = 1
var bestNear = 1.0e12
for c in range(world.capCount)
if c != prio[0] && world.caps[c].ownerArmy != army
let sc = wto_xz_dist_sq(world.caps[c].center, spawnPt)
if sc < bestNear
bestNear = sc
prio[1] = c
if prio[1] >= 0
prioCnt = 2
var remaining = n
for c in range(world.capCount)
if world.caps[c].ownerArmy == army && remaining > (prioCnt > 0 ? 1 : 0)
let keep = min(WTO_AI_CMD_DOM_MAX_DEFENDERS, remaining - (prioCnt > 0 ? 1 : 0))
let urg = world.caps[c].contested ? WTO_URGENCY_HIGH : WTO_URGENCY_LOW
wto_cmd_push_demands(c, WTO_CMD_DEFEND, urg, keep, dCap, dRole, dUrg, dCount)
remaining -= keep
if prioCnt == 0
let perCap = max(1, remaining / max(1, world.capCount))
for c in range(world.capCount)
let take = c == world.capCount - 1 ? remaining : min(remaining, perCap)
let urg = world.caps[c].contested ? WTO_URGENCY_HIGH : WTO_URGENCY_LOW
wto_cmd_push_demands(c, WTO_CMD_OVERWATCH, urg, take, dCap, dRole, dUrg, dCount)
remaining -= take
return 0
let firstShare = prioCnt == 1 ? remaining : (remaining + 1) / 2
for p in range(prioCnt)
let share = p == 0 ? firstShare : (remaining - firstShare)
if share <= 0
continue
let nAssault = clamp((share * WTO_AI_CMD_DOM_ASSAULT_PCT + 50) / 100, 1, share)
let nOverwatch = max(0, share - nAssault)
wto_cmd_push_demands(prio[p], WTO_CMD_ASSAULT, WTO_URGENCY_HIGH, nAssault, dCap, dRole, dUrg, dCount)
wto_cmd_push_demands(prio[p], WTO_CMD_OVERWATCH, WTO_URGENCY_MED, nOverwatch, dCap, dRole, dUrg, dCount)
return prio[0]
[never_inline]
def public wto_cmd_apply_recall_demands(world : WtoWorldSnap const&; army, n : int;
lanes : WtoTeamLanes const&; enemiesInCap : int[8];
var dCap : int[64]&; var dRole : int[64]&;
var dUrg : int[64]&; dCount : int)
for c in range(world.capCount)
let k = wto_lanes_cap_key(army, c)
if !lanes.recallActive[k]
continue
let needed = clamp(enemiesInCap[c] + 1, 1, max(1, n - 1))
var curDef = 0
var curOff = 0
for di in range(dCount)
if dCap[di] == c && dRole[di] == WTO_CMD_DEFEND
dUrg[di] = WTO_URGENCY_HIGH
curDef++
if wto_order_is_offensive(dRole[di])
curOff++
for stage in range(2)
for di in range(dCount)
if curDef >= needed
break
if dCap[di] == c && dRole[di] == WTO_CMD_DEFEND
continue
let isSupport = dRole[di] == WTO_CMD_RESERVE || dRole[di] == WTO_CMD_OVERWATCH
let canPullOff = stage == 1 && wto_order_is_offensive(dRole[di]) && curOff > 1
if (stage == 0 && isSupport) || canPullOff
if wto_order_is_offensive(dRole[di])
curOff--
dCap[di] = c
dRole[di] = WTO_CMD_DEFEND
dUrg[di] = WTO_URGENCY_HIGH
curDef++