refactor(repo)!: move apps, shared packages, and patch definitions

Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:

  apps/server        the local server (was packages/local-service),
                     package @wto/server
  packages/patcher   builds the game copy (was packages/build),
                     package @wto/patcher
  patches/exe        exe patch definitions (was exe-patches)
  patches/gui        GUI script patches (was gui-patches)

Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".

The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.

The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.


Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.

BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 03:20:54 +08:00
1 parent 9c813ccf7d
commit 930ea07630
476 files changed
+275 -251

No files matched your search

@@ -0,0 +1,32 @@
/** The offline version's game modes (docs/implementation notes; implementation notes J). */
import type { GameModeDeclaration } from './game-mode-declaration.ts';
import { PVE_BATTLES } from './pve-battles.ts';
import { RANDOM_BATTLES } from './random-battles.ts';
import { SIMULATOR_BATTLES } from './simulator-battles.ts';
import { SPECIAL_EVENTS } from './special-events.ts';
import { SUB_GAME_MODES } from './sub-game-modes.ts';
export const GAME_MODE_CATALOGUE: readonly GameModeDeclaration[] = checked([
...RANDOM_BATTLES,
...SUB_GAME_MODES,
...SIMULATOR_BATTLES,
...PVE_BATTLES,
...SPECIAL_EVENTS,
]);
function checked(modes: readonly GameModeDeclaration[]): readonly GameModeDeclaration[] {
const seenIds = new Set<number>();
const seenNameTags = new Set<string>();
for (const mode of modes) {
if (seenIds.has(mode.gameModeId)) {
throw new Error(`game-mode catalogue: gameModeId ${mode.gameModeId} is used twice`);
}
seenIds.add(mode.gameModeId);
const nameTag = `${mode.name}\0${mode.tag ?? ''}`;
if (seenNameTags.has(nameTag)) {
throw new Error(`game-mode catalogue: (${mode.name}, tag="${mode.tag ?? ''}") is used twice`);
}
seenNameTags.add(nameTag);
}
return modes;
}
@@ -0,0 +1,72 @@
/**
* What the offline game-mode catalogue declares about one mode (docs/implementation notes,
* 3.3). Everything else in a mode definition is derived from the game's own files.
*/
/** Vehicle classes, named as the stock UI names unit types in event craft rules (scripts/unit/baseUnitTypes.nut). */
export type UnitClass = 'aircraft' | 'tank' | 'ship' | 'helicopter';
export type ModeDifficulty = 'arcade' | 'realistic' | 'simulator';
/**
* Where the stock UI shows the mode (scripts/events/eventDisplayType.nut): random_battle
* and pve_battle in the game-mode selection, regular in the events window.
*/
export type DisplayType = 'random_battle' | 'pve_battle' | 'regular';
/** Which multiplayer missions (game-data/datasets/multiplayer-missions.ts) the mode rotates. */
export interface MissionSelection {
/** Categories of config/mislist.blk; only listed categories are used, whatever their flags. */
readonly categories: readonly string[];
/** The mission must state that these vehicle classes are allowed. */
readonly requireAllowed: readonly UnitClass[];
/** Keep only missions whose name matches. */
readonly include?: RegExp;
/** Drop missions whose name matches. */
readonly exclude?: RegExp;
}
export interface GameModeDeclaration {
/** Fixed forever: the client remembers modes by it. */
readonly gameModeId: number;
/** The stock name where the game has one (docs/implementation notes). */
readonly name: string;
/**
* Sub-mode tag prefix recognized by `scripts/matching/matchinggamemodes.nut:28-42`
* (`regular_with_night_`, `small_teams_`, `bullet_hell_`, `nuclear_escalation_`,
* `naval_ec_ab_`, `naval_ec_rb_`). Empty or omitted for primary modes.
*/
readonly tag?: string;
readonly economicName: string;
/** A single key of the game's localization (a composite key makes the stock UI log an error). */
readonly locName: string;
readonly difficulty: ModeDifficulty;
readonly displayType: DisplayType;
/** Events-window chapter; only for modes shown there. */
readonly chapter?: string;
/**
* Whether multiple crew slots participate (`scripts/events/eventsstate.nut:76`). Defaults to
* `true`; `false` for single-slot modes (`air_realistic` and its `small_teams_` sub-mode).
*/
readonly multiSlot?: boolean;
/** Minimum `mrank` exposed on the parent mode for Night Battles (`scripts/events/eventinfo.nut:134-136`). */
readonly minMRankForNightBattles?: number;
/** Minimum `mrank` exposed on the parent mode for Tactical Skies (`scripts/events/eventinfo.nut:137`). */
readonly minMRankForSmallTeamsBattles?: number;
/** Minimum suitable vehicles required in the crew bar (`scripts/events/secondgamemodesutils.nut:70-71`). */
readonly minCraftsToPlay?: number;
/** Minimum `mrank` per vehicle class emitted into `teamA`/`teamB.allowedCrafts` (`mranks.min`). */
readonly allowedCraftMinMrank?: Partial<Readonly<Record<UnitClass, number>>>;
/** Explicit `minTeamSize` / `maxTeamSize` override (`scripts/events/secondgamemodesutils.nut:40-54`). */
readonly teamSizeOverride?: { readonly min: number; readonly max: number };
/** Minimum `mrank` enforced by local matchmaking before selecting this sub-mode. */
readonly minQueueMrank?: number;
/** Mission time-of-day override applied when launching this mode (e.g. `"Night"`). */
readonly environmentOverride?: string;
/** Uses `BattleTuning.smallTeamsMaxPlayers` instead of `BattleTuning.maxPlayers` when true. */
readonly isSmallTeams?: boolean;
/** The vehicle class a player must bring; the mode is greyed out without one. */
readonly requiredClass: UnitClass;
readonly allowedClasses: readonly UnitClass[];
readonly missions: MissionSelection;
}
@@ -0,0 +1,44 @@
/**
* The mission pools of the regular battle modes, by vehicle class. Categories come from
* char.vromfs.bin config/mislist.blk ("skirmish"); the vehicle-type requirement keeps only
* missions that say the class is allowed.
*
* Exclude missions whose names contain "newbie" from the standard offline mission pools.
* See docs/implementation notes.
*/
import type { MissionSelection } from './game-mode-declaration.ts';
const NEWBIE_MISSIONS = /newbie/i;
export const AIR_BATTLE_MISSIONS: MissionSelection = {
categories: ['air_dom', 'airfield_dom', 'ground_strike', 'base_dom', 'air_conq'],
requireAllowed: ['aircraft'],
exclude: NEWBIE_MISSIONS,
};
export const GROUND_BATTLE_MISSIONS: MissionSelection = {
categories: ['air_ground_Dom', 'air_ground_Conq', 'air_ground_Bttl'],
requireAllowed: ['tank'],
exclude: NEWBIE_MISSIONS,
};
export const NAVAL_BATTLE_MISSIONS: MissionSelection = {
categories: ['air_naval_Dom', 'air_naval_Conq', 'air_naval_Tdm'],
requireAllowed: ['ship'],
exclude: NEWBIE_MISSIONS,
};
export const BULLET_HELL_MISSIONS: MissionSelection = {
categories: ['bullet_hell'],
requireAllowed: ['aircraft'],
};
export const NUCLEAR_ESCALATION_MISSIONS: MissionSelection = {
categories: ['nuclear_escalation'],
requireAllowed: ['aircraft'],
};
export const NAVAL_EC_MISSIONS: MissionSelection = {
categories: ['naval_n2m'],
requireAllowed: ['ship'],
};
@@ -0,0 +1,32 @@
/**
* Player-versus-AI modes, shown in the game-mode selection (display type pve_battle).
*
* The game has no stock mode names for these; the display names are the game's own texts:
* "chapters/assault" (Air Assault), "chapters/air_ground_PvE" (Assault) and
* "missions/helicopter_event_arcade". Missions:
* - air assault: the "*_survive_arcade_pve" missions of the "pve" category;
* - ground assault: the "*battle_for_survival_8_players_pve" missions of the same category
* (they do not state their vehicle types, so none is required of them);
* - helicopters: the "air_h2m" category (helicopter PvE missions).
*/
import type { GameModeDeclaration } from './game-mode-declaration.ts';
const PVE = { difficulty: 'arcade', displayType: 'pve_battle' } as const;
export const PVE_BATTLES: readonly GameModeDeclaration[] = [
{
gameModeId: 21, name: 'air_assault_pve', economicName: 'air_assault_pve', locName: 'chapters/assault', ...PVE,
requiredClass: 'aircraft', allowedClasses: ['aircraft'],
missions: { categories: ['pve'], requireAllowed: ['aircraft'], include: /_survive_arcade_pve$/i },
},
{
gameModeId: 22, name: 'tank_assault_pve', economicName: 'tank_assault_pve', locName: 'chapters/air_ground_PvE', ...PVE,
requiredClass: 'tank', allowedClasses: ['tank'],
missions: { categories: ['pve'], requireAllowed: [], include: /battle_for_survival_8_players_pve$/i },
},
{
gameModeId: 23, name: 'helicopter_pve_arcade', economicName: 'helicopter_pve_arcade', locName: 'missions/helicopter_event_arcade', ...PVE,
requiredClass: 'helicopter', allowedClasses: ['helicopter'],
missions: { categories: ['air_h2m'], requireAllowed: ['helicopter'] },
},
];
@@ -0,0 +1,52 @@
/**
* Random battles: shown in the game-mode selection. Names are the stock ones the UI scripts
* know (scripts/events/eventInfo.nut eventIdsForMainGameModeList,
* scripts/gameModes/gameModeManagerState.nut, scripts/gameModes/psnActivities.nut); display
* names are the game's "missions/<mode>_event_<difficulty>" texts (lang menu_events.csv).
* Economic names are the keys the game's per-event tables use: char.vromfs.bin config/rank.blk
* ExpSkillBonus{} and aces.vromfs.bin config/gameplay.blk RandomSpawnUnits{}, which the stock
* scripts read through getEventEconomicName (scripts/statistics/mpstatistics.nut,
* scripts/unit/randomunitsforceweapon.nut).
*
* `minMRankForSmallTeamsBattles` (27 = BR 10.0, Air RB) and `minMRankForNightBattles`
* (27 = BR 10.0, Ground RB) come from `scripts/events/secondgamemodesutils.nut:25-26`,
* `scripts/unlocks/personalunlocks.nut:12`, and `config/unlocks.blk` (`title_prowler_in_the_night`).
*/
import type { GameModeDeclaration } from './game-mode-declaration.ts';
import { AIR_BATTLE_MISSIONS, GROUND_BATTLE_MISSIONS, NAVAL_BATTLE_MISSIONS } from './mission-pools.ts';
const AIR_REALISTIC_SMALL_TEAMS_MIN_MRANK = 27;
const GROUND_REALISTIC_NIGHT_MIN_MRANK = 27;
const AIR = { requiredClass: 'aircraft', allowedClasses: ['aircraft'], missions: AIR_BATTLE_MISSIONS } as const;
const GROUND = { requiredClass: 'tank', allowedClasses: ['tank', 'aircraft', 'helicopter'], missions: GROUND_BATTLE_MISSIONS } as const;
const NAVAL = { requiredClass: 'ship', allowedClasses: ['ship', 'aircraft'], missions: NAVAL_BATTLE_MISSIONS } as const;
export const RANDOM_BATTLES: readonly GameModeDeclaration[] = [
{
gameModeId: 1, name: 'air_arcade', economicName: 'air_arcade', locName: 'missions/air_event_arcade',
difficulty: 'arcade', displayType: 'random_battle', ...AIR,
},
{
gameModeId: 2, name: 'air_realistic', economicName: 'air_realistic', locName: 'missions/air_event_historical',
difficulty: 'realistic', displayType: 'random_battle', multiSlot: false,
minMRankForSmallTeamsBattles: AIR_REALISTIC_SMALL_TEAMS_MIN_MRANK, ...AIR,
},
{
gameModeId: 3, name: 'tank_event_in_random_battles_arcade', economicName: 'tank_event_in_random_battles_arcade',
locName: 'missions/tank_event_in_random_battles_arcade', difficulty: 'arcade', displayType: 'random_battle', ...GROUND,
},
{
gameModeId: 4, name: 'tank_event_in_random_battles_historical', economicName: 'tank_random_battles_historical_base',
locName: 'missions/tank_event_in_random_battles_historical', difficulty: 'realistic', displayType: 'random_battle',
minMRankForNightBattles: GROUND_REALISTIC_NIGHT_MIN_MRANK, ...GROUND,
},
{
gameModeId: 5, name: 'ship_event_in_random_battles_arcade', economicName: 'ship_event_in_random_battles_arcade',
locName: 'missions/ship_event_arcade', difficulty: 'arcade', displayType: 'random_battle', ...NAVAL,
},
{
gameModeId: 6, name: 'ship_event_in_random_battles_realistic', economicName: 'ship_event_in_random_battles_realistic',
locName: 'missions/ship_event_historical', difficulty: 'realistic', displayType: 'random_battle', ...NAVAL,
},
];
@@ -0,0 +1,33 @@
/**
* Simulator battles: listed in the events window under the "simulation_battles" chapter,
* which is what the stock "Simulator Battles" tile opens and what lights it up
* (scripts/gameModes/gameModeManagerState.nut, custom_mode_fullreal).
*
* Air and ground use the stock names that have short display texts in the game
* ("missions/short/air_simulation_timeDelay_battles", "missions/short/tank_random_battles_simulation");
* the game has no stock name for naval simulator battles, so that one is named after its
* display text "missions/ship_event_simulator". The ground economic name is the rank.blk
* ExpSkillBonus{} key (see random-battles.ts).
*/
import type { GameModeDeclaration } from './game-mode-declaration.ts';
import { AIR_BATTLE_MISSIONS, GROUND_BATTLE_MISSIONS, NAVAL_BATTLE_MISSIONS } from './mission-pools.ts';
const SIMULATOR = { difficulty: 'simulator', displayType: 'regular', chapter: 'simulation_battles' } as const;
export const SIMULATOR_BATTLES: readonly GameModeDeclaration[] = [
{
gameModeId: 11, name: 'air_simulation_timeDelay_battles', economicName: 'air_simulation_timeDelay_battles',
locName: 'missions/air_simulation_timeDelay_battles', ...SIMULATOR,
requiredClass: 'aircraft', allowedClasses: ['aircraft'], missions: AIR_BATTLE_MISSIONS,
},
{
gameModeId: 12, name: 'tank_random_battles_simulation', economicName: 'tank_event_in_random_battles_simulation',
locName: 'missions/tank_event_in_random_battles_simulator', ...SIMULATOR,
requiredClass: 'tank', allowedClasses: ['tank', 'aircraft', 'helicopter'], missions: GROUND_BATTLE_MISSIONS,
},
{
gameModeId: 13, name: 'ship_event_simulator', economicName: 'ship_event_simulator',
locName: 'missions/ship_event_simulator', ...SIMULATOR,
requiredClass: 'ship', allowedClasses: ['ship', 'aircraft'], missions: NAVAL_BATTLE_MISSIONS,
},
];
@@ -0,0 +1,17 @@
/**
* Events shown in the events window.
*
* The Great War: the two First World War missions of the "test" category of
* config/mislist.blk (great_war_Dom, great_war_inv_Dom). Display name: the game's
* "loading_bg/login_layer_the_great_war" text.
*/
import type { GameModeDeclaration } from './game-mode-declaration.ts';
export const SPECIAL_EVENTS: readonly GameModeDeclaration[] = [
{
gameModeId: 31, name: 'great_war_event', economicName: 'great_war_event', locName: 'loading_bg/login_layer_the_great_war',
difficulty: 'arcade', displayType: 'regular', chapter: 'special_events',
requiredClass: 'tank', allowedClasses: ['tank', 'aircraft'],
missions: { categories: ['test'], requireAllowed: ['tank'], include: /^great_war_/i },
},
];
@@ -0,0 +1,119 @@
/**
* Stock 2.61.0.37 sub-game-modes (`secondGameModesPanel`, `scripts/matching/matchinggamemodes.nut:28-42`
* and `scripts/events/secondgamemodesutils.nut:25-30, 355-390, 606-654`):
*
* Each sub-mode shares its parent mode's `name` and `economicName` (`matchinggamemodes.nut:74-77, 93`
* and `config/unlocks.blk` `title_prowler_in_the_night`), while carrying its stock `tag` prefix so:
* - `matchingGameModes.notifyGmChanged()` excludes it from the top-level mode drawer (`isSubGameMode`);
* - `mapPreferencesParams.getMapsListImpl()` excludes it from the parent mode's map-ban list;
* - `secondGameModesUtils.nut` binds each toggle strictly to the matching `economicName` (Ground RB
* only gets Night Battles; Air RB gets Nuclear Escalation, Tactical Skies, and Bullet Hell; Naval
* AB/RB get Enduring Confrontation; Ground AB and Air AB get none);
* - `queueEvent.nut` includes or excludes its `gameModeId` in `match.enqueue` `game_modes_list`.
*/
import type { GameModeDeclaration } from './game-mode-declaration.ts';
import {
AIR_BATTLE_MISSIONS,
BULLET_HELL_MISSIONS,
GROUND_BATTLE_MISSIONS,
NAVAL_EC_MISSIONS,
NUCLEAR_ESCALATION_MISSIONS,
} from './mission-pools.ts';
/** Protocol thresholds defined in `scripts/events/secondgamemodesutils.nut:25-30`. */
const MIN_MRANK_NIGHT_BATTLES = 27;
const MIN_MRANK_SMALL_TEAMS = 27;
const MIN_MRANK_BULLET_HELL = 22;
const MIN_CRAFTS_BULLET_HELL = 2;
const MIN_MRANK_NUCLEAR_ESCALATION = 23;
const MIN_MRANK_NAVAL_EC = 7;
export const SUB_GAME_MODES: readonly GameModeDeclaration[] = [
{
gameModeId: 101,
name: 'tank_event_in_random_battles_historical',
tag: 'regular_with_night_tank_realistic',
economicName: 'tank_random_battles_historical_base',
locName: 'missions/tank_event_in_random_battles_historical',
difficulty: 'realistic',
displayType: 'random_battle',
minQueueMrank: MIN_MRANK_NIGHT_BATTLES,
environmentOverride: 'Night',
requiredClass: 'tank',
allowedClasses: ['tank', 'aircraft', 'helicopter'],
missions: GROUND_BATTLE_MISSIONS,
},
{
gameModeId: 102,
name: 'air_realistic',
tag: 'small_teams_air_realistic',
economicName: 'air_realistic',
locName: 'missions/air_event_historical',
difficulty: 'realistic',
displayType: 'random_battle',
multiSlot: false,
teamSizeOverride: { min: 6, max: 12 },
minQueueMrank: MIN_MRANK_SMALL_TEAMS,
isSmallTeams: true,
requiredClass: 'aircraft',
allowedClasses: ['aircraft'],
missions: AIR_BATTLE_MISSIONS,
},
{
gameModeId: 103,
name: 'air_realistic',
tag: 'nuclear_escalation_air_realistic',
economicName: 'air_realistic',
locName: 'missions/air_event_historical',
difficulty: 'realistic',
displayType: 'random_battle',
allowedCraftMinMrank: { aircraft: MIN_MRANK_NUCLEAR_ESCALATION },
minQueueMrank: MIN_MRANK_NUCLEAR_ESCALATION,
requiredClass: 'aircraft',
allowedClasses: ['aircraft'],
missions: NUCLEAR_ESCALATION_MISSIONS,
},
{
gameModeId: 104,
name: 'air_realistic',
tag: 'bullet_hell_air_realistic',
economicName: 'air_realistic',
locName: 'missions/air_event_historical',
difficulty: 'realistic',
displayType: 'random_battle',
minCraftsToPlay: MIN_CRAFTS_BULLET_HELL,
allowedCraftMinMrank: { aircraft: MIN_MRANK_BULLET_HELL },
minQueueMrank: MIN_MRANK_BULLET_HELL,
requiredClass: 'aircraft',
allowedClasses: ['aircraft'],
missions: BULLET_HELL_MISSIONS,
},
{
gameModeId: 105,
name: 'ship_event_in_random_battles_arcade',
tag: 'naval_ec_ab_ship_arcade',
economicName: 'ship_event_in_random_battles_arcade',
locName: 'missions/ship_event_arcade',
difficulty: 'arcade',
displayType: 'random_battle',
allowedCraftMinMrank: { ship: MIN_MRANK_NAVAL_EC },
minQueueMrank: MIN_MRANK_NAVAL_EC,
requiredClass: 'ship',
allowedClasses: ['ship', 'aircraft'],
missions: NAVAL_EC_MISSIONS,
},
{
gameModeId: 106,
name: 'ship_event_in_random_battles_realistic',
tag: 'naval_ec_rb_ship_realistic',
economicName: 'ship_event_in_random_battles_realistic',
locName: 'missions/ship_event_historical',
difficulty: 'realistic',
displayType: 'random_battle',
allowedCraftMinMrank: { ship: MIN_MRANK_NAVAL_EC },
minQueueMrank: MIN_MRANK_NAVAL_EC,
requiredClass: 'ship',
allowedClasses: ['ship', 'aircraft'],
missions: NAVAL_EC_MISSIONS,
},
];
+77
View File
@@ -0,0 +1,77 @@
/**
* The game modes the local matching server offers: the catalogue's modes, each filled in
* from the game's own files at start-up. A mode none of whose missions are in the player's
* game files is left out (and reported), since it could not be played.
*
* The same object will serve the battle flow later (docs/implementation notes): which missions
* and team rules a chosen mode has.
*/
import type { MissionHeader, MultiplayerMissions } from '../game-data/datasets/multiplayer-missions.ts';
import { GAME_MODE_CATALOGUE } from './catalogue/catalogue.ts';
import type { GameModeDeclaration } from './catalogue/game-mode-declaration.ts';
import { selectMissions } from './mission-pool.ts';
import { buildModeDefinition, type ModeDefinition } from './mode-definition.ts';
export interface OfferedGameMode {
readonly declaration: GameModeDeclaration;
readonly missions: readonly MissionHeader[];
readonly definition: ModeDefinition;
}
export class GameModes {
readonly #byId = new Map<number, OfferedGameMode>();
readonly #byName = new Map<string, OfferedGameMode>();
readonly #byEconomicName = new Map<string, OfferedGameMode[]>();
readonly #countries: readonly string[];
constructor(missions: MultiplayerMissions, countries: readonly string[], report: (line: string) => void,
catalogue: readonly GameModeDeclaration[] = GAME_MODE_CATALOGUE) {
this.#countries = [...countries];
for (const mode of catalogue) {
const selected = selectMissions(mode.missions, missions);
if (selected.length === 0) {
report(`game mode ${mode.name}${mode.tag ? `.${mode.tag}` : ''}: no missions in the game files, left out`);
continue;
}
const offered: OfferedGameMode = {
declaration: mode,
missions: selected,
definition: buildModeDefinition(mode, selected, countries),
};
this.#byId.set(mode.gameModeId, offered);
if (!mode.tag) this.#byName.set(mode.name, offered);
const group = this.#byEconomicName.get(mode.economicName) ?? [];
group.push(offered);
this.#byEconomicName.set(mode.economicName, group);
}
report(`game modes: ${this.#byId.size} of ${catalogue.length} offered`);
}
ids(): number[] {
return [...this.#byId.keys()];
}
countries(): readonly string[] {
return this.#countries;
}
byId(id: number): OfferedGameMode | undefined {
return this.#byId.get(id);
}
byName(name: string): OfferedGameMode | undefined {
return this.#byName.get(name);
}
byEconomicName(economicName: string): readonly OfferedGameMode[] {
return this.#byEconomicName.get(economicName) ?? [];
}
/** Definitions of the known ids among those asked for, in the order asked. */
definitions(ids: readonly number[]): ModeDefinition[] {
return ids.flatMap((id): ModeDefinition[] => {
const offered = this.#byId.get(id);
return offered ? [offered.definition] : [];
});
}
}
@@ -0,0 +1,30 @@
/** Choose a mode's missions from the game's multiplayer missions (docs/implementation notes). */
import type { MissionHeader, MultiplayerMissions } from '../game-data/datasets/multiplayer-missions.ts';
import type { MissionSelection, UnitClass } from './catalogue/game-mode-declaration.ts';
/** The switch a mission's mission_settings/mission/allowedUnitTypes block uses for each class. */
const ALLOWED_SWITCH: Readonly<Record<UnitClass, string>> = {
aircraft: 'isAirplanesAllowed',
tank: 'isTanksAllowed',
ship: 'isShipsAllowed',
helicopter: 'isHelicoptersAllowed',
};
/** The selected missions in the order the game lists them, without repeats. */
export function selectMissions(selection: MissionSelection, index: MultiplayerMissions): MissionHeader[] {
const chosen = new Map<string, MissionHeader>();
for (const category of index.categories) {
if (!selection.categories.includes(category.name)) continue;
for (const name of category.missions) {
const mission = index.missions[name];
if (mission && !chosen.has(name) && matches(selection, mission)) chosen.set(name, mission);
}
}
return [...chosen.values()];
}
function matches(selection: MissionSelection, mission: MissionHeader): boolean {
if (selection.include && !selection.include.test(mission.name)) return false;
if (selection.exclude?.test(mission.name)) return false;
return selection.requireAllowed.every((unitClass) => mission.allowedUnitTypes[ALLOWED_SWITCH[unitClass]] === true);
}
@@ -0,0 +1,98 @@
/**
* A game mode in the form the stock UI reads from the matching server
* (match.fetch_game_modes_info, docs/implementation notes):
*
* - difficulty: the matching name (scripts/difficulty.nut matchingName: arcade, realistic,
* simulation); mission_decl.difficulty: the mission name of the same difficulty
* (arcade, realistic, hardcore; scripts/events/eventsManager.nut diffTable).
* - teamA / teamB: identical, so the UI treats the mode as symmetric
* (scripts/events/eventTeamsInfo.nut initSidesOnce); a missing team B would count as
* playable and mark the mode invalid. Craft rules name a vehicle class; requiredCrafts
* is what greys the mode out for a player without that class (gameModeManagerState.nut
* createEventGameMode).
* - mission_decl.missions_list: mission name -> {} (a value may carry "enableIf" rank
* limits, scripts/missions/mapPreferencesParams.nut; none are set).
* - tag: required, the script reads it unguarded (scripts/matching/matchingGameModes.nut,
* onGameModesUpdated; local verification stopped there without it). Tag prefixes mark sub-modes
* (night battles, small teams, bullet hell, nuclear escalation, naval EC;
* SUB_GAME_MODE_TAG_PREFIXES in matchingGameModes.nut:28-42).
* - rankCalcMode: required, read unguarded when the slotbar computes the lineup's battle
* rating (scripts/slotbar/slotbarPresets/calcRanks.nut calculateBR; local verification).
* "average" or "maximum" (lang: multiplayer/battleRatingCalcHint/*); random battles
* take the highest battle rating of the lineup.
*
* Fields the stock scripts read unguarded only in later stages are not set yet:
* suggestToChangeTeamOnQueueDisbalanceSec (queueing for an event, eventsHandler.nut) and
* missionsBanMode (map preferences; absent means none, mapPreferencesParams.nut).
*/
import type { MissionHeader } from '../game-data/datasets/multiplayer-missions.ts';
import type { GameModeDeclaration, ModeDifficulty } from './catalogue/game-mode-declaration.ts';
const MATCHING_DIFFICULTY: Readonly<Record<ModeDifficulty, string>> = {
arcade: 'arcade',
realistic: 'realistic',
simulator: 'simulation',
};
export const MISSION_DIFFICULTY: Readonly<Record<ModeDifficulty, string>> = {
arcade: 'arcade',
realistic: 'realistic',
simulator: 'hardcore',
};
export type ModeDefinition = Readonly<Record<string, unknown>>;
export function buildModeDefinition(mode: GameModeDeclaration, missions: readonly MissionHeader[],
countries: readonly string[]): ModeDefinition {
const minTeamSize = mode.teamSizeOverride?.min ?? 1;
const maxTeamSize = mode.teamSizeOverride?.max ?? teamSize(mode, missions);
const team = {
countries: [...countries],
allowedCrafts: mode.allowedClasses.map((unitClass) => {
const minMrank = mode.allowedCraftMinMrank?.[unitClass];
return minMrank === undefined
? { class: unitClass }
: { class: unitClass, mranks: { min: minMrank } };
}),
requiredCrafts: [{ class: mode.requiredClass }],
minTeamSize,
maxTeamSize,
};
return {
gameModeId: mode.gameModeId,
name: mode.name,
tag: mode.tag ?? '',
economicName: mode.economicName,
loc_name: mode.locName,
difficulty: MATCHING_DIFFICULTY[mode.difficulty],
rankCalcMode: 'maximum',
displayType: mode.displayType,
multiSlot: mode.multiSlot ?? true,
minTeamSize,
...(mode.chapter === undefined ? {} : { chapter: mode.chapter }),
...(mode.minCraftsToPlay === undefined ? {} : { minCraftsToPlay: mode.minCraftsToPlay }),
...(mode.minMRankForNightBattles === undefined ? {} : { minMRankForNightBattles: mode.minMRankForNightBattles }),
...(mode.minMRankForSmallTeamsBattles === undefined ? {} : { minMRankForSmallTeamsBattles: mode.minMRankForSmallTeamsBattles }),
visible: true,
disabled: false,
teamA: team,
teamB: structuredClone(team),
mission_decl: {
difficulty: MISSION_DIFFICULTY[mode.difficulty],
missions_list: Object.fromEntries(missions.map((mission) => [mission.name, {}])),
},
};
}
/**
* The fewest player spawn slots per side among the missions, so every mission can hold a
* full team. A side without player slots is the AI side of a PvE mission and is not counted.
*/
function teamSize(mode: GameModeDeclaration, missions: readonly MissionHeader[]): number {
const slots = missions.flatMap(({ playerSlots: { teamA, teamB } }) => {
const sides = [teamA, teamB].filter((count) => count > 0);
return sides.length ? [Math.min(...sides)] : [];
});
if (!slots.length) throw new Error(`game mode ${mode.name}: none of its missions lists player spawn slots`);
return Math.min(...slots);
}