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.
264 lines
10 KiB
TypeScript
264 lines
10 KiB
TypeScript
/**
|
|
* Pure matchmaking rank (`mrank`) calculation and deterministic BR-matched `customBots`
|
|
* vehicle-pool selection (`scripts/slotbar/slotbarpresets/calcranks.nut`).
|
|
*
|
|
* `BotSystem` (`aces.exe` `0x11af3f0`) reads `MissionSettings.customBots` using bare country
|
|
* names (`"usa"`, `"germany"`, ...) and three sub-blocks: `allowedTanks` (`tank`),
|
|
* `allowedAircrafts` (`aircraft`), and `allowedShips` (`ship`).
|
|
*/
|
|
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
|
|
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_';
|
|
|
|
export interface CraftRankEntry {
|
|
readonly unitClass: UnitClass | undefined;
|
|
readonly mrank: number;
|
|
}
|
|
|
|
export interface BotPoolEntry {
|
|
readonly name: string;
|
|
readonly country: string;
|
|
readonly weight: number;
|
|
readonly aircraftLoadout?: BotAircraftLoadout;
|
|
readonly tankLoadout?: BotTankLoadout;
|
|
}
|
|
|
|
export interface CustomBotsPool {
|
|
readonly tanks: readonly BotPoolEntry[];
|
|
readonly aircrafts: readonly BotPoolEntry[];
|
|
readonly ships: readonly BotPoolEntry[];
|
|
}
|
|
|
|
/** Offline tank pool weights by vehicle class (`tuning/ground-ai.jsonc` `lineupWeights`). */
|
|
export interface TankLineupWeights {
|
|
readonly spaa: number;
|
|
readonly lightTank: number;
|
|
readonly tankDestroyer: number;
|
|
readonly heavyTank: number;
|
|
readonly mediumTank: number;
|
|
readonly other: number;
|
|
}
|
|
|
|
export interface BotPoolQuery {
|
|
readonly difficulty: ModeDifficulty;
|
|
readonly requiredClass: UnitClass;
|
|
readonly allowedClasses: readonly UnitClass[];
|
|
readonly countries: readonly string[];
|
|
readonly centerMrank: number;
|
|
readonly minMrank: number;
|
|
readonly maxMrank: number;
|
|
readonly limitPerType: number;
|
|
}
|
|
|
|
export function stripCountryPrefix(country: string): string {
|
|
return country.startsWith(COUNTRY_PREFIX) ? country.slice(COUNTRY_PREFIX.length) : country;
|
|
}
|
|
|
|
export function unitClassOfExpClass(expClass: string): UnitClass | undefined {
|
|
return unitClassOfVehicleType(vehicleTypeOfClass(expClass));
|
|
}
|
|
|
|
export function unitClassOfTypeCode(unitTypeCode: number): UnitClass | undefined {
|
|
return unitClassOfVehicleType(vehicleTypeById(unitTypeCode));
|
|
}
|
|
|
|
export function vehicleMrank(vehicle: CatalogueVehicle, difficulty: ModeDifficulty, requiredClass: UnitClass): number {
|
|
if (difficulty === 'arcade') return vehicle.economicRankArcade;
|
|
if (difficulty === 'simulator') {
|
|
return requiredClass === 'tank' && vehicle.economicRankTankSimulation !== undefined
|
|
? vehicle.economicRankTankSimulation
|
|
: vehicle.economicRankSimulation;
|
|
}
|
|
return requiredClass === 'tank' && vehicle.economicRankTankHistorical !== undefined
|
|
? vehicle.economicRankTankHistorical
|
|
: vehicle.economicRankHistorical;
|
|
}
|
|
|
|
/**
|
|
* Maximum `mrank` among crafts allowed in the mode (`calcranks.nut` `filterCrafts` +
|
|
* `specialShipsFilter`: in naval modes, aircraft above `maxShipMrank + 1` are ignored).
|
|
*/
|
|
export function maxModeMrank(
|
|
crafts: readonly CraftRankEntry[],
|
|
requiredClass: UnitClass,
|
|
allowedClasses: readonly UnitClass[],
|
|
): number {
|
|
const allowedSet = new Set(allowedClasses);
|
|
const matching = crafts.filter((craft) => craft.unitClass !== undefined && allowedSet.has(craft.unitClass));
|
|
if (!matching.some((craft) => craft.unitClass === requiredClass)) return 0;
|
|
|
|
let filtered = matching;
|
|
if (requiredClass === 'ship') {
|
|
const maxShip = matching
|
|
.filter((craft) => craft.unitClass === 'ship')
|
|
.reduce((max, craft) => Math.max(max, craft.mrank), 0);
|
|
filtered = matching.filter((craft) => craft.unitClass !== 'aircraft' || craft.mrank <= maxShip + 1);
|
|
}
|
|
return filtered.reduce((max, craft) => Math.max(max, Math.max(0, Math.trunc(craft.mrank))), 0);
|
|
}
|
|
|
|
export function lineupMrank(
|
|
vehicleNames: readonly string[],
|
|
byName: ReadonlyMap<string, CatalogueVehicle>,
|
|
difficulty: ModeDifficulty,
|
|
requiredClass: UnitClass,
|
|
allowedClasses: readonly UnitClass[],
|
|
mrankDeltas: ReadonlyMap<string, number>,
|
|
): number {
|
|
const crafts: CraftRankEntry[] = vehicleNames.flatMap((name) => {
|
|
const vehicle = byName.get(name);
|
|
if (!vehicle) return [];
|
|
return [{
|
|
unitClass: unitClassOfExpClass(vehicle.unitClass),
|
|
mrank: lineupVehicleMrank(vehicle, difficulty, requiredClass, mrankDeltas),
|
|
}];
|
|
});
|
|
return maxModeMrank(crafts, requiredClass, allowedClasses);
|
|
}
|
|
|
|
function lineupVehicleMrank(
|
|
vehicle: CatalogueVehicle,
|
|
difficulty: ModeDifficulty,
|
|
requiredClass: UnitClass,
|
|
mrankDeltas: ReadonlyMap<string, number>,
|
|
): number {
|
|
return vehicleMrank(vehicle, difficulty, requiredClass) + (mrankDeltas.get(vehicle.name) ?? 0);
|
|
}
|
|
|
|
/**
|
|
* Without `tankWeights` every pool entry keeps the stock weight of 1.
|
|
*/
|
|
export function selectCustomBots(
|
|
vehicles: readonly CatalogueVehicle[],
|
|
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: 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 };
|
|
}) : aircrafts,
|
|
ships: allowed.has('ship') ? pickCategoryPool(vehicles, orderedCountries, 'ship', query) : [],
|
|
};
|
|
}
|
|
|
|
function pickCategoryPool(
|
|
vehicles: readonly CatalogueVehicle[],
|
|
orderedCountries: readonly string[],
|
|
category: 'tank' | 'aircraft' | 'ship',
|
|
query: BotPoolQuery,
|
|
tankWeights?: TankLineupWeights,
|
|
): BotPoolEntry[] {
|
|
const countrySet = new Set(orderedCountries);
|
|
const eligible = vehicles.filter((vehicle) =>
|
|
vehicle.inTechTree
|
|
&& !vehicle.onlyShownWhenOwned
|
|
&& !vehicle.premiumPack
|
|
&& !vehicle.gift
|
|
&& !vehicle.event
|
|
&& vehicle.researchType === undefined
|
|
&& countrySet.has(vehicle.country)
|
|
&& unitClassOfExpClass(vehicle.unitClass) === category);
|
|
if (eligible.length === 0) return [];
|
|
|
|
const sortedByCloseness = [...eligible].sort((a, b) => {
|
|
const distA = Math.abs(vehicleMrank(a, query.difficulty, query.requiredClass) - query.centerMrank);
|
|
const distB = Math.abs(vehicleMrank(b, query.difficulty, query.requiredClass) - query.centerMrank);
|
|
return distA !== distB ? distA - distB : a.name.localeCompare(b.name);
|
|
});
|
|
const inWindow = sortedByCloseness.filter((vehicle) => {
|
|
const mrank = vehicleMrank(vehicle, query.difficulty, query.requiredClass);
|
|
return mrank >= query.minMrank && mrank <= query.maxMrank;
|
|
});
|
|
const source = inWindow.length > 0 ? inWindow : sortedByCloseness.slice(0, query.limitPerType);
|
|
return roundRobinByCountry(source, orderedCountries, query.limitPerType, (vehicle) => tankPoolWeight(vehicle, tankWeights));
|
|
}
|
|
|
|
function roundRobinByCountry(
|
|
vehicles: readonly CatalogueVehicle[],
|
|
orderedCountries: readonly string[],
|
|
limit: number,
|
|
weightOf: (vehicle: CatalogueVehicle) => number,
|
|
): BotPoolEntry[] {
|
|
const buckets = new Map<string, CatalogueVehicle[]>(orderedCountries.map((country) => [country, []]));
|
|
for (const vehicle of vehicles) buckets.get(vehicle.country)?.push(vehicle);
|
|
const out: BotPoolEntry[] = [];
|
|
for (let index = 0; out.length < limit; index++) {
|
|
let added = false;
|
|
for (const country of orderedCountries) {
|
|
const vehicle = buckets.get(country)?.[index];
|
|
if (!vehicle) continue;
|
|
out.push({ name: vehicle.name, country: stripCountryPrefix(country), weight: weightOf(vehicle) });
|
|
added = true;
|
|
if (out.length >= limit) break;
|
|
}
|
|
if (!added) break;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
function tankPoolWeight(vehicle: CatalogueVehicle, weights: TankLineupWeights | undefined): number {
|
|
if (weights === undefined) return 1;
|
|
if (vehicle.unitClass === 'exp_SPAA') return weights.spaa;
|
|
if (vehicle.isLightTank) return weights.lightTank;
|
|
if (vehicle.unitClass === 'exp_tank_destroyer') return weights.tankDestroyer;
|
|
if (vehicle.unitClass === 'exp_heavy_tank') return weights.heavyTank;
|
|
if (vehicle.unitClass === 'exp_tank') return weights.mediumTank;
|
|
return weights.other;
|
|
}
|
|
|
|
function unitClassOfVehicleType(type: VehicleType | undefined): UnitClass | undefined {
|
|
if (type === 'Tank') return 'tank';
|
|
if (type === 'Aircraft') return 'aircraft';
|
|
if (type === 'Helicopter') return 'helicopter';
|
|
if (type === 'Ship' || type === 'Boat') return 'ship';
|
|
return undefined;
|
|
}
|
|
|
|
export function activeVehiclesForMode(
|
|
declaration: GameModeDeclaration,
|
|
slotVehicles: readonly string[],
|
|
selectedSlotVehicle: string | undefined,
|
|
byName: ReadonlyMap<string, CatalogueVehicle>,
|
|
): readonly string[] {
|
|
if (declaration.multiSlot !== false) return slotVehicles;
|
|
if (!selectedSlotVehicle) return [];
|
|
const selected = byName.get(selectedSlotVehicle);
|
|
return selected && unitClassOfExpClass(selected.unitClass) === declaration.requiredClass
|
|
? [selectedSlotVehicle]
|
|
: [];
|
|
}
|
|
|
|
export function isModeEligibleForLineup(
|
|
declaration: GameModeDeclaration,
|
|
slotVehicles: readonly string[],
|
|
selectedSlotVehicle: string | undefined,
|
|
byName: ReadonlyMap<string, CatalogueVehicle>,
|
|
mrankDeltas: ReadonlyMap<string, number>,
|
|
): boolean {
|
|
if (!declaration.tag && declaration.multiSlot !== false) return true;
|
|
const active = activeVehiclesForMode(declaration, slotVehicles, selectedSlotVehicle, byName);
|
|
const minMrank = declaration.minQueueMrank ?? 0;
|
|
const minCrafts = declaration.minCraftsToPlay ?? 1;
|
|
const matchingCount = active.filter((name) => {
|
|
const vehicle = byName.get(name);
|
|
if (!vehicle || unitClassOfExpClass(vehicle.unitClass) !== declaration.requiredClass) return false;
|
|
return lineupVehicleMrank(vehicle, declaration.difficulty, declaration.requiredClass, mrankDeltas) >= minMrank;
|
|
}).length;
|
|
return matchingCount >= minCrafts;
|
|
}
|