Files
WT-Offline/packages/local-service/src/profile/crew-slots.ts
T
N0VAN0M4LY ed0136f5fc feat(crew): add crew presets and grant reserve vehicles
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.
2026-11-24 14:18:02 +08:00

39 lines
1.8 KiB
TypeScript

/**
* Putting vehicles into crew slots: the first choice (cln_set_starting_info) and applying a
* slotbar preset (cln_bulk_train_aircraft) send a list of crew slot -> vehicle (gui.vromfs.bin
* scripts/crew/crewTrain.nut createBatchTrainCrewRequestBlk); taking a vehicle into one slot
* or clearing it (cln_train_aircraft) sends a single one. An empty vehicle name leaves the
* slot empty.
*
* A slot can only take a vehicle the player owns, as online. Training a crew for a vehicle
* costs nothing yet: the economy rules do not exist so far.
*/
import type { BlkBlock } from '@wto/blk';
import { crewOf, emptyCrewSlot, putVehicleInCrew, trainCrewFor } from './profile-crews.ts';
import { ownsVehicle } from './profile-hangar.ts';
export interface CrewSlotAssignment {
readonly crewId: number;
/** Empty: leave the slot empty. */
readonly vehicle: string;
}
/** Every crew exists and every vehicle is owned. */
export function canAssignCrewSlots(profile: BlkBlock, assignments: readonly CrewSlotAssignment[]): boolean {
return assignments.every(({ crewId, vehicle }) => crewOf(profile, crewId) !== undefined && (vehicle === '' || ownsVehicle(profile, vehicle)));
}
/** Apply assignments that canAssignCrewSlots accepted. */
export function assignCrewSlots(profile: BlkBlock, assignments: readonly CrewSlotAssignment[]): void {
for (const { crewId, vehicle } of assignments) {
const crew = crewOf(profile, crewId)!;
if (vehicle === '') emptyCrewSlot(crew);
else putVehicleInCrew(crew, vehicle);
}
}
/** Train one crew for a vehicle without changing its slot; the assignment must have passed canAssignCrewSlots. */
export function trainCrewKeepingSlot(profile: BlkBlock, { crewId, vehicle }: CrewSlotAssignment): void {
if (vehicle !== '') trainCrewFor(crewOf(profile, crewId)!, vehicle);
}