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.
136 lines
5.7 KiB
TypeScript
136 lines
5.7 KiB
TypeScript
/**
|
|
* 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');
|
|
}
|