30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import type { GameConfig, Location, ShipModel } from "@deadhead/content";
|
||
|
||
/**
|
||
* The distance pay and fuel are charged on (decision 0.5.84): the route distance
|
||
* scaled down for long legs, `reference × (distance / reference)^exponent`.
|
||
* A leg of the reference length (Earth–Moon) is unchanged; an exponent of 1
|
||
* makes it the plain distance. Range, travel time and XP use the plain distance.
|
||
*/
|
||
export function economicDistance(distanceMillionKm: number, config: GameConfig): number {
|
||
const { referenceMillionKm, exponent } = config.economicDistance;
|
||
return referenceMillionKm * (distanceMillionKm / referenceMillionKm) ** exponent;
|
||
}
|
||
|
||
/**
|
||
* Fuel cost in credits: economic distance × the ship's cost per million km ×
|
||
* the origin's launch multiplier.
|
||
*/
|
||
export function fuelCost(
|
||
ship: ShipModel,
|
||
origin: Location,
|
||
distanceMillionKm: number,
|
||
config: GameConfig,
|
||
): number {
|
||
return (
|
||
economicDistance(distanceMillionKm, config) *
|
||
ship.fuelCostPerMillionKm *
|
||
origin.launchCostMultiplier
|
||
);
|
||
}
|