/** * The vehicles as research and purchase see them: the catalogue (game-data vehicle-catalogue) * with each vehicle's type and how it is obtained. * * Kinds, checked in this order: * part the separate part of a split vehicle; comes with its main vehicle * hidden shop.blk showOnlyWhenBought: event and promotion prizes, mission copies, * drones, ship floatplanes; the stock UI only shows them to players who own * them, so they are not offered * squadron researchType clanVehicle: researched with squadron research points or bought * early for golden eagles (feature-inventory I, later); no rank requirement * gift gift:t: packs and marketplace vehicles; the stock scripts never offer them * for silver lions or golden eagles (scripts/unit/unitShopInfo.nut * canBuyUnitEvenNotInShop); the local shop gives them (feature-inventory G, later) * event event:t (feature-inventory G, later) * premium costGold > 0 or premPackAir (the scripts' isUnitSpecial): bought for golden * eagles without research, rank or previous vehicle * research reqExp > 0: researched, then bought * purchase no reqExp: bought without research (helicopters that start a branch, free * vehicles unlocked by an achievement, reserve vehicles) */ import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts'; import { vehicleTypeOfClass, type VehicleType } from './vehicle-types.ts'; export type VehicleKind = 'part' | 'hidden' | 'squadron' | 'gift' | 'event' | 'premium' | 'research' | 'purchase'; export interface TreeVehicle extends CatalogueVehicle { readonly type: VehicleType; readonly kind: VehicleKind; } const SQUADRON_RESEARCH = 'clanVehicle'; export class TechTree { readonly #vehicles: ReadonlyMap; constructor(catalogue: readonly CatalogueVehicle[]) { const parts = new Set(catalogue.filter((vehicle) => vehicle.inTechTree).flatMap((vehicle) => vehicle.parts)); const vehicles = new Map(); for (const vehicle of catalogue) { const type = vehicleTypeOfClass(vehicle.unitClass); // Without a type or country the client's status function locks the vehicle (0x911750, 0x961dd0). if (type && vehicle.country) vehicles.set(vehicle.name, { ...vehicle, type, kind: kindOf(vehicle, parts) }); } this.#vehicles = vehicles; } vehicle(name: string): TreeVehicle | undefined { return this.#vehicles.get(name); } /** Every vehicle with a type and country, in the tech tree or not. */ all(): Iterable { return this.#vehicles.values(); } /** The countries and vehicle types that have vehicles in the tech tree, with their highest rank. */ branches(): { country: string; type: VehicleType; highestRank: number }[] { const highest = new Map(); for (const vehicle of this.#vehicles.values()) { if (!vehicle.inTechTree) continue; const key = `${vehicle.country}/${vehicle.type}`; const known = highest.get(key); if (!known) highest.set(key, { country: vehicle.country, type: vehicle.type, highestRank: vehicle.rank }); else known.highestRank = Math.max(known.highestRank, vehicle.rank); } return [...highest.values()]; } hasCountry(country: string): boolean { for (const vehicle of this.#vehicles.values()) if (vehicle.inTechTree && vehicle.country === country) return true; return false; } } function kindOf(vehicle: CatalogueVehicle, parts: ReadonlySet): VehicleKind { if (parts.has(vehicle.name)) return 'part'; if (vehicle.onlyShownWhenOwned) return 'hidden'; if (vehicle.researchType === SQUADRON_RESEARCH) return 'squadron'; if (vehicle.gift) return 'gift'; if (vehicle.event) return 'event'; if (vehicle.goldenEagles > 0 || vehicle.premiumPack) return 'premium'; return vehicle.researchPoints > 0 ? 'research' : 'purchase'; } /** Premium-like vehicles for unlock conditions that count "premium" vehicles separately (unlocks.blk premium:b). */ export function isPremiumKind(kind: VehicleKind): boolean { return kind === 'premium' || kind === 'gift' || kind === 'event'; }