Files
WT-Offline/apps/server/src/matching/battle-launch-notify.ts
T
N0VAN0M4LY d0e4797fe7 feat(battle): add Nuclear Escalation tactical and strategic nuclear carriers
Connect stage-unlocked nuclear carriers to Air Realistic sub-mode 103
(Nuclear Escalation) and expose a player toggle for stage-3 megaton
strategic bombers:

- Dataset & profile grants: extract tactical killstreak nuclear carriers
  (5 kt / 30 kt Nuclear Escalation presets) and megaton strategic bombers
  (nt_b_52h / nt_tu_95m) from wpcost.blk in battle-spawn-rules (v4), and
  grant their required weapon/modification records in
  support-plane-modifications.ts.
- Server slot selection & tuning: add nuclearEscalationStrategicBombers
  (default true) in tuning/battle.jsonc, battle-tuning.ts, and
  launcher-tuning.ts; add one nation-matched tactical carrier per session
  rank bracket (with allowedWeapons limited to its Nuclear Escalation
  presets) and, when enabled, one stage-3 strategic bomber to
  extraBattleSlots; include modeTag in battle launch notifications.
- GUI patch & launcher UI: add battle/filter-extra-slot-weapons on
  scripts/weaponry/weaponryinfo.nut to filter extra-slot presets by
  allowedWeapons (hiding Ground RB zero-yield presets at stage 0) and to
  fall back to LocalMP launch metadata for GameModeRestrictions; expose
  the strategic bomber toggle in the launcher Battle tuning section.

Verified with root and launcher typechecks, launcher build, full
check-gui on 2.61.0.37 and 2.61.0.58 (49 patches across 37 .nut files),
and slot selection check across all 10 nations on 2.61.0.58 stock data;
pending in-game verification.
2026-12-02 23:03:15 +08:00

92 lines
3.6 KiB
TypeScript

/**
* The `mrpc.generic_notify` message that starts a local battle (`from: "wto_battle"`,
* `func: "launch"`), received by the client's launch script patch
* (patches/gui/battle/launch-local-battle-from-queue).
*
* - `mission`: the complete mission settings for `select_training_mission`, as a typed tree
* `{ p: [[name, type, value], ...], b: [[name, node], ...] }` with type "t", "i", "r" or "b".
* Matching notifications are JSON, which cannot tell 1 from 1.0; the engine reads ints and reals
* with typed getters, so the type travels with every value. Repeated blocks stay separate.
* - `lobby`: the session lobby settings the client's own room scripts read during the battle
* (game mode and both sides' countries).
* - `battle`: what the client keeps for this battle (session id for the settlement, extra slots,
* `spawnScore` for Ground Realistic Battles, and `awards` for the in-battle reward banner).
*/
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';
type WireParam = readonly [name: string, type: 't' | 'i' | 'r' | 'b', value: string | number | boolean];
interface WireBlock {
readonly p: readonly WireParam[];
readonly b: ReadonlyArray<readonly [name: string, block: WireBlock]>;
}
export interface BattleLaunchNotify extends Record<string, unknown> {
readonly from: 'wto_battle';
readonly func: 'launch';
readonly mission: WireBlock;
readonly lobby: Readonly<Record<string, unknown>>;
readonly battle: Readonly<Record<string, unknown>>;
}
export function battleLaunchNotify(
plan: BattleLaunchPlan,
awards: BannerParams,
scores: Readonly<Record<string, number>>,
): BattleLaunchNotify {
return {
from: 'wto_battle',
func: 'launch',
mission: toWire(battleMissionSettings(plan, scores)),
lobby: {
game_mode_id: plan.modeId,
game_mode_name: plan.modeName,
economicName: plan.economicName,
symmetricTeams: plan.symmetricTeams,
country_allies: plan.countriesAllies.map(withCountryPrefix),
country_axis: plan.countriesAxis.map(withCountryPrefix),
mission: {
name: plan.missionName,
difficulty: plan.difficulty,
...(plan.maxRespawns === undefined ? {} : { maxRespawns: plan.maxRespawns }),
},
},
battle: {
sessionId: plan.sessionId,
modeName: plan.modeName,
...(plan.modeTag ? { modeTag: plan.modeTag } : {}),
economicName: plan.economicName,
country: plan.country,
missionName: plan.missionName,
...(plan.selectedSlot ? { selectedSlot: plan.selectedSlot } : {}),
extraBattleSlots: plan.extraBattleSlots,
...(plan.spawnScore ? { spawnScore: plan.spawnScore } : {}),
awards,
},
};
}
function toWire(block: BlkBlock): WireBlock {
return {
p: block.params.map((param) => [param.name, ...wireValue(param.name, param.value)] as const),
b: block.blocks.map((child) => [child.name, toWire(child)] as const),
};
}
function wireValue(name: string, value: BlkValue): readonly ['t' | 'i' | 'r' | 'b', string | number | boolean] {
switch (value.type) {
case 'string': return ['t', value.value];
case 'int': return ['i', value.value];
case 'real': return ['r', value.value];
case 'bool': return ['b', value.value];
default: throw new Error(`mission settings parameter ${name} has type ${value.type}, which the launch message cannot carry`);
}
}
function withCountryPrefix(country: string): string {
return country.startsWith('country_') ? country : `country_${country}`;
}