Promote expert crews to ace when their vehicle RP reaches train3Cost_exp

Settlement already added an expert crew's battle RP to expertToAceProgress but capped
it at train3Cost_exp and left the crew at expert. The stock tooltip says ace is
"obtained for free when the crew gets {expAmount} with the current vehicle"
(crew/qualification/specDescriptionPart), and the client's discount stages end at
75 % (wp_get_specialization_cost_gold -> aces.exe 2.61.0.37 0x9165f0). The crew now
becomes ace once the RP reaches the target and its progress entry is dropped, as
the client drops an empty expertToAceProgress block (0x93b4eb). The ace price no
longer has its own "free at 100 %" case, so it matches the price the client shows.

Checked: typecheck.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 12:48:59 +08:00
1 parent 2b1c300203
commit 5b75dd5c59
3 files changed
+28 -4

No files matched your search

@@ -22,6 +22,11 @@
* against the helicopter target like any other (inferred). Once the destination branch has
* nothing left to research the RP goes to the vehicle's own branch again (inferred; the option
* cannot be switched on then, shop.nut onMoveExpToHelicoptersChange).
* - Crews: an expert crew's RP with the vehicle adds up in expertToAceProgress (the stock tooltip:
* "Crew experience with selected vehicle"; the battle's total RP is used, inferred) and lowers
* the ace price by the expert_to_ace_cost_reduce stages; at train3Cost_exp the crew becomes ace
* ("...or obtained for free when the crew gets {expAmount} with the current vehicle",
* crew/qualification/specDescriptionPart; promoted at once, inferred).
*
* Each vehicle's breakdown is returned in the shape of the `EULT_SESSION_RESULT`
* `container.researchPoints.unit` entries the stock debriefing explains RP with
@@ -34,7 +39,7 @@ import type { UnitClass } from '../game-modes/catalogue/game-mode-declaration.ts
import { isResearchable, type EquipmentCatalogue } from '../modifications/equipment-catalogue.ts';
import { pickDefaultResearchableModule } from '../modifications/module-state.ts';
import { isModuleResearched, ModuleStatus, vehicleModuleState } from '../modifications/module-status.ts';
import { addExpertToAceRp, specializationOf } from '../profile/profile-crew-skills.ts';
import { addExpertToAceRp, clearExpertToAceRp, expertToAceRp, setSpecialization, specializationOf } from '../profile/profile-crew-skills.ts';
import { crewForVehicleInCountry } from '../profile/profile-crews.ts';
import { destinationRpDomain, type VehicleDomain } from '../profile/profile-dest-rp.ts';
import { ownedVehicles } from '../profile/profile-hangar.ts';
@@ -65,6 +70,9 @@ import type { TreeVehicle } from '../research/tech-tree.ts';
import { VehicleStatus } from '../research/vehicle-status.ts';
import type { EarnedRpItem } from './battle-result-log.ts';
const EXPERT = 1;
const ACE = 2;
export interface BattleRpDeps {
readonly research: ResearchRules;
readonly efficiency: ResearchEfficiency;
@@ -406,7 +414,10 @@ function investAceCrewRp(
const targetRp = catalogue.training(vehicleName)?.aceResearchPoints ?? 0;
if (targetRp <= 0) return;
const crew = crewForVehicleInCountry(profile, country, vehicleName);
if (crew && specializationOf(crew, vehicleName) === 1) {
addExpertToAceRp(crew, vehicleName, amount, targetRp);
if (!crew || specializationOf(crew, vehicleName) !== EXPERT) return;
addExpertToAceRp(crew, vehicleName, amount, targetRp);
if (expertToAceRp(crew, vehicleName) >= targetRp) {
setSpecialization(crew, vehicleName, ACE);
clearExpertToAceRp(crew, vehicleName);
}
}
@@ -56,13 +56,18 @@ export class CrewSkillCatalogue {
return this.#training.get(vehicle);
}
/**
* The price the client shows (wp_get_specialization_cost_gold -> aces.exe 2.61.0.37 0x9165f0):
* train3Cost_gold less the discount of the last expert_to_ace_cost_reduce stage whose percent
* the crew's RP with the vehicle has reached. A crew that reaches train3Cost_exp becomes ace
* without buying (battle/battle-rp-investment.ts).
*/
aceGoldenEaglesPrice(vehicle: string, earnedAceRp: number): number {
const prices = this.#training.get(vehicle);
if (!prices) return 0;
const baseGold = Math.max(0, prices.aceGoldenEagles);
const targetRp = prices.aceResearchPoints;
if (baseGold === 0 || targetRp <= 0 || earnedAceRp <= 0) return baseGold;
if (earnedAceRp >= targetRp) return 0;
const progressPercent = Math.floor((earnedAceRp * 100) / targetRp);
let discount = 0;
for (const stage of this.#aceDiscountStages) {
@@ -98,6 +98,14 @@ export function addExpertToAceRp(crew: BlkBlock, vehicle: string, deltaRp: numbe
if (next !== current) setParam(ensureBlock(crew, ACE_PROGRESS), vehicle, { type: 'int', value: next });
}
/** Drop the vehicle's Expert-to-Ace RP, and the block when it is empty (as the client does, 0x93b4eb). */
export function clearExpertToAceRp(crew: BlkBlock, vehicle: string): void {
const progress = findBlock(crew, ACE_PROGRESS);
if (!progress) return;
progress.params = progress.params.filter((param) => param.name !== vehicle);
if (progress.params.length === 0 && progress.blocks.length === 0) crew.blocks = crew.blocks.filter((block) => block !== progress);
}
function intOf(block: BlkBlock, name: string): number {
const value = findParam(block, name)?.value;
if (value?.type === 'int64') return Number(value.value);