/** * Dataset: every vehicle's modifications, ammunition, weapon presets and spare, with their * research and purchase facts. * * char.vromfs.bin config/wpcost.blk, per vehicle: * needBuyToOpenNextInTier:i researched modifications of tier N needed to open tier N+1 * modifications{ { tier:i reqExp:i value:i costGold:i openCostGold:i * reqModification:t (repeated) maxCount:i ammoCount:i addMrank:i ... } } * Ammunition and expendables are modifications too (tier 0, maxCount, ammoCount). * weapons{ { value:i costGold:i maxCount:i reqModification:t ... } } * Paid presets (bombs, rockets) are bought by the piece, up to maxCount; the rest are free, * custom_presets (the custom preset slots) among them. * spare{ value:i costGold:i } * * Only what the file says is recorded; what it means is the rules layer's (modifications/). */ import type { BlkBlock } from '@wto/blk'; import { findBlock } from '@wto/blk'; import { boolField, numberField, stringField, stringList } from './blk-fields.ts'; import type { Dataset } from './dataset.ts'; const VEHICLE_ECONOMY = 'config/wpcost.blk'; const MODIFICATIONS_CONFIG = 'config/modifications.blk'; /** wpcost.blk has needBuyToOpenNextInTier1..4; the modification tree has tiers 1..5 at most. */ const TIER_REQUIREMENT_COUNT = 4; export interface ModificationFacts { readonly name: string; readonly tier: number; /** reqExp; 0 when the modification is not researched (ammunition, expendables, premium). */ readonly researchPoints: number; readonly silverLions: number; readonly goldenEagles: number; /** openCostGold: golden eagles to get it without the research (scaled by progress). */ readonly openGoldenEagles: number; /** reqModification, repeated: modifications that must be bought first. */ readonly requires: readonly string[]; /** maxCount; 0 when the modification is not counted (bought once). */ readonly maxCount: number; /** ammoCount present: an ammunition belt or shell type. */ readonly ammunition: boolean; /** addMrank: selectable matchmaking rank increase unlocked by owning this modification. */ readonly addMrank?: number; /** Initial enabled state when acquired (`turn_it_off` / `isEnabledByDefaultForAddMrank`). */ readonly defaultEnabled: boolean; /** Non-bullet `group` name when modifications in the same group are mutually exclusive. */ readonly exclusiveGroup?: string; } export interface WeaponFacts { readonly name: string; /** value: silver lions per piece. */ readonly silverLions: number; readonly goldenEagles: number; /** reqModification (direct + inherited from `sum_weapons` containers, initUnitWeapons.nut). */ readonly requires: readonly string[]; /** maxCount; 0 when the preset is not bought by the piece. */ readonly maxCount: number; /** True for `isWeaponForCustomSlot` single-weapon containers referenced by `sum_weapons`. */ readonly forCustomSlot?: boolean; /** `sum_weapons` container names referenced by a selectable preset. */ readonly sumWeapons?: readonly string[]; } export interface VehicleEquipment { readonly vehicle: string; /** needBuyToOpenNextInTier1..4 (index 0 = tier 1). */ readonly tierRequirements: readonly number[]; readonly modifications: readonly ModificationFacts[]; readonly weapons: readonly WeaponFacts[]; /** spare; absent when the vehicle has no spare price. */ readonly spare?: { readonly silverLions: number; readonly goldenEagles: number }; } interface GlobalModificationMeta { readonly turnOffByDefault: boolean; readonly bulletGroup: boolean; readonly group?: string; } export const vehicleEquipment: Dataset = { id: 'vehicle-equipment', version: 5, extract: (source) => { const modMeta = readGlobalModificationMeta(source.readBlk('char.vromfs.bin', MODIFICATIONS_CONFIG)); return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) => equipmentOf(vehicle, modMeta)); }, }; function readGlobalModificationMeta(configRoot: BlkBlock): ReadonlyMap { const modsBlock = findBlock(configRoot, 'modifications'); const map = new Map(); for (const entry of modsBlock?.blocks ?? []) { const effects = findBlock(entry, 'effects'); const bulletGroup = Boolean( effects?.params.some((p) => p.name === 'bulletMod' || p.name === 'additiveBulletMod') || effects?.blocks.some((b) => b.name === 'bulletMod' || b.name === 'additiveBulletMod'), ); const group = stringField(entry, 'group'); map.set(entry.name, { turnOffByDefault: boolField(entry, 'turn_it_off') === true, bulletGroup, ...(group !== undefined ? { group } : {}), }); } return map; } function equipmentOf(vehicle: BlkBlock, modMeta: ReadonlyMap): VehicleEquipment { const tierRequirements: number[] = []; for (let tier = 1; tier <= TIER_REQUIREMENT_COUNT; tier++) tierRequirements.push(numberField(vehicle, `needBuyToOpenNextInTier${tier}`) ?? 0); const spare = findBlock(vehicle, 'spare'); return { vehicle: vehicle.name, tierRequirements, modifications: (findBlock(vehicle, 'modifications')?.blocks ?? []).map((mod) => modificationOf(mod, modMeta.get(mod.name))), weapons: weaponsOf(findBlock(vehicle, 'weapons')), ...(spare ? { spare: { silverLions: numberField(spare, 'value') ?? 0, goldenEagles: numberField(spare, 'costGold') ?? 0 } } : {}), }; } function modificationOf(modification: BlkBlock, meta: GlobalModificationMeta | undefined): ModificationFacts { const ammunition = numberField(modification, 'ammoCount') !== undefined; const addMrank = numberField(modification, 'addMrank'); const defaultEnabled = !(meta?.turnOffByDefault ?? false) && (boolField(modification, 'isEnabledByDefaultForAddMrank') ?? true); const group = stringField(modification, 'group') ?? meta?.group; const exclusiveGroup = !ammunition && !(meta?.bulletGroup ?? false) ? group : undefined; return { name: modification.name, tier: numberField(modification, 'tier') ?? 0, researchPoints: numberField(modification, 'reqExp') ?? 0, silverLions: numberField(modification, 'value') ?? 0, goldenEagles: numberField(modification, 'costGold') ?? 0, openGoldenEagles: numberField(modification, 'openCostGold') ?? 0, requires: stringList(modification, 'reqModification'), maxCount: numberField(modification, 'maxCount') ?? 0, ammunition, ...(addMrank !== undefined ? { addMrank } : {}), defaultEnabled, ...(exclusiveGroup !== undefined ? { exclusiveGroup } : {}), }; } function weaponsOf(weaponsBlock: BlkBlock | undefined): WeaponFacts[] { if (!weaponsBlock) return []; const containerRequires = new Map(); for (const entry of weaponsBlock.blocks) { if (boolField(entry, 'isWeaponForCustomSlot') === true) { containerRequires.set(entry.name, stringList(entry, 'reqModification')); } } // Keep `isWeaponForCustomSlot` container blocks too: native `shop_is_weapon_purchased` // (aces.exe 0x15562f0 -> 0x913570) checks every `sum_weapons` container against `profile.weapons{}`. return weaponsBlock.blocks.map((entry) => weaponOf(entry, containerRequires)); } function weaponOf(entry: BlkBlock, containerRequires: ReadonlyMap): WeaponFacts { const forCustomSlot = boolField(entry, 'isWeaponForCustomSlot') === true; const requires = [...stringList(entry, 'reqModification')]; const sumWeapons: string[] = []; for (const param of findBlock(entry, 'sum_weapons')?.params ?? []) { if (!sumWeapons.includes(param.name)) sumWeapons.push(param.name); for (const req of containerRequires.get(param.name) ?? []) { if (!requires.includes(req)) requires.push(req); } } return { name: entry.name, silverLions: numberField(entry, 'value') ?? 0, goldenEagles: numberField(entry, 'costGold') ?? 0, requires, maxCount: numberField(entry, 'maxCount') ?? 0, ...(forCustomSlot ? { forCustomSlot: true } : {}), ...(sumWeapons.length > 0 ? { sumWeapons } : {}), }; }