tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

52 lignes · 2017 octetsBrut · Historique
1/**
2 * Game rules the UI uses for estimates, from https://starfleet.glo.quebec/docs ("Rules",
3 * navigate/jump/refuel/repair cards). The server stays the authority: these numbers only
4 * drive previews, hints and the trade helper, and every real move is still validated
5 * (and can be dry-run) by the API.
6 *
7 * ASSUMPTIONS (flagged for team review):
8 * - Fuel rounding: the docs say "a unit of fuel per 10 of distance"; we round up.
9 * - Jumps: the docs list `not_enough_fuel` for jumps but give no rate; we assume the
10 * same unit per 10 of the distance between the two systems.
11 * - Nebulae make trips "slower" by an undocumented factor; estimates ignore it and
12 * callers flag nebula legs instead.
13 */
14
15export const TRIP_BASE_S = 15;
16export const TRIP_S_PER_DISTANCE_OVER_SPEED = 10;
17export const JUMP_BASE_S = 60;
18export const JUMP_DISTANCE_PER_S = 50;
19export const DISTANCE_PER_FUEL = 10;
20export const DISTANCE_PER_HULL_POINT = 50;
21export const NEBULA_WEAR_FACTOR = 2;
22export const JUMP_WEAR = 2;
23export const HULL_MAX = 100;
24
25export interface Point {
26 x: number;
27 y: number;
28}
29
30export function distance(a: Point, b: Point): number {
31 return Math.hypot(a.x - b.x, a.y - b.y);
32}
33
34/** In-system trip: 15 s plus 10 s per unit of distance over the ship's speed. */
35export function tripSeconds(dist: number, speed: number): number {
36 return TRIP_BASE_S + (TRIP_S_PER_DISTANCE_OVER_SPEED * dist) / Math.max(speed, 1);
37}
38
39/** Jump between linked gates: 60 s plus 1 s per 50 units between the systems. */
40export function jumpSeconds(dist: number): number {
41 return JUMP_BASE_S + dist / JUMP_DISTANCE_PER_S;
42}
43
44/** Fuel burned over `dist` (in-system trip, or assumed for a jump — see header). */
45export function fuelFor(dist: number): number {
46 return Math.ceil(dist / DISTANCE_PER_FUEL);
47}
48
49/** Hull points a trip wears: 1 per 50 of distance, doubled in a nebula. */
50export function tripWear(dist: number, nebula: boolean): number {
51 return (dist / DISTANCE_PER_HULL_POINT) * (nebula ? NEBULA_WEAR_FACTOR : 1);
52}