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.
This commit is contained in:
1 parent
45ff082a36
commit
d5008baeff
11 files changed
+582
-188
No files matched your search
@@ -105,6 +105,13 @@ function readCommanderSection(cmd: TuningReader): GroundAiTuning['commander'] {
|
||||
overwatchStandOffM: cmd.number('overwatchStandOffM', { min: 25.0, max: 350.0 }),
|
||||
flankStandOffM: cmd.number('flankStandOffM', { min: 25.0, max: 300.0 }),
|
||||
spaaFollowOffsetM: cmd.number('spaaFollowOffsetM', { min: 40.0, max: 500.0 }),
|
||||
flankMaxLengthRatio: cmd.number('flankMaxLengthRatio', { min: 1.05, max: 3.0 }),
|
||||
flankMinSeparationM: cmd.number('flankMinSeparationM', { min: 15.0, max: 200.0 }),
|
||||
rallyProgressFrac: cmd.number('rallyProgressFrac', { min: 0.1, max: 0.75 }),
|
||||
rallyWaitSec: cmd.number('rallyWaitSec', { min: 3.0, max: 60.0 }),
|
||||
rallyMinFrac: cmd.number('rallyMinFrac', { min: 0.25, max: 1.0 }),
|
||||
rallyRadiusM: cmd.number('rallyRadiusM', { min: 15.0, max: 140.0 }),
|
||||
recallSafeHoldSec: cmd.number('recallSafeHoldSec', { min: 3.0, max: 60.0 }),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,14 @@
|
||||
"domMaxDefendersPerCap": 1,
|
||||
"overwatchStandOffM": 95.0,
|
||||
"flankStandOffM": 75.0,
|
||||
"spaaFollowOffsetM": 160.0
|
||||
"spaaFollowOffsetM": 160.0,
|
||||
"flankMaxLengthRatio": 1.6,
|
||||
"flankMinSeparationM": 45.0,
|
||||
"rallyProgressFrac": 0.40,
|
||||
"rallyWaitSec": 25.0,
|
||||
"rallyMinFrac": 0.66,
|
||||
"rallyRadiusM": 55.0,
|
||||
"recallSafeHoldSec": 15.0
|
||||
},
|
||||
|
||||
"macro": {
|
||||
|
||||
@@ -5,6 +5,7 @@ module wto_ai_commander_anchors_common shared
|
||||
|
||||
require ecs
|
||||
require math
|
||||
require Dacoll
|
||||
require %appGame.wtoai.wto_ai_config_common
|
||||
require %appGame.wtoai.wto_ai_math_common
|
||||
require %appGame.wtoai.wto_ai_order_common
|
||||
@@ -129,9 +130,15 @@ def public wto_cmd_pick_role_anchor(world : WtoWorldSnap const&; army : int; eid
|
||||
return chosen
|
||||
return wto_clamp_battle_xz(cap.center - toCap * (cap.radius + 18.0), world.battleCenter, world.battleRadius, 40.0)
|
||||
|
||||
[never_inline]
|
||||
def private wto_cmd_has_open_sky(pos : float3) : bool
|
||||
var p0 = pos + float3(0.0, 2.5, 0.0)
|
||||
let upDir = float3(0.0, 1.0, 0.0)
|
||||
return !rayhit_normalized(p0, upDir, 45.0, ETF_ALL, -1)
|
||||
|
||||
[never_inline]
|
||||
def public wto_cmd_assign_spaa(world : WtoWorldSnap const&; now : float; myPos, frontPt : float3;
|
||||
var slot : WtoBotSlot&)
|
||||
airActive : bool; var slot : WtoBotSlot&)
|
||||
let army = slot.army
|
||||
assume ord = slot.order
|
||||
let needNew = !ord.spaaAnchorValid || now >= ord.spaaRelocateAt || (slot.fire.lastShotAt > ord.spaaRelocateAt - WTO_AI_MACRO_SPAA_RELOCATE_SEC && (now - slot.fire.lastShotAt) > 3.0)
|
||||
@@ -139,22 +146,35 @@ def public wto_cmd_assign_spaa(world : WtoWorldSnap const&; now : float; myPos,
|
||||
let spawnPt = world.teamSpawnValid[army] ? world.teamSpawnCenter[army] : myPos
|
||||
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_CMD_SPAA_FOLLOW_OFFSET_M
|
||||
let followOff = airActive ? (WTO_AI_CMD_SPAA_FOLLOW_OFFSET_M * 1.15) : WTO_AI_CMD_SPAA_FOLLOW_OFFSET_M
|
||||
let base = frontPt - toFront * followOff
|
||||
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)
|
||||
cand = wto_cmd_clamp_away_enemy_spawn(world, army, cand)
|
||||
if !wto_terrain_point_valid(army, cand)
|
||||
cand = myPos
|
||||
ord.spaaAnchorPos = cand
|
||||
var picked = myPos
|
||||
var foundOpen = false
|
||||
for attempt in range(5)
|
||||
let phase = int((uint(slot.eid) + uint(tickIdx) + uint(attempt)) % 5u)
|
||||
let side = float(phase - 2) * 42.0
|
||||
var cand = wto_clamp_battle_xz(base + lat * side, world.battleCenter, world.battleRadius, 45.0)
|
||||
cand = wto_cmd_clamp_away_enemy_spawn(world, army, cand)
|
||||
if !wto_terrain_point_valid(army, cand)
|
||||
continue
|
||||
if !foundOpen
|
||||
picked = cand
|
||||
if wto_cmd_has_open_sky(cand)
|
||||
picked = cand
|
||||
foundOpen = true
|
||||
break
|
||||
ord.spaaAnchorPos = picked
|
||||
ord.spaaAnchorValid = true
|
||||
ord.spaaRelocateAt = now + WTO_AI_MACRO_SPAA_RELOCATE_SEC
|
||||
ord.role = WTO_CMD_SPAA
|
||||
ord.capIndex = -1
|
||||
ord.laneId = 0
|
||||
ord.routeRelayValid = false
|
||||
ord.rallyHold = false
|
||||
ord.goalPos = ord.spaaAnchorPos
|
||||
ord.urgency = WTO_URGENCY_LOW
|
||||
ord.maxStopRangeM = wto_order_max_stop_range(WTO_CMD_SPAA, WTO_URGENCY_LOW, WTO_AI_FC_MAX_RANGE_M)
|
||||
ord.urgency = airActive ? WTO_URGENCY_MED : WTO_URGENCY_LOW
|
||||
ord.maxStopRangeM = wto_order_max_stop_range(WTO_CMD_SPAA, ord.urgency, WTO_AI_FC_MAX_RANGE_M)
|
||||
ord.overwatchOutside = true
|
||||
ord.cautious = false
|
||||
ord.assignedAt = now
|
||||
|
||||
@@ -12,134 +12,13 @@ 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
|
||||
|
||||
[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 private 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 private 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 private 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
|
||||
// Pick center-most non-friendly cap first, then nearest non-friendly cap to spawn.
|
||||
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]
|
||||
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;
|
||||
capIdx, cmdRole, urgency : int; lanes : WtoTeamLanes const&;
|
||||
var capInsiders : int[8]&; var capAssigned : int[8]&;
|
||||
var slot : WtoBotSlot&)
|
||||
assume ord = slot.order
|
||||
@@ -155,6 +34,30 @@ def private wto_cmd_apply_order(world : WtoWorldSnap const&; army : int; now : f
|
||||
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)
|
||||
@@ -162,6 +65,7 @@ def private wto_cmd_apply_order(world : WtoWorldSnap const&; army : int; now : f
|
||||
|
||||
[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]&)
|
||||
@@ -175,7 +79,6 @@ def private wto_cmd_match_and_log(world : WtoWorldSnap const&; army : int; now :
|
||||
for c in range(WTO_MAX_CAPS)
|
||||
capInsiders[c] = 0
|
||||
capAssigned[c] = 0
|
||||
// Pass 1: honor 20s role hysteresis unless cap ownership/mode forced a rebalance.
|
||||
if !forceRebalance
|
||||
for ci in range(candCount)
|
||||
let bIdx = cands[ci]
|
||||
@@ -186,9 +89,8 @@ def private wto_cmd_match_and_log(world : WtoWorldSnap const&; army : int; now :
|
||||
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], capInsiders, capAssigned, bots[bIdx])
|
||||
wto_cmd_apply_order(world, army, now, dCap[di], dRole[di], dUrg[di], lanes, capInsiders, capAssigned, bots[bIdx])
|
||||
break
|
||||
// Pass 2: deterministic best suitability + distance match for remaining slots.
|
||||
for di in range(dCount)
|
||||
if demUsed[di]
|
||||
continue
|
||||
@@ -210,12 +112,13 @@ def private wto_cmd_match_and_log(world : WtoWorldSnap const&; army : int; now :
|
||||
if bestCi >= 0
|
||||
demUsed[di] = true
|
||||
botUsed[bestCi] = true
|
||||
wto_cmd_apply_order(world, army, now, dCap[di], dRole[di], dUrg[di], capInsiders, capAssigned, bots[cands[bestCi]])
|
||||
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 bots : WtoBotSlot[64]&)
|
||||
forceRebalance : bool; var lanes : WtoTeamLanes&;
|
||||
var bots : WtoBotSlot[64]&)
|
||||
var cands : int[64]
|
||||
var candPos : float3[64]
|
||||
var spaaIdx : int[64]
|
||||
@@ -241,6 +144,9 @@ def private wto_cmd_assign_army(world : WtoWorldSnap const&; army : int; now : f
|
||||
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
|
||||
@@ -248,8 +154,12 @@ def private wto_cmd_assign_army(world : WtoWorldSnap const&; army : int; now : f
|
||||
ord.expiresAt = now + 30.0
|
||||
ord.valid = true
|
||||
for si in range(spaaCount)
|
||||
wto_cmd_assign_spaa(world, now, spaaPos[si], world.battleCenter, bots[spaaIdx[si]])
|
||||
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]
|
||||
@@ -262,13 +172,26 @@ def private wto_cmd_assign_army(world : WtoWorldSnap const&; army : int; now : f
|
||||
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_match_and_log(world, army, now, forceRebalance, candCount, cands, candPos, dCount, dCap, dRole, dUrg, spaaCount, bots)
|
||||
let frontPt = world.caps[clamp(primaryCap, 0, world.capCount - 1)].center
|
||||
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, bots[spaaIdx[si]])
|
||||
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 bots : WtoBotSlot[64]&)
|
||||
wto_cmd_assign_army(world, 1, now, forceRebalance, bots)
|
||||
wto_cmd_assign_army(world, 2, now, forceRebalance, bots)
|
||||
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)
|
||||
@@ -0,0 +1,168 @@
|
||||
// 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++
|
||||
@@ -0,0 +1,234 @@
|
||||
// Team-level navmesh flank lanes (center / left / right), 40% rally staging & launch state,
|
||||
// cap recall timers, and enemy air threat tracking.
|
||||
options indenting = 2
|
||||
options no_global_heap = true
|
||||
module wto_ai_lanes_common shared
|
||||
|
||||
require ecs
|
||||
require math
|
||||
require pathfinder
|
||||
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_terrain_common
|
||||
require %appGame.wtoai.wto_ai_world_common
|
||||
|
||||
let public WTO_LANE_CENTER = 0
|
||||
let public WTO_LANE_LEFT = 1
|
||||
let public WTO_LANE_RIGHT = 2
|
||||
|
||||
[safe_when_uninitialized]
|
||||
struct public WtoTeamLanes
|
||||
built : bool[16]
|
||||
centerLen : float[16]
|
||||
centerMid : float3[16]
|
||||
flankValid : bool[32]
|
||||
flankRelay : float3[32]
|
||||
rallyPos : float3[48]
|
||||
rallyStartAt : float[48]
|
||||
rallyReleased : bool[48]
|
||||
capSafeSince : float[16]
|
||||
recallActive : bool[16]
|
||||
enemyAirActive : bool[3]
|
||||
enemyAirSeenAt : float[3]
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_cap_key(army, capIdx : int) : int
|
||||
return clamp(army - 1, 0, 1) * 8 + clamp(capIdx, 0, 7)
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_sub_key(army, capIdx, laneId : int) : int
|
||||
return wto_lanes_cap_key(army, capIdx) * 3 + clamp(laneId, 0, 2)
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_reset(var lanes : WtoTeamLanes&)
|
||||
for i in range(16)
|
||||
lanes.built[i] = false
|
||||
lanes.centerLen[i] = 0.0
|
||||
lanes.centerMid[i] = float3(0.0, 0.0, 0.0)
|
||||
lanes.capSafeSince[i] = -100.0
|
||||
lanes.recallActive[i] = false
|
||||
for i in range(32)
|
||||
lanes.flankValid[i] = false
|
||||
lanes.flankRelay[i] = float3(0.0, 0.0, 0.0)
|
||||
for i in range(48)
|
||||
lanes.rallyPos[i] = float3(0.0, 0.0, 0.0)
|
||||
lanes.rallyStartAt[i] = -100.0
|
||||
lanes.rallyReleased[i] = false
|
||||
for a in range(3)
|
||||
lanes.enemyAirActive[a] = false
|
||||
lanes.enemyAirSeenAt[a] = -100.0
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_reset_rallies(var lanes : WtoTeamLanes&)
|
||||
for i in range(48)
|
||||
lanes.rallyStartAt[i] = -100.0
|
||||
lanes.rallyReleased[i] = false
|
||||
|
||||
[never_inline]
|
||||
def private wto_nav_project_pt(navIdx : int; var pt : float3&) : bool
|
||||
if project_to_nearest_navmesh_point_no_obstacles_ex(navIdx, pt, float3(28.0, 64.0, 28.0))
|
||||
return true
|
||||
return project_to_nearest_navmesh_point_no_obstacles_ex(navIdx, pt, float3(150.0, 120.0, 150.0))
|
||||
|
||||
[never_inline]
|
||||
def private wto_measure_nav_path(navIdx : int; fromPt, toPt : float3; sampleFrac : float;
|
||||
var outLen : float&; var outSample : float3&) : bool
|
||||
var sPt = fromPt
|
||||
var gPt = toPt
|
||||
if !wto_nav_project_pt(navIdx, sPt) || !wto_nav_project_pt(navIdx, gPt)
|
||||
return false
|
||||
var ok = false
|
||||
var totalLen = 0.0
|
||||
var sample = lerp(sPt, gPt, sampleFrac)
|
||||
find_path_ex(navIdx, sPt, gPt, float3(32.0, 48.0, 32.0), 9.0, 2.5, null) <| $(path : array<float3>#)
|
||||
let n = length(path)
|
||||
if n < 2
|
||||
return
|
||||
ok = true
|
||||
for i in range(1, n)
|
||||
totalLen += length(path[i] - path[i - 1])
|
||||
let targetD = totalLen * clamp(sampleFrac, 0.05, 0.95)
|
||||
var acc = 0.0
|
||||
sample = path[n - 1]
|
||||
for i in range(1, n)
|
||||
let seg = length(path[i] - path[i - 1])
|
||||
if acc + seg >= targetD && seg > 0.01
|
||||
sample = lerp(path[i - 1], path[i], (targetD - acc) / seg)
|
||||
break
|
||||
acc += seg
|
||||
outLen = totalLen
|
||||
outSample = sample
|
||||
return ok && totalLen > 1.0
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_ensure_cap(world : WtoWorldSnap const&; army, capIdx : int;
|
||||
var lanes : WtoTeamLanes&)
|
||||
let k = wto_lanes_cap_key(army, capIdx)
|
||||
if lanes.built[k] || capIdx < 0 || capIdx >= world.capCount || !world.teamSpawnValid[army]
|
||||
return
|
||||
let navIdx = pathfinder_is_loaded_ex(1) ? 1 : (pathfinder_is_loaded_ex(0) ? 0 : -1)
|
||||
if navIdx < 0
|
||||
return
|
||||
lanes.built[k] = true
|
||||
let spawnPt = world.teamSpawnCenter[army]
|
||||
let capPt = world.caps[capIdx].center
|
||||
var cLen = 0.0
|
||||
var cRally = lerp(spawnPt, capPt, WTO_AI_CMD_RALLY_PROG_FRAC)
|
||||
if !wto_measure_nav_path(navIdx, spawnPt, capPt, WTO_AI_CMD_RALLY_PROG_FRAC, cLen, cRally)
|
||||
cLen = max(80.0, sqrt(wto_xz_dist_sq(spawnPt, capPt)))
|
||||
var cMid = lerp(spawnPt, capPt, 0.5)
|
||||
var dummyLen = 0.0
|
||||
let _midOk = wto_measure_nav_path(navIdx, spawnPt, capPt, 0.5, dummyLen, cMid)
|
||||
lanes.centerLen[k] = cLen
|
||||
lanes.centerMid[k] = cMid
|
||||
lanes.rallyPos[k * 3 + WTO_LANE_CENTER] = cRally
|
||||
|
||||
let toCap = wto_xz_normalize(capPt - spawnPt, float3(1.0, 0.0, 0.0))
|
||||
let lat = float3(-toCap.z, 0.0, toCap.x)
|
||||
let straightD = sqrt(wto_xz_dist_sq(spawnPt, capPt))
|
||||
let swing = clamp(straightD * 0.34, 80.0, 260.0)
|
||||
for side in range(2)
|
||||
let sign = side == 0 ? 1.0 : -1.0
|
||||
var relay = wto_clamp_battle_xz(lerp(spawnPt, capPt, 0.5) + lat * (sign * swing), world.battleCenter, world.battleRadius, 45.0)
|
||||
let fKey = k * 2 + side
|
||||
lanes.flankValid[fKey] = false
|
||||
if !wto_nav_project_pt(navIdx, relay) || !wto_terrain_point_valid(army, relay)
|
||||
continue
|
||||
if sqrt(wto_xz_dist_sq(relay, cMid)) < WTO_AI_CMD_FLANK_MIN_SEP_M
|
||||
continue
|
||||
var len1 = 0.0
|
||||
var len2 = 0.0
|
||||
var rPt = lerp(spawnPt, relay, 0.8)
|
||||
var dummy = relay
|
||||
if !wto_measure_nav_path(navIdx, spawnPt, relay, 0.8, len1, rPt)
|
||||
continue
|
||||
if !wto_measure_nav_path(navIdx, relay, capPt, 0.5, len2, dummy)
|
||||
continue
|
||||
if (len1 + len2) > cLen * WTO_AI_CMD_FLANK_MAX_RATIO
|
||||
continue
|
||||
lanes.flankValid[fKey] = true
|
||||
lanes.flankRelay[fKey] = relay
|
||||
lanes.rallyPos[k * 3 + side + 1] = rPt
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_update_team_intel(world : WtoWorldSnap const&; now : float;
|
||||
var lanes : WtoTeamLanes&)
|
||||
let airMaxSq = wto_sq(3200.0)
|
||||
for a in range(1, 3)
|
||||
var sawAir = false
|
||||
for i in range(world.unitCount)
|
||||
assume u = world.units[i]
|
||||
if u.isAlive && u.isAir && u.army != a && wto_xz_dist_sq(u.pos, world.battleCenter) <= airMaxSq
|
||||
sawAir = true
|
||||
break
|
||||
if sawAir
|
||||
lanes.enemyAirSeenAt[a] = now
|
||||
lanes.enemyAirActive[a] = sawAir || (now - lanes.enemyAirSeenAt[a]) <= 12.0
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_update_recall(world : WtoWorldSnap const&; army : int; now : float;
|
||||
var lanes : WtoTeamLanes&; var outEnemiesInCap : int[8]&)
|
||||
for c in range(WTO_MAX_CAPS)
|
||||
outEnemiesInCap[c] = 0
|
||||
for c in range(world.capCount)
|
||||
let k = wto_lanes_cap_key(army, c)
|
||||
if world.caps[c].ownerArmy != army
|
||||
lanes.recallActive[k] = false
|
||||
lanes.capSafeSince[k] = now
|
||||
continue
|
||||
let radSq = wto_sq(world.caps[c].radius + 35.0)
|
||||
var enemies = 0
|
||||
for i in range(world.unitCount)
|
||||
assume u = world.units[i]
|
||||
if u.isAlive && u.isGround && u.army != army && wto_xz_dist_sq(u.pos, world.caps[c].center) <= radSq
|
||||
enemies++
|
||||
outEnemiesInCap[c] = enemies
|
||||
if world.caps[c].contested || enemies > 0
|
||||
if !lanes.recallActive[k] && WTO_AI_DIAG_TELEMETRY
|
||||
print("WTO_AI|RECALL|t={now}|army={army}|cap={c}|enemies={enemies}|contested={world.caps[c].contested}\n")
|
||||
lanes.recallActive[k] = true
|
||||
lanes.capSafeSince[k] = now
|
||||
elif lanes.recallActive[k] && (now - lanes.capSafeSince[k]) >= WTO_AI_CMD_RECALL_SAFE_SEC
|
||||
lanes.recallActive[k] = false
|
||||
|
||||
[never_inline]
|
||||
def public wto_lanes_update_rallies(world : WtoWorldSnap const&; army : int; now : float;
|
||||
var lanes : WtoTeamLanes&; var bots : WtoBotSlot[64]&)
|
||||
let rallyRadSq = wto_sq(WTO_AI_CMD_RALLY_RADIUS_M)
|
||||
for c in range(world.capCount)
|
||||
wto_lanes_ensure_cap(world, army, c, lanes)
|
||||
for lane in range(3)
|
||||
let sk = wto_lanes_sub_key(army, c, lane)
|
||||
if lanes.rallyReleased[sk]
|
||||
continue
|
||||
let rPos = lanes.rallyPos[sk]
|
||||
if length_sq(rPos) < 1.0
|
||||
lanes.rallyReleased[sk] = true
|
||||
continue
|
||||
let rDistToCapSq = wto_xz_dist_sq(rPos, world.caps[c].center)
|
||||
var assigned = 0
|
||||
var arrived = 0
|
||||
for i in range(WTO_MAX_BOTS)
|
||||
assume b = bots[i]
|
||||
if !b.used || b.army != army || !b.order.valid || b.order.capIndex != c || b.order.laneId != lane || !wto_order_is_offensive(b.order.role)
|
||||
continue
|
||||
let uIdx = wto_world_find_unit(world, b.eid)
|
||||
if uIdx < 0
|
||||
continue
|
||||
assigned++
|
||||
let pos = world.units[uIdx].pos
|
||||
if wto_xz_dist_sq(pos, rPos) <= rallyRadSq || wto_xz_dist_sq(pos, world.caps[c].center) < rDistToCapSq
|
||||
arrived++
|
||||
if assigned <= 1
|
||||
lanes.rallyReleased[sk] = true
|
||||
continue
|
||||
if arrived > 0 && lanes.rallyStartAt[sk] < 0.0
|
||||
lanes.rallyStartAt[sk] = now
|
||||
let enough = float(arrived) >= float(assigned) * WTO_AI_CMD_RALLY_MIN_FRAC
|
||||
let timedOut = lanes.rallyStartAt[sk] >= 0.0 && (now - lanes.rallyStartAt[sk]) >= WTO_AI_CMD_RALLY_WAIT_SEC
|
||||
if enough || timedOut
|
||||
lanes.rallyReleased[sk] = true
|
||||
if WTO_AI_DIAG_TELEMETRY
|
||||
print("WTO_AI|RALLY_GO|t={now}|army={army}|cap={c}|lane={lane}|arrived={arrived}/{assigned}|timeout={timedOut}\n")
|
||||
@@ -25,7 +25,11 @@ struct public WtoTaskOrder
|
||||
valid : bool = false
|
||||
role : int = 0
|
||||
capIndex : int = -1
|
||||
laneId : int = 0
|
||||
goalPos : float3 = float3(0.0, 0.0, 0.0)
|
||||
routeRelayValid : bool = false
|
||||
routeRelayPos : float3 = float3(0.0, 0.0, 0.0)
|
||||
rallyHold : bool = false
|
||||
urgency : int = 1
|
||||
maxStopRangeM : float = 800.0
|
||||
assignedAt : float = -100.0
|
||||
|
||||
@@ -21,32 +21,6 @@ def private wto_project_nav_wide(navIdx : int; var pt : float3&) : bool
|
||||
return true
|
||||
return project_to_nearest_navmesh_point_no_obstacles_ex(navIdx, pt, float3(165.0, 130.0, 165.0))
|
||||
|
||||
[never_inline]
|
||||
def private wto_ensure_wing_relay(world : WtoWorldSnap const&; myPos, dest : float3; var slot : WtoBotSlot&)
|
||||
assume rt = slot.route
|
||||
if !rt.wingInit
|
||||
rt.wingInit = true
|
||||
let h = uint(slot.eid)
|
||||
rt.wingSign = int(h % 5u) - 2
|
||||
rt.laneOffsetM = float(int((h / 5u) % 5u) - 2) * 4.5
|
||||
let capIdx = slot.order.capIndex
|
||||
if rt.wingCapIdx == capIdx
|
||||
return
|
||||
rt.wingCapIdx = capIdx
|
||||
rt.wingRelayValid = false
|
||||
let dist = sqrt(wto_xz_dist_sq(myPos, dest))
|
||||
if rt.wingSign == 0 || dist < 140.0
|
||||
return
|
||||
let toGoal = wto_xz_normalize(dest - myPos, float3(1.0, 0.0, 0.0))
|
||||
let lat = float3(-toGoal.z, 0.0, toGoal.x)
|
||||
let anchor = lerp(myPos, dest, 0.58)
|
||||
let swing = clamp(dist * 0.30, 55.0, 240.0) * (abs(rt.wingSign) == 2 ? 1.0 : 0.55)
|
||||
let side = swing * (rt.wingSign > 0 ? 1.0 : -1.0)
|
||||
var relay = wto_clamp_battle_xz(anchor + lat * side, world.battleCenter, world.battleRadius, 40.0)
|
||||
if wto_terrain_point_valid(slot.army, relay) && !wto_terrain_has_cliff_ahead(relay, toGoal, 16.0)
|
||||
rt.wingRelayPos = relay
|
||||
rt.wingRelayValid = true
|
||||
|
||||
[never_inline]
|
||||
def private wto_replan_corridor(now : float; myPos, goal : float3; var rt : WtoRouteState&)
|
||||
rt.nextReplanAt = now + 2.8
|
||||
@@ -69,16 +43,24 @@ def private wto_replan_corridor(now : float; myPos, goal : float3; var rt : WtoR
|
||||
let total = length(path)
|
||||
if total <= 0
|
||||
return
|
||||
let stride = max(1, (total + maxKeep - 1) / maxKeep)
|
||||
var idx = 0
|
||||
while idx < total && rt.corridorLen < maxKeep
|
||||
rt.corridor[rt.corridorLen] = path[idx]
|
||||
rt.corridorLen++
|
||||
idx += stride
|
||||
rt.corridor[0] = path[0]
|
||||
rt.corridorLen = 1
|
||||
let minStepSq = total > maxKeep ? wto_sq(max(12.0, float(total) * 9.0 / float(maxKeep))) : 0.0
|
||||
for i in range(1, total)
|
||||
if rt.corridorLen >= maxKeep
|
||||
break
|
||||
let prev = rt.corridor[rt.corridorLen - 1]
|
||||
var isCorner = false
|
||||
if i + 1 < total
|
||||
let d0 = wto_xz_normalize(path[i] - prev, float3(1.0, 0.0, 0.0))
|
||||
let d1 = wto_xz_normalize(path[i + 1] - path[i], d0)
|
||||
isCorner = dot(d0, d1) < 0.86
|
||||
if i == total - 1 || isCorner || wto_xz_dist_sq(prev, path[i]) >= minStepSq
|
||||
rt.corridor[rt.corridorLen] = path[i]
|
||||
rt.corridorLen++
|
||||
if rt.corridorLen < maxKeep && wto_xz_dist_sq(rt.corridor[rt.corridorLen - 1], path[total - 1]) > 9.0
|
||||
rt.corridor[rt.corridorLen] = path[total - 1]
|
||||
rt.corridorLen++
|
||||
// Append exact final destination when the goal sits off-road (e.g. hilltop capture zone).
|
||||
if rt.corridorLen > 0 && rt.corridorLen < WTO_MAX_PATH_PTS && wto_xz_dist_sq(rt.corridor[rt.corridorLen - 1], goal) > 64.0
|
||||
rt.corridor[rt.corridorLen] = goal
|
||||
rt.corridorLen++
|
||||
@@ -156,13 +138,19 @@ def public wto_route_select_waypoint(world : WtoWorldSnap const&; now : float;
|
||||
return rt.detourPos
|
||||
rt.detourValid = false
|
||||
|
||||
if !rt.wingInit
|
||||
rt.wingInit = true
|
||||
rt.laneOffsetM = float(int((uint(slot.eid) / 5u) % 5u) - 2) * 4.0
|
||||
let st = slot.tactics.state
|
||||
let useWing = st == WTO_STATE_MARCH || st == WTO_STATE_PREAIM || st == WTO_STATE_RELOAD_ADVANCE
|
||||
if useWing
|
||||
wto_ensure_wing_relay(world, myPos, finalGoal, slot)
|
||||
if useWing && rt.wingRelayValid && wto_xz_dist_sq(myPos, rt.wingRelayPos) <= 625.0
|
||||
rt.wingRelayValid = false
|
||||
let activeGoal = (useWing && rt.wingRelayValid) ? rt.wingRelayPos : finalGoal
|
||||
let useRelay = (st == WTO_STATE_MARCH || st == WTO_STATE_PREAIM || st == WTO_STATE_RELOAD_ADVANCE) && slot.order.routeRelayValid
|
||||
var activeGoal = finalGoal
|
||||
if useRelay
|
||||
let relay = slot.order.routeRelayPos
|
||||
let distMeToRelaySq = wto_xz_dist_sq(myPos, relay)
|
||||
let distMeToGoalSq = wto_xz_dist_sq(myPos, finalGoal)
|
||||
let distRelayToGoalSq = wto_xz_dist_sq(relay, finalGoal)
|
||||
if slot.order.rallyHold || (distMeToRelaySq > 1444.0 && distMeToGoalSq > distRelayToGoalSq)
|
||||
activeGoal = relay
|
||||
|
||||
if now >= rt.nextShortcutAt
|
||||
wto_try_shortcut(world, now, myPos, activeGoal, slot)
|
||||
|
||||
@@ -27,6 +27,7 @@ require %appGame.wtoai.wto_ai_types_common
|
||||
require %appGame.wtoai.wto_ai_specs_common
|
||||
require %appGame.wtoai.wto_ai_world_common
|
||||
require %appGame.wtoai.wto_ai_crowd_common
|
||||
require %appGame.wtoai.wto_ai_lanes_common
|
||||
require %appGame.wtoai.wto_ai_commander_common
|
||||
require %appGame.wtoai.wto_ai_perceive_common
|
||||
require %appGame.wtoai.wto_ai_tactics_common
|
||||
@@ -37,9 +38,11 @@ require %appGame.wtoai.wto_ai_diag_common
|
||||
|
||||
var private @safe_when_uninitialized g_world : WtoWorldSnap
|
||||
var private @safe_when_uninitialized g_crowd : WtoCrowdSummary
|
||||
var private @safe_when_uninitialized g_lanes : WtoTeamLanes
|
||||
var private @safe_when_uninitialized g_bots : WtoBotSlot[64]
|
||||
var private g_last_world_frame : float = -1.0
|
||||
var private g_next_cmd_at : float = 0.0
|
||||
var private g_next_rally_at : float = 0.0
|
||||
var private g_cmd_dirty : bool = true
|
||||
var private g_last_zone_ver : int = -1
|
||||
var private g_fire_budget : int = 0
|
||||
@@ -51,9 +54,11 @@ def private wto_any_layer_active() : bool
|
||||
[never_inline]
|
||||
def private wto_reset_runtime()
|
||||
wto_world_reset(g_world)
|
||||
wto_lanes_reset(g_lanes)
|
||||
g_crowd = WtoCrowdSummary()
|
||||
g_last_world_frame = -1.0
|
||||
g_next_cmd_at = 0.0
|
||||
g_next_rally_at = 0.0
|
||||
g_cmd_dirty = true
|
||||
g_last_zone_ver = -1
|
||||
g_next_diag_at = 0.0
|
||||
@@ -200,11 +205,29 @@ def wto_ai_world_tick_es(act : UpdateStageInfoAct)
|
||||
let zoneChanged = g_world.zoneVersion != g_last_zone_ver
|
||||
if zoneChanged
|
||||
g_last_zone_ver = g_world.zoneVersion
|
||||
wto_lanes_reset_rallies(g_lanes)
|
||||
g_cmd_dirty = true
|
||||
if WTO_AI_LAYER_MACRO && (now >= g_next_cmd_at || g_cmd_dirty)
|
||||
g_next_cmd_at = now + WTO_AI_CMD_REBALANCE_SEC
|
||||
g_next_rally_at = now + 1.0
|
||||
g_cmd_dirty = false
|
||||
wto_commander_update_all(g_world, now, zoneChanged, g_bots)
|
||||
wto_commander_update_all(g_world, now, zoneChanged, g_lanes, g_bots)
|
||||
elif WTO_AI_LAYER_MACRO && now >= g_next_rally_at
|
||||
g_next_rally_at = now + 1.0
|
||||
wto_lanes_update_rallies(g_world, 1, now, g_lanes, g_bots)
|
||||
wto_lanes_update_rallies(g_world, 2, now, g_lanes, g_bots)
|
||||
for i in range(WTO_MAX_BOTS)
|
||||
assume b = g_bots[i]
|
||||
if b.used && b.order.valid && b.order.rallyHold && b.order.capIndex >= 0
|
||||
let sk = wto_lanes_sub_key(b.army, b.order.capIndex, b.order.laneId)
|
||||
if g_lanes.rallyReleased[sk]
|
||||
b.order.rallyHold = false
|
||||
if b.order.role == WTO_CMD_FLANK && b.order.laneId > 0
|
||||
let ck = wto_lanes_cap_key(b.army, b.order.capIndex)
|
||||
b.order.routeRelayValid = g_lanes.flankValid[ck * 2 + b.order.laneId - 1]
|
||||
b.order.routeRelayPos = g_lanes.flankRelay[ck * 2 + b.order.laneId - 1]
|
||||
else
|
||||
b.order.routeRelayValid = false
|
||||
if WTO_AI_DIAG_TELEMETRY && now >= g_next_diag_at
|
||||
g_next_diag_at = now + WTO_AI_DIAG_INTERVAL_SEC
|
||||
wto_diag_log_telemetry(g_world, now, g_bots, g_crowd)
|
||||
|
||||
@@ -183,6 +183,12 @@ def public wto_tactics_update(world : WtoWorldSnap const&; now, dt : float;
|
||||
if !hasGroundTgt && now < p.watchUntil && slot.order.urgency != WTO_URGENCY_HIGH && distGoal <= 35.0
|
||||
wto_sm_set_state(now, WTO_STATE_MARCH, myPos, 0.0, "watch_last_exit", distXZ, slot)
|
||||
return
|
||||
// Hold at the 40% rally staging point until the group launches (unless threatened inside 300 m).
|
||||
if slot.order.rallyHold && slot.order.routeRelayValid && distXZ > WTO_AI_FC_MID_RANGE_M
|
||||
let rallyHoldRad = max(18.0, WTO_AI_CMD_RALLY_RADIUS_M * 0.55)
|
||||
if wto_xz_dist_sq(myPos, slot.order.routeRelayPos) <= rallyHoldRad * rallyHoldRad
|
||||
wto_sm_set_state(now, WTO_STATE_MARCH, myPos, 0.0, "rally_wait", distXZ, slot)
|
||||
return
|
||||
let marchSpd = wto_sm_march_speed(slot, distGoal)
|
||||
let marchGoal = distGoal <= 8.0 ? myPos : baseGoal
|
||||
wto_sm_set_state(now, WTO_STATE_MARCH, marchGoal, marchSpd, "march_task", distXZ, slot)
|
||||
@@ -36,6 +36,13 @@ export interface GroundAiConfig {
|
||||
readonly overwatchStandOffM: number;
|
||||
readonly flankStandOffM: number;
|
||||
readonly spaaFollowOffsetM: number;
|
||||
readonly flankMaxLengthRatio: number;
|
||||
readonly flankMinSeparationM: number;
|
||||
readonly rallyProgressFrac: number;
|
||||
readonly rallyWaitSec: number;
|
||||
readonly rallyMinFrac: number;
|
||||
readonly rallyRadiusM: number;
|
||||
readonly recallSafeHoldSec: number;
|
||||
};
|
||||
readonly macro: {
|
||||
readonly openingSplitSec: number;
|
||||
@@ -218,6 +225,13 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] {
|
||||
['WTO_AI_CMD_OVERWATCH_STANDOFF_M', 'float', c.commander.overwatchStandOffM],
|
||||
['WTO_AI_CMD_FLANK_STANDOFF_M', 'float', c.commander.flankStandOffM],
|
||||
['WTO_AI_CMD_SPAA_FOLLOW_OFFSET_M', 'float', c.commander.spaaFollowOffsetM],
|
||||
['WTO_AI_CMD_FLANK_MAX_RATIO', 'float', c.commander.flankMaxLengthRatio],
|
||||
['WTO_AI_CMD_FLANK_MIN_SEP_M', 'float', c.commander.flankMinSeparationM],
|
||||
['WTO_AI_CMD_RALLY_PROG_FRAC', 'float', c.commander.rallyProgressFrac],
|
||||
['WTO_AI_CMD_RALLY_WAIT_SEC', 'float', c.commander.rallyWaitSec],
|
||||
['WTO_AI_CMD_RALLY_MIN_FRAC', 'float', c.commander.rallyMinFrac],
|
||||
['WTO_AI_CMD_RALLY_RADIUS_M', 'float', c.commander.rallyRadiusM],
|
||||
['WTO_AI_CMD_RECALL_SAFE_SEC', 'float', c.commander.recallSafeHoldSec],
|
||||
['WTO_AI_MACRO_OPENING_SPLIT_SEC', 'float', c.macro.openingSplitSec],
|
||||
['WTO_AI_MACRO_CAP_MAX_INSIDERS', 'int', c.macro.capMaxInsiders],
|
||||
['WTO_AI_MACRO_RECAP_MIN_BOTS', 'int', c.macro.recaptureMinBots],
|
||||
|
||||
Reference in new issue
Block a user