Limit classic Air Realistic and Tactical Skies to historical mission variants. Read stock airfield ranges, select against the rank sent to the mission loader, and keep fixed-layout limits in battle tuning. Inspected mission data from 2.61.0.37 and 2.61.0.43. Root and launcher type checks pass. Gameplay awaits manual acceptance.
52 lines
2.3 KiB
TypeScript
52 lines
2.3 KiB
TypeScript
/** Build the offline Air Realistic rotation from the stock mission variants and ranked airfield imports. */
|
|
import { AIR_HISTORICAL_MISSION_FOLDER, type MissionHeader } from '../game-data/datasets/multiplayer-missions.ts';
|
|
|
|
interface MissionRankRange {
|
|
readonly minMRank: number;
|
|
readonly maxMRank: number;
|
|
}
|
|
|
|
export interface MissionRotationRanks {
|
|
readonly byMission: ReadonlyMap<string, readonly MissionRankRange[]>;
|
|
readonly maxMrank: number;
|
|
}
|
|
|
|
export function airRealisticMissionRanks(selected: readonly MissionHeader[], fixedLayoutMaxMrank: number): MissionRotationRanks {
|
|
const historical = selected.filter((mission) => mission.path.startsWith(AIR_HISTORICAL_MISSION_FOLDER)
|
|
&& !mission.airfieldLayoutProblem && !mission.locName?.split(';').includes('missions/air_newbie'));
|
|
const byMission = new Map<string, readonly MissionRankRange[]>();
|
|
|
|
const topRankStarts = historical.flatMap((mission) => mission.airfieldLayouts.flatMap((layout) =>
|
|
layout.tier === 'top' ? [layout.minMRank] : []));
|
|
if (topRankStarts.length === 0) return { byMission, maxMrank: 0 };
|
|
const belowTopMax = Math.min(...topRankStarts) - 1;
|
|
let maxMrank = 0;
|
|
for (const mission of historical) {
|
|
const ranges = mission.airfieldLayouts.length === 0
|
|
? [{ minMRank: 0, maxMRank: Math.min(fixedLayoutMaxMrank, belowTopMax) }]
|
|
: mission.airfieldLayouts.map(({ tier, minMRank, maxMRank }) => ({
|
|
minMRank,
|
|
maxMRank: tier === 'top' ? maxMRank : Math.min(maxMRank, belowTopMax),
|
|
}));
|
|
const supported = mergeRankRanges(ranges);
|
|
if (supported.length === 0) continue;
|
|
byMission.set(mission.name, supported);
|
|
maxMrank = Math.max(maxMrank, supported.at(-1)!.maxMRank);
|
|
}
|
|
return { byMission, maxMrank };
|
|
}
|
|
|
|
function mergeRankRanges(ranges: readonly MissionRankRange[]): MissionRankRange[] {
|
|
const sorted = ranges.filter(({ minMRank, maxMRank }) => minMRank <= maxMRank).sort((a, b) => a.minMRank - b.minMRank);
|
|
const merged: MissionRankRange[] = [];
|
|
for (const range of sorted) {
|
|
const previous = merged.at(-1);
|
|
if (previous && range.minMRank <= previous.maxMRank + 1) {
|
|
merged[merged.length - 1] = { minMRank: previous.minMRank, maxMRank: Math.max(previous.maxMRank, range.maxMRank) };
|
|
} else {
|
|
merged.push(range);
|
|
}
|
|
}
|
|
return merged;
|
|
}
|