feat(ground-ai): add ready-rack dual-ammo bot spawn loadouts and shell switching

Select realistic ready-rack dual-shell loadouts for AI tanks on the local
server, inject them natively on bot spawn, and switch between anti-armor
and soft-target shells in battle:

- Add the loadout section to tuning/ground-ai.jsonc (lowReadyRackThreshold,
  topUpAmmoCount, primaryAmmoPct, secondaryMinRounds,
  penetrationCompareDistM), validated in ground-ai-tuning.ts.
- Add the tank-bot-ammo v2 dataset (apps/server/src/game-data/datasets/
  tank-bot-ammo.ts) reading primary cannon weapon name, capacity,
  firstStage/autoLoad shell ready-rack counts (excluding separate charges),
  and selectable shell modifications (using Lanz-Odermatt kinetic fields,
  cumulativeDamage, armorpower, and transitive reqModification chains).
- Add selectBotTankLoadouts (apps/server/src/battle/bot-tank-loadouts.ts):
  carry ready-rack count when >= 15 (top up to 22 when smaller or absent,
  clamped to gun capacity), skip SPAA/belt autocannons, pick highest-tier
  APFSDS/anti-armor primary (~80%) plus HE/HESH/HEAT secondary (~20%, min
  3 rounds) when available, and attach required addModification entries and
  per-tank wtoAmmo_<unit> strings to customBots when mode != stock.
- Hook Unit::changeAircraft (already located dynamically on .37 and .58) in
  native/wto-net/src/local_mp_loadout.c to assign the 24-byte
  ChangeUnitReflection.bullets entries via bullet_vec_assign for LocalMP
  bot spawns (async == 0, non-local bot MPlayer), leaving player spawns
  untouched.
- Track soft-target vs anti-armor shell classes in wto_ai_specs_common.das
  and write gun.nextBulletType in wto_ai_fire_common.das to queue HE/HESH
  against light/narrow targets and APFSDS/AP against MBTs/heavy armor.

Verified MSVC build of wto_ws.dll (0 warnings in project C sources), root
and launcher type checks, 14/14 check-patches on 2.61.0.58, 12/12 LocalMP
module installation, clean daScript load (wto_ai_runtime.das loaded in
211 ms, 0 compile errors), and real 2.61.0.58 loadout selection on
cn_ztz_96a (18 APFSDS + 4 HE), germ_leopard_2a4 (12 DM23 + 3 HEATFS),
ussr_t_80bvm (22 3BM60 + 6 HE), us_m1a2_abrams (14 M829A2 + 4 HEAT-MP),
ussr_t_34_1941 (18 APHEBC + 4 HE), and ussr_zsu_23_4 (stock belt kept).
Live battle acceptance begins in Step 9.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 19:25:04 +08:00
1 parent d5008baeff
commit ac35c25851
14 files changed
+601 -10

No files matched your search

