Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
102 lines
5.2 KiB
TypeScript
102 lines
5.2 KiB
TypeScript
/**
|
|
* 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<N> / expPenaltyPercentForLowerRank<N> 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<diffCode> 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<Record<EconomyDifficulty, number>> = { 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<string>;
|
|
|
|
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<string>): 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<string> {
|
|
const highestRank = new Map(tree.branches().map((branch) => [`${branch.country}/${branch.type}`, branch.highestRank]));
|
|
const highestMrank = new Map<string, number>();
|
|
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<string>();
|
|
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,
|
|
);
|
|
}
|