Derive reserve vehicles from the stock economy data. Grant all reserves and mark the basic takeoff and landing tutorials complete in new saves. Apply the same grants through the format 2 migration. Use shared crew slot rules for first-run selection, presets, training, assignment, and removal.
46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
/**
|
|
* Crews in the profile, as in Gaijin's config/default_user.blk:
|
|
*
|
|
* crews{
|
|
* c0{
|
|
* country:t="country_usa"
|
|
* aircrafts{ trained:t="bf2c_1" trained:t="p-26a_34_m2" current:t="bf2c_1" }
|
|
* }
|
|
* }
|
|
*
|
|
* "trained" lists the vehicles the crew is trained for (repeated), "current" is the vehicle
|
|
* in its slot.
|
|
*/
|
|
import { ensureBlock, type BlkBlock } from '@wto/blk';
|
|
|
|
const CREWS = 'crews';
|
|
const VEHICLES = 'aircrafts';
|
|
const TRAINED = 'trained';
|
|
const CURRENT = 'current';
|
|
|
|
export function crewOf(profile: BlkBlock, crewId: number): BlkBlock | undefined {
|
|
return profile.blocks.find((block) => block.name === CREWS)?.blocks.find((crew) => crew.name === `c${crewId}`);
|
|
}
|
|
|
|
/** Leave the crew's slot empty; the vehicles it is trained for stay trained. */
|
|
export function emptyCrewSlot(crew: BlkBlock): void {
|
|
const vehicles = crew.blocks.find((block) => block.name === VEHICLES);
|
|
if (vehicles) vehicles.params = vehicles.params.filter((param) => param.name !== CURRENT);
|
|
}
|
|
|
|
/** Train the crew for the vehicle, if it is not yet; the vehicle in its slot stays. "current" stays last, as in Gaijin's profiles. */
|
|
export function trainCrewFor(crew: BlkBlock, vehicle: string): void {
|
|
const vehicles = ensureBlock(crew, VEHICLES);
|
|
const trained = vehicles.params.some((param) => param.name === TRAINED && param.value.type === 'string' && param.value.value === vehicle);
|
|
if (trained) return;
|
|
const current = vehicles.params.filter((param) => param.name === CURRENT);
|
|
vehicles.params = [...vehicles.params.filter((param) => param.name !== CURRENT), { name: TRAINED, value: { type: 'string', value: vehicle } }, ...current];
|
|
}
|
|
|
|
/** Train the crew for the vehicle (if it is not yet) and put the vehicle in its slot. */
|
|
export function putVehicleInCrew(crew: BlkBlock, vehicle: string): void {
|
|
emptyCrewSlot(crew);
|
|
trainCrewFor(crew, vehicle);
|
|
ensureBlock(crew, VEHICLES).params.push({ name: CURRENT, value: { type: 'string', value: vehicle } });
|
|
}
|