feat(ground-ai): add task order, mode-aware commander v1, and world fixes
Replace the per-bot greedy cap scorer (wto_ai_macro_common.das) with a whole-team commander and explicit task order contract, and fix the world, spec, and navigation bugs found during the codebase audit: - Classify ground battle modes (bttl, conq, dom) in multiplayer-missions v5 from mislist.blk categories (with suffix fallback for event maps) and emit wtoGroundMode in customRules/customBots. - Add the commander section to tuning/ground-ai.jsonc with range and sum validation, compiled into WTO_AI_CMD_* constants. - Split zone/mode/spawn refresh into wto_ai_world_zones_common.das and fix four world snapshot bugs: stop double-recording deaths in wreck scans and deduplicate with a ring cursor, refresh units before spawn fallback while retrying real respawn points, fall back battleCenter to spawns when capCount is 0, and relax cap radius clamping to 10..180 m. - Fix limited-traverse yaw overwrite in wto_ai_specs_common.das and compute pivot turn angle against wishDir in wto_ai_nav_common.das. - Introduce WtoTaskOrder (wto_ai_order_common.das) and whole-team commander v1 (wto_ai_commander_common.das + wto_ai_commander_anchors_common.das): mode-aware role quotas (Bttl, Conq, Dom), deterministic distance + vehicle-suitability matching, 20-second role hysteresis, separate total-assigned vs cap-insider counters, frontline-relative SPAA anchors, EventZoneCaptured immediate rebalance, and per-team WTO_AI|CMD telemetry. Verified root and launcher type checks, multiplayer-missions v5 dataset extraction (1140 missions with Bttl/Conq/Dom classification), isolated 2.61.0.58 build (18 ground AI modules packed), and clean in-engine daScript compilation/load (wto_ai_runtime.das loaded in 155 ms, 0 compile errors). Live battle tuning and acceptance deferred until the full pipeline is wired.
This commit is contained in:
1 parent
73bae4785f
commit
7e5eb99696
18 files changed
+863
-340
No files matched your search
@@ -130,6 +130,7 @@ function customBotsBlock(plan: BattleLaunchPlan): BlkBlock {
|
||||
setParam(bots, 'wtoPlayerTeam', text(String(plan.playerTeam)));
|
||||
setParam(bots, 'wtoTeamACountries', text(plan.countriesAllies.join(';')));
|
||||
setParam(bots, 'wtoTeamBCountries', text(plan.countriesAxis.join(';')));
|
||||
if (plan.mission.groundMode !== undefined) setParam(bots, 'wtoGroundMode', text(plan.mission.groundMode));
|
||||
if (plan.maxRespawns === UNLIMITED_RESPAWNS) setParam(bots, 'wtoUnlimitedRespawns', text('1'));
|
||||
setParam(bots, 'numBotRespawnsInMultiSlot', integer(plan.airBotRespawns));
|
||||
setParam(bots, 'numTankBotRespawnsInMultiSlot', integer(plan.tankBotRespawns));
|
||||
|
||||
@@ -41,9 +41,13 @@ interface AirfieldLayoutData {
|
||||
readonly airfieldLayoutProblem?: string;
|
||||
}
|
||||
|
||||
export type GroundBattleMode = 'bttl' | 'conq' | 'dom';
|
||||
|
||||
export interface MissionHeader extends AirfieldLayoutData {
|
||||
readonly name: string;
|
||||
readonly path: string;
|
||||
/** Ground mission tactical layout derived from mislist category (or suffix fallback for events). */
|
||||
readonly groundMode?: GroundBattleMode;
|
||||
readonly level?: string;
|
||||
readonly type?: string;
|
||||
readonly environment?: string;
|
||||
@@ -72,7 +76,7 @@ export interface MultiplayerMissions {
|
||||
|
||||
export const multiplayerMissions: Dataset<MultiplayerMissions> = {
|
||||
id: 'multiplayer-missions',
|
||||
version: 4,
|
||||
version: 5,
|
||||
extract(source: DatasetSource): MultiplayerMissions {
|
||||
const section = blockAt(source.readBlk('char.vromfs.bin', MISSION_LIST), MULTIPLAYER_SECTION);
|
||||
if (!section) throw new Error(`${MISSION_LIST} has no "${MULTIPLAYER_SECTION}" block`);
|
||||
@@ -82,6 +86,7 @@ export const multiplayerMissions: Dataset<MultiplayerMissions> = {
|
||||
missions: stringList(block, 'm'),
|
||||
}));
|
||||
|
||||
const groundModeByMission = indexGroundModes(categories);
|
||||
const paths = source.listFiles('mis.vromfs.bin');
|
||||
const pathByName = missionPathsByLowerName(paths);
|
||||
const knownPaths = new Set(paths);
|
||||
@@ -94,12 +99,34 @@ export const multiplayerMissions: Dataset<MultiplayerMissions> = {
|
||||
const document = source.readBlk('mis.vromfs.bin', path);
|
||||
const airfields = path.startsWith(AIR_HISTORICAL_MISSION_FOLDER)
|
||||
? readAirfieldLayouts(source, document, knownPaths, airfieldsByPath) : { airfieldLayouts: [] };
|
||||
missions[name] = readHeader(name, path, document, airfields);
|
||||
const groundMode = groundModeByMission.get(name) ?? groundModeFromName(name);
|
||||
missions[name] = readHeader(name, path, document, airfields, groundMode);
|
||||
}
|
||||
return { categories, missions };
|
||||
},
|
||||
};
|
||||
|
||||
function indexGroundModes(categories: readonly MissionCategory[]): Map<string, GroundBattleMode> {
|
||||
const byName = new Map<string, GroundBattleMode>();
|
||||
for (const category of categories) {
|
||||
const mode: GroundBattleMode | undefined =
|
||||
category.name === 'air_ground_Bttl' ? 'bttl'
|
||||
: category.name === 'air_ground_Conq' ? 'conq'
|
||||
: category.name === 'air_ground_Dom' ? 'dom'
|
||||
: undefined;
|
||||
if (!mode) continue;
|
||||
for (const name of category.missions) if (!byName.has(name)) byName.set(name, mode);
|
||||
}
|
||||
return byName;
|
||||
}
|
||||
|
||||
function groundModeFromName(name: string): GroundBattleMode | undefined {
|
||||
if (/_Bttl\d*$/i.test(name)) return 'bttl';
|
||||
if (/_Conq\d*$/i.test(name)) return 'conq';
|
||||
if (/_Dom\d*$/i.test(name)) return 'dom';
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function missionPathsByLowerName(paths: readonly string[]): Map<string, string> {
|
||||
const byName = new Map<string, string>();
|
||||
const repeated = new Set<string>();
|
||||
@@ -114,11 +141,12 @@ function missionPathsByLowerName(paths: readonly string[]): Map<string, string>
|
||||
}
|
||||
|
||||
function readHeader(
|
||||
name: string, path: string, document: BlkBlock, airfields: AirfieldLayoutData,
|
||||
name: string, path: string, document: BlkBlock, airfields: AirfieldLayoutData, groundMode?: GroundBattleMode,
|
||||
): MissionHeader {
|
||||
const settings = blockAt(document, 'mission_settings');
|
||||
const mission = blockAt(settings, 'mission');
|
||||
const optional = {
|
||||
groundMode,
|
||||
level: stringField(mission, 'level'),
|
||||
type: stringField(mission, 'type'),
|
||||
environment: stringField(mission, 'environment'),
|
||||
|
||||
@@ -34,6 +34,7 @@ export function readGroundAiTuning(reader: TuningReader): GroundAiTuning {
|
||||
tacticsTickSec: cadence.number('tacticsTickSec', { min: 0.05, max: 2 }),
|
||||
navTickSec: cadence.number('navTickSec', { min: 0.05, max: 2 }),
|
||||
},
|
||||
commander: readCommanderSection(reader.object('commander')),
|
||||
macro: readMacroSection(reader.object('macro')),
|
||||
crowd: readCrowdSection(reader.object('crowd')),
|
||||
terrain: readTerrainSection(reader.object('terrain')),
|
||||
@@ -68,6 +69,42 @@ function readLineupWeights(weights: TuningReader): TankLineupWeights {
|
||||
};
|
||||
}
|
||||
|
||||
function readCommanderSection(cmd: TuningReader): GroundAiTuning['commander'] {
|
||||
const pct = { min: 0, max: 100 };
|
||||
const bttlAssaultPct = cmd.int('bttlAssaultPct', pct);
|
||||
const bttlFlankPct = cmd.int('bttlFlankPct', pct);
|
||||
const bttlOverwatchPct = cmd.int('bttlOverwatchPct', pct);
|
||||
if (bttlAssaultPct + bttlFlankPct + bttlOverwatchPct > 100) {
|
||||
throw new TuningError('tuning file ground-ai.jsonc: commander Bttl percentages must sum to <= 100');
|
||||
}
|
||||
const conqAssaultPct = cmd.int('conqAssaultPct', pct);
|
||||
const conqFlankPct = cmd.int('conqFlankPct', pct);
|
||||
if (conqAssaultPct + conqFlankPct > 100) {
|
||||
throw new TuningError('tuning file ground-ai.jsonc: commander Conq assault + flank percentages must sum to <= 100');
|
||||
}
|
||||
const conqHoldDefendPct = cmd.int('conqHoldDefendPct', pct);
|
||||
const conqHoldOverwatchPct = cmd.int('conqHoldOverwatchPct', pct);
|
||||
if (conqHoldDefendPct + conqHoldOverwatchPct > 100) {
|
||||
throw new TuningError('tuning file ground-ai.jsonc: commander Conq hold percentages must sum to <= 100');
|
||||
}
|
||||
return {
|
||||
rebalanceSec: cmd.number('rebalanceSec', { min: 1.0, max: 30.0 }),
|
||||
roleHoldSec: cmd.number('roleHoldSec', { min: 0.0, max: 120.0 }),
|
||||
bttlAssaultPct,
|
||||
bttlFlankPct,
|
||||
bttlOverwatchPct,
|
||||
conqAssaultPct,
|
||||
conqFlankPct,
|
||||
conqHoldDefendPct,
|
||||
conqHoldOverwatchPct,
|
||||
domAssaultPct: cmd.int('domAssaultPct', pct),
|
||||
domMaxDefendersPerCap: cmd.int('domMaxDefendersPerCap', { min: 0, max: 4 }),
|
||||
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 }),
|
||||
};
|
||||
}
|
||||
|
||||
function readMacroSection(macro: TuningReader): GroundAiTuning['macro'] {
|
||||
const recaptureMinBots = macro.int('recaptureMinBots', { min: 1, max: 8 });
|
||||
const recaptureMaxBots = macro.int('recaptureMaxBots', { min: 1, max: 12 });
|
||||
|
||||
@@ -26,6 +26,24 @@
|
||||
"navTickSec": 0.2
|
||||
},
|
||||
|
||||
// Team commander role quotas and timing (offline values).
|
||||
"commander": {
|
||||
"rebalanceSec": 5.0,
|
||||
"roleHoldSec": 20.0,
|
||||
"bttlAssaultPct": 45,
|
||||
"bttlFlankPct": 15,
|
||||
"bttlOverwatchPct": 20,
|
||||
"conqAssaultPct": 50,
|
||||
"conqFlankPct": 20,
|
||||
"conqHoldDefendPct": 30,
|
||||
"conqHoldOverwatchPct": 30,
|
||||
"domAssaultPct": 70,
|
||||
"domMaxDefendersPerCap": 1,
|
||||
"overwatchStandOffM": 95.0,
|
||||
"flankStandOffM": 75.0,
|
||||
"spaaFollowOffsetM": 160.0
|
||||
},
|
||||
|
||||
"macro": {
|
||||
"openingSplitSec": 40.0,
|
||||
"capMaxInsiders": 2,
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
// Anchor point selection and safety helpers for the team commander.
|
||||
options indenting = 2
|
||||
options no_global_heap = true
|
||||
module wto_ai_commander_anchors_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_terrain_common
|
||||
|
||||
[never_inline]
|
||||
def public wto_cmd_vehicle_penalty(unitRole, cmdRole : int) : float
|
||||
if cmdRole == WTO_CMD_FLANK
|
||||
if unitRole == WTO_ROLE_LIGHT
|
||||
return -180.0
|
||||
if unitRole == WTO_ROLE_HEAVY
|
||||
return 120.0
|
||||
if unitRole == WTO_ROLE_TD
|
||||
return 160.0
|
||||
return 0.0
|
||||
if cmdRole == WTO_CMD_OVERWATCH || cmdRole == WTO_CMD_DEFEND
|
||||
if unitRole == WTO_ROLE_TD
|
||||
return -160.0
|
||||
if unitRole == WTO_ROLE_HEAVY
|
||||
return -40.0
|
||||
if unitRole == WTO_ROLE_LIGHT
|
||||
return 120.0
|
||||
return 0.0
|
||||
if cmdRole == WTO_CMD_ASSAULT
|
||||
if unitRole == WTO_ROLE_MEDIUM || unitRole == WTO_ROLE_HEAVY
|
||||
return -80.0
|
||||
if unitRole == WTO_ROLE_TD
|
||||
return 140.0
|
||||
return 0.0
|
||||
return 0.0
|
||||
|
||||
[never_inline]
|
||||
def public wto_cmd_log_summary(world : WtoWorldSnap const&; army : int; now : float;
|
||||
candCount : int; cands : int[64]; candPos : float3[64];
|
||||
capAssigned, capInsiders : int[8]; spaaCount : int;
|
||||
bots : WtoBotSlot[64])
|
||||
if !WTO_AI_DIAG_TELEMETRY
|
||||
return
|
||||
var rCnt : int[6]
|
||||
for r in range(6)
|
||||
rCnt[r] = 0
|
||||
rCnt[WTO_CMD_SPAA] = spaaCount
|
||||
var atFront = 0
|
||||
for ci in range(candCount)
|
||||
assume b = bots[cands[ci]]
|
||||
rCnt[clamp(b.order.role, 0, 5)]++
|
||||
if wto_order_is_offensive(b.order.role) && b.order.capIndex >= 0 && wto_xz_dist_sq(candPos[ci], world.caps[b.order.capIndex].center) <= 40000.0
|
||||
atFront++
|
||||
print("WTO_AI|CMD|t={now}|army={army}|mode={world.battleMode}|n={candCount}|roles={rCnt[0]}/{rCnt[1]}/{rCnt[2]}/{rCnt[3]}/{rCnt[5]}|caps={capAssigned[0]}/{capAssigned[1]}/{capAssigned[2]}|in={capInsiders[0]}/{capInsiders[1]}/{capInsiders[2]}|front={atFront}\n")
|
||||
|
||||
[never_inline]
|
||||
def public wto_cmd_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 public wto_cmd_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_try_anchor_candidate(world : WtoWorldSnap const&; army : int; rawPos : float3;
|
||||
var outPos : float3&) : bool
|
||||
var cand = wto_cmd_clamp_away_enemy_spawn(world, army, rawPos)
|
||||
cand = wto_clamp_battle_xz(cand, world.battleCenter, world.battleRadius, 40.0)
|
||||
if wto_terrain_point_valid(army, cand)
|
||||
outPos = cand
|
||||
return true
|
||||
return false
|
||||
|
||||
[never_inline]
|
||||
def public wto_cmd_pick_role_anchor(world : WtoWorldSnap const&; army : int; eid : EntityId;
|
||||
capIdx, cmdRole : int; insideCircle : 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)
|
||||
var chosen = cap.center
|
||||
|
||||
if cmdRole == WTO_CMD_ASSAULT && insideCircle
|
||||
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 pt = float3(cap.center.x + cos(slotAng) * inRad, cap.center.y, cap.center.z + sin(slotAng) * inRad)
|
||||
if wto_terrain_point_valid(army, pt)
|
||||
return pt
|
||||
return cap.center
|
||||
|
||||
let sideSign = (h & 1u) == 0u ? 1.0 : -1.0
|
||||
let tier = float((h / 2u) % 3u)
|
||||
var latDist = cap.radius + 18.0 + tier * 12.0
|
||||
var backDist = 14.0 + tier * 10.0
|
||||
if cmdRole == WTO_CMD_FLANK
|
||||
latDist = max(cap.radius + 20.0, WTO_AI_CMD_FLANK_STANDOFF_M + tier * 16.0)
|
||||
backDist = 8.0 - tier * 12.0
|
||||
elif cmdRole == WTO_CMD_OVERWATCH
|
||||
latDist = (tier - 1.0) * 34.0 + sideSign * 22.0
|
||||
backDist = max(cap.radius + 25.0, WTO_AI_CMD_OVERWATCH_STANDOFF_M + tier * 18.0)
|
||||
elif cmdRole == WTO_CMD_DEFEND || cmdRole == WTO_CMD_RESERVE
|
||||
latDist = sideSign * (cap.radius + 14.0 + tier * 12.0)
|
||||
backDist = 12.0 + tier * 10.0
|
||||
|
||||
for attempt in range(4)
|
||||
let flip = (attempt == 1 || attempt == 3) ? -1.0 : 1.0
|
||||
let scale = attempt >= 2 ? 0.6 : 1.0
|
||||
let cand = cap.center + lat * (sideSign * latDist * flip * scale) - toCap * (backDist * scale)
|
||||
if wto_try_anchor_candidate(world, army, cand, chosen)
|
||||
return chosen
|
||||
return wto_clamp_battle_xz(cap.center - toCap * (cap.radius + 18.0), world.battleCenter, world.battleRadius, 40.0)
|
||||
|
||||
[never_inline]
|
||||
def public wto_cmd_assign_spaa(world : WtoWorldSnap const&; now : float; myPos, frontPt : float3;
|
||||
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)
|
||||
if needNew
|
||||
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 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
|
||||
ord.spaaAnchorValid = true
|
||||
ord.spaaRelocateAt = now + WTO_AI_MACRO_SPAA_RELOCATE_SEC
|
||||
ord.role = WTO_CMD_SPAA
|
||||
ord.capIndex = -1
|
||||
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.overwatchOutside = true
|
||||
ord.cautious = false
|
||||
ord.assignedAt = now
|
||||
ord.expiresAt = now + WTO_AI_MACRO_SPAA_RELOCATE_SEC
|
||||
ord.valid = true
|
||||
@@ -0,0 +1,274 @@
|
||||
// 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_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]
|
||||
|
||||
[never_inline]
|
||||
def private wto_cmd_apply_order(world : WtoWorldSnap const&; army : int; now : float;
|
||||
capIdx, cmdRole, urgency : int;
|
||||
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)
|
||||
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;
|
||||
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
|
||||
// Pass 1: honor 20s role hysteresis unless cap ownership/mode forced a rebalance.
|
||||
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], capInsiders, capAssigned, bots[bIdx])
|
||||
break
|
||||
// Pass 2: deterministic best suitability + distance match for remaining slots.
|
||||
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], 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]&)
|
||||
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.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, bots[spaaIdx[si]])
|
||||
return
|
||||
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_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
|
||||
for si in range(spaaCount)
|
||||
wto_cmd_assign_spaa(world, now, spaaPos[si], frontPt, 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)
|
||||
@@ -202,7 +202,7 @@ def public wto_drive_step_phys(var unit : Unit?; unitMissionName : string;
|
||||
return
|
||||
if !wto_prepare_phys_owner(gm, actor, now, slot)
|
||||
return
|
||||
if !slot.driveCmd.valid || (!slot.macro.valid && !WTO_AI_LAYER_TACTICS)
|
||||
if !slot.driveCmd.valid || (!slot.order.valid && !WTO_AI_LAYER_TACTICS)
|
||||
wto_drive_handle_failure(gm, actor, slot, "invalid_drive_cmd", false)
|
||||
return
|
||||
if now > slot.nextNavAt + WTO_AI_NAV_TICK_SEC
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
// 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)
|
||||
@@ -243,6 +243,7 @@ def public wto_nav_update(var world : WtoWorldSnap&; now : float;
|
||||
bestDir = wishDir
|
||||
|
||||
slot.nav.steerDir = bestDir
|
||||
let turnDeg = acos(clamp(dot(bestDir, hullFwd), -1.0, 1.0)) * WTO_RAD_TO_DEG
|
||||
let turnDeg = acos(clamp(dot(wishDir, hullFwd), -1.0, 1.0)) * WTO_RAD_TO_DEG
|
||||
let needPivot = turnDeg >= WTO_AI_NAV_PIVOT_ANGLE_DEG || (slot.nav.frontClearM < slot.spec.halfLen + 1.8 && turnDeg > 32.0)
|
||||
wto_set_drive_cmd(slot.driveCmd, needPivot ? WTO_DRIVE_PIVOT : WTO_DRIVE_CRUISE, myPos + bestDir * 22.0, bestDir, slot.tactics.desiredSpeedMps, slot.nav.frontClearM, slot.nav.rearClearM)
|
||||
let cmdDir = needPivot ? wishDir : bestDir
|
||||
wto_set_drive_cmd(slot.driveCmd, needPivot ? WTO_DRIVE_PIVOT : WTO_DRIVE_CRUISE, myPos + cmdDir * 22.0, cmdDir, slot.tactics.desiredSpeedMps, slot.nav.frontClearM, slot.nav.rearClearM)
|
||||
@@ -0,0 +1,53 @@
|
||||
// Task order contract between the team commander and per-bot hull behavior.
|
||||
// Every per-bot decision reads `WtoTaskOrder` rather than guessing team intent.
|
||||
options indenting = 2
|
||||
options no_global_heap = true
|
||||
module wto_ai_order_common shared
|
||||
|
||||
let public WTO_MODE_UNKNOWN = 0
|
||||
let public WTO_MODE_BTTL = 1
|
||||
let public WTO_MODE_CONQ = 2
|
||||
let public WTO_MODE_DOM = 3
|
||||
|
||||
let public WTO_CMD_ASSAULT = 0
|
||||
let public WTO_CMD_FLANK = 1
|
||||
let public WTO_CMD_OVERWATCH = 2
|
||||
let public WTO_CMD_DEFEND = 3
|
||||
let public WTO_CMD_RESERVE = 4
|
||||
let public WTO_CMD_SPAA = 5
|
||||
|
||||
let public WTO_URGENCY_LOW = 0
|
||||
let public WTO_URGENCY_MED = 1
|
||||
let public WTO_URGENCY_HIGH = 2
|
||||
|
||||
[safe_when_uninitialized]
|
||||
struct public WtoTaskOrder
|
||||
valid : bool = false
|
||||
role : int = 0
|
||||
capIndex : int = -1
|
||||
goalPos : float3 = float3(0.0, 0.0, 0.0)
|
||||
urgency : int = 1
|
||||
maxStopRangeM : float = 800.0
|
||||
assignedAt : float = -100.0
|
||||
expiresAt : float = -100.0
|
||||
cautious : bool = false
|
||||
overwatchOutside : bool = false
|
||||
spaaAnchorValid : bool = false
|
||||
spaaAnchorPos : float3 = float3(0.0, 0.0, 0.0)
|
||||
spaaRelocateAt : float = -100.0
|
||||
|
||||
[never_inline]
|
||||
def public wto_order_is_offensive(role : int) : bool
|
||||
return role == WTO_CMD_ASSAULT || role == WTO_CMD_FLANK
|
||||
|
||||
[never_inline]
|
||||
def public wto_order_max_stop_range(role, urgency : int; maxEngageRangeM : float) : float
|
||||
if role == WTO_CMD_ASSAULT || role == WTO_CMD_FLANK
|
||||
return 300.0
|
||||
if role == WTO_CMD_OVERWATCH
|
||||
return maxEngageRangeM
|
||||
if role == WTO_CMD_DEFEND
|
||||
return urgency == WTO_URGENCY_HIGH ? 300.0 : maxEngageRangeM
|
||||
if role == WTO_CMD_RESERVE
|
||||
return 800.0
|
||||
return 300.0
|
||||
@@ -29,7 +29,7 @@ def private wto_ensure_wing_relay(world : WtoWorldSnap const&; myPos, dest : flo
|
||||
let h = uint(slot.eid)
|
||||
rt.wingSign = int(h % 5u) - 2
|
||||
rt.laneOffsetM = float(int((h / 5u) % 5u) - 2) * 4.5
|
||||
let capIdx = slot.macro.capIndex
|
||||
let capIdx = slot.order.capIndex
|
||||
if rt.wingCapIdx == capIdx
|
||||
return
|
||||
rt.wingCapIdx = capIdx
|
||||
|
||||
@@ -21,11 +21,12 @@ require %appGame.wt_events
|
||||
require %game.events
|
||||
require %game.unit.unit_events
|
||||
require %appGame.wtoai.wto_ai_config_common
|
||||
require %appGame.wtoai.wto_ai_order_common
|
||||
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_macro_common
|
||||
require %appGame.wtoai.wto_ai_commander_common
|
||||
require %appGame.wtoai.wto_ai_tactics_common
|
||||
require %appGame.wtoai.wto_ai_nav_common
|
||||
require %appGame.wtoai.wto_ai_drive_common
|
||||
@@ -35,7 +36,9 @@ var private @safe_when_uninitialized g_world : WtoWorldSnap
|
||||
var private @safe_when_uninitialized g_crowd : WtoCrowdSummary
|
||||
var private @safe_when_uninitialized g_bots : WtoBotSlot[64]
|
||||
var private g_last_world_frame : float = -1.0
|
||||
var private g_next_macro_at : float = 0.0
|
||||
var private g_next_cmd_at : float = 0.0
|
||||
var private g_cmd_dirty : bool = true
|
||||
var private g_last_zone_ver : int = -1
|
||||
var private g_next_diag_at : float = 0.0
|
||||
|
||||
def private wto_any_layer_active() : bool
|
||||
@@ -46,7 +49,9 @@ def private wto_reset_runtime()
|
||||
wto_world_reset(g_world)
|
||||
g_crowd = WtoCrowdSummary()
|
||||
g_last_world_frame = -1.0
|
||||
g_next_macro_at = 0.0
|
||||
g_next_cmd_at = 0.0
|
||||
g_cmd_dirty = true
|
||||
g_last_zone_ver = -1
|
||||
g_next_diag_at = 0.0
|
||||
for i in range(WTO_MAX_BOTS)
|
||||
if g_bots[i].drive.routeBOwned
|
||||
@@ -82,6 +87,7 @@ def private wto_acquire_slot(eid : EntityId; army : int; now : float) : int
|
||||
g_bots[freeIdx].nextTacticsAt = now + float(freeIdx % 8) * (WTO_AI_TACTICS_TICK_SEC / 8.0)
|
||||
g_bots[freeIdx].nextNavAt = now + float(freeIdx % 10) * (WTO_AI_NAV_TICK_SEC / 10.0)
|
||||
g_bots[freeIdx].route.nextReplanAt = now + float(freeIdx % 12) * 0.2
|
||||
g_cmd_dirty = true
|
||||
return freeIdx
|
||||
|
||||
[never_inline]
|
||||
@@ -153,16 +159,25 @@ def private wto_log_telemetry(now : float)
|
||||
def wto_ai_mission_reset_es(evt : Event)
|
||||
wto_reset_runtime()
|
||||
|
||||
[es(tag=server)]
|
||||
def wto_ai_zone_captured_es(evt : EventZoneCaptured)
|
||||
if !wto_any_layer_active()
|
||||
return
|
||||
g_world.zoneVersion++
|
||||
g_cmd_dirty = true
|
||||
print("WTO_AI|ZONE_CAP|area={evt.areaId}|from={int(evt.wasArmy)}|to={int(evt.army)}\n")
|
||||
|
||||
[es(tag=server, on_event=(EventOnUnitDead, EventUnitBecameDead))]
|
||||
def wto_ai_unit_dead_es(evt : Event; eid : EntityId; unit__ref : UnitRef)
|
||||
let u = unit__ref.unit
|
||||
if u != null && as_gm(u) != null && (int(u.army) == 1 || int(u.army) == 2)
|
||||
wto_world_record_death(g_world, int(u.army), u.pos, float(get_app().usefulTotalTime))
|
||||
wto_world_record_death(g_world, eid, int(u.army), u.pos, float(get_app().usefulTotalTime))
|
||||
let idx = wto_find_slot(eid)
|
||||
if idx >= 0
|
||||
if g_bots[idx].drive.routeBOwned
|
||||
wto_drive_request_control(eid, 0)
|
||||
g_bots[idx] = WtoBotSlot()
|
||||
g_cmd_dirty = true
|
||||
|
||||
[es(tag=server, on_disappear, on_event=EventUnitRespawn)]
|
||||
def wto_ai_unit_cleanup_es(evt : Event; eid : EntityId)
|
||||
@@ -171,6 +186,7 @@ def wto_ai_unit_cleanup_es(evt : Event; eid : EntityId)
|
||||
if g_bots[idx].drive.routeBOwned
|
||||
wto_drive_request_control(eid, 0)
|
||||
g_bots[idx] = WtoBotSlot()
|
||||
g_cmd_dirty = true
|
||||
|
||||
[es(tag=server)]
|
||||
def wto_ai_unit_damage_es(evt : EventUnitDamage; eid : EntityId)
|
||||
@@ -203,9 +219,14 @@ def wto_ai_world_tick_es(act : UpdateStageInfoAct)
|
||||
print("WTO_AI|RUNTIME_READY\n")
|
||||
wto_world_refresh(now, g_world)
|
||||
wto_crowd_update_all(g_world, g_bots, g_crowd)
|
||||
if WTO_AI_LAYER_MACRO && now >= g_next_macro_at
|
||||
g_next_macro_at = now + WTO_AI_MACRO_TICK_SEC
|
||||
wto_macro_update_all(g_world, now, g_bots)
|
||||
let zoneChanged = g_world.zoneVersion != g_last_zone_ver
|
||||
if zoneChanged
|
||||
g_last_zone_ver = g_world.zoneVersion
|
||||
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_cmd_dirty = false
|
||||
wto_commander_update_all(g_world, now, zoneChanged, g_bots)
|
||||
if WTO_AI_DIAG_TELEMETRY && now >= g_next_diag_at
|
||||
g_next_diag_at = now + WTO_AI_DIAG_INTERVAL_SEC
|
||||
wto_log_telemetry(now)
|
||||
|
||||
@@ -50,11 +50,13 @@ def private wto_parse_turret_limits(turretBlk : DataBlock const?; var spec : Wto
|
||||
maxPitch = max(maxPitch, lim2.w)
|
||||
let limitsBlk = *turretBlk |> datablock_get_block_by_name("limits")
|
||||
if limitsBlk != null
|
||||
let yawRange = *limitsBlk |> datablock_getPoint2("yaw", float2(-180.0, 180.0))
|
||||
let pitchRange = *limitsBlk |> datablock_getPoint2("pitch", float2(-8.0, 22.0))
|
||||
maxAbsYaw = max(maxAbsYaw, max(abs(yawRange.x), abs(yawRange.y)))
|
||||
minPitch = min(minPitch, pitchRange.x)
|
||||
maxPitch = max(maxPitch, pitchRange.y)
|
||||
let yawRange = *limitsBlk |> datablock_getPoint2("yaw", float2(0.0, 0.0))
|
||||
let pitchRange = *limitsBlk |> datablock_getPoint2("pitch", float2(0.0, 0.0))
|
||||
if abs(yawRange.x) > 0.1 || abs(yawRange.y) > 0.1
|
||||
maxAbsYaw = max(maxAbsYaw, max(abs(yawRange.x), abs(yawRange.y)))
|
||||
if pitchRange.x < -0.1 || pitchRange.y > 0.1
|
||||
minPitch = min(minPitch, pitchRange.x)
|
||||
maxPitch = max(maxPitch, pitchRange.y)
|
||||
if maxAbsYaw > 0.5
|
||||
spec.yawLimitDeg = clamp(maxAbsYaw, 4.0, 180.0)
|
||||
spec.isLimitedTraverse = spec.yawLimitDeg < 75.0
|
||||
|
||||
@@ -136,7 +136,7 @@ def private wto_handle_combat_or_march(world : WtoWorldSnap const&; now : float;
|
||||
myPos, threatDir : float3; var slot : WtoBotSlot&)
|
||||
assume tac = slot.tactics
|
||||
assume p = slot.perceive
|
||||
let baseGoal = slot.macro.valid ? slot.macro.goalPos : world.battleCenter
|
||||
let baseGoal = slot.order.valid ? slot.order.goalPos : world.battleCenter
|
||||
if p.hasClearLos && !!p.targetEid && !p.targetIsAir
|
||||
let dist = sqrt(wto_xz_dist_sq(myPos, p.knownPos))
|
||||
// Shoot-and-scoot: back into cover during reload when medium-close and reverse gear is capable.
|
||||
@@ -151,8 +151,9 @@ def private wto_handle_combat_or_march(world : WtoWorldSnap const&; now : float;
|
||||
tac.moveGoal = tac.peekHomePos
|
||||
tac.desiredSpeedMps = slot.spec.vMaxRev
|
||||
return
|
||||
// Gun ready (or nearly ready): halt unstabilized chassis or long-range sniper shots cleanly!
|
||||
if !slot.fire.reloading && dist <= WTO_AI_FC_MAX_RANGE_M
|
||||
// Gun ready: respect task order's maxStopRangeM so assault/flank bots keep advancing!
|
||||
let stopLimit = slot.order.valid ? slot.order.maxStopRangeM : WTO_AI_FC_MAX_RANGE_M
|
||||
if !slot.fire.reloading && dist <= min(WTO_AI_FC_MAX_RANGE_M, stopLimit)
|
||||
if !slot.spec.hasVertStab || dist > 420.0 || slot.spec.isLimitedTraverse
|
||||
tac.posture = WTO_POSTURE_ENGAGE_HALT
|
||||
tac.moveGoal = myPos
|
||||
@@ -179,7 +180,7 @@ def private wto_handle_combat_or_march(world : WtoWorldSnap const&; now : float;
|
||||
tac.posture = WTO_POSTURE_ENGAGE_HALT
|
||||
tac.desiredSpeedMps = 0.0
|
||||
else
|
||||
let capScale = slot.macro.cautious ? 0.72 : 0.96
|
||||
let capScale = slot.order.cautious ? 0.72 : 0.96
|
||||
tac.desiredSpeedMps = distGoal < 24.0 ? min(slot.spec.vMaxFwd * 0.55, 6.0) : (slot.spec.vMaxFwd * capScale)
|
||||
|
||||
[never_inline]
|
||||
@@ -188,11 +189,11 @@ def public wto_tactics_update(var world : WtoWorldSnap&; now, dt : float;
|
||||
var slot : WtoBotSlot&; var crowdSummary : WtoCrowdSummary&)
|
||||
if !WTO_AI_LAYER_TACTICS
|
||||
slot.tactics.posture = WTO_POSTURE_MARCH
|
||||
slot.tactics.moveGoal = slot.macro.valid ? slot.macro.goalPos : myPos
|
||||
slot.tactics.moveGoal = slot.order.valid ? slot.order.goalPos : myPos
|
||||
slot.tactics.desiredSpeedMps = slot.spec.vMaxFwd * 0.9
|
||||
return
|
||||
wto_perceive_update(world, now, dt, myPos, hullFwd, slot)
|
||||
let fallbackGoal = slot.macro.valid ? slot.macro.goalPos : world.battleCenter
|
||||
let fallbackGoal = slot.order.valid ? slot.order.goalPos : world.battleCenter
|
||||
let threatRef = !!slot.perceive.targetEid ? slot.perceive.knownPos : fallbackGoal
|
||||
let threatDir = wto_xz_normalize(threatRef - myPos, wto_xz_normalize(hullFwd, float3(1.0, 0.0, 0.0)))
|
||||
if wto_handle_crippled_or_spaa(world, now, myPos, hullFwd, threatDir, isBurn, slot)
|
||||
|
||||
@@ -4,6 +4,7 @@ options no_global_heap = true
|
||||
module wto_ai_types_common shared
|
||||
|
||||
require ecs
|
||||
require %appGame.wtoai.wto_ai_order_common
|
||||
|
||||
let public WTO_MAX_BOTS = 64
|
||||
let public WTO_MAX_UNITS = 96
|
||||
@@ -86,6 +87,7 @@ struct public WtoCapSnap
|
||||
radius : float = 25.0
|
||||
ownerArmy : int = 0
|
||||
progress : float = 0.0
|
||||
contested : bool = false
|
||||
|
||||
[safe_when_uninitialized]
|
||||
struct public WtoDeathEvent
|
||||
@@ -115,14 +117,16 @@ struct public WtoWorldSnap
|
||||
units : WtoUnitSnap[96]
|
||||
wreckCount : int = 0
|
||||
wrecks : WtoWreckSnap[64]
|
||||
recordedDeadCount : int = 0
|
||||
deadIdCursor : int = 0
|
||||
recordedDeadEids : EntityId[64]
|
||||
battleMode : int = 0
|
||||
zoneVersion : int = 0
|
||||
capCount : int = 0
|
||||
caps : WtoCapSnap[8]
|
||||
nextCapRefreshAt : float = -100.0
|
||||
battleCenter : float3 = float3(0.0, 0.0, 0.0)
|
||||
battleRadius : float = 0.0
|
||||
spawnsResolved : bool = false
|
||||
teamSpawnFromPoints : bool[3]
|
||||
teamSpawnValid : bool[3]
|
||||
teamSpawnCenter : float3[3]
|
||||
deathCursor : int = 0
|
||||
@@ -148,17 +152,6 @@ struct public WtoCrowdSummary
|
||||
minPairDistM : float = 999.0
|
||||
disperseEvents : int = 0
|
||||
|
||||
[safe_when_uninitialized]
|
||||
struct public WtoMacroOrder
|
||||
goalPos : float3 = float3(0.0, 0.0, 0.0)
|
||||
capIndex : int = -1
|
||||
cautious : bool = false
|
||||
overwatchOutside : bool = false
|
||||
spaaAnchorValid : bool = false
|
||||
spaaAnchorPos : float3 = float3(0.0, 0.0, 0.0)
|
||||
spaaRelocateAt : float = -100.0
|
||||
valid : bool = false
|
||||
|
||||
[safe_when_uninitialized]
|
||||
struct public WtoPerceiveState
|
||||
targetEid : EntityId = INVALID_ENTITY_ID
|
||||
@@ -288,7 +281,7 @@ struct public WtoBotSlot
|
||||
nextNavAt : float = -100.0
|
||||
spec : WtoVehicleSpec = WtoVehicleSpec()
|
||||
crowd : WtoCrowdInfo = WtoCrowdInfo()
|
||||
macro : WtoMacroOrder = WtoMacroOrder()
|
||||
order : WtoTaskOrder = WtoTaskOrder()
|
||||
perceive : WtoPerceiveState = WtoPerceiveState()
|
||||
tactics : WtoTacticsState = WtoTacticsState()
|
||||
route : WtoRouteState = WtoRouteState()
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
// World observation layer: builds one flat per-frame snapshot of units, wrecks, authoritative
|
||||
// capture zones, respawn anchors, and ring buffers for deaths, traffic jams, and radio spots.
|
||||
// World observation layer: builds one flat per-frame snapshot of units, wrecks,
|
||||
// capture zones, respawn anchors, and ring buffers for deaths, jams, and radio spots.
|
||||
options indenting = 2
|
||||
options no_global_heap = true
|
||||
module wto_ai_world_common shared
|
||||
|
||||
require ecs
|
||||
require math
|
||||
require strings
|
||||
require DagorMath
|
||||
require Mission
|
||||
require Unit
|
||||
require IGroundModel
|
||||
require HeavyVehicleModel
|
||||
require Dacoll
|
||||
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_zones_common
|
||||
|
||||
[never_inline]
|
||||
def public wto_world_reset(var snap : WtoWorldSnap&)
|
||||
@@ -24,16 +22,18 @@ def public wto_world_reset(var snap : WtoWorldSnap&)
|
||||
snap.matchStartAt = -100.0
|
||||
snap.unitCount = 0
|
||||
snap.wreckCount = 0
|
||||
snap.recordedDeadCount = 0
|
||||
snap.deadIdCursor = 0
|
||||
snap.battleMode = WTO_MODE_UNKNOWN
|
||||
snap.zoneVersion = 0
|
||||
snap.capCount = 0
|
||||
snap.nextCapRefreshAt = -100.0
|
||||
snap.battleCenter = float3(0.0, 0.0, 0.0)
|
||||
snap.battleRadius = 0.0
|
||||
snap.spawnsResolved = false
|
||||
snap.deathCursor = 0
|
||||
snap.jamCursor = 0
|
||||
snap.radioCursor = 0
|
||||
for a in range(3)
|
||||
snap.teamSpawnFromPoints[a] = false
|
||||
snap.teamSpawnValid[a] = false
|
||||
snap.teamSpawnCenter[a] = float3(0.0, 0.0, 0.0)
|
||||
for i in range(WTO_MAX_WRECKS)
|
||||
@@ -46,9 +46,15 @@ def public wto_world_reset(var snap : WtoWorldSnap&)
|
||||
snap.radioSpots[i] = WtoRadioSpot()
|
||||
|
||||
[never_inline]
|
||||
def public wto_world_record_death(var snap : WtoWorldSnap&; army : int; pos : float3; now : float)
|
||||
def public wto_world_record_death(var snap : WtoWorldSnap&; eid : EntityId; army : int; pos : float3; now : float)
|
||||
if !wto_is_finite3(pos)
|
||||
return
|
||||
if !!eid
|
||||
for i in range(WTO_MAX_WRECKS)
|
||||
if snap.recordedDeadEids[i] == eid
|
||||
return
|
||||
snap.recordedDeadEids[snap.deadIdCursor % WTO_MAX_WRECKS] = eid
|
||||
snap.deadIdCursor = (snap.deadIdCursor + 1) % 100000
|
||||
let idx = snap.deathCursor % WTO_MAX_DEATHS
|
||||
snap.deaths[idx].pos = pos
|
||||
snap.deaths[idx].army = army
|
||||
@@ -126,15 +132,6 @@ def private wto_record_wreck_once(var snap : WtoWorldSnap&; eid : EntityId; u :
|
||||
snap.wrecks[wIdx].halfLen = max(2.0, max(abs(box.boxMin.x), abs(box.boxMax.x)))
|
||||
snap.wrecks[wIdx].halfWid = max(1.1, max(abs(box.boxMin.z), abs(box.boxMax.z)))
|
||||
snap.wreckCount = wIdx + 1
|
||||
let wArmy = int(u.army)
|
||||
if wArmy != 1 && wArmy != 2
|
||||
return
|
||||
for r in range(snap.recordedDeadCount)
|
||||
if snap.recordedDeadEids[r] == eid
|
||||
return
|
||||
let dst = snap.recordedDeadCount < WTO_MAX_WRECKS ? snap.recordedDeadCount++ : int(uint(eid) % uint(WTO_MAX_WRECKS))
|
||||
snap.recordedDeadEids[dst] = eid
|
||||
wto_world_record_death(snap, wArmy, u.pos, snap.time)
|
||||
|
||||
[never_inline]
|
||||
def private wto_refresh_units(var snap : WtoWorldSnap&)
|
||||
@@ -187,113 +184,14 @@ def private wto_refresh_units(var snap : WtoWorldSnap&)
|
||||
if snap.units[i].isGround
|
||||
snap.units[i].isLightTag = has(snap.units[i].eid, "unit_tag__light_vehicle")
|
||||
|
||||
[never_inline]
|
||||
def private wto_snap_cap_y(x, refY, z : float) : float
|
||||
let top = float3(x, refY + 25.0, z)
|
||||
var drop = 65.0
|
||||
if tracedown_normalized(top, drop, ETF_LMESH | ETF_HEIGHTMAP | ETF_STRUCTURES)
|
||||
return top.y - drop
|
||||
let hiTop = float3(x, max(refY + 120.0, 800.0), z)
|
||||
var hiDrop = hiTop.y + 200.0
|
||||
if tracedown_normalized(hiTop, hiDrop, ETF_LMESH | ETF_HEIGHTMAP)
|
||||
return hiTop.y - hiDrop
|
||||
return refY
|
||||
|
||||
[never_inline]
|
||||
def private wto_refresh_caps(var snap : WtoWorldSnap&)
|
||||
snap.capCount = 0
|
||||
var pCount = 0
|
||||
var pIds : int[8]
|
||||
var pPos : float3[8]
|
||||
var pRad : float[8]
|
||||
var pOwn : int[8]
|
||||
query() <| $ [es] (capture_zone__zoneId : int; transform : float3x4;
|
||||
capture_zone__name : string = ""; sphere_zone__radius : float = 0.0;
|
||||
capzone__approximateRadius : float = 0.0; capzone__owningTeam : int = -1)
|
||||
if pCount >= WTO_MAX_CAPS || capture_zone__zoneId < 0
|
||||
return
|
||||
var rad = max(sphere_zone__radius, capzone__approximateRadius)
|
||||
if rad <= 2.0 && !empty(capture_zone__name)
|
||||
let areaId = get_area_id(capture_zone__name)
|
||||
if areaId >= 0
|
||||
let lim = get_area_limits_xz(areaId)
|
||||
rad = 0.25 * (abs(lim.z - lim.x) + abs(lim.w - lim.y))
|
||||
if rad <= 2.0
|
||||
rad = 0.5 * min(length(transform[0]), length(transform[2]))
|
||||
pIds[pCount] = capture_zone__zoneId
|
||||
pPos[pCount] = transform[3]
|
||||
pRad[pCount] = clamp(rad > 2.0 ? rad : 25.0, 14.0, 80.0)
|
||||
pOwn[pCount] = (capzone__owningTeam == 1 || capzone__owningTeam == 2) ? capzone__owningTeam : 0
|
||||
pCount++
|
||||
for_each_capture_zone() <| $(zone : CaptureZone)
|
||||
if snap.capCount >= WTO_MAX_CAPS || !zone.isEnabled
|
||||
return
|
||||
var f = -1
|
||||
for p in range(pCount)
|
||||
if pIds[p] == zone.id
|
||||
f = p
|
||||
break
|
||||
if f < 0
|
||||
return
|
||||
let c = float3(pPos[f].x, wto_snap_cap_y(pPos[f].x, pPos[f].y, pPos[f].z), pPos[f].z)
|
||||
let cIdx = snap.capCount
|
||||
snap.caps[cIdx].zoneId = zone.id
|
||||
snap.caps[cIdx].center = c
|
||||
snap.caps[cIdx].radius = pRad[f]
|
||||
snap.caps[cIdx].ownerArmy = pOwn[f]
|
||||
snap.caps[cIdx].progress = float(zone.captureProgressVal)
|
||||
snap.capCount = cIdx + 1
|
||||
|
||||
[never_inline]
|
||||
def private wto_refresh_bounds_and_spawns(var snap : WtoWorldSnap&)
|
||||
var sum = float3(0.0, 0.0, 0.0)
|
||||
var cnt = 0
|
||||
for i in range(snap.capCount)
|
||||
sum += snap.caps[i].center
|
||||
cnt++
|
||||
if cnt > 0
|
||||
snap.battleCenter = sum / float(cnt)
|
||||
var maxDSq = 0.0
|
||||
for i in range(snap.capCount)
|
||||
maxDSq = max(maxDSq, wto_xz_dist_sq(snap.caps[i].center, snap.battleCenter))
|
||||
snap.battleRadius = clamp(sqrt(maxDSq) + 650.0, 850.0, 2400.0)
|
||||
if snap.spawnsResolved
|
||||
return
|
||||
var sumPos : float3[3]
|
||||
var spCnt : int[3]
|
||||
for a in range(3)
|
||||
sumPos[a] = float3(0.0, 0.0, 0.0)
|
||||
spCnt[a] = 0
|
||||
let maxDistSq = wto_sq(max(snap.battleRadius * 2.2, 2200.0))
|
||||
get_respawn_points() <| $(active, resptype, team, pos)
|
||||
if !active || (team != 1 && team != 2)
|
||||
return
|
||||
if resptype == "human" || resptype == "aircraft" || resptype == "helicopter"
|
||||
return
|
||||
if snap.battleRadius > 1.0 && wto_xz_dist_sq(pos, snap.battleCenter) > maxDistSq
|
||||
return
|
||||
sumPos[team] += pos
|
||||
spCnt[team]++
|
||||
for a in range(1, 3)
|
||||
if spCnt[a] == 0
|
||||
for i in range(snap.unitCount)
|
||||
assume u = snap.units[i]
|
||||
if u.isAlive && u.isGround && u.army == a
|
||||
sumPos[a] += u.pos
|
||||
spCnt[a]++
|
||||
if spCnt[a] > 0
|
||||
snap.teamSpawnCenter[a] = sumPos[a] / float(spCnt[a])
|
||||
snap.teamSpawnValid[a] = true
|
||||
snap.spawnsResolved = snap.teamSpawnValid[1] && snap.teamSpawnValid[2]
|
||||
|
||||
[never_inline]
|
||||
def public wto_world_refresh(now : float; var snap : WtoWorldSnap&)
|
||||
snap.time = now
|
||||
if snap.matchStartAt < -50.0
|
||||
snap.matchStartAt = now
|
||||
wto_refresh_units(snap)
|
||||
if now >= snap.nextCapRefreshAt
|
||||
snap.nextCapRefreshAt = now + 0.5
|
||||
wto_refresh_caps(snap)
|
||||
wto_refresh_bounds_and_spawns(snap)
|
||||
wto_refresh_units(snap)
|
||||
wto_world_refresh_caps(snap)
|
||||
wto_world_refresh_bounds_and_spawns(snap)
|
||||
snap.valid = true
|
||||
@@ -0,0 +1,185 @@
|
||||
// Capture zone, battle mode detection, and team spawn anchor resolution for the world snapshot.
|
||||
options indenting = 2
|
||||
options no_global_heap = true
|
||||
module wto_ai_world_zones_common shared
|
||||
|
||||
require ecs
|
||||
require math
|
||||
require strings
|
||||
require DagorMath
|
||||
require Mission
|
||||
require Unit
|
||||
require Dacoll
|
||||
require %appGame.wtoai.wto_ai_math_common
|
||||
require %appGame.wtoai.wto_ai_order_common
|
||||
require %appGame.wtoai.wto_ai_types_common
|
||||
|
||||
[never_inline]
|
||||
def private wto_snap_cap_y(x, refY, z : float) : float
|
||||
let top = float3(x, refY + 25.0, z)
|
||||
var drop = 65.0
|
||||
if tracedown_normalized(top, drop, ETF_LMESH | ETF_HEIGHTMAP | ETF_STRUCTURES)
|
||||
return top.y - drop
|
||||
let hiTop = float3(x, max(refY + 120.0, 800.0), z)
|
||||
var hiDrop = hiTop.y + 200.0
|
||||
if tracedown_normalized(hiTop, hiDrop, ETF_LMESH | ETF_HEIGHTMAP)
|
||||
return hiTop.y - hiDrop
|
||||
return refY
|
||||
|
||||
[never_inline]
|
||||
def private wto_detect_battle_mode(var snap : WtoWorldSnap&; nameHint : int)
|
||||
if snap.battleMode != WTO_MODE_UNKNOWN || snap.capCount <= 0
|
||||
return
|
||||
var own0 = 0
|
||||
var own1 = 0
|
||||
var own2 = 0
|
||||
for i in range(snap.capCount)
|
||||
let o = snap.caps[i].ownerArmy
|
||||
if o == 1
|
||||
own1++
|
||||
elif o == 2
|
||||
own2++
|
||||
else
|
||||
own0++
|
||||
if nameHint != WTO_MODE_UNKNOWN
|
||||
snap.battleMode = nameHint
|
||||
elif own1 >= 1 && own2 >= 1
|
||||
snap.battleMode = WTO_MODE_BTTL
|
||||
elif snap.capCount == 1
|
||||
snap.battleMode = WTO_MODE_CONQ
|
||||
else
|
||||
snap.battleMode = WTO_MODE_DOM
|
||||
print("WTO_AI|MODE|mode={snap.battleMode}|caps={snap.capCount}|own={own0}/{own1}/{own2}\n")
|
||||
|
||||
[never_inline]
|
||||
def private wto_collect_zone_entities(var pIds : int[8]&; var pPos : float3[8]&;
|
||||
var pRad : float[8]&; var pOwn : int[8]&;
|
||||
var nameHint : int&) : int
|
||||
var pCount = 0
|
||||
query() <| $ [es] (capture_zone__zoneId : int; transform : float3x4;
|
||||
capture_zone__name : string = ""; sphere_zone__radius : float = 0.0;
|
||||
capzone__approximateRadius : float = 0.0; capzone__owningTeam : int = -1)
|
||||
if pCount >= WTO_MAX_CAPS || capture_zone__zoneId < 0
|
||||
return
|
||||
if nameHint == WTO_MODE_UNKNOWN && !empty(capture_zone__name)
|
||||
if find(capture_zone__name, "bttl") >= 0
|
||||
nameHint = WTO_MODE_BTTL
|
||||
elif find(capture_zone__name, "conq") >= 0
|
||||
nameHint = WTO_MODE_CONQ
|
||||
elif find(capture_zone__name, "dom") >= 0
|
||||
nameHint = WTO_MODE_DOM
|
||||
var rad = max(sphere_zone__radius, capzone__approximateRadius)
|
||||
if rad <= 2.0 && !empty(capture_zone__name)
|
||||
let areaId = get_area_id(capture_zone__name)
|
||||
if areaId >= 0
|
||||
let lim = get_area_limits_xz(areaId)
|
||||
rad = 0.25 * (abs(lim.z - lim.x) + abs(lim.w - lim.y))
|
||||
if rad <= 2.0
|
||||
rad = 0.5 * min(length(transform[0]), length(transform[2]))
|
||||
pIds[pCount] = capture_zone__zoneId
|
||||
pPos[pCount] = transform[3]
|
||||
pRad[pCount] = clamp(rad > 2.0 ? rad : 25.0, 10.0, 180.0)
|
||||
pOwn[pCount] = (capzone__owningTeam == 1 || capzone__owningTeam == 2) ? capzone__owningTeam : 0
|
||||
pCount++
|
||||
return pCount
|
||||
|
||||
[never_inline]
|
||||
def public wto_world_refresh_caps(var snap : WtoWorldSnap&)
|
||||
let prevCount = snap.capCount
|
||||
var prevOwners : int[8]
|
||||
for i in range(WTO_MAX_CAPS)
|
||||
prevOwners[i] = i < prevCount ? snap.caps[i].ownerArmy : -1
|
||||
snap.capCount = 0
|
||||
var pIds : int[8]
|
||||
var pPos : float3[8]
|
||||
var pRad : float[8]
|
||||
var pOwn : int[8]
|
||||
var nameHint = WTO_MODE_UNKNOWN
|
||||
let pCount = wto_collect_zone_entities(pIds, pPos, pRad, pOwn, nameHint)
|
||||
for_each_capture_zone() <| $(zone : CaptureZone)
|
||||
if snap.capCount >= WTO_MAX_CAPS || !zone.isEnabled
|
||||
return
|
||||
var f = -1
|
||||
for p in range(pCount)
|
||||
if pIds[p] == zone.id
|
||||
f = p
|
||||
break
|
||||
if f < 0
|
||||
return
|
||||
let c = float3(pPos[f].x, wto_snap_cap_y(pPos[f].x, pPos[f].y, pPos[f].z), pPos[f].z)
|
||||
let cIdx = snap.capCount
|
||||
let own = pOwn[f]
|
||||
let prog = float(zone.captureProgressVal)
|
||||
snap.caps[cIdx].zoneId = zone.id
|
||||
snap.caps[cIdx].center = c
|
||||
snap.caps[cIdx].radius = pRad[f]
|
||||
snap.caps[cIdx].ownerArmy = own
|
||||
snap.caps[cIdx].progress = prog
|
||||
snap.caps[cIdx].contested = (own == 1 && prog > -99.0) || (own == 2 && prog < 99.0) || (own == 0 && abs(prog) > 1.0)
|
||||
snap.capCount = cIdx + 1
|
||||
wto_detect_battle_mode(snap, nameHint)
|
||||
var changed = snap.capCount != prevCount
|
||||
for i in range(snap.capCount)
|
||||
if !changed && snap.caps[i].ownerArmy != prevOwners[i]
|
||||
changed = true
|
||||
if changed
|
||||
snap.zoneVersion++
|
||||
|
||||
[never_inline]
|
||||
def private wto_resolve_team_spawns(var snap : WtoWorldSnap&)
|
||||
if snap.teamSpawnFromPoints[1] && snap.teamSpawnFromPoints[2]
|
||||
return
|
||||
var sumPos : float3[3]
|
||||
var spCnt : int[3]
|
||||
for a in range(3)
|
||||
sumPos[a] = float3(0.0, 0.0, 0.0)
|
||||
spCnt[a] = 0
|
||||
let maxDistSq = wto_sq(max(snap.battleRadius * 2.2, 2200.0))
|
||||
get_respawn_points() <| $(active, resptype, team, pos)
|
||||
if !active || (team != 1 && team != 2)
|
||||
return
|
||||
if resptype == "human" || resptype == "aircraft" || resptype == "helicopter"
|
||||
return
|
||||
if snap.battleRadius > 1.0 && wto_xz_dist_sq(pos, snap.battleCenter) > maxDistSq
|
||||
return
|
||||
sumPos[team] += pos
|
||||
spCnt[team]++
|
||||
for a in range(1, 3)
|
||||
if spCnt[a] > 0
|
||||
snap.teamSpawnCenter[a] = sumPos[a] / float(spCnt[a])
|
||||
snap.teamSpawnValid[a] = true
|
||||
snap.teamSpawnFromPoints[a] = true
|
||||
elif !snap.teamSpawnValid[a]
|
||||
var uSum = float3(0.0, 0.0, 0.0)
|
||||
var uCnt = 0
|
||||
for i in range(snap.unitCount)
|
||||
assume u = snap.units[i]
|
||||
if u.isAlive && u.isGround && u.army == a
|
||||
uSum += u.pos
|
||||
uCnt++
|
||||
if uCnt > 0
|
||||
snap.teamSpawnCenter[a] = uSum / float(uCnt)
|
||||
snap.teamSpawnValid[a] = true
|
||||
|
||||
[never_inline]
|
||||
def public wto_world_refresh_bounds_and_spawns(var snap : WtoWorldSnap&)
|
||||
var sum = float3(0.0, 0.0, 0.0)
|
||||
for i in range(snap.capCount)
|
||||
sum += snap.caps[i].center
|
||||
if snap.capCount > 0
|
||||
snap.battleCenter = sum / float(snap.capCount)
|
||||
var maxDSq = 0.0
|
||||
for i in range(snap.capCount)
|
||||
maxDSq = max(maxDSq, wto_xz_dist_sq(snap.caps[i].center, snap.battleCenter))
|
||||
snap.battleRadius = clamp(sqrt(maxDSq) + 650.0, 850.0, 2400.0)
|
||||
wto_resolve_team_spawns(snap)
|
||||
if snap.capCount == 0
|
||||
var fallbackSum = float3(0.0, 0.0, 0.0)
|
||||
var fallbackCnt = 0
|
||||
for a in range(1, 3)
|
||||
if snap.teamSpawnValid[a]
|
||||
fallbackSum += snap.teamSpawnCenter[a]
|
||||
fallbackCnt++
|
||||
if fallbackCnt > 0
|
||||
snap.battleCenter = fallbackSum / float(fallbackCnt)
|
||||
snap.battleRadius = 1200.0
|
||||
@@ -21,6 +21,22 @@ export interface GroundAiConfig {
|
||||
readonly tacticsTickSec: number;
|
||||
readonly navTickSec: number;
|
||||
};
|
||||
readonly commander: {
|
||||
readonly rebalanceSec: number;
|
||||
readonly roleHoldSec: number;
|
||||
readonly bttlAssaultPct: number;
|
||||
readonly bttlFlankPct: number;
|
||||
readonly bttlOverwatchPct: number;
|
||||
readonly conqAssaultPct: number;
|
||||
readonly conqFlankPct: number;
|
||||
readonly conqHoldDefendPct: number;
|
||||
readonly conqHoldOverwatchPct: number;
|
||||
readonly domAssaultPct: number;
|
||||
readonly domMaxDefendersPerCap: number;
|
||||
readonly overwatchStandOffM: number;
|
||||
readonly flankStandOffM: number;
|
||||
readonly spaaFollowOffsetM: number;
|
||||
};
|
||||
readonly macro: {
|
||||
readonly openingSplitSec: number;
|
||||
readonly capMaxInsiders: number;
|
||||
@@ -138,6 +154,20 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] {
|
||||
['WTO_AI_MACRO_TICK_SEC', 'float', c.cadence.macroTickSec],
|
||||
['WTO_AI_TACTICS_TICK_SEC', 'float', c.cadence.tacticsTickSec],
|
||||
['WTO_AI_NAV_TICK_SEC', 'float', c.cadence.navTickSec],
|
||||
['WTO_AI_CMD_REBALANCE_SEC', 'float', c.commander.rebalanceSec],
|
||||
['WTO_AI_CMD_ROLE_HOLD_SEC', 'float', c.commander.roleHoldSec],
|
||||
['WTO_AI_CMD_BTTL_ASSAULT_PCT', 'int', c.commander.bttlAssaultPct],
|
||||
['WTO_AI_CMD_BTTL_FLANK_PCT', 'int', c.commander.bttlFlankPct],
|
||||
['WTO_AI_CMD_BTTL_OVERWATCH_PCT', 'int', c.commander.bttlOverwatchPct],
|
||||
['WTO_AI_CMD_CONQ_ASSAULT_PCT', 'int', c.commander.conqAssaultPct],
|
||||
['WTO_AI_CMD_CONQ_FLANK_PCT', 'int', c.commander.conqFlankPct],
|
||||
['WTO_AI_CMD_CONQ_HOLD_DEFEND_PCT', 'int', c.commander.conqHoldDefendPct],
|
||||
['WTO_AI_CMD_CONQ_HOLD_OVERWATCH_PCT', 'int', c.commander.conqHoldOverwatchPct],
|
||||
['WTO_AI_CMD_DOM_ASSAULT_PCT', 'int', c.commander.domAssaultPct],
|
||||
['WTO_AI_CMD_DOM_MAX_DEFENDERS', 'int', c.commander.domMaxDefendersPerCap],
|
||||
['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_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