Files
Flight-Ops/lib/game/catalog.ts
T

69 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Aircraft catalog — in-code constants for now (no DB table yet). One type is
// enough for the MVP; add more entries to PLANE_TYPES as they are designed.
export interface PlaneType {
id: string;
name: string;
// Fuel capacity, liters.
maxFuel: number;
// Fuel burn per km of flight, liters/km (cruise).
burnPerKm: number;
// Cruise speed, km/h — used by the sim tick to advance planes along routes.
speedKmh: number;
// Market price in € (v0.8.0): buying costs `price`, selling pays out
// SELL_FRACTION × price.
price: number;
// Cargo slot capacity (v0.12.0): how many packages can be loaded on one plane.
capacity: number;
}
export const PLANE_TYPES: Record<string, PlaneType> = {
atr72: {
id: 'atr72',
name: 'ATR 72-600',
maxFuel: 6300,
burnPerKm: 1.75, // ~900 kg/h at 510 km/h cruise (Jet-A1 ≈ 0.8 kg/L)
speedKmh: 510,
// €200k — with the starting cash of €20k and typical hop rewards (~€1–3k),
// a second ATR takes sustained play to afford, as intended for the MVP sink.
price: 200_000,
capacity: 6,
},
};
// The plane the player starts with.
export const STARTER_MODEL = 'atr72';
// Jet-A1 fuel price in €/liter (v0.8.0): refueling cost = (maxFuel − fuel) × this.
export const FUEL_PRICE_PER_L = 0.8;
// Fraction of the catalog price paid out when selling a plane (v0.8.0).
export const SELL_FRACTION = 0.5;
// Snapshot shape of one catalog entry in GET /api/state (v0.10.0): `model` is the
// id used by buy/dispatch, `label` the display name — clients compute all market
// previews (buy price, sell payout, refuel cost) from these + the economy constants.
export interface CatalogEntry {
model: string;
label: string;
price: number;
maxFuel: number;
burnPerKm: number;
speedKmh: number;
capacity: number;
}
// The catalog as a flat array, one entry per plane type — the single source of
// truth for both the sim (PLANE_TYPES) and the client snapshot.
export function catalogEntries(): CatalogEntry[] {
return Object.values(PLANE_TYPES).map((t) => ({
model: t.id,
label: t.name,
price: t.price,
maxFuel: t.maxFuel,
burnPerKm: t.burnPerKm,
speedKmh: t.speedKmh,
capacity: t.capacity,
}));
}