feat(ground-ai)!: replace layer switches with complete modes
Ground AI layers could be enabled in any combination, including ones the scripts cannot run (fire control without perception disabled stock aiming and never fired). The configuration now selects one of four complete modes: stock, fire (stock movement, custom fire permission), drive (custom orders and driving, stock firing) and full. The build derives the compiled layer constants from the mode, and an unknown mode is rejected at load time. The offline tank class weights for the AI bot pool move from code into tuning/ground-ai.jsonc (lineupWeights). They apply only when a custom mode is active; stock mode keeps the stock weight of 1 for every vehicle. Verified root and launcher type checks, mode-to-constant compilation for all four modes, rejection of an unknown mode, bot pool weights in stock and custom modes, and temporary 2.61.0.58 game copy builds in full mode (15 script modules packed) and stock mode (no game pack written). BREAKING CHANGE: ground-ai.jsonc drops "enabled" and "layers". Override files set "mode" to "stock", "fire", "drive" or "full" instead.
This commit is contained in:
1 parent
885e3bbb5d
commit
5e521295a3
8 files changed
+117
-51
No files matched your search
@@ -19,6 +19,7 @@ import {
|
||||
isModeEligibleForLineup,
|
||||
lineupMrank,
|
||||
selectCustomBots,
|
||||
type TankLineupWeights,
|
||||
type CustomBotsPool,
|
||||
} from './battle-ranks.ts';
|
||||
import type { BattleSessionStore } from './battle-session-store.ts';
|
||||
@@ -104,6 +105,7 @@ export class BattleMatchmaker {
|
||||
readonly #tuning: BattleTuning;
|
||||
readonly #spawnRules: BattleSpawnRulesData;
|
||||
readonly #aircraftLoadouts: ReadonlyMap<string, BotAircraftLoadout>;
|
||||
readonly #tankWeights: TankLineupWeights | undefined;
|
||||
readonly #filterMissions: MissionPoolFilter | undefined;
|
||||
|
||||
constructor(
|
||||
@@ -113,6 +115,7 @@ export class BattleMatchmaker {
|
||||
tuning: BattleTuning,
|
||||
spawnRules: BattleSpawnRulesData,
|
||||
aircraftLoadouts: ReadonlyMap<string, BotAircraftLoadout>,
|
||||
tankWeights: TankLineupWeights | undefined,
|
||||
filterMissions?: MissionPoolFilter,
|
||||
) {
|
||||
this.#gameModes = gameModes;
|
||||
@@ -122,6 +125,7 @@ export class BattleMatchmaker {
|
||||
this.#tuning = tuning;
|
||||
this.#spawnRules = spawnRules;
|
||||
this.#aircraftLoadouts = aircraftLoadouts;
|
||||
this.#tankWeights = tankWeights;
|
||||
this.#filterMissions = filterMissions;
|
||||
}
|
||||
|
||||
@@ -181,7 +185,7 @@ export class BattleMatchmaker {
|
||||
minMrank,
|
||||
maxMrank,
|
||||
limitPerType: this.#tuning.botPoolLimitPerType,
|
||||
}, declaration.allowBotAircraftLoadouts === false ? undefined : this.#aircraftLoadouts);
|
||||
}, declaration.allowBotAircraftLoadouts === false ? undefined : this.#aircraftLoadouts, this.#tankWeights);
|
||||
return {
|
||||
ok: true,
|
||||
launch: this.#buildLaunchPlan(input, chosenMode, mission, coalitions, playerMrank, minMrank, maxMrank, customBots),
|
||||
|
||||
@@ -31,6 +31,16 @@ export interface CustomBotsPool {
|
||||
readonly ships: readonly BotPoolEntry[];
|
||||
}
|
||||
|
||||
/** Offline tank pool weights by vehicle class (`tuning/ground-ai.jsonc` `lineupWeights`). */
|
||||
export interface TankLineupWeights {
|
||||
readonly spaa: number;
|
||||
readonly lightTank: number;
|
||||
readonly tankDestroyer: number;
|
||||
readonly heavyTank: number;
|
||||
readonly mediumTank: number;
|
||||
readonly other: number;
|
||||
}
|
||||
|
||||
export interface BotPoolQuery {
|
||||
readonly difficulty: ModeDifficulty;
|
||||
readonly requiredClass: UnitClass;
|
||||
@@ -117,14 +127,20 @@ function lineupVehicleMrank(
|
||||
return vehicleMrank(vehicle, difficulty, requiredClass) + (mrankDeltas.get(vehicle.name) ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Without `tankWeights` every pool entry keeps the stock weight of 1.
|
||||
*/
|
||||
export function selectCustomBots(
|
||||
vehicles: readonly CatalogueVehicle[], query: BotPoolQuery, aircraftLoadouts?: ReadonlyMap<string, BotAircraftLoadout>,
|
||||
vehicles: readonly CatalogueVehicle[],
|
||||
query: BotPoolQuery,
|
||||
aircraftLoadouts?: ReadonlyMap<string, BotAircraftLoadout>,
|
||||
tankWeights?: TankLineupWeights,
|
||||
): CustomBotsPool {
|
||||
const allowed = new Set(query.allowedClasses);
|
||||
const orderedCountries = [...new Set(query.countries.map((c) => (c.startsWith(COUNTRY_PREFIX) ? c : `${COUNTRY_PREFIX}${c}`)))];
|
||||
const aircrafts = allowed.has('aircraft') ? pickCategoryPool(vehicles, orderedCountries, 'aircraft', query) : [];
|
||||
return {
|
||||
tanks: allowed.has('tank') ? pickCategoryPool(vehicles, orderedCountries, 'tank', query) : [],
|
||||
tanks: allowed.has('tank') ? pickCategoryPool(vehicles, orderedCountries, 'tank', query, tankWeights) : [],
|
||||
aircrafts: query.requiredClass === 'aircraft' && aircraftLoadouts ? aircrafts.map((entry) => {
|
||||
const aircraftLoadout = aircraftLoadouts.get(entry.name);
|
||||
return aircraftLoadout === undefined ? entry : { ...entry, aircraftLoadout };
|
||||
@@ -138,6 +154,7 @@ function pickCategoryPool(
|
||||
orderedCountries: readonly string[],
|
||||
category: 'tank' | 'aircraft' | 'ship',
|
||||
query: BotPoolQuery,
|
||||
tankWeights?: TankLineupWeights,
|
||||
): BotPoolEntry[] {
|
||||
const countrySet = new Set(orderedCountries);
|
||||
const eligible = vehicles.filter((vehicle) =>
|
||||
@@ -160,15 +177,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, category);
|
||||
const source = inWindow.length > 0 ? inWindow : sortedByCloseness.slice(0, query.limitPerType);
|
||||
return roundRobinByCountry(source, orderedCountries, query.limitPerType, (vehicle) => tankPoolWeight(vehicle, tankWeights));
|
||||
}
|
||||
|
||||
function roundRobinByCountry(
|
||||
vehicles: readonly CatalogueVehicle[],
|
||||
orderedCountries: readonly string[],
|
||||
limit: number,
|
||||
category: 'tank' | 'aircraft' | 'ship',
|
||||
weightOf: (vehicle: CatalogueVehicle) => number,
|
||||
): BotPoolEntry[] {
|
||||
const buckets = new Map<string, CatalogueVehicle[]>(orderedCountries.map((country) => [country, []]));
|
||||
for (const vehicle of vehicles) buckets.get(vehicle.country)?.push(vehicle);
|
||||
@@ -178,8 +195,7 @@ function roundRobinByCountry(
|
||||
for (const country of orderedCountries) {
|
||||
const vehicle = buckets.get(country)?.[index];
|
||||
if (!vehicle) continue;
|
||||
const weight = category === 'tank' ? tankBotPoolWeight(vehicle) : 1;
|
||||
out.push({ name: vehicle.name, country: stripCountryPrefix(country), weight });
|
||||
out.push({ name: vehicle.name, country: stripCountryPrefix(country), weight: weightOf(vehicle) });
|
||||
added = true;
|
||||
if (out.length >= limit) break;
|
||||
}
|
||||
@@ -188,13 +204,14 @@ 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 tankPoolWeight(vehicle: CatalogueVehicle, weights: TankLineupWeights | undefined): number {
|
||||
if (weights === undefined) return 1;
|
||||
if (vehicle.unitClass === 'exp_SPAA') return weights.spaa;
|
||||
if (vehicle.isLightTank) return weights.lightTank;
|
||||
if (vehicle.unitClass === 'exp_tank_destroyer') return weights.tankDestroyer;
|
||||
if (vehicle.unitClass === 'exp_heavy_tank') return weights.heavyTank;
|
||||
if (vehicle.unitClass === 'exp_tank') return weights.mediumTank;
|
||||
return weights.other;
|
||||
}
|
||||
|
||||
function unitClassOfVehicleType(type: VehicleType | undefined): UnitClass | undefined {
|
||||
|
||||
@@ -188,6 +188,7 @@ export async function startServer(options: ServerOptions): Promise<RunningServer
|
||||
tuning.battle,
|
||||
spawnRules,
|
||||
botAircraftLoadouts,
|
||||
tuning.groundAi.mode === 'stock' ? undefined : tuning.groundAi.lineupWeights,
|
||||
(ctx) => modRuntime.runBattleFilterMissions(ctx),
|
||||
);
|
||||
const economy = new BattleEconomy(
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
* Typed, range-validated reader for `tuning/ground-ai.jsonc`.
|
||||
*/
|
||||
import type { DiscoveredMod } from '@wto/mods';
|
||||
import type { GroundAiConfig } from '@wto/patcher';
|
||||
import { GROUND_AI_MODES, type GroundAiConfig, type GroundAiMode } from '@wto/patcher';
|
||||
import type { TankLineupWeights } from '../battle/battle-ranks.ts';
|
||||
import { tuningFiles } from './tuning-loader.ts';
|
||||
import { TuningError, type TuningReader } from './tuning-reader.ts';
|
||||
|
||||
export type GroundAiTuning = GroundAiConfig;
|
||||
export interface GroundAiTuning extends GroundAiConfig {
|
||||
/** Tank pool weights by class, used only when a custom ground AI mode is active. */
|
||||
readonly lineupWeights: TankLineupWeights;
|
||||
}
|
||||
|
||||
const DRIVE_MODES = new Set(['vehicle_phys', 'movesys']);
|
||||
|
||||
@@ -19,17 +23,11 @@ export function loadGroundAiTuning(
|
||||
}
|
||||
|
||||
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'),
|
||||
},
|
||||
mode: readMode(reader),
|
||||
lineupWeights: readLineupWeights(reader.object('lineupWeights')),
|
||||
cadence: {
|
||||
maxBots: cadence.int('maxBots', { min: 1, max: 64 }),
|
||||
macroTickSec: cadence.number('macroTickSec', { min: 0.1, max: 5 }),
|
||||
@@ -49,6 +47,27 @@ export function readGroundAiTuning(reader: TuningReader): GroundAiTuning {
|
||||
};
|
||||
}
|
||||
|
||||
function readMode(reader: TuningReader): GroundAiMode {
|
||||
const mode = reader.string('mode');
|
||||
const known = GROUND_AI_MODES.find((candidate) => candidate === mode);
|
||||
if (known === undefined) {
|
||||
throw new TuningError(`tuning file ground-ai.jsonc: mode must be one of ${GROUND_AI_MODES.map((m) => `"${m}"`).join(', ')} (found "${mode}")`);
|
||||
}
|
||||
return known;
|
||||
}
|
||||
|
||||
function readLineupWeights(weights: TuningReader): TankLineupWeights {
|
||||
const range = { min: 0.01, max: 10 };
|
||||
return {
|
||||
spaa: weights.number('spaa', range),
|
||||
lightTank: weights.number('lightTank', range),
|
||||
tankDestroyer: weights.number('tankDestroyer', range),
|
||||
heavyTank: weights.number('heavyTank', range),
|
||||
mediumTank: weights.number('mediumTank', range),
|
||||
other: weights.number('other', range),
|
||||
};
|
||||
}
|
||||
|
||||
function readMacroSection(macro: TuningReader): GroundAiTuning['macro'] {
|
||||
const recaptureMinBots = macro.int('recaptureMinBots', { min: 1, max: 8 });
|
||||
const recaptureMaxBots = macro.int('recaptureMaxBots', { min: 1, max: 12 });
|
||||
|
||||
Reference in new issue
Block a user