Carry the queued aircraft and crew index into LocalMP, apply the native single-spawn limits to players and aircraft bots, and disable spares for single-slot modes. Verified with root and launcher type checks, check-patches and check-gui for 2.61.0.37 and 2.61.0.43, and an isolated launch-payload check.
153 lines
7.8 KiB
TypeScript
153 lines
7.8 KiB
TypeScript
/**
|
|
* The extra vehicles a battle adds to the player's lineup (online the battle server adds them):
|
|
*
|
|
* - Support plane (the nuclear carrier): gameplay.blk missionSupportPlane, keyed by the game mode
|
|
* name; the preset whose rankRange holds the session's top rank, the unit of the player's
|
|
* country, with its fixed weapon and its spawnScoreToUse as a fixed spawn cost.
|
|
* - Strike UCAV: wpcost.blk ucav_*_killstreak of the player's country. The game files have no rule
|
|
* for when it is offered or what it costs; both are in tuning/battle.jsonc (the cost as seen in
|
|
* the live game, the offer rule offline design).
|
|
* - Extra vehicles from gameplay.blk RandomSpawnUnits, keyed by the event economic name: one
|
|
* vehicle per group of the player's country (ground RB: a tank and an SPAA), drawn at launch and
|
|
* shown in the lineup as a plain vehicle, as the live game does (a 12.7 US lineup received an
|
|
* M1A1 12.0 and an ADATS 12.0, no dice; screenshot of the live game). Rules from the official
|
|
* changelog ("Line of Contact", 2025-12-16): offered to lineups of BR 9.3 and higher (the
|
|
* groups' minPlayerMRank), with no condition on what the lineup holds; the vehicle depends on the
|
|
* player's BR and the session's BR and is never of the session's top BR; when no vehicle fits,
|
|
* lower BR vehicles are used. Worked examples there: in a 9.7-10.7 session a player at 10.7 gets
|
|
* 9.7-10.3 and a player at 9.7 gets 9.3-10.0. The window formula is not published;
|
|
* `randomWindow` is fitted to those examples with the group's own parameters (inferred). Their
|
|
* spawn cost comes from the stock spawn score formula (the live screenshot's 110 and 80 match it).
|
|
*/
|
|
import { randomInt } from 'node:crypto';
|
|
import type {
|
|
BattleSpawnRulesData,
|
|
RandomSpawnGroup,
|
|
RandomSpawnUnit,
|
|
SupportPlanePreset,
|
|
} from '../game-data/datasets/battle-spawn-rules.ts';
|
|
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
|
|
import type { GameModeDeclaration } from '../game-modes/catalogue/game-mode-declaration.ts';
|
|
import type { BattleTuning } from './battle-tuning.ts';
|
|
import { vehicleMrank } from './battle-ranks.ts';
|
|
|
|
/** The LocalMP host tracks crew slots in a 32-bit mask (native LMP_MP_OFF_BROKEN_SLOTS_MASK). */
|
|
export const MAX_BATTLE_CREW_SLOTS = 32;
|
|
|
|
export interface ExtraBattleSlot {
|
|
readonly unitName: string;
|
|
/** Fixed spawn cost (mission customSpawnScore.persistent_costs); absent = the stock formula. */
|
|
readonly persistentCost?: number;
|
|
/** Every modification of the unit is enabled. */
|
|
readonly allModifications: boolean;
|
|
/** The modifications enabled when not `allModifications`; the unit is otherwise stock. */
|
|
readonly modifications: readonly string[];
|
|
readonly forceWeapon?: string;
|
|
/** The RandomSpawnUnits group the vehicle was drawn from. */
|
|
readonly groupName?: string;
|
|
}
|
|
|
|
export interface ExtraBattleSlotsInput {
|
|
readonly country: string;
|
|
readonly slotVehicles: readonly string[];
|
|
readonly declaration: GameModeDeclaration;
|
|
/** The lineup's mrank the session was matched on. */
|
|
readonly playerMrank: number;
|
|
readonly sessionMaxMrank: number;
|
|
readonly vehiclesByName: ReadonlyMap<string, CatalogueVehicle>;
|
|
readonly rules: BattleSpawnRulesData;
|
|
readonly tuning: Pick<BattleTuning, 'strikeUcavModes' | 'strikeUcavSessionMrankAllowance' | 'strikeUcavSpawnScore'>;
|
|
}
|
|
|
|
export function selectExtraBattleSlots(input: ExtraBattleSlotsInput): readonly ExtraBattleSlot[] {
|
|
const room = MAX_BATTLE_CREW_SLOTS - input.slotVehicles.length;
|
|
if (input.declaration.multiSlot === false || room <= 0) return [];
|
|
|
|
const supportSlots: ExtraBattleSlot[] = [];
|
|
const supportPlane = supportPlaneSlot(input);
|
|
if (supportPlane) supportSlots.push(supportPlane);
|
|
const ucav = strikeUcavSlot(input);
|
|
if (ucav) supportSlots.push(ucav);
|
|
|
|
// Keep room for fixed support vehicles while displaying random vehicle groups first.
|
|
const slots: ExtraBattleSlot[] = [];
|
|
for (const group of input.rules.randomSpawnUnits[input.declaration.economicName]?.[input.country] ?? []) {
|
|
if (slots.length + supportSlots.length >= room) break;
|
|
const options = randomGroupOptions(group, input);
|
|
if (options.length === 0) continue;
|
|
const chosen = options[randomInt(options.length)]!;
|
|
slots.push({
|
|
unitName: chosen.unitName,
|
|
allModifications: false,
|
|
modifications: chosen.addModifications,
|
|
...(chosen.forceWeapon ? { forceWeapon: chosen.forceWeapon } : {}),
|
|
groupName: group.name,
|
|
});
|
|
}
|
|
|
|
return [...slots, ...supportSlots].slice(0, room);
|
|
}
|
|
|
|
function supportPlaneSlot(input: ExtraBattleSlotsInput): ExtraBattleSlot | undefined {
|
|
const presets: readonly SupportPlanePreset[] = input.rules.supportPlanes[input.declaration.name] ?? [];
|
|
const preset = presets.find((p) => input.sessionMaxMrank >= p.minMrank && input.sessionMaxMrank <= p.maxMrank);
|
|
const unit = preset?.units[input.country];
|
|
if (!preset || !unit) return undefined;
|
|
return {
|
|
unitName: unit.unitName,
|
|
persistentCost: preset.spawnScoreToUse,
|
|
allModifications: true,
|
|
modifications: [],
|
|
forceWeapon: unit.weapon,
|
|
};
|
|
}
|
|
|
|
function strikeUcavSlot(input: ExtraBattleSlotsInput): ExtraBattleSlot | undefined {
|
|
if (!input.tuning.strikeUcavModes.includes(input.declaration.name)) return undefined;
|
|
const ucav = input.rules.strikeUcavs.find((entry) => entry.country === input.country);
|
|
const vehicle = ucav && input.vehiclesByName.get(ucav.unitName);
|
|
if (!ucav || !vehicle) return undefined;
|
|
const ucavMrank = vehicleMrank(vehicle, input.declaration.difficulty, input.declaration.requiredClass);
|
|
if (input.sessionMaxMrank < ucavMrank - input.tuning.strikeUcavSessionMrankAllowance) return undefined;
|
|
// Offline design: the UCAV comes fully upgraded and keeps its weapon choice (the game files force no preset).
|
|
return {
|
|
unitName: ucav.unitName,
|
|
persistentCost: input.tuning.strikeUcavSpawnScore,
|
|
allModifications: true,
|
|
modifications: [],
|
|
};
|
|
}
|
|
|
|
/**
|
|
* The options of one random group: the group's vehicles inside `randomWindow`, or, when none fits,
|
|
* those of the highest rank below it. Vehicles already in the lineup are left out (offline
|
|
* design: the lineup does not hold the same vehicle twice).
|
|
*/
|
|
function randomGroupOptions(group: RandomSpawnGroup, input: ExtraBattleSlotsInput): RandomSpawnUnit[] {
|
|
if (input.playerMrank < group.minPlayerMrank) return [];
|
|
const { low, high } = randomWindow(group, input.playerMrank, input.sessionMaxMrank);
|
|
const lineup = new Set(input.slotVehicles);
|
|
const ranked = group.units.flatMap((unit) => {
|
|
const vehicle = input.vehiclesByName.get(unit.unitName);
|
|
if (!vehicle || lineup.has(unit.unitName)) return [];
|
|
const mrank = vehicleMrank(vehicle, input.declaration.difficulty, input.declaration.requiredClass);
|
|
return mrank <= high ? [{ unit, mrank }] : [];
|
|
});
|
|
const inWindow = ranked.filter((entry) => entry.mrank >= low);
|
|
if (inWindow.length > 0) return inWindow.map((entry) => entry.unit);
|
|
const best = Math.max(...ranked.map((entry) => entry.mrank));
|
|
return ranked.filter((entry) => entry.mrank === best).map((entry) => entry.unit);
|
|
}
|
|
|
|
/**
|
|
* Inferred window (the formula is not published): the top option is the player's rank, raised to
|
|
* at least `maxDiffBetweenTopUnitAndSessionRank` below the session's top rank and capped one rank
|
|
* below it; the window spans `mRanksCount` ranks under the top option. With the stock values
|
|
* (2 and 2) this gives both official examples: session 10.7 (mrank 29), player 10.7 (29) ->
|
|
* mranks 26-28 = BR 9.7-10.3; player 9.7 (26) -> mranks 25-27 = BR 9.3-10.0.
|
|
*/
|
|
function randomWindow(group: RandomSpawnGroup, playerMrank: number, sessionMaxMrank: number) {
|
|
const high = Math.min(Math.max(playerMrank, sessionMaxMrank - group.maxDiffBetweenTopUnitAndSessionRank), sessionMaxMrank - 1);
|
|
return { low: Math.max(0, high - group.mranksCount), high };
|
|
}
|