fix(battle): present extra lineup slots as ordinary vehicles

The live game draws one vehicle from each RandomSpawnUnits group at
launch and shows it as a plain lineup vehicle (a 12.7 US lineup gets an
M1A1 12.0 and an ADATS 12.0, no dice), so the random_units state and the
patch that filled it are gone. The strike UCAV costs 750 spawn points,
the live game's value, now in tuning/battle.jsonc.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 07:28:48 +08:00
1 parent e3c5880023
commit 9f28a84cd3
12 files changed
+41 -94

No files matched your search

@@ -1,5 +1,5 @@
// Add the extra vehicles the local service chose for a LocalMP battle (nuclear carrier, strike UCAV, // Add the extra vehicles the local service chose for a LocalMP battle (nuclear carrier, strike UCAV,
// random tank / SPAA / naval aircraft) to the in-battle crew list. // the RandomSpawnUnits tank / SPAA / naval aircraft) to the in-battle crew list.
// Why the client: online the battle server adds them to the player's crews; a LocalMP host has no // Why the client: online the battle server adds them to the player's crews; a LocalMP host has no
// battle server, and the in-battle crew list comes from the native get_crew_info. // battle server, and the in-battle crew list comes from the native get_crew_info.
// Without it: the lineup holds only the player's own vehicles. // Without it: the lineup holds only the player's own vehicles.
@@ -1,7 +1,7 @@
// Lock the weapon preset the local service set for an extra LocalMP vehicle (the nuclear carrier's // Lock the weapon preset the local service set for an extra LocalMP vehicle (the nuclear carrier's
// bomb, the RandomSpawnUnits forceWeapon). // bomb, the RandomSpawnUnits forceWeapon of a naval extra aircraft).
// Why the client: online getForcedUnitWeapon finds the random vehicle's weapon through the room // Why the client: online the battle server sends the extra vehicles with their weapon; on a LocalMP
// event, which a LocalMP host does not have, and the nuclear carrier comes from the server. // host the local service chooses them, and getForcedUnitWeapon only knows mission and room data.
// Without it: the extra vehicles spawn with whatever preset the respawn screen picks. // Without it: the extra vehicles spawn with whatever preset the respawn screen picks.
{ {
"id": "battle/force-extra-slot-weapons", "id": "battle/force-extra-slot-weapons",
@@ -1,6 +1,6 @@
function getForcedUnitWeapon(unit) { function getForcedUnitWeapon(unit) {
// WTOffline: the extra slots the local service added to a LocalMP lineup carry their forced // WTOffline: the extra vehicles the local service added to a LocalMP lineup carry their forced
// weapon (nuclear carrier, RandomSpawnUnits forceWeapon); online the room event resolves it. // weapon (nuclear carrier, RandomSpawnUnits forceWeapon); online the battle server sends it.
foreach (wtoSlot in (require("nestdb").ndbTryRead(["wto", "activeBattle"])?.extraBattleSlots ?? [])) foreach (wtoSlot in (require("nestdb").ndbTryRead(["wto", "activeBattle"])?.extraBattleSlots ?? []))
if (wtoSlot?.unitName == unit.name && (wtoSlot?.forceWeapon ?? "") != "") if (wtoSlot?.unitName == unit.name && (wtoSlot?.forceWeapon ?? "") != "")
return wtoSlot.forceWeapon return wtoSlot.forceWeapon
@@ -1,3 +0,0 @@
function getMyStateBlk() {
return get_user_custom_state(userIdInt64.get(), false)
}
@@ -1,22 +0,0 @@
// Fill the local player's random_units state with the options of each random vehicle group the
// local service drew for a LocalMP battle.
// Why the client: online the battle server writes it into the player's custom state; the stock
// slotbar reads it for the dice icon, the group name, the BR range and the list of options.
// Without it: the random vehicles look like plain lineup vehicles.
{
"id": "battle/populate-random-spawn-units-state",
"title": "Fill the random_units state of the local player in LocalMP",
"file": "scripts/miscustomrules/rulebase.nut",
"features": [
"K-补充载具"
],
"verified_on": [
"2.61.0.37"
],
"edits": [
{
"find": "find.nut",
"replace": "replace.nut"
}
]
}
@@ -1,21 +0,0 @@
function getMyStateBlk() {
let wtoUid = userIdInt64.get()
local wtoStateBlk = get_user_custom_state(wtoUid, false)
let { ndbTryRead } = require("nestdb")
let wtoRandom = ndbTryRead(["wto", "activeBattle"])?.randomUnits
if (wtoRandom == null || wtoRandom.len() == 0)
return wtoStateBlk
if (wtoStateBlk == null)
wtoStateBlk = get_user_custom_state(wtoUid, true) ?? DataBlock()
if (wtoStateBlk?.random_units == null) {
let wtoRuBlk = wtoStateBlk.addNewBlock("random_units")
foreach (wtoGroupName, wtoUnits in wtoRandom) {
if (wtoUnits == null || wtoUnits.len() == 0)
continue
let wtoGroupBlk = wtoRuBlk.addNewBlock(wtoGroupName)
foreach (wtoUnitName in wtoUnits)
wtoGroupBlk[wtoUnitName] = true
}
}
return wtoStateBlk
}
@@ -5,16 +5,19 @@
* name; the preset whose rankRange holds the session's top rank, the unit of the player's * 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. * 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 * - Strike UCAV: wpcost.blk ucav_*_killstreak of the player's country. The game files have no rule
* for when it is offered; that is offline design in tuning/battle.jsonc. Its spawn cost comes * for when it is offered or what it costs; both are in tuning/battle.jsonc (the cost as seen in
* from the stock spawn score formula. * the live game, the offer rule offline design).
* - Random vehicles (dice slots): gameplay.blk RandomSpawnUnits, keyed by the event economic name, * - Extra vehicles from gameplay.blk RandomSpawnUnits, keyed by the event economic name: one
* one slot per group of the player's country. Rules from the official changelog ("Line of * vehicle per group of the player's country (ground RB: a tank and an SPAA), drawn at launch and
* Contact", 2025-12-16): offered to lineups of BR 9.3 and higher (the groups' minPlayerMRank), * shown in the lineup as a plain vehicle, as the live game does (a 12.7 US lineup received an
* with no condition on what the lineup holds; the options depend on the player's BR and the * M1A1 12.0 and an ADATS 12.0, no dice; screenshot of the live game). Rules from the official
* session's BR and never include the session's top BR; when no vehicle fits, lower BR vehicles * changelog ("Line of Contact", 2025-12-16): offered to lineups of BR 9.3 and higher (the
* are used. Worked examples there: in a 9.7-10.7 session a player at 10.7 gets 9.7-10.3 and a * groups' minPlayerMRank), with no condition on what the lineup holds; the vehicle depends on the
* player at 9.7 gets 9.3-10.0. The window formula is not published; `randomWindow` is fitted to * player's BR and the session's BR and is never of the session's top BR; when no vehicle fits,
* those examples with the group's own parameters (inferred, see there). * 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 { randomInt } from 'node:crypto';
import type { import type {
@@ -40,7 +43,7 @@ export interface ExtraBattleSlot {
/** The modifications enabled when not `allModifications`; the unit is otherwise stock. */ /** The modifications enabled when not `allModifications`; the unit is otherwise stock. */
readonly modifications: readonly string[]; readonly modifications: readonly string[];
readonly forceWeapon?: string; readonly forceWeapon?: string;
/** The RandomSpawnUnits group the slot was drawn from (a dice slot). */ /** The RandomSpawnUnits group the vehicle was drawn from. */
readonly groupName?: string; readonly groupName?: string;
} }
@@ -53,18 +56,12 @@ export interface ExtraBattleSlotsInput {
readonly sessionMaxMrank: number; readonly sessionMaxMrank: number;
readonly vehiclesByName: ReadonlyMap<string, CatalogueVehicle>; readonly vehiclesByName: ReadonlyMap<string, CatalogueVehicle>;
readonly rules: BattleSpawnRulesData; readonly rules: BattleSpawnRulesData;
readonly tuning: Pick<BattleTuning, 'strikeUcavModes' | 'strikeUcavSessionMrankAllowance'>; readonly tuning: Pick<BattleTuning, 'strikeUcavModes' | 'strikeUcavSessionMrankAllowance' | 'strikeUcavSpawnScore'>;
} }
export interface ExtraBattleSlotsPlan { export function selectExtraBattleSlots(input: ExtraBattleSlotsInput): readonly ExtraBattleSlot[] {
readonly extraBattleSlots: readonly ExtraBattleSlot[];
/** The `random_units` state of the player: every option of each drawn group, by group name. */
readonly randomUnits: Readonly<Record<string, readonly string[]>>;
}
export function selectExtraBattleSlots(input: ExtraBattleSlotsInput): ExtraBattleSlotsPlan {
const room = MAX_BATTLE_CREW_SLOTS - input.slotVehicles.length; const room = MAX_BATTLE_CREW_SLOTS - input.slotVehicles.length;
if (input.declaration.multiSlot === false || room <= 0) return { extraBattleSlots: [], randomUnits: {} }; if (input.declaration.multiSlot === false || room <= 0) return [];
const slots: ExtraBattleSlot[] = []; const slots: ExtraBattleSlot[] = [];
const supportPlane = supportPlaneSlot(input); const supportPlane = supportPlaneSlot(input);
@@ -72,12 +69,10 @@ export function selectExtraBattleSlots(input: ExtraBattleSlotsInput): ExtraBattl
const ucav = strikeUcavSlot(input); const ucav = strikeUcavSlot(input);
if (ucav) slots.push(ucav); if (ucav) slots.push(ucav);
const randomUnits: Record<string, readonly string[]> = {};
for (const group of input.rules.randomSpawnUnits[input.declaration.economicName]?.[input.country] ?? []) { for (const group of input.rules.randomSpawnUnits[input.declaration.economicName]?.[input.country] ?? []) {
const options = randomGroupOptions(group, input); const options = randomGroupOptions(group, input);
if (options.length === 0) continue; if (options.length === 0) continue;
const chosen = options[randomInt(options.length)]!; const chosen = options[randomInt(options.length)]!;
randomUnits[group.name] = options.map((unit) => unit.unitName);
slots.push({ slots.push({
unitName: chosen.unitName, unitName: chosen.unitName,
allModifications: false, allModifications: false,
@@ -87,12 +82,7 @@ export function selectExtraBattleSlots(input: ExtraBattleSlotsInput): ExtraBattl
}); });
} }
const kept = slots.slice(0, room); return slots.slice(0, room);
const keptGroups = new Set(kept.flatMap((slot) => slot.groupName ?? []));
return {
extraBattleSlots: kept,
randomUnits: Object.fromEntries(Object.entries(randomUnits).filter(([name]) => keptGroups.has(name))),
};
} }
function supportPlaneSlot(input: ExtraBattleSlotsInput): ExtraBattleSlot | undefined { function supportPlaneSlot(input: ExtraBattleSlotsInput): ExtraBattleSlot | undefined {
@@ -117,14 +107,18 @@ function strikeUcavSlot(input: ExtraBattleSlotsInput): ExtraBattleSlot | undefin
const ucavMrank = vehicleMrank(vehicle, input.declaration.difficulty, input.declaration.requiredClass); const ucavMrank = vehicleMrank(vehicle, input.declaration.difficulty, input.declaration.requiredClass);
if (input.sessionMaxMrank < ucavMrank - input.tuning.strikeUcavSessionMrankAllowance) return undefined; 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). // Offline design: the UCAV comes fully upgraded and keeps its weapon choice (the game files force no preset).
return { unitName: ucav.unitName, allModifications: true, modifications: [] }; 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, * 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 (the stock * those of the highest rank below it. Vehicles already in the lineup are left out (offline
* slotbar hides a lineup vehicle that a random group lists as disabled, rulebase.nut * design: the lineup does not hold the same vehicle twice).
* isUnitEnabledByRandomGroups, so listing them would be ambiguous).
*/ */
function randomGroupOptions(group: RandomSpawnGroup, input: ExtraBattleSlotsInput): RandomSpawnUnit[] { function randomGroupOptions(group: RandomSpawnGroup, input: ExtraBattleSlotsInput): RandomSpawnUnit[] {
if (input.playerMrank < group.minPlayerMrank) return []; if (input.playerMrank < group.minPlayerMrank) return [];
@@ -67,7 +67,6 @@ export interface BattleLaunchPlan {
readonly useSpawnScore: boolean; readonly useSpawnScore: boolean;
readonly customBots: CustomBotsPool; readonly customBots: CustomBotsPool;
readonly extraBattleSlots: readonly ExtraBattleSlot[]; readonly extraBattleSlots: readonly ExtraBattleSlot[];
readonly randomUnits: Readonly<Record<string, readonly string[]>>;
} }
export type MatchmakeOutcome = export type MatchmakeOutcome =
@@ -193,7 +192,7 @@ export class BattleMatchmaker {
startedAtSec: serverTimeToUnixSeconds(serverTimeNow()), startedAtSec: serverTimeToUnixSeconds(serverTimeNow()),
}); });
const allowedSet = new Set(declaration.allowedClasses); const allowedSet = new Set(declaration.allowedClasses);
const extraPlan = selectExtraBattleSlots({ const extraBattleSlots = selectExtraBattleSlots({
country: input.country, country: input.country,
slotVehicles: input.slotVehicles, slotVehicles: input.slotVehicles,
declaration, declaration,
@@ -233,8 +232,7 @@ export class BattleMatchmaker {
useShipBots: allowedSet.has('ship'), useShipBots: allowedSet.has('ship'),
useSpawnScore: declaration.requiredClass === 'tank' && declaration.difficulty === 'realistic', useSpawnScore: declaration.requiredClass === 'tank' && declaration.difficulty === 'realistic',
customBots, customBots,
extraBattleSlots: extraPlan.extraBattleSlots, extraBattleSlots,
randomUnits: extraPlan.randomUnits,
}; };
} }
} }
@@ -22,6 +22,7 @@ export interface BattleTuning {
readonly simColdWarMinMrank: number; readonly simColdWarMinMrank: number;
readonly strikeUcavModes: readonly string[]; readonly strikeUcavModes: readonly string[];
readonly strikeUcavSessionMrankAllowance: number; readonly strikeUcavSessionMrankAllowance: number;
readonly strikeUcavSpawnScore: number;
readonly tankBotRespawns: number; readonly tankBotRespawns: number;
readonly airBotRespawns: number; readonly airBotRespawns: number;
} }
@@ -62,6 +63,7 @@ export function readBattleTuning(reader: TuningReader): BattleTuning {
simColdWarMinMrank: reader.int('simColdWarMinMrank', { min: 0, max: 40 }), simColdWarMinMrank: reader.int('simColdWarMinMrank', { min: 0, max: 40 }),
strikeUcavModes: reader.stringList('strikeUcavModes'), strikeUcavModes: reader.stringList('strikeUcavModes'),
strikeUcavSessionMrankAllowance: reader.int('strikeUcavSessionMrankAllowance', { min: 0, max: 12 }), strikeUcavSessionMrankAllowance: reader.int('strikeUcavSessionMrankAllowance', { min: 0, max: 12 }),
strikeUcavSpawnScore: reader.int('strikeUcavSpawnScore', { min: 1, max: 10000 }),
tankBotRespawns: reader.int('tankBotRespawns', { min: 1, max: 10 }), tankBotRespawns: reader.int('tankBotRespawns', { min: 1, max: 10 }),
airBotRespawns: reader.int('airBotRespawns', { min: 1, max: 10 }), airBotRespawns: reader.int('airBotRespawns', { min: 1, max: 10 }),
}; };
@@ -57,7 +57,6 @@ export function battleLaunchNotify(
country: plan.country, country: plan.country,
missionName: plan.missionName, missionName: plan.missionName,
extraBattleSlots: plan.extraBattleSlots, extraBattleSlots: plan.extraBattleSlots,
randomUnits: plan.randomUnits,
awards, awards,
}, },
}; };
@@ -104,7 +104,6 @@ function handleEnqueue(
const playerVehicles = new Set([ const playerVehicles = new Set([
...slotVehicles, ...slotVehicles,
...launch.extraBattleSlots.map((slot) => slot.unitName), ...launch.extraBattleSlots.map((slot) => slot.unitName),
...Object.values(launch.randomUnits).flat(),
]); ]);
const awards = deps.economy.bannerParams(playerVehicles, economyDifficulty(modes[0]!.declaration.difficulty)); const awards = deps.economy.bannerParams(playerVehicles, economyDifficulty(modes[0]!.declaration.difficulty));
setImmediate(() => { setImmediate(() => {
+5 -4
View File
@@ -33,12 +33,13 @@
"simColdWarMinMrank": 18, "simColdWarMinMrank": 18,
// Strike UCAV extra slot (char.vromfs.bin config/wpcost.blk ucav_*_killstreak, one per country). // Strike UCAV extra slot (char.vromfs.bin config/wpcost.blk ucav_*_killstreak, one per country).
// The game files have no rule for when it is offered (online the battle server decides), so this // The game files have no rule for when it is offered or what it costs (online the battle server
// is offline design: offered in these game modes when the session's top rank is at least the // decides). Offer rule, offline design: in these game modes, when the session's top rank is at
// UCAV's own rank minus the allowance (0 = the UCAV's BR fits the session). Its spawn cost comes // least the UCAV's own rank minus the allowance (0 = the UCAV's BR fits the session). Spawn cost:
// from the stock spawn score formula (warpoints.blk respawn_points). // 750, as the live game shows for the MQ-1 in a Ground RB 12.7 lineup (screenshot of the live game).
"strikeUcavModes": ["tank_event_in_random_battles_historical"], "strikeUcavModes": ["tank_event_in_random_battles_historical"],
"strikeUcavSessionMrankAllowance": 0, "strikeUcavSessionMrankAllowance": 0,
"strikeUcavSpawnScore": 750,
// AI bot respawn limits per battle in multi-slot versus modes. // AI bot respawn limits per battle in multi-slot versus modes.
"tankBotRespawns": 3, "tankBotRespawns": 3,