/** Choose a mode's missions from the game's multiplayer missions. */ import type { MissionHeader, MultiplayerMissions } from '../game-data/datasets/multiplayer-missions.ts'; import type { MissionSelection, UnitClass } from './catalogue/game-mode-declaration.ts'; /** The switch a mission's mission_settings/mission/allowedUnitTypes block uses for each class. */ const ALLOWED_SWITCH: Readonly> = { aircraft: 'isAirplanesAllowed', tank: 'isTanksAllowed', ship: 'isShipsAllowed', helicopter: 'isHelicoptersAllowed', }; /** The selected missions in the order the game lists them, without repeats. */ export function selectMissions(selection: MissionSelection, index: MultiplayerMissions): MissionHeader[] { const chosen = new Map(); for (const category of index.categories) { if (!selection.categories.includes(category.name)) continue; for (const name of category.missions) { const mission = index.missions[name]; if (mission && !chosen.has(name) && matches(selection, mission)) chosen.set(name, mission); } } return [...chosen.values()]; } function matches(selection: MissionSelection, mission: MissionHeader): boolean { if (selection.include && !selection.include.test(mission.name)) return false; if (selection.exclude?.test(mission.name)) return false; return selection.requireAllowed.every((unitClass) => mission.allowedUnitTypes[ALLOWED_SWITCH[unitClass]] === true); }