feat(patcher,server): wire ground AI tuning, bot weights, and pack build

Add ground-ai.jsonc tuning validation, realistic tank class weights for
customBots pools, on-demand game.vromfs.bin / ailist.blk injection in
@wto/patcher, and launcher/CLI build integration while keeping all
ground AI layers disabled by default in shipped configuration.
This commit is contained in:
N0VAN0M4LY committed 2026-12-03 12:07:30 +08:00
1 parent 18637cf1ff
commit 4ac3484f56
17 files changed
+836 -75

No files matched your search

+14 -3
View File
@@ -160,14 +160,15 @@ function pickCategoryPool(
const mrank = vehicleMrank(vehicle, query.difficulty, query.requiredClass);
return mrank >= query.minMrank && mrank <= query.maxMrank;
});
const source = inWindow.length > 0 ? inWindow : sortedByCloseness.slice(0, query.limitPerType);
return roundRobinByCountry(source, orderedCountries, query.limitPerType);
const source = inWindow.length > 0 ? inWindow : sortedByCloseness.slice(0, query.limitPerType);
return roundRobinByCountry(source, orderedCountries, query.limitPerType, category);
}
function roundRobinByCountry(
vehicles: readonly CatalogueVehicle[],
orderedCountries: readonly string[],
limit: number,
category: 'tank' | 'aircraft' | 'ship',
): BotPoolEntry[] {
const buckets = new Map<string, CatalogueVehicle[]>(orderedCountries.map((country) => [country, []]));
for (const vehicle of vehicles) buckets.get(vehicle.country)?.push(vehicle);
@@ -177,7 +178,8 @@ function roundRobinByCountry(
for (const country of orderedCountries) {
const vehicle = buckets.get(country)?.[index];
if (!vehicle) continue;
out.push({ name: vehicle.name, country: stripCountryPrefix(country), weight: 1 });
const weight = category === 'tank' ? tankBotPoolWeight(vehicle) : 1;
out.push({ name: vehicle.name, country: stripCountryPrefix(country), weight });
added = true;
if (out.length >= limit) break;
}
@@ -186,6 +188,15 @@ function roundRobinByCountry(
return out;
}
function tankBotPoolWeight(vehicle: CatalogueVehicle): number {
if (vehicle.unitClass === 'exp_SPAA') return 0.12;
if (vehicle.isLightTank) return 0.45;
if (vehicle.unitClass === 'exp_tank_destroyer') return 0.55;
if (vehicle.unitClass === 'exp_heavy_tank') return 0.85;
if (vehicle.unitClass === 'exp_tank') return 1.15;
return 1;
}
function unitClassOfVehicleType(type: VehicleType | undefined): UnitClass | undefined {
if (type === 'Tank') return 'tank';
if (type === 'Aircraft') return 'aircraft';
+23 -2
View File
@@ -7,24 +7,45 @@
* will start the service the same way. Stops on Ctrl+C.
*/
import { parseArgs } from 'node:util';
import { discoverMods, type DiscoveredMod } from '@wto/mods';
import { LOOPBACK, startServer } from './server.ts';
function resolveCliMods(modsDir: string | undefined, modIds: readonly string[] | undefined): DiscoveredMod[] {
if (!modsDir || !modIds || modIds.length === 0) return [];
const discovered = discoverMods(modsDir);
const byId = new Map(discovered.mods.map((mod) => [mod.manifest.id, mod]));
return modIds.map((id) => {
const mod = byId.get(id);
if (!mod) throw new Error(`enabled mod "${id}" was not found in ${modsDir}`);
return mod;
});
}
async function main(): Promise<number> {
const { values } = parseArgs({
options: {
game: { type: 'string' },
data: { type: 'string' },
port: { type: 'string' },
'mods-dir': { type: 'string' },
mod: { type: 'string', multiple: true },
},
});
const port = Number(values.port);
if (!values.game || !values.data || !Number.isInteger(port) || port < 1 || port > 65535) {
console.error('usage: cli.ts --game <game folder> --data <data folder> --port <n>');
console.error('usage: cli.ts --game <game folder> --data <data folder> --port <n> [--mods-dir <dir> --mod <id>...]');
return 2;
}
let service;
try {
service = await startServer({ gameFolder: values.game, dataFolder: values.data, port, report: (line) => console.log(line) });
const mods = resolveCliMods(values['mods-dir'], values.mod);
service = await startServer({
gameFolder: values.game,
dataFolder: values.data,
port,
report: (line) => console.log(line),
...(mods.length > 0 ? { mods } : {}),
});
} catch (error) {
const code = (error as NodeJS.ErrnoException).code;
console.error(code === 'EADDRINUSE' ? `port ${port} is already in use; choose another port` : String(error));
@@ -27,11 +27,14 @@ import type { Dataset } from './dataset.ts';
import { shopEntriesByName } from './shop-tree.ts';
const VEHICLE_ECONOMY = 'config/wpcost.blk';
const UNIT_TAGS = 'config/unittags.blk';
export interface CatalogueVehicle {
readonly name: string;
readonly country: string;
readonly unitClass: string;
/** True when config/unittags.blk tags the vehicle with type_light_tank. */
readonly isLightTank?: boolean;
readonly rank: number;
/** wpcost.blk reqAir; absent when empty or missing. */
readonly requires?: string;
@@ -70,15 +73,27 @@ export interface CatalogueVehicle {
export const vehicleCatalogue: Dataset<readonly CatalogueVehicle[]> = {
id: 'vehicle-catalogue',
version: 6,
version: 7,
extract: (source) => {
const shopEntries = shopEntriesByName(source);
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));
const lightTanks = lightTankNames(source.readBlk('char.vromfs.bin', UNIT_TAGS));
return source.readBlk('char.vromfs.bin', VEHICLE_ECONOMY).blocks.map((vehicle) =>
catalogueVehicle(vehicle, shopEntries.get(vehicle.name), treeOrder.get(vehicle.name) ?? -1, lightTanks.has(vehicle.name)),
);
},
};
function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined, treeOrder: number): CatalogueVehicle {
function lightTankNames(unitTagsRoot: BlkBlock): ReadonlySet<string> {
const names = new Set<string>();
for (const unit of unitTagsRoot.blocks) {
const tags = unit.blocks.find((block) => block.name === 'tags');
if (tags && boolField(tags, 'type_light_tank') === true) names.add(unit.name);
}
return names;
}
function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined, treeOrder: number, isLightTank: boolean): CatalogueVehicle {
const requires = stringField(vehicle, 'reqAir');
const researchType = stringField(vehicle, 'researchType');
const requiredUnlock = stringField(shopEntry, 'reqUnlock');
@@ -90,6 +105,7 @@ function catalogueVehicle(vehicle: BlkBlock, shopEntry: BlkBlock | undefined, tr
name: vehicle.name,
country: stringField(vehicle, 'country') ?? '',
unitClass: stringField(vehicle, 'unitClass') ?? '',
...(isLightTank ? { isLightTank: true } : {}),
rank: numberField(vehicle, 'rank') ?? 0,
...(requires ? { requires } : {}),
researchPoints: numberField(vehicle, 'reqExp') ?? 0,
+1
View File
@@ -11,5 +11,6 @@ export { editSaveAccount, editSaveCurrencies, listSaveSummaries, readSaveDetails
export { listSaveAvatars, readSaveAvatar } from './saves/save-avatars.ts';
export { importOfficialBackup, previewOfficialBackup } from './saves/import/official-backup.ts';
export { prepareTransferredProfile } from './saves/transferred-profile.ts';
export { loadGroundAiTuning, type GroundAiTuning } from './tuning/ground-ai-tuning.ts';
export { readLauncherTuning, writeLauncherTuning, type LauncherTuningPatch } from './tuning/launcher-tuning.ts';
export { multiVehiclePackIds } from './store/store-pack-ids.ts';
+144
View File
@@ -0,0 +1,144 @@
/**
* Typed, range-validated reader for `tuning/ground-ai.jsonc`.
*/
import type { DiscoveredMod } from '@wto/mods';
import type { GroundAiConfig } from '@wto/patcher';
import { tuningFiles } from './tuning-loader.ts';
import { TuningError, type TuningReader } from './tuning-reader.ts';
export type GroundAiTuning = GroundAiConfig;
const DRIVE_MODES = new Set(['vehicle_phys', 'movesys']);
export function loadGroundAiTuning(
dataFolder: string | null,
report: (line: string) => void,
mods: readonly DiscoveredMod[] = [],
): GroundAiTuning {
return readGroundAiTuning(tuningFiles(dataFolder, report, undefined, mods).read('ground-ai'));
}
export function readGroundAiTuning(reader: TuningReader): GroundAiTuning {
const layers = reader.object('layers');
const cadence = reader.object('cadence');
const diag = reader.object('diagnostics');
return {
enabled: reader.bool('enabled'),
layers: {
macro: layers.bool('macro'),
tactics: layers.bool('tactics'),
navigation: layers.bool('navigation'),
fireControl: layers.bool('fireControl'),
},
cadence: {
maxBots: cadence.int('maxBots', { min: 1, max: 64 }),
macroTickSec: cadence.number('macroTickSec', { min: 0.1, max: 5 }),
tacticsTickSec: cadence.number('tacticsTickSec', { min: 0.05, max: 2 }),
navTickSec: cadence.number('navTickSec', { min: 0.05, max: 2 }),
},
macro: readMacroSection(reader.object('macro')),
crowd: readCrowdSection(reader.object('crowd')),
terrain: readTerrainSection(reader.object('terrain')),
navigation: readNavigationSection(reader.object('navigation')),
tactics: readTacticsSection(reader.object('tactics')),
fireControl: readFireControlSection(reader.object('fireControl')),
diagnostics: {
telemetry: diag.bool('telemetry'),
telemetryIntervalSec: diag.number('telemetryIntervalSec', { min: 0.5, max: 60 }),
},
};
}
function readMacroSection(macro: TuningReader): GroundAiTuning['macro'] {
const recaptureMinBots = macro.int('recaptureMinBots', { min: 1, max: 8 });
const recaptureMaxBots = macro.int('recaptureMaxBots', { min: 1, max: 12 });
if (recaptureMaxBots < recaptureMinBots) {
throw new TuningError('tuning file ground-ai.jsonc: macro.recaptureMaxBots must be >= macro.recaptureMinBots');
}
return {
openingSplitSec: macro.number('openingSplitSec', { min: 0, max: 180 }),
capMaxInsiders: macro.int('capMaxInsiders', { min: 1, max: 8 }),
recaptureMinBots,
recaptureMaxBots,
capStickyBonusM: macro.number('capStickyBonusM', { min: 0, max: 800 }),
deathZoneRadiusM: macro.number('deathZoneRadiusM', { min: 10, max: 250 }),
deathZoneTtlSec: macro.number('deathZoneTtlSec', { min: 5, max: 300 }),
deathZoneMinKills: macro.int('deathZoneMinKills', { min: 1, max: 16 }),
spaaRearOffsetM: macro.number('spaaRearOffsetM', { min: 40, max: 600 }),
spaaRelocateSec: macro.number('spaaRelocateSec', { min: 5, max: 180 }),
enemySpawnAvoidM: macro.number('enemySpawnAvoidM', { min: 60, max: 600 }),
};
}
function readCrowdSection(crowd: TuningReader): GroundAiTuning['crowd'] {
return {
personalSpaceM: crowd.number('personalSpaceM', { min: 6, max: 40 }),
clusterRadiusM: crowd.number('clusterRadiusM', { min: 12, max: 80 }),
clusterMaxAllies: crowd.int('clusterMaxAllies', { min: 1, max: 10 }),
disperseStepM: crowd.number('disperseStepM', { min: 8, max: 65 }),
disperseHoldSec: crowd.number('disperseHoldSec', { min: 1, max: 15 }),
};
}
function readTerrainSection(terrain: TuningReader): GroundAiTuning['terrain'] {
return {
maxClimbSlopeDeg: terrain.number('maxClimbSlopeDeg', { min: 10, max: 42 }),
maxDropSlopeDeg: terrain.number('maxDropSlopeDeg', { min: 8, max: 40 }),
maxWaterDepthM: terrain.number('maxWaterDepthM', { min: 0.2, max: 2.5 }),
collisionMarginM: terrain.number('collisionMarginM', { min: 0.05, max: 2.0 }),
crestLookaheadM: terrain.number('crestLookaheadM', { min: 8, max: 80 }),
ridgeMaxDwellSec: terrain.number('ridgeMaxDwellSec', { min: 2, max: 60 }),
ridgeMaxShots: terrain.int('ridgeMaxShots', { min: 1, max: 10 }),
};
}
function readNavigationSection(nav: TuningReader): GroundAiTuning['navigation'] {
const driveMode = nav.string('driveMode');
if (!DRIVE_MODES.has(driveMode)) {
throw new TuningError(`tuning file ground-ai.jsonc: navigation.driveMode must be "vehicle_phys" or "movesys" (found "${driveMode}")`);
}
const steerSign = nav.number('steerSign', { min: -1, max: 1 });
if (steerSign !== 1 && steerSign !== -1) {
throw new TuningError('tuning file ground-ai.jsonc: navigation.steerSign must be 1 or -1');
}
return {
driveMode,
maxPhysBots: nav.int('maxPhysBots', { min: 0, max: 64 }),
steerSign,
deadEchoSec: nav.number('deadEchoSec', { min: 0.3, max: 10 }),
cornerBrakeAccel: nav.number('cornerBrakeAccel', { min: 0.5, max: 8 }),
pivotAngleDeg: nav.number('pivotAngleDeg', { min: 25, max: 150 }),
stuckWindowSec: nav.number('stuckWindowSec', { min: 1, max: 15 }),
stuckMinMoveM: nav.number('stuckMinMoveM', { min: 0.5, max: 10 }),
unstickReverseSec: nav.number('unstickReverseSec', { min: 0.8, max: 10 }),
tacticalReverseDistM: nav.number('tacticalReverseDistM', { min: 10, max: 90 }),
tacticalReverseMaxSec: nav.number('tacticalReverseMaxSec', { min: 2, max: 25 }),
};
}
function readTacticsSection(tactics: TuningReader): GroundAiTuning['tactics'] {
return {
visionRangeM: tactics.number('visionRangeM', { min: 200, max: 3500 }),
visionFovDeg: tactics.number('visionFovDeg', { min: 40, max: 180 }),
peripheralRangeM: tactics.number('peripheralRangeM', { min: 30, max: 800 }),
engineAudioRangeM: tactics.number('engineAudioRangeM', { min: 10, max: 250 }),
shotAudioRangeM: tactics.number('shotAudioRangeM', { min: 50, max: 1200 }),
radioShareRangeM: tactics.number('radioShareRangeM', { min: 50, max: 1500 }),
memoryTtlSec: tactics.number('memoryTtlSec', { min: 1, max: 45 }),
targetStickinessSec: tactics.number('targetStickinessSec', { min: 0.5, max: 20 }),
peekCooldownSec: tactics.number('peekCooldownSec', { min: 1, max: 30 }),
};
}
function readFireControlSection(fc: TuningReader): GroundAiTuning['fireControl'] {
return {
maxEngageRangeM: fc.number('maxEngageRangeM', { min: 150, max: 3000 }),
baseAlignDeg: fc.number('baseAlignDeg', { min: 0.1, max: 3.0 }),
closeHitRadiusM: fc.number('closeHitRadiusM', { min: 0.25, max: 2.2 }),
barrelSettleDegSec: fc.number('barrelSettleDegSec', { min: 0.2, max: 12.0 }),
settleHoldSec: fc.number('settleHoldSec', { min: 0.05, max: 1.5 }),
unstabilizedStopSpeedMps: fc.number('unstabilizedStopSpeedMps', { min: 0.1, max: 3.0 }),
stabilizedCreepSpeedMps: fc.number('stabilizedCreepSpeedMps', { min: 1.5, max: 15.0 }),
friendlyCorridorM: fc.number('friendlyCorridorM', { min: 1.0, max: 10.0 }),
};
}
+3
View File
@@ -14,6 +14,7 @@ import { readResearchTuning, type ResearchTuning } from '../research/research-tu
import { readRedeemTuning, type RedeemTuning } from '../store/redeem-tuning.ts';
import { readStoreTuning, type StoreTuning } from '../store/store-tuning.ts';
import type { DiscoveredMod } from '@wto/mods';
import { readGroundAiTuning, type GroundAiTuning } from './ground-ai-tuning.ts';
import { readLimitsTuning, type LimitsTuning } from './limits-tuning.ts';
import { tuningFiles } from './tuning-loader.ts';
@@ -29,6 +30,7 @@ export interface Tuning {
readonly clans: ClanTuning;
readonly battle: BattleTuning;
readonly battleEconomy: BattleEconomyTuning;
readonly groundAi: GroundAiTuning;
readonly limits: LimitsTuning;
}
@@ -50,6 +52,7 @@ export function loadTuning(
clans: readClanTuning(files.read('clans')),
battle: readBattleTuning(files.read('battle')),
battleEconomy: readBattleEconomyTuning(files.read('battle-economy')),
groundAi: readGroundAiTuning(files.read('ground-ai')),
limits: readLimitsTuning(files.read('limits')),
};
}