Files
WT-Offline/apps/server/src/game-data/datasets/battle-spawn-rules.ts
T
N0VAN0M4LY 27fc535301 Split the repository into apps, packages and patches
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.
2026-11-29 03:20:54 +08:00

196 lines
7.7 KiB
TypeScript

/**
* Dataset: the extra vehicles a battle adds to a player's lineup, as the game files list them.
*
* aces.vromfs.bin config/gameplay.blk
* missionSupportPlane{ <event name>{ UnitPreset{ killStreakTagName:t rankRange:ip2 spawnScoreToShow:i
* spawnScoreToUse:i <country>{ unitName:t weapon:t } } } }
* Killstreak aircraft (the nuclear carrier) per session rank bracket, one per country.
* RandomSpawnUnits{ <event economic name>{ <country>{ <group>{ minPlayerMRank:i
* maxDiffBetweenTopUnitAndSessionRank:i mRanksCount:i <unit>{ addModification:t addWeapon:t
* forceWeapon:t } } } } }
* The random vehicle groups (dice slots: random tank and SPAA in ground battles, random fighter
* and bomber in naval battles). The stock client reads the same block for forced weapons
* (scripts/unit/randomunitsforceweapon.nut).
* char.vromfs.bin config/wpcost.blk
* ucav_*_killstreak{ country:t ... }
* The strike UCAVs, one per country.
* char.vromfs.bin config/warpoints.blk respawn_points / TankHistorical
* Starting points and unit cost parameters for Ground Realistic Battles.
*/
import type { BlkBlock } from '@wto/blk';
import { findParam } from '@wto/blk';
import { blockAt, numberField, stringField, stringList } from './blk-fields.ts';
import type { Dataset } from './dataset.ts';
export interface SupportPlaneUnit {
readonly unitName: string;
readonly weapon: string;
}
export interface SupportPlanePreset {
readonly killStreakTag: string;
/** Session rank bracket (`rankRange`, inclusive). */
readonly minMrank: number;
readonly maxMrank: number;
readonly spawnScoreToShow: number;
readonly spawnScoreToUse: number;
/** By country. */
readonly units: Readonly<Record<string, SupportPlaneUnit>>;
}
export interface StrikeUcav {
readonly country: string;
readonly unitName: string;
}
export interface RandomSpawnUnit {
readonly unitName: string;
readonly addModifications: readonly string[];
readonly forceWeapon?: string;
}
export interface RandomSpawnGroup {
/** `tank`, `spaa`, `fighter`, `bomber`: the key of `random_units` and of gui.blk `randomSpawnUnitPresets`. */
readonly name: string;
readonly minPlayerMrank: number;
readonly maxDiffBetweenTopUnitAndSessionRank: number;
readonly mranksCount: number;
readonly units: readonly RandomSpawnUnit[];
}
interface SpawnScoreParameterSet {
readonly parameters: Readonly<Record<string, number>>;
readonly classCosts: Readonly<Record<string, number>>;
}
export interface SpawnScoreRules {
readonly common: Readonly<Record<string, number>>;
readonly tankHistorical: SpawnScoreParameterSet;
readonly overrides: ReadonlyArray<SpawnScoreParameterSet & {
readonly minMrank: number;
readonly maxMrank: number;
}>;
}
export interface BattleSpawnRulesData {
/** By event name (`missionSupportPlane` keys are game mode names). */
readonly supportPlanes: Readonly<Record<string, readonly SupportPlanePreset[]>>;
readonly strikeUcavs: readonly StrikeUcav[];
readonly spawnScore: SpawnScoreRules;
/** By event economic name, then country. */
readonly randomSpawnUnits: Readonly<Record<string, Readonly<Record<string, readonly RandomSpawnGroup[]>>>>;
}
const STRIKE_UCAV_PATTERN = /^ucav_.*_killstreak$/;
export const battleSpawnRules: Dataset<BattleSpawnRulesData> = {
id: 'battle-spawn-rules',
version: 3,
extract: (source) => {
const gameplay = source.readBlk('aces.vromfs.bin', 'config/gameplay.blk');
const wpcost = source.readBlk('char.vromfs.bin', 'config/wpcost.blk');
return {
supportPlanes: extractSupportPlanes(blockAt(gameplay, 'missionSupportPlane')),
strikeUcavs: extractStrikeUcavs(wpcost.blocks),
spawnScore: extractSpawnScore(blockAt(source.readBlk('char.vromfs.bin', 'config/warpoints.blk'), 'respawn_points')),
randomSpawnUnits: extractRandomSpawnUnits(blockAt(gameplay, 'RandomSpawnUnits')),
};
},
};
function extractSpawnScore(root: BlkBlock | undefined): SpawnScoreRules {
const tankHistorical = blockAt(root, 'TankHistorical');
return {
common: numericParams(root),
tankHistorical: spawnScoreParams(tankHistorical),
overrides: (blockAt(tankHistorical, 'override_params_by_session_rank')?.blocks ?? []).map((block) => ({
...spawnScoreParams(block),
minMrank: numberField(block, 'minMRank') ?? -1,
maxMrank: numberField(block, 'maxMRank') ?? -1,
})),
};
}
function spawnScoreParams(block: BlkBlock | undefined): SpawnScoreParameterSet {
return {
parameters: numericParams(block),
classCosts: numericParams(blockAt(block, 'respawn_cost_mul_by_exp_class')),
};
}
function numericParams(block: BlkBlock | undefined): Record<string, number> {
const params = block?.params ?? [];
return Object.fromEntries(params.flatMap(({ name, value }) =>
value.type === 'int' || value.type === 'real' ? [[name, value.value]] : []));
}
function extractSupportPlanes(root: BlkBlock | undefined): Record<string, SupportPlanePreset[]> {
const byEvent: Record<string, SupportPlanePreset[]> = {};
for (const eventBlk of root?.blocks ?? []) {
const presets: SupportPlanePreset[] = [];
for (const preset of eventBlk.blocks) {
if (preset.name !== 'UnitPreset') continue;
const range = findParam(preset, 'rankRange')?.value;
const spawnScoreToUse = numberField(preset, 'spawnScoreToUse');
if (range?.type !== 'ipoint2' || spawnScoreToUse === undefined) continue;
const units: Record<string, SupportPlaneUnit> = {};
for (const countryBlk of preset.blocks) {
const unitName = stringField(countryBlk, 'unitName');
const weapon = stringField(countryBlk, 'weapon');
if (countryBlk.name.startsWith('country_') && unitName && weapon) units[countryBlk.name] = { unitName, weapon };
}
presets.push({
killStreakTag: stringField(preset, 'killStreakTagName') ?? '',
minMrank: range.value[0],
maxMrank: range.value[1],
spawnScoreToShow: numberField(preset, 'spawnScoreToShow') ?? spawnScoreToUse,
spawnScoreToUse,
units,
});
}
if (presets.length > 0) byEvent[eventBlk.name] = presets;
}
return byEvent;
}
function extractStrikeUcavs(wpcostBlocks: readonly BlkBlock[]): StrikeUcav[] {
return wpcostBlocks.flatMap((unitBlk) => {
const country = stringField(unitBlk, 'country') ?? '';
return STRIKE_UCAV_PATTERN.test(unitBlk.name) && country.startsWith('country_')
? [{ country, unitName: unitBlk.name }]
: [];
});
}
function extractRandomSpawnUnits(
root: BlkBlock | undefined,
): Record<string, Record<string, RandomSpawnGroup[]>> {
const byEvent: Record<string, Record<string, RandomSpawnGroup[]>> = {};
for (const eventBlk of root?.blocks ?? []) {
const byCountry: Record<string, RandomSpawnGroup[]> = {};
for (const countryBlk of eventBlk.blocks) {
if (!countryBlk.name.startsWith('country_')) continue;
const groups = countryBlk.blocks.flatMap((groupBlk): RandomSpawnGroup[] => {
const units = groupBlk.blocks.map((unitBlk): RandomSpawnUnit => {
const forceWeapon = stringField(unitBlk, 'forceWeapon');
return {
unitName: unitBlk.name,
addModifications: stringList(unitBlk, 'addModification'),
...(forceWeapon ? { forceWeapon } : {}),
};
});
return units.length === 0 ? [] : [{
name: groupBlk.name,
minPlayerMrank: numberField(groupBlk, 'minPlayerMRank') ?? 0,
maxDiffBetweenTopUnitAndSessionRank: numberField(groupBlk, 'maxDiffBetweenTopUnitAndSessionRank') ?? 0,
mranksCount: numberField(groupBlk, 'mRanksCount') ?? 0,
units,
}];
});
if (groups.length > 0) byCountry[countryBlk.name] = groups;
}
byEvent[eventBlk.name] = byCountry;
}
return byEvent;
}