+5 -1
View File
@@ -25,6 +25,7 @@ import {
import type { BattleSessionStore } from './battle-session-store.ts';
import { battleSpawnScore, type BattleSpawnScore } from './battle-spawn-score.ts';
import type { BotAircraftLoadout } from './bot-aircraft-loadouts.ts';
import type { BotTankLoadout } from './bot-tank-loadouts.ts';
import type { BattleTuning } from './battle-tuning.ts';
export interface BattleCrewSlot {
@@ -106,6 +107,7 @@ export class BattleMatchmaker {
readonly #spawnRules: BattleSpawnRulesData;
readonly #aircraftLoadouts: ReadonlyMap<string, BotAircraftLoadout>;
readonly #tankWeights: TankLineupWeights | undefined;
readonly #tankLoadouts: ReadonlyMap<string, BotTankLoadout> | undefined;
readonly #filterMissions: MissionPoolFilter | undefined;
constructor(
@@ -116,6 +118,7 @@ export class BattleMatchmaker {
spawnRules: BattleSpawnRulesData,
aircraftLoadouts: ReadonlyMap<string, BotAircraftLoadout>,
tankWeights: TankLineupWeights | undefined,
tankLoadouts?: ReadonlyMap<string, BotTankLoadout>,
filterMissions?: MissionPoolFilter,
) {
this.#gameModes = gameModes;
@@ -126,6 +129,7 @@ export class BattleMatchmaker {
this.#spawnRules = spawnRules;
this.#aircraftLoadouts = aircraftLoadouts;
this.#tankWeights = tankWeights;
this.#tankLoadouts = tankLoadouts;
this.#filterMissions = filterMissions;
}
@@ -185,7 +189,7 @@ export class BattleMatchmaker {
minMrank,
maxMrank,
limitPerType: this.#tuning.botPoolLimitPerType,
}, declaration.allowBotAircraftLoadouts === false ? undefined : this.#aircraftLoadouts, this.#tankWeights);
}, declaration.allowBotAircraftLoadouts === false ? undefined : this.#aircraftLoadouts, this.#tankWeights, this.#tankLoadouts);
return {
ok: true,
launch: this.#buildLaunchPlan(input, chosenMode, mission, coalitions, playerMrank, minMrank, maxMrank, customBots),
@@ -141,6 +141,7 @@ function customBotsBlock(plan: BattleLaunchPlan): BlkBlock {
poolBlock('allowedAircrafts', 'aircraft', plan.customBots.aircrafts),
poolBlock('allowedShips', 'ship', plan.customBots.ships),
);
addTankAmmoParams(bots, plan.customBots.tanks);
return bots;
}
@@ -156,11 +157,26 @@ function poolBlock(name: string, entryName: string, entries: CustomBotsPool['tan
setParam(ensureBlock(block, 'preset'), 'name', text(loadout.preset));
for (const modification of loadout.modifications) appendParam(block, 'addModification', text(modification));
}
if (entry.tankLoadout !== undefined) {
for (const modification of entry.tankLoadout.modifications) appendParam(block, 'addModification', text(modification));
}
pool.blocks.push(block);
}
return pool;
}
/** Per-tank bot ammo strings (`weapon|mod0:count0|mod1:count1`) read by local_mp_loadout.c. */
function addTankAmmoParams(bots: BlkBlock, entries: CustomBotsPool['tanks']): void {
const seen = new Set<string>();
for (const entry of entries) {
const loadout = entry.tankLoadout;
if (!loadout || loadout.bullets.length === 0 || seen.has(entry.name)) continue;
seen.add(entry.name);
const parts = [loadout.weaponName, ...loadout.bullets.slice(0, 2).map((s) => `${s.modName}:${s.count}`)];
setParam(bots, `wtoAmmo_${entry.name}`, text(parts.join('|')));
}
}
function text(value: string): BlkValue {
return { type: 'string', value };
}
+8 -1
View File
@@ -10,6 +10,7 @@ import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.t
import type { GameModeDeclaration, ModeDifficulty, UnitClass } from '../game-modes/catalogue/game-mode-declaration.ts';
import { vehicleTypeById, vehicleTypeOfClass, type VehicleType } from '../research/vehicle-types.ts';
import type { BotAircraftLoadout } from './bot-aircraft-loadouts.ts';
import type { BotTankLoadout } from './bot-tank-loadouts.ts';
const COUNTRY_PREFIX = 'country_';
@@ -23,6 +24,7 @@ export interface BotPoolEntry {
readonly country: string;
readonly weight: number;
readonly aircraftLoadout?: BotAircraftLoadout;
readonly tankLoadout?: BotTankLoadout;
}
export interface CustomBotsPool {
@@ -135,12 +137,17 @@ export function selectCustomBots(
query: BotPoolQuery,
aircraftLoadouts?: ReadonlyMap<string, BotAircraftLoadout>,
tankWeights?: TankLineupWeights,
tankLoadouts?: ReadonlyMap<string, BotTankLoadout>,
): CustomBotsPool {
const allowed = new Set(query.allowedClasses);
const orderedCountries = [...new Set(query.countries.map((c) => (c.startsWith(COUNTRY_PREFIX) ? c : `${COUNTRY_PREFIX}${c}`)))];
const aircrafts = allowed.has('aircraft') ? pickCategoryPool(vehicles, orderedCountries, 'aircraft', query) : [];
const rawTanks = allowed.has('tank') ? pickCategoryPool(vehicles, orderedCountries, 'tank', query, tankWeights) : [];
return {
tanks: allowed.has('tank') ? pickCategoryPool(vehicles, orderedCountries, 'tank', query, tankWeights) : [],
tanks: tankLoadouts ? rawTanks.map((entry) => {
const tankLoadout = tankLoadouts.get(entry.name);
return tankLoadout === undefined ? entry : { ...entry, tankLoadout };
}) : rawTanks,
aircrafts: query.requiredClass === 'aircraft' && aircraftLoadouts ? aircrafts.map((entry) => {
const aircraftLoadout = aircraftLoadouts.get(entry.name);
return aircraftLoadout === undefined ? entry : { ...entry, aircraftLoadout };
+135
View File
@@ -0,0 +1,135 @@
/**
* Offline AI tank spawn ammunition selector:
* - Total carried rounds follow the vehicle's first-stage / autoloader ready rack, topped up
* when below the configured threshold (clamped to main gun capacity).
* - Primary shell prefers legal APFSDS, otherwise ranks anti-armor shells by 500 m penetration.
* - Secondary shell carries a small share of HE / HEAT / HESH when available for soft targets.
*/
import type { GroundAiLoadoutConfig } from '@wto/patcher';
import type { TankAmmoProfile, TankBotAmmoData, TankShellChoice } from '../game-data/datasets/tank-bot-ammo.ts';
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
import { vehicleTypeOfClass } from '../research/vehicle-types.ts';
export interface BotTankBulletSlot {
readonly modName: string;
readonly count: number;
}
export interface BotTankLoadout {
readonly weaponName: string;
readonly bullets: readonly BotTankBulletSlot[];
readonly modifications: readonly string[];
}
export function selectBotTankLoadouts(
vehicles: readonly CatalogueVehicle[],
ammoData: TankBotAmmoData,
config: GroundAiLoadoutConfig,
): ReadonlyMap<string, BotTankLoadout> {
const result = new Map<string, BotTankLoadout>();
for (const vehicle of vehicles) {
if (vehicleTypeOfClass(vehicle.unitClass) !== 'Tank' || vehicle.unitClass === 'exp_SPAA') continue;
const profile = ammoData[vehicle.name];
if (!profile || profile.isBelt || profile.maxBullets <= 0) continue;
const loadout = chooseTankLoadout(profile, config);
if (loadout !== undefined) result.set(vehicle.name, loadout);
}
return result;
}
function chooseTankLoadout(profile: TankAmmoProfile, config: GroundAiLoadoutConfig): BotTankLoadout | undefined {
const combatShells = profile.shells.filter((shell) => !isNonCombatShell(shell.bulletType));
if (combatShells.length === 0) return undefined;
const primary = pickPrimaryShell(combatShells);
if (!primary) return undefined;
const totalRounds = computeCarriedRounds(profile, config);
if (totalRounds <= 0) return undefined;
const secondary = pickSecondaryShell(combatShells, primary);
const bullets = splitRounds(primary, secondary, totalRounds, config);
const modSet = new Set<string>();
for (const chosen of [primary, ...(bullets.length > 1 && secondary ? [secondary] : [])]) {
if (chosen.modName) modSet.add(chosen.modName);
for (const req of chosen.requires) modSet.add(req);
}
return {
weaponName: profile.weaponName,
bullets,
modifications: [...modSet].sort(),
};
}
function computeCarriedRounds(profile: TankAmmoProfile, config: GroundAiLoadoutConfig): number {
const want = profile.readyRack >= config.lowReadyRackThreshold
? profile.readyRack
: config.topUpAmmoCount;
return Math.max(1, Math.min(want, profile.maxBullets));
}
function pickPrimaryShell(shells: readonly TankShellChoice[]): TankShellChoice | undefined {
const ranked = [...shells].sort((a, b) => compareAntiArmor(a, b));
return ranked[0];
}
function compareAntiArmor(a: TankShellChoice, b: TankShellChoice): number {
const tierA = antiArmorTier(a.bulletType);
const tierB = antiArmorTier(b.bulletType);
if (tierA !== tierB) return tierB - tierA;
const scoreA = a.pen500Mm + (isApheFamily(a.bulletType) ? 12 : 0);
const scoreB = b.pen500Mm + (isApheFamily(b.bulletType) ? 12 : 0);
if (scoreA !== scoreB) return scoreB - scoreA;
if (a.speedMps !== b.speedMps) return b.speedMps - a.speedMps;
return a.modName.localeCompare(b.modName);
}
function antiArmorTier(bulletType: string): number {
if (bulletType.includes('apds_fs')) return 5;
if (bulletType.includes('atgm')) return 4;
if (bulletType.includes('apds')) return 3;
if (bulletType.includes('heat') || isApheFamily(bulletType) || bulletType.startsWith('ap')) return 2;
if (bulletType.includes('hesh')) return 1;
return 0;
}
function pickSecondaryShell(shells: readonly TankShellChoice[], primary: TankShellChoice): TankShellChoice | undefined {
const candidates = shells.filter((shell) => shell.modName !== primary.modName && isSoftTargetShell(shell.bulletType));
if (candidates.length === 0) return undefined;
return [...candidates].sort((a, b) => {
const heA = a.bulletType.includes('he_frag') ? 2 : (a.bulletType.includes('hesh') ? 1 : 0);
const heB = b.bulletType.includes('he_frag') ? 2 : (b.bulletType.includes('hesh') ? 1 : 0);
if (heA !== heB) return heB - heA;
if (a.speedMps !== b.speedMps) return b.speedMps - a.speedMps;
return a.modName.localeCompare(b.modName);
})[0];
}
function splitRounds(
primary: TankShellChoice,
secondary: TankShellChoice | undefined,
totalRounds: number,
config: GroundAiLoadoutConfig,
): BotTankBulletSlot[] {
if (!secondary || config.primaryAmmoPct >= 100 || config.secondaryMinRounds <= 0 || totalRounds < config.secondaryMinRounds * 2 + 2) {
return [{ modName: primary.modName, count: totalRounds }];
}
const wantSec = Math.round((totalRounds * (100 - config.primaryAmmoPct)) / 100);
const secCount = Math.min(totalRounds - 1, Math.max(config.secondaryMinRounds, wantSec));
const priCount = totalRounds - secCount;
return [
{ modName: primary.modName, count: priCount },
{ modName: secondary.modName, count: secCount },
];
}
function isNonCombatShell(bulletType: string): boolean {
return bulletType.includes('smoke') || bulletType.includes('practice') || bulletType.includes('shrapnel');
}
function isSoftTargetShell(bulletType: string): boolean {
return bulletType.includes('he_frag') || bulletType.includes('hesh') || bulletType.includes('heat');
}
function isApheFamily(bulletType: string): boolean {
return bulletType.includes('aphe') || bulletType.includes('apcbc') || bulletType.includes('apbc');
}