Back to Big Rig Rush
SOURCE / PINNED RELEASE

Made of little things.

Big Rig Rush

Release
91e87bf21ff0…
Author-recorded commit
327727e196f9…
License
LICENSE
Author’s source reference
nostr://npub1sj2vketepqw9v6fmge5fdzuj7atj9sv6qv2jss05n2z6rl64lcfqumdsnt/wss%3A%2F%2Fgit.napplet.soy%2F/n-0a99f0cae40

Archive hash verified: 229261c1ab4372d8…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/game/speed-limits.ts
/**
 * Posted speed limits and speeding fines. Lane speeds are in map units per second;
 * the signs, the HUD and the police radar all work in km/h.
 */

/** Map units to km/h (0.33 m per unit). */
export const KMH_PER_UNIT = 0.33 * 3.6;

/** Lane cruise speed (units/s) → the limit on the sign for that kind of road. */
const POSTED: [number, number][] = [
  [45, 50], // drives
  [55, 60], // streets
  [58, 70], // industrial roads
  [62, 70], // avenues and boulevards
  [72, 80], // country roads
  [88, 100], // ramps
  [112, 130], // expressway
  [150, 170], // spurs
];

export function toKmh(unitsPerSecond: number): number {
  return Math.abs(unitsPerSecond) * KMH_PER_UNIT;
}

/** The posted limit (km/h) for a lane's cruise speed. */
export function postedKmh(laneSpeed: number): number {
  let best = POSTED[0];
  for (const p of POSTED) if (Math.abs(p[0] - laneSpeed) < Math.abs(best[0] - laneSpeed)) best = p;
  if (Math.abs(best[0] - laneSpeed) <= 3) return best[1];
  return Math.max(30, Math.round(toKmh(laneSpeed) / 10) * 10);
}

/** The radar lets a little through: 15 % plus 2 km/h over the limit. */
export function ticketKmh(posted: number): number {
  return Math.round(posted * 1.15 + 2);
}

/** A speeding fine: $60 plus $4 for every km/h over the limit, up to $400. */
export function fineFor(kmh: number, posted: number): number {
  const over = Math.max(0, Math.round(kmh - posted));
  return Math.min(400, 60 + over * 4);
}