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;
}
@@ -40,6 +40,9 @@ export const MISSION_DIFFICULTY: Readonly<Record<ModeDifficulty, string>> = {
simulator: 'hardcore',
};
// globals/missions/respawnCountModes.nut: RESPAWN_COUNT_MODE.SINGLE_SPAWN.
export const SINGLE_SPAWN = 1;
export type ModeDefinition = Readonly<Record<string, unknown>>;
export function buildModeDefinition(mode: GameModeDeclaration, missions: readonly MissionHeader[],
@@ -79,6 +82,7 @@ export function buildModeDefinition(mode: GameModeDeclaration, missions: readonl
teamB: structuredClone(team),
mission_decl: {
difficulty: MISSION_DIFFICULTY[mode.difficulty],
...(mode.multiSlot === false ? { maxRespawns: SINGLE_SPAWN } : {}),
missions_list: Object.fromEntries(missions.map((mission) => [mission.name, {}])),
},
};
@@ -16,6 +16,7 @@ import type { BlkBlock, BlkValue } from '@wto/blk';
import type { BannerParams } from '../battle/battle-economy.ts';
import type { BattleLaunchPlan } from '../battle/battle-matchmaker.ts';
import { battleMissionSettings } from '../battle/battle-mission-settings.ts';
import { SINGLE_SPAWN } from '../game-modes/mode-definition.ts';
type WireParam = readonly [name: string, type: 't' | 'i' | 'r' | 'b', value: string | number | boolean];
@@ -48,7 +49,11 @@ export function battleLaunchNotify(
symmetricTeams: plan.symmetricTeams,
country_allies: plan.countriesAllies.map(withCountryPrefix),
country_axis: plan.countriesAxis.map(withCountryPrefix),
mission: { name: plan.missionName, difficulty: plan.difficulty },
mission: {
name: plan.missionName,
difficulty: plan.difficulty,
...(plan.selectedSlot ? { maxRespawns: SINGLE_SPAWN } : {}),
},
},
battle: {
sessionId: plan.sessionId,
@@ -56,6 +61,7 @@ export function battleLaunchNotify(
economicName: plan.economicName,
country: plan.country,
missionName: plan.missionName,
...(plan.selectedSlot ? { selectedSlot: plan.selectedSlot } : {}),
extraBattleSlots: plan.extraBattleSlots,
...(plan.spawnScore ? { spawnScore: plan.spawnScore } : {}),
awards,
@@ -5,6 +5,7 @@
* - `match.leave_queue` (scripts/queue/queuestate.nut:28)
* - `match.check_reconnect`
*/
import { MAX_BATTLE_CREW_SLOTS } from '../battle/battle-extra-slots.ts';
import { economyDifficulty, type BattleEconomy } from '../battle/battle-economy.ts';
import type { BattleMatchmaker } from '../battle/battle-matchmaker.ts';
import { maxModeMrank, unitClassOfExpClass, unitClassOfTypeCode, type CraftRankEntry } from '../battle/battle-ranks.ts';
@@ -81,16 +82,15 @@ function handleEnqueue(
}
const profile = deps.profiles.profileOf(userId);
const slotVehicles = crewVehiclesOfCountry(profile, playerEntry.country);
const selectedSlotVehicle = playerEntry.selectedSlot !== undefined
? crewSlotVehicleOfCountry(profile, playerEntry.country, playerEntry.selectedSlot)
: undefined;
const idInCountry = playerEntry.selectedSlot;
const selectedSlotVehicle = idInCountry === undefined ? undefined : crewSlotVehicleOfCountry(profile, playerEntry.country, idInCountry);
const outcome = deps.matchmaker.enqueue({
userId,
mode: modes[0]!,
modes,
country: playerEntry.country,
slotVehicles,
...(selectedSlotVehicle !== undefined ? { selectedSlotVehicle } : {}),
...(idInCountry !== undefined && selectedSlotVehicle ? { selectedSlot: { idInCountry, unitName: selectedSlotVehicle } } : {}),
bannedMissions: playerEntry.bannedMissions,
dislikedMissions: playerEntry.dislikedMissions,
});
@@ -101,7 +101,7 @@ function handleEnqueue(
const { launch } = outcome;
session.note(`mode=${launch.modeName}, mission=${launch.missionName}, mrank=${launch.minMrank}..${launch.maxMrank}`);
const playerVehicles = new Set([
...slotVehicles,
...(launch.selectedSlot ? [launch.selectedSlot.unitName] : slotVehicles),
...launch.extraBattleSlots.map((slot) => slot.unitName),
]);
const awards = deps.economy.bannerParams(playerVehicles, economyDifficulty(modes[0]!.declaration.difficulty));
@@ -163,7 +163,8 @@ function extractPlayerEntry(
const country = rawCountry.startsWith('country_') ? rawCountry : `country_${rawCountry}`;
const slots = isRecord(entry?.slots) ? entry.slots : undefined;
const rawSlot = slots?.[country] ?? slots?.[rawCountry];
const selectedSlot = typeof rawSlot === 'number' && Number.isInteger(rawSlot) && rawSlot >= 0 ? rawSlot : undefined;
const selectedSlot = typeof rawSlot === 'number' && Number.isInteger(rawSlot) && rawSlot >= 0 && rawSlot < MAX_BATTLE_CREW_SLOTS
? rawSlot : undefined;
return {
country,
...(selectedSlot !== undefined ? { selectedSlot } : {}),
@@ -0,0 +1,2 @@
function isCrewAvailableInSession(crew, unit = null, needDebug = false) {
let { idInCountry } = crew
@@ -0,0 +1 @@
from "guiRespawn" import getWasReadySlotsMask, getSpareSlotsMask, getDisabledSlotsMask, getBrokenSlotsMask, getDisabledByMatchingSlotsMask, getNumFreeSparesUsed, getNumFreeSparesPerDay
@@ -0,0 +1 @@
let isSpareAircraftInSlot = @(idInCountry) is_bit_set(getSpareSlotsMask(), idInCountry)
@@ -0,0 +1,19 @@
// Feed the matched crew slot into the stock respawn and slot bar availability checks.
// The queued aircraft is known to the offline server, but LocalMP does not receive a matchmaking slot mask.
// Without this bridge, the LocalMP host can offer the rest of the player's lineup in a single-slot battle.
{
"id": "battle/lock-single-slot-lineup",
"title": "Restrict single-slot battles to the queued aircraft",
"features": ["K-Spawn score and respawns"],
"variants": [
{
"written_for": "2.61.0.37",
"file": "scripts/respawn/respawnstate.nut",
"edits": [
{ "find": "find-import.nut", "replace": "replace-import.nut" },
{ "find": "find-mask.nut", "replace": "replace-mask.nut" },
{ "find": "find-crew-check.nut", "replace": "replace-crew-check.nut" }
]
}
]
}
@@ -0,0 +1,6 @@
function isCrewAvailableInSession(crew, unit = null, needDebug = false) {
let { idInCountry } = crew
let selected = getWtoSelectedSlot()
if (selected != null)
return idInCountry == selected.idInCountry && (unit?.name ?? crew?.aircraft) == selected.unitName
&& !is_bit_set(getNativeDisabledSlotsMask(), idInCountry)
@@ -0,0 +1 @@
from "guiRespawn" import getWasReadySlotsMask, getSpareSlotsMask, getDisabledSlotsMask as getNativeDisabledSlotsMask, getBrokenSlotsMask, getDisabledByMatchingSlotsMask, getNumFreeSparesUsed, getNumFreeSparesPerDay
@@ -0,0 +1,11 @@
function getWtoSelectedSlot() {
return require("nestdb").ndbTryRead(["wto", "activeBattle"])?.selectedSlot
}
function getDisabledSlotsMask() {
let mask = getNativeDisabledSlotsMask()
let selected = getWtoSelectedSlot()
return selected == null ? mask : mask | ~(1 << selected.idInCountry)
}
let isSpareAircraftInSlot = @(idInCountry) is_bit_set(getSpareSlotsMask(), idInCountry)