/** * How much of a battle's vehicle Research Points reaches the researched vehicle (game data: * game-data/datasets/research-efficiency.ts; rules from the official wiki "Research Points" * https://wiki.warthunder.com/Research_Points and the news "Following the Roadmap: Vehicle * Research Bonuses", 2024-09-24, whose numbers match rank.blk): * * - Rank difference: researching a vehicle N ranks above or below the one played costs * expPenaltyPercentForHigherRank / expPenaltyPercentForLowerRank percent. A premium * vehicle researching lower-ranked vehicles has no penalty (the older wiki "Research Points" * page says so; the current page does not mention it, so this is kept but unconfirmed). * - Predecessor: playing the vehicle directly before the researched one (its reqAir) adds * expBonusPercentForChildForMode percent and overrides the rank penalty. * - Vehicle Research Bonus: once the player owns a "top" vehicle of a vehicle type in any nation, * every nation's research of that type gets ExpNewNationBonus[type][rank of the researched * vehicle] percent of the base Research Points, for expNewNationBonusDailyBattleCount battles per * nation and type per day (00:00 GMT). A top vehicle is researchable (not premium, pack, event, * squadron or hidden), ends a research line (the first vehicle when the line ends in a group), * sits at the tree's highest rank and is at most two battle rating steps below the tree's * highest battle rating. Not modelled: the exclusion of vehicles "considered new" (the game files * carry no release dates). */ import type { ResearchEfficiencyData } from '../game-data/datasets/research-efficiency.ts'; import type { EconomyDifficulty } from '../game-data/datasets/battle-economy.ts'; import { isPremiumKind, type TechTree, type TreeVehicle } from './tech-tree.ts'; /** The client's diffCode of each difficulty (scripts/airinfo.nut reads the child bonus with it). */ const DIFF_CODE: Readonly> = { arcade: 0, historical: 1, simulation: 2 }; /** Battle rating steps a top vehicle may sit below its tree's highest battle rating. */ const TOP_VEHICLE_MRANK_STEPS = 2; export interface ResearchEfficiencyTerms { readonly childBonusPercent: number; readonly rankDiffPenaltyPercent: number; } export class ResearchEfficiency { readonly #data: ResearchEfficiencyData; readonly #tree: TechTree; readonly #topVehicles: ReadonlySet; constructor(data: ResearchEfficiencyData, tree: TechTree) { this.#data = data; this.#tree = tree; this.#topVehicles = topVehiclesOf(data.lineEnds, tree); } get dailyBonusBattles(): number { return this.#data.nationBonusDailyBattles; } /** Predecessor bonus or rank penalty of RP earned in `played` and invested into `researched`. */ termsFor(played: TreeVehicle, researched: TreeVehicle, difficulty: EconomyDifficulty): ResearchEfficiencyTerms { if (researched.requires === played.name) { return { childBonusPercent: this.#data.childBonusPercent[DIFF_CODE[difficulty]] ?? 0, rankDiffPenaltyPercent: 0 }; } const diff = researched.rank - played.rank; if (diff < 0 && isPremiumKind(played.kind)) return { childBonusPercent: 0, rankDiffPenaltyPercent: 0 }; const series = diff >= 0 ? this.#data.higherRankPenaltyPercent : this.#data.lowerRankPenaltyPercent; const percent = series[Math.min(Math.abs(diff), series.length - 1)] ?? 0; return { childBonusPercent: 0, rankDiffPenaltyPercent: percent }; } /** The Vehicle Research Bonus percent for researching `researched`, given the vehicles the player owns. */ nationBonusPercent(researched: TreeVehicle, owned: ReadonlySet): number { const hasTop = [...this.#topVehicles].some((name) => owned.has(name) && this.#tree.vehicle(name)?.type === researched.type); if (!hasTop) return 0; return this.#data.nationBonusPercent[researched.type]?.[researched.rank] ?? 0; } } function topVehiclesOf(lineEnds: readonly string[], tree: TechTree): Set { const highestRank = new Map(tree.branches().map((branch) => [`${branch.country}/${branch.type}`, branch.highestRank])); const highestMrank = new Map(); for (const vehicle of tree.all()) { if (!vehicle.inTechTree || vehicle.kind === 'hidden' || vehicle.kind === 'part') continue; const key = `${vehicle.country}/${vehicle.type}`; highestMrank.set(key, Math.max(highestMrank.get(key) ?? 0, maxMrank(vehicle))); } const top = new Set(); for (const name of lineEnds) { const vehicle = tree.vehicle(name); if (!vehicle || vehicle.kind !== 'research') continue; const key = `${vehicle.country}/${vehicle.type}`; if (vehicle.rank !== highestRank.get(key)) continue; if (maxMrank(vehicle) < (highestMrank.get(key) ?? 0) - TOP_VEHICLE_MRANK_STEPS) continue; top.add(name); } return top; } /** The highest economic rank of a vehicle over the game modes ("maximum BR among all game modes"). */ function maxMrank(vehicle: TreeVehicle): number { return Math.max( vehicle.economicRankArcade, vehicle.economicRankHistorical, vehicle.economicRankSimulation, vehicle.economicRankTankHistorical ?? 0, vehicle.economicRankTankSimulation ?? 0, ); }