/** * Dataset: what repairing each vehicle costs and how long a free repair takes. * * char.vromfs.bin config/wpcost.blk, per vehicle: * repairCost:i full repair cost (Mode = Arcade, Historical, Simulation) * repairCostPerMin:i repair cost per minute of the vehicle's lifetime in a battle * repairTimeHrs:r full repair time in hours with a crew * repairTimeHrsNoCrew:r full repair time in hours when no crew has the vehicle * freeRepairs:i free repair allowance (falls back to warpoints.blk, then 0) * modifications{ { repairCostCoef:r repairCostCoef:r } } added to the cost factor * char.vromfs.bin config/warpoints.blk: rTimeNoCrewMul:r (no-crew time = repairTimeHrs x it when * repairTimeHrsNoCrew is missing). * char.vromfs.bin config/crew_skills.blk: the crew's groundService skills that shorten the repair: * crew_skills{ groundService{ repair{ use_specializations:b skill_level_exp{ level1..levelN } } } } * specialization_add:r (k = 1..4), repair_ranks{ rank:i }. * * The client reads the same fields: the full cost from the price table (cln_get_price_ex, * aircrafts//repair//cost, aces.exe 2.61.0.37 0x10517b0), times 1 + the * repairCostCoef (else repairCostCoef) of each modification the player has (0x964900); the * repair time in 0x937330 (repair/repair-rules.ts fullRepairHours). */ import { findBlock, type BlkBlock } from '@wto/blk'; import { blockAt, numberField } from './blk-fields.ts'; import type { Dataset } from './dataset.ts'; export const REPAIR_MODES = ['Arcade', 'Historical', 'Simulation'] as const; export type RepairMode = (typeof REPAIR_MODES)[number]; export type PerRepairMode = Readonly>; export interface VehicleRepair { readonly name: string; readonly cost: PerRepairMode; readonly costPerMin: PerRepairMode; /** Allowance shown by scripts/unit/unit.nut and scripts/airinfo.nut. */ readonly freeRepairs: number; /** Hours; 0 when the data has none. */ readonly timeHours: PerRepairMode; /** Hours; -1 when the data has none (the client's default, 0x964e30). */ readonly noCrewTimeHours: PerRepairMode; /** Modifications with a repair cost coefficient. */ readonly modCoefs: Readonly>; } /** The crew skills that shorten a repair (crew_skills.blk). */ export interface CrewRepairSkill { /** Levels of groundService/repair (the length of its skill_level_exp). */ readonly maxLevel: number; readonly usesSpecializations: boolean; /** specialization1_add .. specialization4_add (0 when missing). */ readonly specializationAdds: readonly number[]; /** repair_ranks: the highest vehicle rank a groundService/repairRank level covers, index = level - 1. */ readonly ranksByQualification: readonly number[]; /** groundService/repairRank min_skill_level. */ readonly minQualification: number; } export interface VehicleRepairData { readonly vehicles: readonly VehicleRepair[]; readonly noCrewTimeMul: number; readonly crewSkill: CrewRepairSkill; } const SPECIALIZATION_ADDS = 4; export const vehicleRepair: Dataset = { id: 'vehicle-repair', version: 3, extract: (source) => { const warpoints = source.readBlk('char.vromfs.bin', 'config/warpoints.blk'); const defaultFreeRepairs = numberField(warpoints, 'freeRepairs') ?? 0; const vehicles = source.readBlk('char.vromfs.bin', 'config/wpcost.blk').blocks.flatMap((vehicle): VehicleRepair[] => { const cost = perMode(vehicle, 'repairCost', 0); if (REPAIR_MODES.every((mode) => cost[mode] <= 0)) return []; const modCoefs: Record = {}; for (const mod of blockAt(vehicle, 'modifications')?.blocks ?? []) { const base = numberField(mod, 'repairCostCoef'); const coefs = Object.fromEntries(REPAIR_MODES.map((mode) => [mode, numberField(mod, `repairCostCoef${mode}`) ?? base ?? 0])) as Record; if (REPAIR_MODES.some((mode) => coefs[mode] !== 0)) modCoefs[mod.name] = coefs; } return [{ name: vehicle.name, cost, costPerMin: perMode(vehicle, 'repairCostPerMin', 0), freeRepairs: Math.max(0, Math.trunc(numberField(vehicle, 'freeRepairs') ?? defaultFreeRepairs)), timeHours: perMode(vehicle, 'repairTimeHrs', 0), noCrewTimeHours: perMode(vehicle, 'repairTimeHrsNoCrew', -1), modCoefs, }]; }); return { vehicles, noCrewTimeMul: numberField(warpoints, 'rTimeNoCrewMul') ?? 1, crewSkill: crewRepairSkill(source.readBlk('char.vromfs.bin', 'config/crew_skills.blk')), }; }, }; function crewRepairSkill(crewSkills: BlkBlock): CrewRepairSkill { const groundService = findBlock(findBlock(crewSkills, 'crew_skills') ?? crewSkills, 'groundService'); const repair = groundService && findBlock(groundService, 'repair'); const qualification = groundService && findBlock(groundService, 'repairRank'); const levels = repair && findBlock(repair, 'skill_level_exp'); const ranks = findBlock(crewSkills, 'repair_ranks'); const ranksByQualification: number[] = []; for (let level = 1; ranks && numberField(ranks, `rank${level}`) !== undefined; level++) ranksByQualification.push(numberField(ranks, `rank${level}`)!); return { maxLevel: levels?.params.length ?? numberField(crewSkills, 'max_skill_level') ?? 0, usesSpecializations: repair?.params.some((param) => param.name === 'use_specializations' && param.value.type === 'bool' && param.value.value) ?? false, specializationAdds: Array.from({ length: SPECIALIZATION_ADDS }, (_, index) => numberField(crewSkills, `specialization${index + 1}_add`) ?? 0), ranksByQualification, minQualification: (qualification && numberField(qualification, 'min_skill_level')) ?? 0, }; } function perMode(vehicle: BlkBlock, prefix: string, missing: number): PerRepairMode { return Object.fromEntries(REPAIR_MODES.map((mode) => { const value = numberField(vehicle, `${prefix}${mode}`); return [mode, value === undefined ? missing : Math.max(0, value)]; })) as Record; }