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:
1 parent
d5008baeff
commit
ac35c25851
14 files changed
+601
-10
No files matched your search
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* Dataset: primary cannon weapon name, capacity, first-stage/autoloader ready-rack count,
|
||||
* and selectable ammunition groups (with penetration and prerequisite modifications) for
|
||||
* every ground tank model in `aces.vromfs.bin` + `char.vromfs.bin`.
|
||||
*/
|
||||
import { findBlock, type BlkBlock } from '@wto/blk';
|
||||
import type { Dataset, DatasetSource } from './dataset.ts';
|
||||
import { boolField, numberField, stringField, stringList } from './blk-fields.ts';
|
||||
|
||||
const VEHICLE_ECONOMY = 'config/wpcost.blk';
|
||||
const MODIFICATIONS_CONFIG = 'config/modifications.blk';
|
||||
const TANK_MODELS_PREFIX = 'gamedata/units/tankmodels/';
|
||||
|
||||
export interface TankShellChoice {
|
||||
/** Modification name expected by ChangeUnitReflection.bullets[i] (`""` for stock default). */
|
||||
readonly modName: string;
|
||||
readonly bulletType: string;
|
||||
readonly speedMps: number;
|
||||
/** Estimated normal penetration at 500 m (mm) for deterministic ranking. */
|
||||
readonly pen500Mm: number;
|
||||
/** Transitive prerequisite modifications needed to unlock this shell. */
|
||||
readonly requires: readonly string[];
|
||||
}
|
||||
|
||||
export interface TankAmmoProfile {
|
||||
readonly weaponName: string;
|
||||
readonly maxBullets: number;
|
||||
readonly isBelt: boolean;
|
||||
/** Total firstStage / autoLoad / ammoLoadedInGun shell slots (excluding separate charges). */
|
||||
readonly readyRack: number;
|
||||
readonly shells: readonly TankShellChoice[];
|
||||
}
|
||||
|
||||
export type TankBotAmmoData = Readonly<Record<string, TankAmmoProfile>>;
|
||||
|
||||
interface GlobalModInfo {
|
||||
readonly bulletMod?: string;
|
||||
readonly requires: readonly string[];
|
||||
}
|
||||
|
||||
interface WeaponBulletMeta {
|
||||
readonly bulletType: string;
|
||||
readonly speedMps: number;
|
||||
readonly pen500Mm: number;
|
||||
}
|
||||
|
||||
export const tankBotAmmo: Dataset<TankBotAmmoData> = {
|
||||
id: 'tank-bot-ammo',
|
||||
version: 2,
|
||||
extract(source: DatasetSource): TankBotAmmoData {
|
||||
const globalMods = readGlobalModInfo(source.readBlk('char.vromfs.bin', MODIFICATIONS_CONFIG));
|
||||
const wpcost = source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY);
|
||||
const acesPaths = new Set(source.listFiles('aces.vromfs.bin').map((p) => p.toLowerCase()));
|
||||
const weaponCache = new Map<string, { isBelt: boolean; defaultBullet?: WeaponBulletMeta; sets: Map<string, WeaponBulletMeta> }>();
|
||||
const out: Record<string, TankAmmoProfile> = {};
|
||||
|
||||
for (const vehicleBlk of wpcost.blocks) {
|
||||
const unitPath = `${TANK_MODELS_PREFIX}${vehicleBlk.name.toLowerCase()}.blk`;
|
||||
if (!acesPaths.has(unitPath)) continue;
|
||||
const profile = extractTankProfile(source, acesPaths, weaponCache, globalMods, vehicleBlk, unitPath);
|
||||
if (profile !== undefined) out[vehicleBlk.name] = profile;
|
||||
}
|
||||
return out;
|
||||
},
|
||||
};
|
||||
|
||||
function readGlobalModInfo(root: BlkBlock): ReadonlyMap<string, GlobalModInfo> {
|
||||
const mods = findBlock(root, 'modifications');
|
||||
const map = new Map<string, GlobalModInfo>();
|
||||
for (const entry of mods?.blocks ?? []) {
|
||||
const effects = findBlock(entry, 'effects');
|
||||
const bulletMod = stringField(effects, 'additiveBulletMod') ?? stringField(effects, 'bulletMod');
|
||||
map.set(entry.name, {
|
||||
...(bulletMod !== undefined ? { bulletMod } : {}),
|
||||
requires: stringList(entry, 'reqModification'),
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function extractTankProfile(
|
||||
source: DatasetSource,
|
||||
acesPaths: ReadonlySet<string>,
|
||||
weaponCache: Map<string, { isBelt: boolean; defaultBullet?: WeaponBulletMeta; sets: Map<string, WeaponBulletMeta> }>,
|
||||
globalMods: ReadonlyMap<string, GlobalModInfo>,
|
||||
wpcostVehicle: BlkBlock,
|
||||
unitPath: string,
|
||||
): TankAmmoProfile | undefined {
|
||||
const unitBlk = source.readBlk('aces.vromfs.bin', unitPath);
|
||||
const mainWeapon = findMainGunBlock(unitBlk);
|
||||
if (!mainWeapon) return undefined;
|
||||
const rawBlkPath = stringField(mainWeapon, 'blk');
|
||||
const maxBullets = Math.trunc(numberField(mainWeapon, 'bullets') ?? 0);
|
||||
if (!rawBlkPath || maxBullets <= 0) return undefined;
|
||||
const lowerBlkPath = rawBlkPath.toLowerCase();
|
||||
if (!acesPaths.has(lowerBlkPath)) return undefined;
|
||||
|
||||
const weaponName = basenameWithoutExt(rawBlkPath);
|
||||
const weaponMeta = loadWeaponMeta(source, weaponCache, lowerBlkPath);
|
||||
const readyRack = countReadyRackShells(unitBlk, stringField(mainWeapon, 'trigger') ?? 'gunner0');
|
||||
const shells = collectSelectableShells(wpcostVehicle, unitBlk, globalMods, weaponMeta);
|
||||
if (shells.length === 0) return undefined;
|
||||
return { weaponName, maxBullets, isBelt: weaponMeta.isBelt, readyRack, shells };
|
||||
}
|
||||
|
||||
function findMainGunBlock(unitBlk: BlkBlock): BlkBlock | undefined {
|
||||
const common = findBlock(unitBlk, 'commonWeapons');
|
||||
if (!common) return undefined;
|
||||
return common.blocks.find((block) =>
|
||||
stringField(block, 'trigger') === 'gunner0'
|
||||
&& !(stringField(block, 'blk') ?? '').toLowerCase().includes('dummy_weapon'));
|
||||
}
|
||||
|
||||
function countReadyRackShells(unitBlk: BlkBlock, mainTrigger: string): number {
|
||||
const stowages = findBlock(unitBlk, 'ammoStowages');
|
||||
if (!stowages) return 0;
|
||||
let total = 0;
|
||||
for (const stow of stowages.blocks) {
|
||||
const triggers = stringList(stow, 'weaponTrigger');
|
||||
if (triggers.length > 0 && !triggers.includes(mainTrigger)) continue;
|
||||
for (const cluster of stow.blocks) {
|
||||
if (cluster.name !== 'shells') continue;
|
||||
const isReady = boolField(cluster, 'firstStage') === true
|
||||
|| boolField(cluster, 'autoLoad') === true
|
||||
|| boolField(cluster, 'ammoLoadedInGun') === true;
|
||||
if (!isReady) continue;
|
||||
for (const slot of cluster.blocks) total += Math.max(0, Math.trunc(numberField(slot, 'count') ?? 0));
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
function loadWeaponMeta(
|
||||
source: DatasetSource,
|
||||
cache: Map<string, { isBelt: boolean; defaultBullet?: WeaponBulletMeta; sets: Map<string, WeaponBulletMeta> }>,
|
||||
lowerPath: string,
|
||||
) {
|
||||
const cached = cache.get(lowerPath);
|
||||
if (cached) return cached;
|
||||
const blk = source.readBlk('aces.vromfs.bin', lowerPath);
|
||||
const isBelt = boolField(blk, 'isBulletBelt') === true;
|
||||
const defaultBlock = findBlock(blk, 'bullet');
|
||||
const defaultBullet = defaultBlock ? parseBulletMeta(defaultBlock) : undefined;
|
||||
const sets = new Map<string, WeaponBulletMeta>();
|
||||
for (const child of blk.blocks) {
|
||||
if (child.name === 'bullet') continue;
|
||||
const subBullet = findBlock(child, 'bullet');
|
||||
if (!subBullet) continue;
|
||||
const meta = parseBulletMeta(subBullet);
|
||||
if (meta) sets.set(child.name, meta);
|
||||
}
|
||||
const entry = { isBelt, ...(defaultBullet ? { defaultBullet } : {}), sets };
|
||||
cache.set(lowerPath, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
function parseBulletMeta(bullet: BlkBlock): WeaponBulletMeta | undefined {
|
||||
const bulletType = (stringField(bullet, 'bulletType') ?? '').toLowerCase();
|
||||
if (!bulletType) return undefined;
|
||||
const speedMps = numberField(bullet, 'speed') ?? 0;
|
||||
const pen500Mm = estimatePen500Mm(bullet, bulletType, speedMps);
|
||||
return { bulletType, speedMps, pen500Mm };
|
||||
}
|
||||
|
||||
function estimatePen500Mm(bullet: BlkBlock, bulletType: string, speedMps: number): number {
|
||||
const cum = numberField(findBlock(bullet, 'cumulativeDamage'), 'armorPower');
|
||||
const apBlock = findBlock(bullet, 'armorpower');
|
||||
const ap500 = numberField(apBlock, 'ArmorPower500m') ?? numberField(apBlock, 'ArmorPower0m') ?? 0;
|
||||
if (bulletType.includes('apds_fs')) {
|
||||
const dmgBlock = findBlock(bullet, 'damage');
|
||||
const kinetic = dmgBlock ? findBlock(dmgBlock, 'kinetic') : undefined;
|
||||
const workLen = numberField(kinetic, 'lanzOdermattWorkingLength')
|
||||
?? numberField(kinetic, 'WorkingLength')
|
||||
?? numberField(kinetic, 'Length')
|
||||
?? 0;
|
||||
const density = numberField(kinetic, 'lanzOdermattDensity') ?? numberField(kinetic, 'Density') ?? 17000;
|
||||
if (workLen > 0) return Math.max(ap500, Math.round(workLen * Math.sqrt(density / 7850) * (speedMps / 1700) * 0.85));
|
||||
return Math.max(ap500, Math.round(speedMps * 0.24));
|
||||
}
|
||||
if (cum !== undefined && cum > ap500) return cum;
|
||||
if (ap500 > 0) return ap500;
|
||||
const mass = numberField(bullet, 'mass') ?? 0;
|
||||
const cal = numberField(bullet, 'damageCaliber') ?? numberField(bullet, 'caliber') ?? 0;
|
||||
if (mass > 0 && cal > 0 && speedMps > 100 && !bulletType.includes('he_') && !bulletType.includes('smoke')) {
|
||||
return Math.round(0.0022 * Math.pow(mass, 0.55) * Math.pow(speedMps, 1.43) / Math.pow(cal * 1000, 0.65));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function collectSelectableShells(
|
||||
wpcostVehicle: BlkBlock,
|
||||
unitBlk: BlkBlock,
|
||||
globalMods: ReadonlyMap<string, GlobalModInfo>,
|
||||
weaponMeta: { defaultBullet?: WeaponBulletMeta; sets: Map<string, WeaponBulletMeta> },
|
||||
): TankShellChoice[] {
|
||||
const out: TankShellChoice[] = [];
|
||||
if (weaponMeta.defaultBullet) {
|
||||
out.push({ modName: '', ...weaponMeta.defaultBullet, requires: [] });
|
||||
}
|
||||
const wpModsBlock = findBlock(wpcostVehicle, 'modifications');
|
||||
const unitModsBlock = findBlock(unitBlk, 'modifications');
|
||||
const reqMap = new Map<string, readonly string[]>();
|
||||
for (const mod of wpModsBlock?.blocks ?? []) reqMap.set(mod.name, stringList(mod, 'reqModification'));
|
||||
|
||||
for (const mod of wpModsBlock?.blocks ?? []) {
|
||||
if (numberField(mod, 'ammoCount') === undefined) continue;
|
||||
const unitMod = unitModsBlock ? findBlock(unitModsBlock, mod.name) : undefined;
|
||||
const unitModEffects = unitMod ? findBlock(unitMod, 'effects') : undefined;
|
||||
const setName = stringField(unitModEffects, 'additiveBulletMod')
|
||||
?? stringField(unitModEffects, 'bulletMod')
|
||||
?? globalMods.get(mod.name)?.bulletMod
|
||||
?? mod.name;
|
||||
const meta = weaponMeta.sets.get(setName);
|
||||
if (!meta) continue;
|
||||
out.push({
|
||||
modName: mod.name,
|
||||
...meta,
|
||||
requires: collectTransitiveReqs(mod.name, reqMap, globalMods),
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function collectTransitiveReqs(
|
||||
modName: string,
|
||||
reqMap: ReadonlyMap<string, readonly string[]>,
|
||||
globalMods: ReadonlyMap<string, GlobalModInfo>,
|
||||
): string[] {
|
||||
const seen = new Set<string>();
|
||||
const queue = [...(reqMap.get(modName) ?? []), ...(globalMods.get(modName)?.requires ?? [])];
|
||||
while (queue.length > 0) {
|
||||
const next = queue.pop()!;
|
||||
if (!next || next === modName || seen.has(next)) continue;
|
||||
seen.add(next);
|
||||
for (const parent of reqMap.get(next) ?? []) queue.push(parent);
|
||||
}
|
||||
return [...seen].sort();
|
||||
}
|
||||
|
||||
function basenameWithoutExt(path: string): string {
|
||||
const slash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
|
||||
const file = slash >= 0 ? path.slice(slash + 1) : path;
|
||||
return file.endsWith('.blk') ? file.slice(0, -4) : file;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { BattleEconomy } from './battle/battle-economy.ts';
|
||||
import { BattleMatchmaker } from './battle/battle-matchmaker.ts';
|
||||
import { BattleSessionStore } from './battle/battle-session-store.ts';
|
||||
import { selectBotAircraftLoadouts } from './battle/bot-aircraft-loadouts.ts';
|
||||
import { selectBotTankLoadouts } from './battle/bot-tank-loadouts.ts';
|
||||
import { actionTable } from './char/actions/action-table.ts';
|
||||
import { CharService } from './char/char-service.ts';
|
||||
import { ClanStore } from './clans/clan-store.ts';
|
||||
@@ -31,6 +32,7 @@ import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
||||
import { decorCatalogue } from './game-data/datasets/decor-catalogue.ts';
|
||||
import { externalItemSources } from './game-data/datasets/external-item-sources.ts';
|
||||
import { flightModelPresets } from './game-data/datasets/flight-model-presets.ts';
|
||||
import { tankBotAmmo } from './game-data/datasets/tank-bot-ammo.ts';
|
||||
import { itemCatalogue } from './game-data/datasets/item-catalogue.ts';
|
||||
import { multiplayerMissions, type MultiplayerMissions } from './game-data/datasets/multiplayer-missions.ts';
|
||||
import { shopCountries } from './game-data/datasets/shop-countries.ts';
|
||||
@@ -173,6 +175,9 @@ export async function startServer(options: ServerOptions): Promise<RunningServer
|
||||
}, report);
|
||||
const webUi = new WebUiService(datasets.load(webIcons), labels, options.dataFolder, artwork);
|
||||
const botAircraftLoadouts = selectBotAircraftLoadouts(vehicles, datasets.load(flightModelPresets), equipment);
|
||||
const botTankLoadouts = tuning.groundAi.mode === 'stock'
|
||||
? undefined
|
||||
: selectBotTankLoadouts(vehicles, datasets.load(tankBotAmmo), tuning.groundAi.loadout);
|
||||
gameFiles.releasePacks();
|
||||
|
||||
let matching: MatchingService | undefined;
|
||||
@@ -189,6 +194,7 @@ export async function startServer(options: ServerOptions): Promise<RunningServer
|
||||
spawnRules,
|
||||
botAircraftLoadouts,
|
||||
tuning.groundAi.mode === 'stock' ? undefined : tuning.groundAi.lineupWeights,
|
||||
botTankLoadouts,
|
||||
(ctx) => modRuntime.runBattleFilterMissions(ctx),
|
||||
);
|
||||
const economy = new BattleEconomy(
|
||||
|
||||
@@ -27,6 +27,7 @@ export function readGroundAiTuning(reader: TuningReader): GroundAiTuning {
|
||||
const diag = reader.object('diagnostics');
|
||||
return {
|
||||
mode: readMode(reader),
|
||||
loadout: readLoadoutSection(reader.object('loadout')),
|
||||
lineupWeights: readLineupWeights(reader.object('lineupWeights')),
|
||||
cadence: {
|
||||
maxBots: cadence.int('maxBots', { min: 1, max: 64 }),
|
||||
@@ -60,6 +61,16 @@ function readMode(reader: TuningReader): GroundAiMode {
|
||||
return known;
|
||||
}
|
||||
|
||||
function readLoadoutSection(loadout: TuningReader): GroundAiTuning['loadout'] {
|
||||
return {
|
||||
lowReadyRackThreshold: loadout.int('lowReadyRackThreshold', { min: 1, max: 60 }),
|
||||
topUpAmmoCount: loadout.int('topUpAmmoCount', { min: 4, max: 80 }),
|
||||
primaryAmmoPct: loadout.int('primaryAmmoPct', { min: 50, max: 100 }),
|
||||
secondaryMinRounds: loadout.int('secondaryMinRounds', { min: 0, max: 20 }),
|
||||
penetrationCompareDistM: loadout.int('penetrationCompareDistM', { min: 100, max: 2000 }),
|
||||
};
|
||||
}
|
||||
|
||||
function readLineupWeights(weights: TuningReader): TankLineupWeights {
|
||||
const range = { min: 0.01, max: 10 };
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user