/** * Dataset: the extra vehicles a battle adds to a player's lineup, as the game files list them. * * aces.vromfs.bin config/gameplay.blk * missionSupportPlane{ { UnitPreset{ killStreakTagName:t rankRange:ip2 spawnScoreToShow:i * spawnScoreToUse:i { unitName:t weapon:t } } } } * Killstreak aircraft (the nuclear carrier) per session rank bracket, one per country. * RandomSpawnUnits{ { { { minPlayerMRank:i * maxDiffBetweenTopUnitAndSessionRank:i mRanksCount:i { addModification:t addWeapon:t * forceWeapon:t } } } } } * The random vehicle groups (dice slots: random tank and SPAA in ground battles, random fighter * and bomber in naval battles). The stock client reads the same block for forced weapons * (scripts/unit/randomunitsforceweapon.nut). * char.vromfs.bin config/wpcost.blk * ucav_*_killstreak{ country:t ... } * The strike UCAVs, one per country. * *_killstreak / nt_* with weapons..totalNuclearYield:i * Tactical (5 kt / 30 kt) and strategic (>= 1000 kt) nuclear carriers for Nuclear Escalation. * char.vromfs.bin config/warpoints.blk respawn_points / TankHistorical * Starting points and unit cost parameters for Ground Realistic Battles. */ import type { BlkBlock } from '@wto/blk'; import { findParam } from '@wto/blk'; import { blockAt, boolField, numberField, stringField, stringList } from './blk-fields.ts'; import type { Dataset } from './dataset.ts'; export interface SupportPlaneUnit { readonly unitName: string; readonly weapon: string; } export interface SupportPlanePreset { readonly killStreakTag: string; /** Session rank bracket (`rankRange`, inclusive). */ readonly minMrank: number; readonly maxMrank: number; readonly spawnScoreToShow: number; readonly spawnScoreToUse: number; /** By country. */ readonly units: Readonly>; } export interface StrikeUcav { readonly country: string; readonly unitName: string; } export interface NuclearCarrierWeapon { readonly name: string; readonly yieldKt: number; } export interface NuclearCarrierUnit { readonly country: string; readonly unitName: string; readonly mrank: number; readonly weapons: readonly NuclearCarrierWeapon[]; } export interface RandomSpawnUnit { readonly unitName: string; readonly addModifications: readonly string[]; readonly forceWeapon?: string; } export interface RandomSpawnGroup { /** `tank`, `spaa`, `fighter`, `bomber`: the key of `random_units` and of gui.blk `randomSpawnUnitPresets`. */ readonly name: string; readonly minPlayerMrank: number; readonly maxDiffBetweenTopUnitAndSessionRank: number; readonly mranksCount: number; readonly units: readonly RandomSpawnUnit[]; } interface SpawnScoreParameterSet { readonly parameters: Readonly>; readonly classCosts: Readonly>; } export interface SpawnScoreRules { readonly common: Readonly>; readonly tankHistorical: SpawnScoreParameterSet; readonly overrides: ReadonlyArray; } export interface BattleSpawnRulesData { /** By event name (`missionSupportPlane` keys are game mode names). */ readonly supportPlanes: Readonly>; readonly strikeUcavs: readonly StrikeUcav[]; /** Killstreak nuclear carriers carrying 5 kt / 30 kt Nuclear Escalation presets. */ readonly nuclearEscalationTacticalCarriers: readonly NuclearCarrierUnit[]; /** Megaton-class strategic nuclear bombers (`nt_*` with totalNuclearYield >= 1000 kt). */ readonly nuclearEscalationStrategicBombers: readonly NuclearCarrierUnit[]; readonly spawnScore: SpawnScoreRules; /** By event economic name, then country. */ readonly randomSpawnUnits: Readonly>>>; } const STRIKE_UCAV_PATTERN = /^ucav_.*_killstreak$/; const KILLSTREAK_PATTERN = /_killstreak$/; const STRATEGIC_BOMBER_PATTERN = /^nt_/; const STRATEGIC_YIELD_MIN_KT = 1000; export const battleSpawnRules: Dataset = { id: 'battle-spawn-rules', version: 4, extract: (source) => { const gameplay = source.readBlk('aces.vromfs.bin', 'config/gameplay.blk'); const wpcost = source.readBlk('char.vromfs.bin', 'config/wpcost.blk'); return { supportPlanes: extractSupportPlanes(blockAt(gameplay, 'missionSupportPlane')), strikeUcavs: extractStrikeUcavs(wpcost.blocks), nuclearEscalationTacticalCarriers: extractNuclearCarriers(wpcost.blocks, 'tactical'), nuclearEscalationStrategicBombers: extractNuclearCarriers(wpcost.blocks, 'strategic'), spawnScore: extractSpawnScore(blockAt(source.readBlk('char.vromfs.bin', 'config/warpoints.blk'), 'respawn_points')), randomSpawnUnits: extractRandomSpawnUnits(blockAt(gameplay, 'RandomSpawnUnits')), }; }, }; function extractSpawnScore(root: BlkBlock | undefined): SpawnScoreRules { const tankHistorical = blockAt(root, 'TankHistorical'); return { common: numericParams(root), tankHistorical: spawnScoreParams(tankHistorical), overrides: (blockAt(tankHistorical, 'override_params_by_session_rank')?.blocks ?? []).map((block) => ({ ...spawnScoreParams(block), minMrank: numberField(block, 'minMRank') ?? -1, maxMrank: numberField(block, 'maxMRank') ?? -1, })), }; } function spawnScoreParams(block: BlkBlock | undefined): SpawnScoreParameterSet { return { parameters: numericParams(block), classCosts: numericParams(blockAt(block, 'respawn_cost_mul_by_exp_class')), }; } function numericParams(block: BlkBlock | undefined): Record { const params = block?.params ?? []; return Object.fromEntries(params.flatMap(({ name, value }) => value.type === 'int' || value.type === 'real' ? [[name, value.value]] : [])); } function extractSupportPlanes(root: BlkBlock | undefined): Record { const byEvent: Record = {}; for (const eventBlk of root?.blocks ?? []) { const presets: SupportPlanePreset[] = []; for (const preset of eventBlk.blocks) { if (preset.name !== 'UnitPreset') continue; const range = findParam(preset, 'rankRange')?.value; const spawnScoreToUse = numberField(preset, 'spawnScoreToUse'); if (range?.type !== 'ipoint2' || spawnScoreToUse === undefined) continue; const units: Record = {}; for (const countryBlk of preset.blocks) { const unitName = stringField(countryBlk, 'unitName'); const weapon = stringField(countryBlk, 'weapon'); if (countryBlk.name.startsWith('country_') && unitName && weapon) units[countryBlk.name] = { unitName, weapon }; } presets.push({ killStreakTag: stringField(preset, 'killStreakTagName') ?? '', minMrank: range.value[0], maxMrank: range.value[1], spawnScoreToShow: numberField(preset, 'spawnScoreToShow') ?? spawnScoreToUse, spawnScoreToUse, units, }); } if (presets.length > 0) byEvent[eventBlk.name] = presets; } return byEvent; } function extractStrikeUcavs(wpcostBlocks: readonly BlkBlock[]): StrikeUcav[] { return wpcostBlocks.flatMap((unitBlk) => { const country = stringField(unitBlk, 'country') ?? ''; return STRIKE_UCAV_PATTERN.test(unitBlk.name) && country.startsWith('country_') ? [{ country, unitName: unitBlk.name }] : []; }); } function extractNuclearCarriers( wpcostBlocks: readonly BlkBlock[], kind: 'tactical' | 'strategic', ): NuclearCarrierUnit[] { const carriers: NuclearCarrierUnit[] = []; for (const unitBlk of wpcostBlocks) { const country = stringField(unitBlk, 'country') ?? ''; if (!country.startsWith('country_')) continue; if (kind === 'tactical' && !KILLSTREAK_PATTERN.test(unitBlk.name)) continue; if (kind === 'strategic' && !STRATEGIC_BOMBER_PATTERN.test(unitBlk.name)) continue; const weaponsBlk = blockAt(unitBlk, 'weapons'); if (!weaponsBlk) continue; const weapons: NuclearCarrierWeapon[] = []; for (const weaponBlk of weaponsBlk.blocks) { if (boolField(weaponBlk, 'isWeaponForCustomSlot') === true) continue; if (boolField(weaponBlk, 'hideInGui') === true) continue; if (weaponBlk.name.includes('without_countermeasures')) continue; const yieldKt = numberField(weaponBlk, 'totalNuclearYield') ?? 0; if (yieldKt <= 0) continue; if (kind === 'tactical' && yieldKt >= STRATEGIC_YIELD_MIN_KT) continue; if (kind === 'strategic' && yieldKt < STRATEGIC_YIELD_MIN_KT) continue; weapons.push({ name: weaponBlk.name, yieldKt }); } if (weapons.length === 0) continue; weapons.sort((a, b) => a.yieldKt - b.yieldKt || a.name.localeCompare(b.name)); const mrank = numberField(unitBlk, 'economicRankHistorical') ?? numberField(unitBlk, 'economicRank') ?? 0; carriers.push({ country, unitName: unitBlk.name, mrank, weapons }); } carriers.sort((a, b) => a.country.localeCompare(b.country) || a.mrank - b.mrank || a.unitName.localeCompare(b.unitName)); return carriers; } function extractRandomSpawnUnits( root: BlkBlock | undefined, ): Record> { const byEvent: Record> = {}; for (const eventBlk of root?.blocks ?? []) { const byCountry: Record = {}; for (const countryBlk of eventBlk.blocks) { if (!countryBlk.name.startsWith('country_')) continue; const groups = countryBlk.blocks.flatMap((groupBlk): RandomSpawnGroup[] => { const units = groupBlk.blocks.map((unitBlk): RandomSpawnUnit => { const forceWeapon = stringField(unitBlk, 'forceWeapon'); return { unitName: unitBlk.name, addModifications: stringList(unitBlk, 'addModification'), ...(forceWeapon ? { forceWeapon } : {}), }; }); return units.length === 0 ? [] : [{ name: groupBlk.name, minPlayerMrank: numberField(groupBlk, 'minPlayerMRank') ?? 0, maxDiffBetweenTopUnitAndSessionRank: numberField(groupBlk, 'maxDiffBetweenTopUnitAndSessionRank') ?? 0, mranksCount: numberField(groupBlk, 'mRanksCount') ?? 0, units, }]; }); if (groups.length > 0) byCountry[countryBlk.name] = groups; } byEvent[eventBlk.name] = byCountry; } return byEvent; }