Keep a default vehicle research target for each branch

The accelerated research dialog reads currUnit when it first opens.
Assign a valid target whenever an eligible vehicle exists and replace
stale selections when refreshing a profile.

Prefer an available direct successor when configured. Otherwise use
the configured rank or tech tree order. Type checking and profile
initialization passed. In-game acceptance is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 13:41:29 +08:00
1 parent d609188acc
commit a09ac41299
8 files changed
+115 -7

No files matched your search

@@ -46,6 +46,8 @@ export interface CatalogueVehicle {
readonly researchType?: string;
/** Listed in config/shop.blk. */
readonly inTechTree: boolean;
/** Position in config/shop.blk (countries, branches, columns top to bottom, in file order); -1 when not listed. */
readonly treeOrder: number;
/** shop.blk reqUnlock. */
readonly requiredUnlock?: string;
/** shop.blk slaveUnit, repeated. */
@@ -62,14 +64,15 @@ export interface CatalogueVehicle {
export const vehicleCatalogue: Dataset<readonly CatalogueVehicle[]> = {
id: 'vehicle-catalogue',
version: 4,
version: 5,
extract: (source) => {
const shopEntries = shopEntriesByName(source);
return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) => catalogueVehicle(vehicle, shopEntries.get(vehicle.name)));
const treeOrder = new Map([...shopEntries.keys()].map((name, index) => [name, index]));
return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) => catalogueVehicle(vehicle, shopEntries.get(vehicle.name), treeOrder.get(vehicle.name) ?? -1));
},
};
function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined): CatalogueVehicle {
function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined, treeOrder: number): CatalogueVehicle {
const requires = stringField(vehicle, 'reqAir');
const researchType = stringField(vehicle, 'researchType');
const requiredUnlock = stringField(shopEntry, 'reqUnlock');
@@ -88,6 +91,7 @@ function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined): C
event: stringField(vehicle, 'event') !== undefined,
...(researchType ? { researchType } : {}),
inTechTree: shopEntry !== undefined,
treeOrder,
...(requiredUnlock ? { requiredUnlock } : {}),
parts: shopEntry ? shopEntry.params.flatMap((param) => (param.name === 'slaveUnit' && param.value.type === 'string' && param.value.value ? [param.value.value] : [])) : [],
onlyShownWhenOwned: boolField(shopEntry, 'showOnlyWhenBought') ?? false,
@@ -0,0 +1,37 @@
/**
* Picking a research target for a branch that has none.
*
* The stock game never leaves a country and vehicle type without a vehicle in research while
* one can be researched: the char server sets the target itself, and the client only asks the
* player to confirm it (aces.exe 2.61.0.37 0x17a45e0 shop_get_countries_list_with_autoset_units
* returns {country, unit = currUnit, prevUnit}; scripts/researches/researchActions.nut
* checkNonApprovedResearches opens scripts/shop/shopCheckResearch.nut, which keeps a target
* that is still being researched). Which vehicle the server picks is not in the client, so the
* pick is offline tuning (tuning/research.jsonc autoTargetPick).
*/
import type { AutoTargetPick, ResearchTuning } from './research-tuning.ts';
import type { TreeVehicle } from './tech-tree.ts';
/** The vehicle to research among the branch's researchable candidates; undefined when there are none. */
export function pickResearchTarget(
candidates: readonly TreeVehicle[],
tuning: ResearchTuning,
previousUnitName: string = '',
): TreeVehicle | undefined {
if (tuning.preferLineSuccessor && previousUnitName) {
const successors = candidates.filter((vehicle) => vehicle.requires === previousUnitName);
if (successors.length > 0) return [...successors].sort(ORDERS[tuning.autoTargetPick])[0];
}
return [...candidates].sort(ORDERS[tuning.autoTargetPick])[0];
}
type Order = (a: TreeVehicle, b: TreeVehicle) => number;
const byTree: Order = (a, b) => a.treeOrder - b.treeOrder;
const byPointsThenTree: Order = (a, b) => a.researchPoints - b.researchPoints || byTree(a, b);
const ORDERS: Readonly<Record<AutoTargetPick, Order>> = {
highestRank: (a, b) => b.rank - a.rank || byPointsThenTree(a, b),
lowestRank: (a, b) => a.rank - b.rank || byPointsThenTree(a, b),
treeOrder: byTree,
};
@@ -11,7 +11,7 @@
* needs; more is cut down to that.
* - When a vehicle's research points reach what it needs and it is the target, the target is
* cleared and the vehicle recorded as just finished, which makes the client offer the next
* research.
* research; the refresh after the change (research-state.ts) then picks the next target.
*/
import type { BlkBlock } from '@wto/blk';
import { balanceOf, pay } from '../profile/profile-currency.ts';
@@ -25,6 +25,7 @@ import { TrophyCatalogue } from '../inventory/trophy-catalogue.ts';
import { ItemCatalogue } from '../items/item-catalogue.ts';
import { StoreCatalogue } from '../store/store-catalogue.ts';
import type { Tuning } from '../tuning/tuning.ts';
import type { ResearchTuning } from './research-tuning.ts';
import { TechTree } from './tech-tree.ts';
export interface ResearchRules {
@@ -33,6 +34,8 @@ export interface ResearchRules {
readonly vehicleUnlocks: readonly UnlockDefinition[];
readonly crewSlotPrices: CrewSlotPrices;
readonly researchPointsPerGoldenEagle: number;
/** How a branch without a research target gets one (tuning/research.jsonc; implementation notes). */
readonly researchTuning: ResearchTuning;
/** Modifications, ammunition, weapon presets and spares of every vehicle. */
readonly equipment: EquipmentCatalogue;
/** Decorations for sale. */
@@ -63,6 +66,7 @@ export function loadResearchRules(datasets: DatasetCache, tuning: Tuning): Resea
vehicleUnlocks: datasets.load(vehicleUnlocks),
crewSlotPrices: datasets.load(crewSlotPrices),
researchPointsPerGoldenEagle: datasets.load(researchPointsPerGoldenEagle),
researchTuning: tuning.research,
equipment: new EquipmentCatalogue(datasets.load(vehicleEquipment)),
decor: new DecorShop(datasets.load(decorCatalogue)),
crew: new CrewSkillCatalogue(datasets.load(crewSkillData)),
@@ -8,11 +8,15 @@
* a vehicle can open a rank, a rank can earn an unlock).
* 2. Write every vehicle's status into unitResearch: owned vehicles have no entry, locked
* vehicles only keep one while they hold research points.
* 3. Drop research targets that are no longer researchable (bought, researched, ...).
* 3. Keep every branch researching while it can: a target that is no
* longer researchable (bought, researched, ...) is replaced, and a branch without one gets
* one, picked by auto-research-target.ts; "" only when nothing can be researched.
*/
import type { BlkBlock } from '@wto/blk';
import { pickResearchTarget } from './auto-research-target.ts';
import type { TreeVehicle } from './tech-tree.ts';
import { ownedVehicles } from '../profile/profile-hangar.ts';
import { researchTarget, setResearchTarget } from '../profile/profile-research-targets.ts';
import { finishedResearch, researchTarget, setResearchTarget } from '../profile/profile-research-targets.ts';
import { earnedUnlocks } from '../profile/profile-unlocks.ts';
import { removeVehicleResearch, researchPointsOf, setVehicleStatus } from '../profile/profile-vehicle-research.ts';
import { openEarnedRanks } from './era-progress.ts';
@@ -39,12 +43,34 @@ export function refreshResearchState(profile: BlkBlock, rules: ResearchRules): v
else setVehicleStatus(profile, vehicle.name, status);
}
const candidates = researchCandidates(rules, statuses);
for (const { country, type } of rules.techTree.branches()) {
const target = researchTarget(profile, country, type);
if (target && statuses.get(target) !== VehicleStatus.CAN_RESEARCH) setResearchTarget(profile, country, type, '');
if (target && statuses.get(target) === VehicleStatus.CAN_RESEARCH) continue;
const previous = target || finishedResearch(profile, country, type);
const next = pickResearchTarget(candidates.get(`${country}/${type}`) ?? [], rules.researchTuning, previous);
setResearchTarget(profile, country, type, next?.name ?? '');
}
}
/**
* The vehicles a branch target can be chosen from, by "country/type": what the stock scripts
* offer as a research target (scripts/unit/unitStatus.nut canResearchUnit; squadron vehicles
* have their own target, implementation notes, and are left out as scripts/shop/shopCheckResearch.nut
* getMaxRankResearchingUnitByCountry does).
*/
function researchCandidates(rules: ResearchRules, statuses: ReadonlyMap<string, VehicleStatus>): Map<string, TreeVehicle[]> {
const byBranch = new Map<string, TreeVehicle[]>();
for (const vehicle of rules.techTree.all()) {
if (vehicle.kind !== 'research' || statuses.get(vehicle.name) !== VehicleStatus.CAN_RESEARCH) continue;
const key = `${vehicle.country}/${vehicle.type}`;
const list = byBranch.get(key);
if (list) list.push(vehicle);
else byBranch.set(key, [vehicle]);
}
return byBranch;
}
/** The current status of one vehicle the player does not own; undefined when it is owned or unknown. */
export function currentStatus(profile: BlkBlock, rules: ResearchRules, vehicle: string): VehicleStatus | undefined {
return vehicleStatuses({ profile, owned: ownedVehicles(profile), earnedUnlocks: earnedUnlocks(profile), techTree: rules.techTree }).get(vehicle);
@@ -0,0 +1,21 @@
/** Typed content of tuning/research.jsonc: research rules the offline version decides itself. */
import { TuningError, type TuningReader } from '../tuning/tuning-reader.ts';
export const AUTO_TARGET_PICKS = ['lowestRank', 'highestRank', 'treeOrder'] as const;
export type AutoTargetPick = (typeof AUTO_TARGET_PICKS)[number];
export interface ResearchTuning {
/** Whether finishing or buying the current target prefers its direct tech-tree successor first. */
readonly preferLineSuccessor: boolean;
/** Which researchable vehicle becomes the target when there is no line successor (or on a new save). */
readonly autoTargetPick: AutoTargetPick;
}
export function readResearchTuning(file: TuningReader): ResearchTuning {
const preferLineSuccessor = file.bool('preferLineSuccessor');
const pick = file.string('autoTargetPick');
if (!(AUTO_TARGET_PICKS as readonly string[]).includes(pick)) {
throw new TuningError(`tuning file research.jsonc: autoTargetPick must be one of ${AUTO_TARGET_PICKS.join(', ')} (found ${JSON.stringify(pick)})`);
}
return { preferLineSuccessor, autoTargetPick: pick as AutoTargetPick };
}
@@ -10,6 +10,7 @@ import { readRecyclingTuning, type RecyclingTuning } from '../inventory/recyclin
import { readSupplyChestTuning, type SupplyChestTuning } from '../inventory/supply-chest-tuning.ts';
import { readTrophyTuning, type TrophyTuning } from '../inventory/trophy-tuning.ts';
import { readNewProfileTuning, type NewProfileTuning } from '../profile/new-profile-tuning.ts';
import { readResearchTuning, type ResearchTuning } from '../research/research-tuning.ts';
import { readRedeemTuning, type RedeemTuning } from '../store/redeem-tuning.ts';
import { readStoreTuning, type StoreTuning } from '../store/store-tuning.ts';
import { readLimitsTuning, type LimitsTuning } from './limits-tuning.ts';
@@ -19,6 +20,7 @@ export interface Tuning {
readonly store: StoreTuning;
readonly redeemCodes: RedeemTuning;
readonly newProfile: NewProfileTuning;
readonly research: ResearchTuning;
readonly marketplace: MarketplaceTuning;
readonly supplyChests: SupplyChestTuning;
readonly recycling: RecyclingTuning;
@@ -33,6 +35,7 @@ export function loadTuning(dataFolder: string, report: (line: string) => void):
store: readStoreTuning(files.read('store')),
redeemCodes: readRedeemTuning(files.read('redeem-codes')),
newProfile: readNewProfileTuning(files.read('new-profile')),
research: readResearchTuning(files.read('research')),
marketplace: readMarketplaceTuning(files.read('marketplace')),
supplyChests: readSupplyChestTuning(files.read('supply-chests')),
recycling: readRecyclingTuning(files.read('recycling')),
@@ -0,0 +1,13 @@
// 研发的离线版自定规则(implementation notes 第 4.5 节)。
{
// 当前研发目标完成或被买下后,若同一研发线的直接后继载具(reqAir 指向刚完成的这辆)已可研发,优先接续它。
"preferLineSuccessor": true,
// 没有同线直接后继(如新存档、当前研发线到头或下一等级尚未开放)时,从该系可研发载具里挑哪一辆:
// 原版也由服务器自动选(客户端函数 shop_get_countries_list_with_autoset_units 读的就是服务器自动设的研发目标),
// 但怎么选是服务器的规则,客户端里没有,所以这里是离线版自定;玩家随时可以在科技树里改选。
// "highestRank" 等级最高的(与原版"选择下一个研发目标"窗口默认挑车一致,优先推进当前已开放的最高等级);同等级选所需研发点最少的,再相同按科技树先后
// "lowestRank" 等级最低的;同等级选所需研发点最少的,再相同按科技树先后
// "treeOrder" 科技树里排在最前面的
"autoTargetPick": "highestRank"
}