diff --git a/packages/local-service/src/battle/battle-rp-investment.ts b/packages/local-service/src/battle/battle-rp-investment.ts index ea312d2..110bffa 100644 --- a/packages/local-service/src/battle/battle-rp-investment.ts +++ b/packages/local-service/src/battle/battle-rp-investment.ts @@ -13,6 +13,15 @@ * `researchUnits..exp:i64`, and the stock client asks the player for the next * research (scripts/researches/researchActions.nut) and spends the banked RP on it * (cln_move_exp_to_unit). A branch without a research target banks the RP unchanged. + * - Destination branch: with "Research of helicopters by playing ground vehicles" on (profile + * researchUnits//destTypeRP, profile/profile-dest-rp.ts) the vehicle's branch is + * the destination one: "Research points earned in battles by playing on the ground vehicles of + * this country will be fully invested in the research of helicopters. Ground vehicles will not + * be researched.", modifications are researched as usual (lang + * shop/research_helicopters_by_ground_vehicles_tooltip, _confirm). The rank penalty is taken + * 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). * * Each vehicle's breakdown is returned in the shape of the `EULT_SESSION_RESULT` * `container.researchPoints.unit` entries the stock debriefing explains RP with @@ -27,7 +36,7 @@ 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 { crewForVehicleInCountry } from '../profile/profile-crews.ts'; -import { readRedirectedResearchDomain, type VehicleDomain } from '../profile/profile-dest-rp.ts'; +import { destinationRpDomain, type VehicleDomain } from '../profile/profile-dest-rp.ts'; import { ownedVehicles } from '../profile/profile-hangar.ts'; import { moduleResearchPoints, setModuleResearchPoints } from '../profile/profile-module-research.ts'; import { researchBonusBattlesUsed, useResearchBonusBattle } from '../profile/profile-research-bonus.ts'; @@ -240,9 +249,14 @@ function branchOf( ctx: RpContext, ): { country: string; type: string } | undefined { const played = research.techTree.vehicle(vehicle); - if (played) return { country: played.country, type: readRedirectedResearchDomain(profile, played.country, played.type) }; + if (played) return { country: played.country, type: redirectedBranch(profile, research, played.country, played.type) }; const fallback = fallbackBranch(profile, ctx.country, ctx.requiredClass); - return { country: ctx.country, type: readRedirectedResearchDomain(profile, ctx.country, fallback) }; + return { country: ctx.country, type: redirectedBranch(profile, research, ctx.country, fallback) }; +} + +function redirectedBranch(profile: BlkBlock, research: ResearchRules, country: string, type: VehicleDomain): VehicleDomain { + const destination = destinationRpDomain(profile, country, type); + return destination && hasUnresearchedBranchVehicle(profile, research, country, destination) ? destination : type; } function fallbackBranch(profile: BlkBlock, country: string, requiredClass: UnitClass): VehicleDomain { diff --git a/packages/local-service/src/profile/profile-dest-rp.ts b/packages/local-service/src/profile/profile-dest-rp.ts index 5342abd..5a03d49 100644 --- a/packages/local-service/src/profile/profile-dest-rp.ts +++ b/packages/local-service/src/profile/profile-dest-rp.ts @@ -13,13 +13,13 @@ * (ES_UNIT_TYPE_INVALID), exposed to Squirrel by getDestinationRPUnitType (0x15532f0). * - Writer (0x9307eb..0x93082a): writes "destTypeRP" only when 0 <= destType <= 6 * and omits the parameter when disabled (-1). + * Battle settlement applies it in battle/battle-rp-investment.ts. */ import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk'; import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts'; import type { TechTree } from '../research/tech-tree.ts'; import { VEHICLE_TYPES, vehicleTypeById, type VehicleType } from '../research/vehicle-types.ts'; import { removeParam, stringField } from './blk-fields.ts'; -import { researchTarget } from './profile-research-targets.ts'; const RESEARCH_UNITS = 'researchUnits'; const DEST_TYPE_PREFIX = 'destTypeRP'; @@ -79,18 +79,3 @@ export function applySetDestinationRpRule( setDestinationRpDomain(profile, country, sourceDomain, destinationDomain); return ACCEPTED; } - -/** - * Resolve the effective research branch for battle settlement: returns the redirected domain - * (such as 'Helicopter' when playing 'Tank') when configured and that branch still has an - * active currUnit research target, otherwise falls back to sourceDomain. - */ -export function readRedirectedResearchDomain( - profile: BlkBlock, - country: string, - sourceDomain: VehicleDomain, -): VehicleDomain { - const redirected = destinationRpDomain(profile, country, sourceDomain); - if (!redirected) return sourceDomain; - return researchTarget(profile, country, redirected) !== '' ? redirected : sourceDomain; -}