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
@@ -1,8 +1,8 @@
|
||||
// Register the host callbacks get_max_spawn_score and get_unit_spawn_score that the client scripts lack, and
|
||||
// keep the mission's persistent spawn costs (customSpawnScore/persistent_costs) from being scaled by weapons.
|
||||
// Supply the missing get_max_spawn_score and get_unit_spawn_score callbacks from the battle launch plan.
|
||||
// Fixed support costs (customSpawnScore/persistent_costs) ignore the current weapon multiplier.
|
||||
// Why the client: on a dedicated server these callbacks are server scripts; a LocalMP host has none.
|
||||
// Without it: spawn points are always 0 in modes with spawn scores (ground realistic and others).
|
||||
// Kept from the baseline; not re-reviewed in the LocalMP rework.
|
||||
// Without it: LocalMP ground realistic starts with zero points and has no base vehicle costs.
|
||||
// aces.exe 2.61.0.37: initSpawnScoreFunction at 0x2e4559, getSpawnScoreFunction at 0x2e2463.
|
||||
{
|
||||
"id": "battle/local-host-spawn-score",
|
||||
"title": "Register the LocalMP host's spawn score callbacks",
|
||||
|
||||
@@ -1,47 +1,7 @@
|
||||
function calcWtoMaxSpawnScore(_userId, _maxRank) {
|
||||
let ranksShared = require("%appGlobals/ranks_common_shared.nut")
|
||||
let mathMod = require("math")
|
||||
let baseCoef = ranksShared.get_spawn_score_param("base_respawn_points_coef", 450)
|
||||
let maxMul = ranksShared.get_spawn_score_param("maxRespawnPointsMul", 1.0)
|
||||
return mathMod.max(0, mathMod.round(baseCoef * maxMul).tointeger())
|
||||
}
|
||||
let { ndbTryRead } = require("nestdb")
|
||||
let wtoSpawnScore = @() ndbTryRead(["wto", "activeBattle"])?.spawnScore
|
||||
|
||||
function calcWtoUnitSpawnScore(_userId, unitName, _unitRankArg) {
|
||||
if (unitName == null || unitName == "")
|
||||
return 0
|
||||
let ranksShared = require("%appGlobals/ranks_common_shared.nut")
|
||||
let { get_current_mission_info_cached, get_wpcost_blk } = require("blkGetters")
|
||||
let { round_by_value } = require("%sqstd/math.nut")
|
||||
let mathMod = require("math")
|
||||
let misBlk = get_current_mission_info_cached()
|
||||
let persistentCost = misBlk?.customSpawnScore?.persistent_costs?[unitName] ?? 0
|
||||
if (persistentCost > 0)
|
||||
return persistentCost.tointeger()
|
||||
let unitClass = ranksShared.getWpcostUnitClass(unitName)
|
||||
let costMul = ranksShared.get_spawn_score_param(unitName, null)
|
||||
?? ranksShared.get_spawn_score_param(unitClass, 0.0)
|
||||
if (costMul <= 0.0)
|
||||
return 0
|
||||
let baseCoef = ranksShared.get_spawn_score_param("base_respawn_points_coef", 450)
|
||||
let unitType = ranksShared.get_unit_type_by_unit_name(unitName)
|
||||
let brDiffMul = ranksShared.get_spawn_score_param($"br_diff_mul_{unitType}", 0.0)
|
||||
let maxBrDiff = ranksShared.get_spawn_score_param("max_br_diff", 1.0)
|
||||
let sessionMaxRank = misBlk?.ranks?.max ?? 0
|
||||
let unitBlk = get_wpcost_blk()?[unitName]
|
||||
let ediff = ranksShared.get_mission_mode()
|
||||
let unitRank = ranksShared.get_unit_blk_economic_rank_by_mode(unitBlk, ediff, sessionMaxRank)
|
||||
local brFactor = 1.0
|
||||
if (maxBrDiff > 0.0 && brDiffMul != 0.0) {
|
||||
let sessionBr = ranksShared.calcBattleRatingFromRank(sessionMaxRank)
|
||||
let unitBr = ranksShared.calcBattleRatingFromRank(unitRank)
|
||||
let brDiff = mathMod.clamp(sessionBr - unitBr, 0.0, maxBrDiff)
|
||||
brFactor = 1.0 - brDiffMul * (brDiff / maxBrDiff)
|
||||
}
|
||||
let rawScore = baseCoef * costMul * brFactor
|
||||
return mathMod.max(1, round_by_value(rawScore, 10).tointeger())
|
||||
}
|
||||
|
||||
function calcWtoUnitSpawnScoreWeaponMul(unitname, weapon, bulletArray, presetTbl = {}) {
|
||||
function wtoUnitSpawnScoreWeaponMul(unitname, weapon, bulletArray, presetTbl = {}) {
|
||||
let { get_current_mission_info_cached } = require("blkGetters")
|
||||
let persistentCost = get_current_mission_info_cached()?.customSpawnScore?.persistent_costs?[unitname] ?? 0
|
||||
if (persistentCost > 0)
|
||||
@@ -49,7 +9,7 @@ function calcWtoUnitSpawnScoreWeaponMul(unitname, weapon, bulletArray, presetTbl
|
||||
return get_unit_spawn_score_weapon_mul(unitname, weapon, bulletArray, presetTbl)
|
||||
}
|
||||
|
||||
registerRespondent("get_max_spawn_score", calcWtoMaxSpawnScore)
|
||||
registerRespondent("get_unit_spawn_score", calcWtoUnitSpawnScore)
|
||||
registerRespondent("get_max_spawn_score", @(_userId, _maxRank) wtoSpawnScore()?.maxScore ?? 0)
|
||||
registerRespondent("get_unit_spawn_score", @(_userId, unitName, _unitRank) wtoSpawnScore()?.unitCosts?[unitName] ?? 0)
|
||||
registerRespondent("get_spawn_score_type_mul", get_spawn_score_type_mul)
|
||||
registerRespondent("get_unit_spawn_score_weapon_mul", calcWtoUnitSpawnScoreWeaponMul)
|
||||
registerRespondent("get_unit_spawn_score_weapon_mul", wtoUnitSpawnScoreWeaponMul)
|
||||
@@ -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