fix(battle): calculate base spawn scores before launch
This commit is contained in:
1 parent
15145d8c1c
commit
44825ed6b5
6 files changed
+138
-53
No files matched your search
@@ -22,6 +22,7 @@ import {
|
||||
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 EnqueueBattleInput {
|
||||
@@ -65,6 +66,7 @@ export interface BattleLaunchPlan {
|
||||
readonly useTankBots: boolean;
|
||||
readonly useShipBots: boolean;
|
||||
readonly useSpawnScore: boolean;
|
||||
readonly spawnScore?: BattleSpawnScore;
|
||||
readonly customBots: CustomBotsPool;
|
||||
readonly extraBattleSlots: readonly ExtraBattleSlot[];
|
||||
}
|
||||
@@ -203,6 +205,7 @@ export class BattleMatchmaker {
|
||||
rules: this.#spawnRules,
|
||||
tuning: this.#tuning,
|
||||
});
|
||||
const useSpawnScore = declaration.requiredClass === 'tank' && declaration.difficulty === 'realistic';
|
||||
return {
|
||||
sessionId: session.sessionId,
|
||||
modeId: declaration.gameModeId,
|
||||
@@ -231,7 +234,10 @@ export class BattleMatchmaker {
|
||||
airBotRespawns: this.#tuning.airBotRespawns,
|
||||
useTankBots: allowedSet.has('tank'),
|
||||
useShipBots: allowedSet.has('ship'),
|
||||
useSpawnScore: declaration.requiredClass === 'tank' && declaration.difficulty === 'realistic',
|
||||
useSpawnScore,
|
||||
...(useSpawnScore ? {
|
||||
spawnScore: battleSpawnScore(input.slotVehicles, extraBattleSlots, maxMrank, this.#vehiclesByName, this.#spawnRules.spawnScore),
|
||||
} : {}),
|
||||
customBots,
|
||||
extraBattleSlots,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Static spawn scores for the player's Ground Realistic lineup and support vehicles.
|
||||
* The parameter order and BR conversion follow globals/ranks_common_shared.nut
|
||||
* (get_spawn_score_param, get_unit_blk_economic_rank_by_mode, calcBattleRatingFromRank).
|
||||
* The linear BR discount and ten-point rounding are inferred from the data and observed
|
||||
* costs. Changing weapon and ammunition multipliers remain the stock client's job.
|
||||
*/
|
||||
import type { SpawnScoreRules } from '../game-data/datasets/battle-spawn-rules.ts';
|
||||
import type { CatalogueVehicle } from '../game-data/datasets/vehicle-catalogue.ts';
|
||||
import { vehicleTypeOfClass, type VehicleType } from '../research/vehicle-types.ts';
|
||||
import type { ExtraBattleSlot } from './battle-extra-slots.ts';
|
||||
import { vehicleMrank } from './battle-ranks.ts';
|
||||
|
||||
export interface BattleSpawnScore {
|
||||
readonly maxScore: number;
|
||||
readonly unitCosts: Readonly<Record<string, number>>;
|
||||
}
|
||||
|
||||
/** Spawn score types used by ranks_common_shared.nut (boat and ship share one type). */
|
||||
const SPAWN_TYPES: Readonly<Record<VehicleType, string>> = {
|
||||
Aircraft: 'Air',
|
||||
Helicopter: 'Air',
|
||||
Tank: 'Tank',
|
||||
Ship: 'Ship',
|
||||
Boat: 'Ship',
|
||||
Human: 'Human',
|
||||
Transport: 'Transport',
|
||||
};
|
||||
|
||||
export function battleSpawnScore(
|
||||
lineup: readonly string[],
|
||||
extraSlots: readonly ExtraBattleSlot[],
|
||||
sessionMaxMrank: number,
|
||||
vehicles: ReadonlyMap<string, CatalogueVehicle>,
|
||||
rules: SpawnScoreRules,
|
||||
): BattleSpawnScore {
|
||||
const override = rules.overrides.find(({ minMrank, maxMrank }) => sessionMaxMrank >= minMrank && sessionMaxMrank <= maxMrank);
|
||||
const params = {
|
||||
...rules.common,
|
||||
...rules.tankHistorical.classCosts,
|
||||
...rules.tankHistorical.parameters,
|
||||
...override?.classCosts,
|
||||
...override?.parameters,
|
||||
};
|
||||
const base = params.base_respawn_points_coef ?? 450;
|
||||
const maxScore = Math.max(0, Math.round(base * (params.maxRespawnPointsMul ?? 1)));
|
||||
const maxBrDiff = params.max_br_diff ?? 1;
|
||||
const sessionBr = battleRating(sessionMaxMrank);
|
||||
const unitCosts: Record<string, number> = {};
|
||||
for (const unit of new Set([...lineup, ...extraSlots.map((slot) => slot.unitName)])) {
|
||||
if (unit === '') continue;
|
||||
const vehicle = vehicles.get(unit);
|
||||
const unitClass = vehicle?.unitClass || 'exp_zero';
|
||||
const multiplier = params[unit] ?? params[unitClass] ?? 0;
|
||||
if (multiplier <= 0) {
|
||||
unitCosts[unit] = 0;
|
||||
continue;
|
||||
}
|
||||
const type = vehicleTypeOfClass(unitClass);
|
||||
const spawnType = unitClass === 'exp_ai_sam_tracking_radar' ? 'Tank' : type ? SPAWN_TYPES[type] : 'Invalid';
|
||||
const rank = vehicle ? vehicleMrank(vehicle, 'realistic', 'tank') : sessionMaxMrank;
|
||||
const brDiff = Math.min(Math.max(0, sessionBr - battleRating(rank)), maxBrDiff);
|
||||
const discount = maxBrDiff > 0 ? (params[`br_diff_mul_${spawnType}`] ?? 0) * brDiff / maxBrDiff : 0;
|
||||
unitCosts[unit] = Math.max(1, Math.round(base * multiplier * (1 - discount) / 10) * 10);
|
||||
}
|
||||
for (const { unitName, persistentCost } of extraSlots) {
|
||||
if (persistentCost !== undefined && persistentCost > 0) unitCosts[unitName] = persistentCost;
|
||||
}
|
||||
return { maxScore, unitCosts };
|
||||
}
|
||||
|
||||
function battleRating(mrank: number): number {
|
||||
return Math.round((mrank / 3 + 1) * 10) / 10;
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
* char.vromfs.bin config/wpcost.blk
|
||||
* ucav_*_killstreak{ country:t ... }
|
||||
* The strike UCAVs, one per country.
|
||||
* char.vromfs.bin config/warpoints.blk respawn_points / TankHistorical
|
||||
* Starting points and unit cost parameters for Ground Realistic Battles.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { findParam } from '@wto/blk';
|
||||
@@ -56,10 +58,25 @@ export interface RandomSpawnGroup {
|
||||
readonly units: readonly RandomSpawnUnit[];
|
||||
}
|
||||
|
||||
interface SpawnScoreParameterSet {
|
||||
readonly parameters: Readonly<Record<string, number>>;
|
||||
readonly classCosts: Readonly<Record<string, number>>;
|
||||
}
|
||||
|
||||
export interface SpawnScoreRules {
|
||||
readonly common: Readonly<Record<string, number>>;
|
||||
readonly tankHistorical: SpawnScoreParameterSet;
|
||||
readonly overrides: ReadonlyArray<SpawnScoreParameterSet & {
|
||||
readonly minMrank: number;
|
||||
readonly maxMrank: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface BattleSpawnRulesData {
|
||||
/** By event name (`missionSupportPlane` keys are game mode names). */
|
||||
readonly supportPlanes: Readonly<Record<string, readonly SupportPlanePreset[]>>;
|
||||
readonly strikeUcavs: readonly StrikeUcav[];
|
||||
readonly spawnScore: SpawnScoreRules;
|
||||
/** By event economic name, then country. */
|
||||
readonly randomSpawnUnits: Readonly<Record<string, Readonly<Record<string, readonly RandomSpawnGroup[]>>>>;
|
||||
}
|
||||
@@ -68,18 +85,45 @@ const STRIKE_UCAV_PATTERN = /^ucav_.*_killstreak$/;
|
||||
|
||||
export const battleSpawnRules: Dataset<BattleSpawnRulesData> = {
|
||||
id: 'battle-spawn-rules',
|
||||
version: 2,
|
||||
version: 3,
|
||||
extract: (source) => {
|
||||
const gameplay = source.readBlk('aces.vromfs.bin', 'config/gameplay.blk');
|
||||
const wpcost = source.readBlk('char.vromfs.bin', 'config/wpcost.blk');
|
||||
return {
|
||||
supportPlanes: extractSupportPlanes(blockAt(gameplay, 'missionSupportPlane')),
|
||||
strikeUcavs: extractStrikeUcavs(wpcost.blocks),
|
||||
spawnScore: extractSpawnScore(blockAt(source.readBlk('char.vromfs.bin', 'config/warpoints.blk'), 'respawn_points')),
|
||||
randomSpawnUnits: extractRandomSpawnUnits(blockAt(gameplay, 'RandomSpawnUnits')),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function extractSpawnScore(root: BlkBlock | undefined): SpawnScoreRules {
|
||||
const tankHistorical = blockAt(root, 'TankHistorical');
|
||||
return {
|
||||
common: numericParams(root),
|
||||
tankHistorical: spawnScoreParams(tankHistorical),
|
||||
overrides: (blockAt(tankHistorical, 'override_params_by_session_rank')?.blocks ?? []).map((block) => ({
|
||||
...spawnScoreParams(block),
|
||||
minMrank: numberField(block, 'minMRank') ?? -1,
|
||||
maxMrank: numberField(block, 'maxMRank') ?? -1,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function spawnScoreParams(block: BlkBlock | undefined): SpawnScoreParameterSet {
|
||||
return {
|
||||
parameters: numericParams(block),
|
||||
classCosts: numericParams(blockAt(block, 'respawn_cost_mul_by_exp_class')),
|
||||
};
|
||||
}
|
||||
|
||||
function numericParams(block: BlkBlock | undefined): Record<string, number> {
|
||||
const params = block?.params ?? [];
|
||||
return Object.fromEntries(params.flatMap(({ name, value }) =>
|
||||
value.type === 'int' || value.type === 'real' ? [[name, value.value]] : []));
|
||||
}
|
||||
|
||||
function extractSupportPlanes(root: BlkBlock | undefined): Record<string, SupportPlanePreset[]> {
|
||||
const byEvent: Record<string, SupportPlanePreset[]> = {};
|
||||
for (const eventBlk of root?.blocks ?? []) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* - `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,
|
||||
* and `awards`, the parameters of the in-battle reward banner, battle-economy.ts BannerParams).
|
||||
* `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';
|
||||
@@ -57,6 +57,7 @@ export function battleLaunchNotify(
|
||||
country: plan.country,
|
||||
missionName: plan.missionName,
|
||||
extraBattleSlots: plan.extraBattleSlots,
|
||||
...(plan.spawnScore ? { spawnScore: plan.spawnScore } : {}),
|
||||
awards,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user