deadhead-space-freight-tycoon/packages/sim/src/eligibility.ts

27 lines
1023 B
TypeScript

import type { LandingClass, Location, ShipModel } from "@deadhead/content";
import type { GameTime } from "./clock";
import { routeDistance } from "./distance";
const LANDING_RANK: Record<LandingClass, number> = { vacuum: 0, atmospheric: 1, hardened: 2 };
export type RouteCheck = { ok: true } | { ok: false; reason: "cannot-land" | "out-of-range" };
/** Whether a ship's landing class meets a location's landing requirement. */
export function canLandAt(ship: ShipModel, location: Location): boolean {
return LANDING_RANK[ship.landingClass] >= LANDING_RANK[location.landingRequirement];
}
/** Whether a ship can fly from one location to another at a game time, or why not. */
export function checkRoute(
ship: ShipModel,
from: Location,
to: Location,
gameTime: GameTime,
): RouteCheck {
if (!canLandAt(ship, to)) return { ok: false, reason: "cannot-land" };
if (routeDistance(from, to, gameTime) > ship.fuelRangeMillionKm) {
return { ok: false, reason: "out-of-range" };
}
return { ok: true };
}