fix(battle): enforce single-sortie Air Realistic rules

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.
This commit is contained in:
N0VAN0M4LY committed 2026-12-01 12:05:42 +08:00
1 parent 6c55c64222
commit 7ba66340b6
14 files changed
+122 -56

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@ 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). */
const MAX_BATTLE_CREW_SLOTS = 32;
export const MAX_BATTLE_CREW_SLOTS = 32;
export interface ExtraBattleSlot {
readonly unitName: string;
+21 -46
View File
@@ -10,28 +10,33 @@ import type { BattleSpawnRulesData } from '../game-data/datasets/battle-spawn-ru
import type { MissionHeader } from '../game-data/datasets/multiplayer-missions.ts';
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
import type { GameModes, OfferedGameMode } from '../game-modes/game-modes.ts';
import { MISSION_DIFFICULTY } from '../game-modes/mode-definition.ts';
import { MISSION_DIFFICULTY, SINGLE_SPAWN } from '../game-modes/mode-definition.ts';
import { serverTimeNow, serverTimeToUnixSeconds } from '../profile/server-time.ts';
import { selectBattleCoalitions, type CoalitionPairing } from './battle-coalitions.ts';
import { selectExtraBattleSlots, type ExtraBattleSlot } from './battle-extra-slots.ts';
import {
activeVehiclesForMode,
isModeEligibleForLineup,
lineupMrank,
selectCustomBots,
unitClassOfExpClass,
vehicleMrank,
type CustomBotsPool,
} from './battle-ranks.ts';
import type { BattleSessionStore } from './battle-session-store.ts';
import { battleSpawnScore, type BattleSpawnScore } from './battle-spawn-score.ts';
import type { BattleTuning } from './battle-tuning.ts';
export interface BattleCrewSlot {
readonly idInCountry: number;
readonly unitName: string;
}
export interface EnqueueBattleInput {
readonly userId: string;
readonly mode: OfferedGameMode;
readonly modes?: readonly OfferedGameMode[];
readonly country: string;
readonly slotVehicles: readonly string[];
readonly selectedSlotVehicle?: string;
readonly selectedSlot?: BattleCrewSlot;
readonly bannedMissions: ReadonlySet<string>;
readonly dislikedMissions: ReadonlySet<string>;
}
@@ -68,6 +73,7 @@ export interface BattleLaunchPlan {
readonly useSpawnScore: boolean;
readonly spawnScore?: BattleSpawnScore;
readonly customBots: CustomBotsPool;
readonly selectedSlot?: BattleCrewSlot;
readonly extraBattleSlots: readonly ExtraBattleSlot[];
}
@@ -103,11 +109,15 @@ export class BattleMatchmaker {
if (!knownCountries.includes(input.country)) return { ok: false, error: 'BAD_PARAMS' };
const candidates = input.modes && input.modes.length > 0 ? input.modes : [input.mode];
const chosenMode = this.#pickQueuedMode(candidates, input.slotVehicles, input.selectedSlotVehicle);
if (!chosenMode) return { ok: false, error: 'PVE_NOT_SUPPORTED' };
const pvpModes = candidates.filter(
(mode) => mode.declaration.displayType !== 'pve_battle' && twoSidedMissionsOf(mode).length > 0,
);
if (pvpModes.length === 0) return { ok: false, error: 'PVE_NOT_SUPPORTED' };
const chosenMode = this.#pickQueuedMode(pvpModes, input.slotVehicles, input.selectedSlot?.unitName);
if (!chosenMode) return { ok: false, error: 'BAD_PARAMS' };
const { declaration } = chosenMode;
const activeVehicles = activeVehiclesForMode(declaration, input.slotVehicles, input.selectedSlotVehicle, this.#vehiclesByName);
const activeVehicles = activeVehiclesForMode(declaration, input.slotVehicles, input.selectedSlot?.unitName, this.#vehiclesByName);
const playerMrank = lineupMrank(
activeVehicles, this.#vehiclesByName, declaration.difficulty, declaration.requiredClass, declaration.allowedClasses,
);
@@ -146,14 +156,9 @@ export class BattleMatchmaker {
slotVehicles: readonly string[],
selectedSlotVehicle: string | undefined,
): OfferedGameMode | undefined {
const pvpModes = candidates.filter(
(mode) => mode.declaration.displayType !== 'pve_battle' && twoSidedMissionsOf(mode).length > 0,
);
if (pvpModes.length === 0) return undefined;
const eligible = pvpModes.filter((mode) =>
const pool = candidates.filter((mode) =>
isModeEligibleForLineup(mode.declaration, slotVehicles, selectedSlotVehicle, this.#vehiclesByName));
const pool = eligible.length > 0 ? eligible : pvpModes.filter((mode) => !mode.declaration.tag);
if (pool.length === 0) return pvpModes[0];
if (pool.length === 0) return candidates.find((mode) => mode.declaration.multiSlot !== false);
const classics = pool.filter((mode) => !mode.declaration.tag);
const subModes = pool.filter((mode) => Boolean(mode.declaration.tag));
if (subModes.length > 0 && classics.length > 0) {
@@ -231,7 +236,7 @@ export class BattleMatchmaker {
maxPlayers,
maxBots,
tankBotRespawns: this.#tuning.tankBotRespawns,
airBotRespawns: this.#tuning.airBotRespawns,
airBotRespawns: declaration.multiSlot === false ? SINGLE_SPAWN : this.#tuning.airBotRespawns,
useTankBots: allowedSet.has('tank'),
useShipBots: allowedSet.has('ship'),
useSpawnScore,
@@ -239,6 +244,7 @@ export class BattleMatchmaker {
spawnScore: battleSpawnScore(input.slotVehicles, extraBattleSlots, maxMrank, this.#vehiclesByName, this.#spawnRules.spawnScore),
} : {}),
customBots,
...(declaration.multiSlot === false && input.selectedSlot ? { selectedSlot: input.selectedSlot } : {}),
extraBattleSlots,
};
}
@@ -248,37 +254,6 @@ function twoSidedMissionsOf(mode: OfferedGameMode): MissionHeader[] {
return mode.missions.filter((m) => m.playerSlots.teamA > 0 && m.playerSlots.teamB > 0);
}
function activeVehiclesForMode(
declaration: OfferedGameMode['declaration'],
slotVehicles: readonly string[],
selectedSlotVehicle: string | undefined,
byName: ReadonlyMap<string, CatalogueVehicle>,
): readonly string[] {
if (declaration.multiSlot !== false || !selectedSlotVehicle) return slotVehicles;
const selected = byName.get(selectedSlotVehicle);
return selected && unitClassOfExpClass(selected.unitClass) === declaration.requiredClass
? [selectedSlotVehicle]
: slotVehicles;
}
function isModeEligibleForLineup(
declaration: OfferedGameMode['declaration'],
slotVehicles: readonly string[],
selectedSlotVehicle: string | undefined,
byName: ReadonlyMap<string, CatalogueVehicle>,
): boolean {
if (!declaration.tag) return true;
const active = activeVehiclesForMode(declaration, slotVehicles, selectedSlotVehicle, byName);
const minMrank = declaration.minQueueMrank ?? 0;
const minCrafts = declaration.minCraftsToPlay ?? 1;
const matchingCount = active.filter((name) => {
const vehicle = byName.get(name);
if (!vehicle || unitClassOfExpClass(vehicle.unitClass) !== declaration.requiredClass) return false;
return vehicleMrank(vehicle, declaration.difficulty, declaration.requiredClass) >= minMrank;
}).length;
return matchingCount >= minCrafts;
}
function pickMission(missions: readonly MissionHeader[], banned: ReadonlySet<string>, disliked: ReadonlySet<string>): MissionHeader {
const unbanned = missions.filter((mission) => !banned.has(mission.name));
const poolAfterBan = unbanned.length > 0 ? unbanned : missions;
@@ -8,6 +8,7 @@
* difficulty. `_gameMode` is left to the client, which takes it from its own native constants.
*/
import { emptyBlock, ensureBlock, setParam, appendParam, type BlkBlock, type BlkParam, type BlkValue } from '@wto/blk';
import { SINGLE_SPAWN } from '../game-modes/mode-definition.ts';
import type { ExtraBattleSlot } from './battle-extra-slots.ts';
import type { BattleLaunchPlan } from './battle-matchmaker.ts';
import type { CustomBotsPool } from './battle-ranks.ts';
@@ -27,7 +28,7 @@ const RULE_KEYS: readonly string[] = [
/** Game type switches of a versus battle with tickets, capture zones and session rewards. */
const VERSUS_SWITCHES: readonly string[] = [
'gt_versus', 'gt_mp_tickets', 'gt_mp_capture', 'gt_use_wp', 'gt_use_xp', 'gt_use_stats', 'gt_use_unlocks',
'allowSpare', 'isLimitedAmmo', 'allowUseArtillerySupport', 'isBotsAllowed', 'autoBalance',
'isLimitedAmmo', 'allowUseArtillerySupport', 'isBotsAllowed', 'autoBalance',
];
/**
@@ -59,6 +60,12 @@ export function battleMissionSettings(plan: BattleLaunchPlan, scores: Readonly<R
setParam(settings, 'symmetricTeams', flag(plan.symmetricTeams));
setParam(settings, 'gt_mp_solo', flag(false));
for (const name of VERSUS_SWITCHES) setParam(settings, name, flag(true));
setParam(settings, 'allowSpare', flag(!plan.selectedSlot));
if (plan.selectedSlot) {
setParam(settings, 'maxRespawns', integer(SINGLE_SPAWN));
// The native mission loader reads the AI limit at the top level, after its bots.blk default.
setParam(settings, 'numBotRespawns', integer(plan.airBotRespawns));
}
setParam(settings, 'useSpawnScore', flag(plan.useSpawnScore));
setParam(settings, 'useTankBots', flag(plan.useTankBots));
setParam(settings, 'useShipBots', flag(plan.useShipBots));
+33 -1
View File
@@ -7,7 +7,7 @@
* `allowedAircrafts` (`aircraft`), and `allowedShips` (`ship`).
*/
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
import type { ModeDifficulty, UnitClass } from '../game-modes/catalogue/game-mode-declaration.ts';
import type { GameModeDeclaration, ModeDifficulty, UnitClass } from '../game-modes/catalogue/game-mode-declaration.ts';
import { vehicleTypeById, vehicleTypeOfClass, type VehicleType } from '../research/vehicle-types.ts';
const COUNTRY_PREFIX = 'country_';
@@ -175,3 +175,35 @@ function unitClassOfVehicleType(type: VehicleType | undefined): UnitClass | unde
if (type === 'Ship' || type === 'Boat') return 'ship';
return undefined;
}
export function activeVehiclesForMode(
declaration: GameModeDeclaration,
slotVehicles: readonly string[],
selectedSlotVehicle: string | undefined,
byName: ReadonlyMap<string, CatalogueVehicle>,
): readonly string[] {
if (declaration.multiSlot !== false) return slotVehicles;
if (!selectedSlotVehicle) return [];
const selected = byName.get(selectedSlotVehicle);
return selected && unitClassOfExpClass(selected.unitClass) === declaration.requiredClass
? [selectedSlotVehicle]
: [];
}
export function isModeEligibleForLineup(
declaration: GameModeDeclaration,
slotVehicles: readonly string[],
selectedSlotVehicle: string | undefined,
byName: ReadonlyMap<string, CatalogueVehicle>,
): boolean {
if (!declaration.tag && declaration.multiSlot !== false) return true;
const active = activeVehiclesForMode(declaration, slotVehicles, selectedSlotVehicle, byName);
const minMrank = declaration.minQueueMrank ?? 0;
const minCrafts = declaration.minCraftsToPlay ?? 1;
const matchingCount = active.filter((name) => {
const vehicle = byName.get(name);
if (!vehicle || unitClassOfExpClass(vehicle.unitClass) !== declaration.requiredClass) return false;
return vehicleMrank(vehicle, declaration.difficulty, declaration.requiredClass) >= minMrank;
}).length;
return matchingCount >= minCrafts;
}