@korial29/tiny-fps 0.118.1 → 0.119.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -616,7 +616,7 @@ var hidden = (w, a, b) => {
616
616
  ], len) < len - 1e-4;
617
617
  };
618
618
  // src/shared/physics.ts
619
- var DT$1 = 1 / 60;
619
+ var DT$2 = 1 / 60;
620
620
  var TAU = Math.PI * 2;
621
621
  /** Overlaps smaller than this are rounding noise, not contact. */
622
622
  var EPS = 1e-6;
@@ -635,11 +635,11 @@ var TOUCH = .001;
635
635
  var norm = (a) => (a % TAU + TAU) % TAU;
636
636
  /** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
637
637
  var forward = (yaw) => [-Math.sin(yaw), -Math.cos(yaw)];
638
- var f32$1 = Math.fround;
639
- var sqrt$1 = Math.sqrt;
640
- var clamp$1 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
638
+ var f32$2 = Math.fround;
639
+ var sqrt$2 = Math.sqrt;
640
+ var clamp$2 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
641
641
  /** The length of (x, z). */
642
- var len$1 = (x, z) => sqrt$1(x * x + z * z);
642
+ var len$1 = (x, z) => sqrt$2(x * x + z * z);
643
643
  /** The unit vector from a player toward a wall or a ledge on each SIDE. */
644
644
  var TOWARD = [
645
645
  [0, 0],
@@ -701,9 +701,9 @@ var spawn = (id, w, n, team = 0) => {
701
701
  const [x, y, z, yaw] = spawns[(n % spawns.length + spawns.length) % spawns.length];
702
702
  return {
703
703
  id,
704
- x: f32$1(x),
705
- y: f32$1(y),
706
- z: f32$1(z),
704
+ x: f32$2(x),
705
+ y: f32$2(y),
706
+ z: f32$2(z),
707
707
  vy: 0,
708
708
  yaw: norm(yaw),
709
709
  pitch: 0,
@@ -736,7 +736,7 @@ var speedOf = (p) => len$1(p.vx, p.vz);
736
736
  /** Whether the brush stops a body of height h whose feet are at y when it walks sideways into it. */
737
737
  var blocks = (b, y, h) => b.max[1] > y + .5 + SKIN && b.min[1] < y + h - SKIN;
738
738
  /** The closest point of the brush footprint to (x, z), as the offset from it to (x, z). */
739
- var gap = (b, x, z) => [x - clamp$1(x, b.min[0], b.max[0]), z - clamp$1(z, b.min[2], b.max[2])];
739
+ var gap = (b, x, z) => [x - clamp$2(x, b.min[0], b.max[0]), z - clamp$2(z, b.min[2], b.max[2])];
740
740
  /**
741
741
  * Pushes the player out of every brush that blocks it and that the circle overlaps, deepest first
742
742
  * (up to 4 passes: two walls in a corner settle in two). The push is along the vector from the
@@ -770,7 +770,7 @@ var shove = (p, w, h, r) => {
770
770
  const d2 = dx * dx + dz * dz;
771
771
  if (d2 >= reach) continue;
772
772
  if (d2) {
773
- const d = sqrt$1(d2);
773
+ const d = sqrt$2(d2);
774
774
  if (r - d > best) {
775
775
  best = r - d;
776
776
  px = dx / d * best;
@@ -818,7 +818,7 @@ var gapTo = (o, x, z) => {
818
818
  const [[ax, ay, az], [bx, by, bz]] = [o.a, o.b];
819
819
  const [ux, uz] = [bx - ax, bz - az];
820
820
  const l2 = ux * ux + uz * uz;
821
- const t = l2 ? clamp$1(((x - ax) * ux + (z - az) * uz) / l2, 0, 1) : 0;
821
+ const t = l2 ? clamp$2(((x - ax) * ux + (z - az) * uz) / l2, 0, 1) : 0;
822
822
  return [
823
823
  x - ax - t * ux,
824
824
  z - az - t * uz,
@@ -837,7 +837,7 @@ var jostle = (p, bodies, h) => {
837
837
  const r = o.r + PLAYER_R;
838
838
  const d2 = dx * dx + dz * dz;
839
839
  if (d2 >= (r - EPS) ** 2 || y + o.h <= p.y + .5 + SKIN || y >= p.y + h - SKIN) continue;
840
- const d = sqrt$1(d2);
840
+ const d = sqrt$2(d2);
841
841
  const [ux, uz] = [o.b[0] - o.a[0], o.b[2] - o.a[2]];
842
842
  const l = len$1(ux, uz);
843
843
  const [nx, nz] = d ? [dx / d, dz / d] : l ? [uz / l, -ux / l] : [1, 0];
@@ -983,7 +983,7 @@ var over = (p, w) => {
983
983
  return near(w, p.x, p.z, 0).some((i) => {
984
984
  const b = w.def.brushes[i];
985
985
  const depth = sign > 0 ? c - b.min[a] : b.max[a] - c;
986
- return f32$1(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
986
+ return f32$2(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
987
987
  });
988
988
  };
989
989
  /** The world's gravity: GRAVITY times the map's share (the moon's half gravity, the user, 2026-11-09). */
@@ -992,7 +992,7 @@ var gravity = (w) => 20 * (w.def.gravity ?? 1);
992
992
  var landingSoon = (p, w) => {
993
993
  if (p.vy >= 0) return false;
994
994
  const [floor] = span(p, w, PLAYER_H);
995
- const t = 6 * DT$1;
995
+ const t = 6 * DT$2;
996
996
  return p.y - floor <= -p.vy * t + .5 * gravity(w) * t * t;
997
997
  };
998
998
  /** Changes the mode, and starts counting the time in it. */
@@ -1010,8 +1010,8 @@ var floored = (p) => !!p.zap && p.stun > 24;
1010
1010
  */
1011
1011
  var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
1012
1012
  p.stun = ticks;
1013
- p.vx = f32$1(dx * knock);
1014
- p.vz = f32$1(dz * knock);
1013
+ p.vx = f32$2(dx * knock);
1014
+ p.vz = f32$2(dz * knock);
1015
1015
  p.dash = Math.min(p.dash, 50);
1016
1016
  p.coyote = 0;
1017
1017
  p.buffer = 0;
@@ -1059,7 +1059,7 @@ var steer = (p, wish, top) => {
1059
1059
  const m = len$1(wish[0], wish[1]);
1060
1060
  if (m < EPS) {
1061
1061
  const s = len$1(p.vx, p.vz);
1062
- const k = s ? Math.max(0, s - 45 * DT$1) / s : 0;
1062
+ const k = s ? Math.max(0, s - 45 * DT$2) / s : 0;
1063
1063
  p.vx *= k;
1064
1064
  p.vz *= k;
1065
1065
  return;
@@ -1069,11 +1069,11 @@ var steer = (p, wish, top) => {
1069
1069
  let [px, pz] = [p.vx - par * wx, p.vz - par * wz];
1070
1070
  const across = len$1(px, pz);
1071
1071
  if (across) {
1072
- const k = Math.max(0, across - 45 * DT$1) / across;
1072
+ const k = Math.max(0, across - 45 * DT$2) / across;
1073
1073
  [px, pz] = [px * k, pz * k];
1074
1074
  }
1075
1075
  top *= m;
1076
- par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$1) : Math.max(top, par - 12 * DT$1);
1076
+ par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$2) : Math.max(top, par - 12 * DT$2);
1077
1077
  p.vx = px + par * wx;
1078
1078
  p.vz = pz + par * wz;
1079
1079
  };
@@ -1086,8 +1086,8 @@ var steer = (p, wish, top) => {
1086
1086
  */
1087
1087
  var fly$1 = (p, w, h, g, snap, bodies) => {
1088
1088
  const y0 = p.y;
1089
- p.x += p.vx * DT$1;
1090
- p.z += p.vz * DT$1;
1089
+ p.x += p.vx * DT$2;
1090
+ p.z += p.vz * DT$2;
1091
1091
  let [cx, cz] = push(p, w, h);
1092
1092
  const [jx, jz] = jostle(p, bodies, h);
1093
1093
  if (jx || jz) {
@@ -1105,8 +1105,8 @@ var fly$1 = (p, w, h, g, snap, bodies) => {
1105
1105
  }
1106
1106
  bound(p, w);
1107
1107
  const [floor, ceil] = span(p, w, h, bodies);
1108
- const vy = p.vy - g * gravity(w) * DT$1;
1109
- p.y += (p.vy + vy) / 2 * DT$1;
1108
+ const vy = p.vy - g * gravity(w) * DT$2;
1109
+ p.y += (p.vy + vy) / 2 * DT$2;
1110
1110
  p.vy = vy;
1111
1111
  if (p.y + h > ceil) {
1112
1112
  p.y = ceil - h;
@@ -1154,16 +1154,16 @@ var hang = (p, w, c) => {
1154
1154
  p.coyote = 0;
1155
1155
  } else {
1156
1156
  const target = Math.max(p.edge - 2, span(p, w, PLAYER_H)[0]);
1157
- p.y += clamp$1(target - p.y, -8 * DT$1, 8 * DT$1);
1157
+ p.y += clamp$2(target - p.y, -8 * DT$2, 8 * DT$2);
1158
1158
  }
1159
1159
  };
1160
1160
  /** Climbing: up to the top, then in from the edge, then standing on it. */
1161
1161
  var climb = (p, w) => {
1162
1162
  const [nx, nz] = TOWARD[p.wall];
1163
- if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT$1);
1163
+ if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT$2);
1164
1164
  else {
1165
- p.x += nx * CLIMB_FWD_SPEED * DT$1;
1166
- p.z += nz * CLIMB_FWD_SPEED * DT$1;
1165
+ p.x += nx * CLIMB_FWD_SPEED * DT$2;
1166
+ p.z += nz * CLIMB_FWD_SPEED * DT$2;
1167
1167
  }
1168
1168
  if (p.y >= p.edge && over(p, w)) {
1169
1169
  enter(p, MODE.GROUND);
@@ -1201,10 +1201,10 @@ var run = (p, w, c) => {
1201
1201
  p.ev |= EV.WALLRUN_END;
1202
1202
  return;
1203
1203
  }
1204
- const k = Math.max(0, s - WALLRUN_DRAG * DT$1) / s;
1204
+ const k = Math.max(0, s - WALLRUN_DRAG * DT$2) / s;
1205
1205
  p.vx = tx * k;
1206
1206
  p.vz = tz * k;
1207
- const pull = Math.min(gap, 4 * DT$1);
1207
+ const pull = Math.min(gap, 4 * DT$2);
1208
1208
  p.x += nx * pull;
1209
1209
  p.z += nz * pull;
1210
1210
  }
@@ -1229,7 +1229,7 @@ var startRun = (p, w, c) => {
1229
1229
  enter(p, MODE.WALLRUN);
1230
1230
  p.wall = side;
1231
1231
  [p.vx, p.vz] = [tx * k, tz * k];
1232
- p.vy = clamp$1(p.vy, 2, 3);
1232
+ p.vy = clamp$2(p.vy, 2, 3);
1233
1233
  p.jumps = 1;
1234
1234
  p.dashes = 1;
1235
1235
  p.coyote = 0;
@@ -1242,7 +1242,7 @@ var startRun = (p, w, c) => {
1242
1242
  var grab = (p, l) => {
1243
1243
  enter(p, MODE.HANG);
1244
1244
  p.wall = l.side;
1245
- p.edge = f32$1(l.top);
1245
+ p.edge = f32$2(l.top);
1246
1246
  if (l.side <= SIDE.WEST) p.x = l.hang;
1247
1247
  else p.z = l.hang;
1248
1248
  p.vx = p.vy = p.vz = 0;
@@ -1253,7 +1253,7 @@ var grab = (p, l) => {
1253
1253
  p.ev |= EV.GRAB;
1254
1254
  };
1255
1255
  /** The modes that move freely: everything but the hang and the climb. */
1256
- var free = (p, w, c) => {
1256
+ var free$1 = (p, w, c) => {
1257
1257
  const ground = p.mode === MODE.GROUND;
1258
1258
  if (c.dash && p.dash === 0 && (ground || (p.mode === MODE.AIR || p.mode === MODE.WALLRUN) && p.dashes > 0)) {
1259
1259
  const [dx, dz] = c.wx || c.wz ? [c.wx, c.wz] : [c.fx, c.fz];
@@ -1325,12 +1325,12 @@ var onGround = (p, w, c, burst) => {
1325
1325
  if (burst) return;
1326
1326
  if (c.stumble) {
1327
1327
  if (speed > 2.5) {
1328
- const k = Math.max(STUMBLE_SPEED, speed - 12 * DT$1) / speed;
1328
+ const k = Math.max(STUMBLE_SPEED, speed - 12 * DT$2) / speed;
1329
1329
  p.vx *= k;
1330
1330
  p.vz *= k;
1331
1331
  } else steer(p, unwalled(p, w, c, heightOf(p)), STUMBLE_SPEED);
1332
1332
  } else if (p.mode === MODE.SLIDE) {
1333
- const k = Math.max(0, speed - 4 * DT$1) / speed;
1333
+ const k = Math.max(0, speed - 4 * DT$2) / speed;
1334
1334
  p.vx *= k;
1335
1335
  p.vz *= k;
1336
1336
  } else if (p.mode === MODE.CROUCH) steer(p, unwalled(p, w, c, LOW_H), 3);
@@ -1351,8 +1351,8 @@ var air = (p, w, c, burst) => {
1351
1351
  }
1352
1352
  if (burst || !c.wx && !c.wz) return;
1353
1353
  const before = len$1(p.vx, p.vz);
1354
- p.vx += c.wx * 14 * DT$1;
1355
- p.vz += c.wz * 14 * DT$1;
1354
+ p.vx += c.wx * 14 * DT$2;
1355
+ p.vz += c.wz * 14 * DT$2;
1356
1356
  cap(p, Math.max(before, 6));
1357
1357
  };
1358
1358
  /**
@@ -1394,7 +1394,7 @@ var move = (p, i, w, team = 0, bodies = []) => {
1394
1394
  }
1395
1395
  if (p.mode === MODE.HANG) hang(p, w, c);
1396
1396
  if (p.mode === MODE.CLIMB) climb(p, w);
1397
- else if (p.mode !== MODE.HANG && !riding) free(p, w, c);
1397
+ else if (p.mode !== MODE.HANG && !riding) free$1(p, w, c);
1398
1398
  if (p.slow) {
1399
1399
  p.slow--;
1400
1400
  cap(p, 3);
@@ -1405,13 +1405,13 @@ var move = (p, i, w, team = 0, bodies = []) => {
1405
1405
  if (p.mode === MODE.AIR && before === MODE.AIR) p.coyote = Math.max(0, p.coyote - 1);
1406
1406
  p.held = i.keys & (KEY.JUMP | KEY.DASH | KEY.USE);
1407
1407
  p.ground = onFloor(p.mode);
1408
- p.x = f32$1(p.x);
1409
- p.y = f32$1(p.y);
1410
- p.z = f32$1(p.z);
1411
- p.vx = f32$1(p.vx);
1412
- p.vy = f32$1(p.vy);
1413
- p.vz = f32$1(p.vz);
1414
- p.edge = f32$1(p.edge);
1408
+ p.x = f32$2(p.x);
1409
+ p.y = f32$2(p.y);
1410
+ p.z = f32$2(p.z);
1411
+ p.vx = f32$2(p.vx);
1412
+ p.vy = f32$2(p.vy);
1413
+ p.vz = f32$2(p.vz);
1414
+ p.edge = f32$2(p.edge);
1415
1415
  };
1416
1416
  // src/shared/blade.ts
1417
1417
  /** Where on the body the blade is, as a share of its height: the chest, which a brush must not cover. */
@@ -2011,7 +2011,7 @@ var powerOf = (ticks) => ticks < 10 ? 1 : 1 + Math.floor(4 * (ticks - 10) / 50);
2011
2011
  /** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
2012
2012
  var BASE$1 = -30;
2013
2013
  /** A building: the footprint x0..x1 by z0..z1 from the street up to a flat roof at `top`, white concrete over a facade. */
2014
- var roof = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
2014
+ var roof$1 = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
2015
2015
  min: [
2016
2016
  x0,
2017
2017
  BASE$1,
@@ -2059,12 +2059,12 @@ var stair = (z, y) => [
2059
2059
  z - k + 1
2060
2060
  ], TEX.CONCRETE));
2061
2061
  [
2062
- roof(4, 57.7, 24, 76, 10),
2063
- roof(4, 36, 24, 53.5, 10, TEX.GLASS),
2064
- roof(4, 20, 24, 36, 12.4),
2065
- roof(4, -5, 24, 7, 12.4, TEX.GLASS),
2066
- roof(27, 20, 47, 50, 8),
2067
- roof(27, 60, 47, 76, 8, TEX.BRICK),
2062
+ roof$1(4, 57.7, 24, 76, 10),
2063
+ roof$1(4, 36, 24, 53.5, 10, TEX.GLASS),
2064
+ roof$1(4, 20, 24, 36, 12.4),
2065
+ roof$1(4, -5, 24, 7, 12.4, TEX.GLASS),
2066
+ roof$1(27, 20, 47, 50, 8),
2067
+ roof$1(27, 60, 47, 76, 8, TEX.BRICK),
2068
2068
  box$1([
2069
2069
  9,
2070
2070
  12.2,
@@ -2251,7 +2251,7 @@ var ladder = (x, z, dx, dz, d, low, tops) => tops.map((top, k) => box$1([
2251
2251
  ], TEX.STEEL, TEX.CONCRETE));
2252
2252
  /** Red's half: z from 120 to 240, then flipped. */
2253
2253
  var half$1 = [
2254
- roof(12, 212, 52, 240, 26, TEX.GLASS),
2254
+ roof$1(12, 212, 52, 240, 26, TEX.GLASS),
2255
2255
  pad(12, 26, 212, 52, 26.12, 212.5, RED$1),
2256
2256
  pad(12, 26, 239.5, 52, 26.12, 240, RED$1),
2257
2257
  pad(12, 26, 212.5, 12.5, 26.12, 239.5, RED$1),
@@ -2294,10 +2294,10 @@ var half$1 = [
2294
2294
  27.5,
2295
2295
  219
2296
2296
  ], TEX.STEEL, TEX.PAINT, RED$1),
2297
- roof(6, 164, 26, 201, 26, TEX.GLASS),
2298
- roof(6, 134, 26, 147, 26, TEX.GLASS),
2299
- roof(6, 201, 26, 212, 19),
2300
- roof(15, 147, 26, 164, 19),
2297
+ roof$1(6, 164, 26, 201, 26, TEX.GLASS),
2298
+ roof$1(6, 134, 26, 147, 26, TEX.GLASS),
2299
+ roof$1(6, 201, 26, 212, 19),
2300
+ roof$1(15, 147, 26, 164, 19),
2301
2301
  box$1([
2302
2302
  14,
2303
2303
  26,
@@ -2397,7 +2397,7 @@ var half$1 = [
2397
2397
  27.3,
2398
2398
  143
2399
2399
  ], TEX.STEEL),
2400
- roof(32, 186, 76, 209, 19),
2400
+ roof$1(32, 186, 76, 209, 19),
2401
2401
  pad(32, 19, 207.5, 76, 19.1, 209, RED$1),
2402
2402
  ...ladder(33, 209, 7, 0, 3, 19, [
2403
2403
  21.2,
@@ -2435,8 +2435,8 @@ var half$1 = [
2435
2435
  top,
2436
2436
  z1
2437
2437
  ], TEX.STEEL, TEX.CONCRETE)),
2438
- roof(32, 166, 64, 182, 21.2, TEX.GLASS),
2439
- roof(32, 140, 64, 161, 19),
2438
+ roof$1(32, 166, 64, 182, 21.2, TEX.GLASS),
2439
+ roof$1(32, 140, 64, 161, 19),
2440
2440
  box$1([
2441
2441
  40,
2442
2442
  21.2,
@@ -2516,10 +2516,10 @@ var half$1 = [
2516
2516
  21.6,
2517
2517
  23.8
2518
2518
  ]),
2519
- roof(76, 213, 100, 240, 14.5, TEX.STEEL),
2519
+ roof$1(76, 213, 100, 240, 14.5, TEX.STEEL),
2520
2520
  pad(76, 14.5, 238.5, 100, 14.6, 240, RED$1),
2521
- roof(76, 185, 100, 209, 14.5),
2522
- roof(76, 138, 100, 181, 14.5, TEX.GLASS),
2521
+ roof$1(76, 185, 100, 209, 14.5),
2522
+ roof$1(76, 138, 100, 181, 14.5, TEX.GLASS),
2523
2523
  box$1([
2524
2524
  80,
2525
2525
  15.7,
@@ -2588,8 +2588,8 @@ var half$1 = [
2588
2588
  ];
2589
2589
  /** What stands on the centre line, symmetric as written: the plaza, its dais and canopy, the beam. */
2590
2590
  var centre$1 = [
2591
- roof(6, 106, 62, 134, 15),
2592
- roof(62, 106, 100, 134, 14.5),
2591
+ roof$1(6, 106, 62, 134, 15),
2592
+ roof$1(62, 106, 100, 134, 14.5),
2593
2593
  box$1([
2594
2594
  34,
2595
2595
  15,
@@ -3009,12 +3009,6 @@ var box = (x0, y0, z0, x1, y1, z1, top, side = top, tint) => ({
3009
3009
  side,
3010
3010
  tint
3011
3011
  });
3012
- var fromBx = ({ min, max }, top, side = top) => ({
3013
- min,
3014
- max,
3015
- top,
3016
- side
3017
- });
3018
3012
  var bx = (x0, y0, z0, x1, y1, z1) => ({
3019
3013
  min: [
3020
3014
  x0,
@@ -3393,13 +3387,12 @@ var [RED, BLUE] = TEAM_TINT;
3393
3387
  var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
3394
3388
  /** The twin of a box across the centre line. */
3395
3389
  var mirror = ({ min, max }) => bx(min[0], min[1], 280 - max[2], max[0], max[1], 280 - min[2]);
3396
- /** The domes' centres, the landing pads (x, z, radius), the shuttles, the modules, the tubes and the masts (centres), red's then blue's: what the scenery draws on. */
3390
+ /** The domes' centres, the landing pads (x, z, radius), the modules, the tubes and the masts (centres), red's then blue's: what the scenery draws on. */
3397
3391
  var PAD = [
3398
3392
  40,
3399
3393
  220,
3400
3394
  13
3401
3395
  ];
3402
- var SHUTTLE = bx(33, .25, 218, 47, 3.25, 222);
3403
3396
  var MASTS = [
3404
3397
  [27.3, 207.3],
3405
3398
  [52.7, 207.3],
@@ -4203,7 +4196,6 @@ var LAYOUT = {
4203
4196
  280 - PAD[1],
4204
4197
  PAD[2]
4205
4198
  ]],
4206
- shuttles: [SHUTTLE, mirror(SHUTTLE)],
4207
4199
  modules: [...MODULES, ...MODULES.map(mirror)],
4208
4200
  tubes: [...TUBES, ...TUBES.map(mirror)],
4209
4201
  masts: [...MASTS, ...MASTS.map(([x, z]) => [x, 280 - z])]
@@ -4274,26 +4266,6 @@ var half = [
4274
4266
  },
4275
4267
  box(60, 0, 259, 70, 1.5, 265, STEEL, PAINT, RED),
4276
4268
  box(27, 0, 207, 53, .25, 233, METAL),
4277
- {
4278
- ...fromBx(SHUTTLE, PAINT),
4279
- tint: [
4280
- .82,
4281
- .84,
4282
- .88
4283
- ]
4284
- },
4285
- {
4286
- ...box(42, 1, 222, 45.8, 1.25, 225.5, METAL),
4287
- ghost: true
4288
- },
4289
- {
4290
- ...box(42, 1, 214.5, 45.8, 1.25, 218, METAL),
4291
- ghost: true
4292
- },
4293
- {
4294
- ...box(43, 3.25, 219.9, 46.8, 5.4, 220.1, PAINT),
4295
- ghost: true
4296
- },
4297
4269
  ...MASTS.map(([x, z]) => box(x - .2, x < 60 ? .25 : 0, z - .2, x + .2, x < 60 ? 10.25 : 10, z + .2, STEEL)),
4298
4270
  box(12, -30, 148 - 2.5 / 2, 24, 0, 148, PAINT, STONE, [
4299
4271
  1,
@@ -4538,6 +4510,17 @@ var MAPS = {
4538
4510
  Math.PI
4539
4511
  ]
4540
4512
  ],
4513
+ ships: [[
4514
+ PAD[0],
4515
+ .25,
4516
+ PAD[1],
4517
+ 0
4518
+ ], [
4519
+ PAD[0],
4520
+ .25,
4521
+ 280 - PAD[1],
4522
+ Math.PI
4523
+ ]],
4541
4524
  doors: [...DOORS, ...DOORS.map(mirror)],
4542
4525
  scenery: "moon",
4543
4526
  helmets: true,
@@ -4766,7 +4749,7 @@ var flagBytes = (state) => state === FLAG$1.CARRIED ? 2 : state === FLAG$1.DROPP
4766
4749
  var encodeSnapshot = (s) => {
4767
4750
  const rovers = (s.rovers ?? []).slice(0, 7);
4768
4751
  const mid = 4 + 62 * s.players.length;
4769
- const end = mid + 54 * rovers.length;
4752
+ const end = mid + 57 * rovers.length;
4770
4753
  const balls = s.balls ?? [];
4771
4754
  const tail = end + 10 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
4772
4755
  const doors = s.doors ?? [];
@@ -4817,10 +4800,15 @@ var encodeSnapshot = (s) => {
4817
4800
  v.setUint8(o + 61, (p.nades ?? 0) << 6 | (p.lob ?? 0));
4818
4801
  });
4819
4802
  rovers.forEach((r, i) => {
4820
- const o = mid + i * 54;
4803
+ const o = mid + i * 57;
4821
4804
  ROVER_F.forEach((k, j) => v.setFloat32(o + 4 * j, r[k]));
4822
4805
  v.setUint8(o + 52, r.driver);
4823
4806
  v.setUint8(o + 53, r.rider);
4807
+ if (r.ship) {
4808
+ v.setUint8(o + 54, 128 | Math.max(0, Math.min(127, r.hp ?? 0)));
4809
+ v.setUint8(o + 55, Math.min(255, Math.ceil((r.wreck ?? 0) / 4)));
4810
+ v.setUint8(o + 56, r.nades ?? 0);
4811
+ }
4824
4812
  });
4825
4813
  v.setUint8(end, s.score[0]);
4826
4814
  v.setUint8(end + 1, s.score[1]);
@@ -4904,6 +4892,405 @@ var beam = (w, p, foes = [], range = 30, [dy, dp] = [0, 0]) => {
4904
4892
  hit
4905
4893
  };
4906
4894
  };
4895
+ // src/shared/ship.ts
4896
+ /** The ship's sizes and its handling. Lengths in metres, rates per second. */
4897
+ var SHIP = {
4898
+ /** From the centre down to the skids' bottom, the hull's height from there, and the hull's half width. */
4899
+ DROP: 1.3,
4900
+ H: 2.6,
4901
+ R: 1.6,
4902
+ /** The hull against the brushes: circles of radius R this far along the nose. */
4903
+ BODY: [
4904
+ 4.8,
4905
+ 0,
4906
+ -4.8
4907
+ ],
4908
+ /** The hull as the shots meet it: spheres of radius HIT this far along the nose. */
4909
+ HITS: [
4910
+ 4.5,
4911
+ 0,
4912
+ -4.5
4913
+ ],
4914
+ HIT: 2.6,
4915
+ /** Thrust along the nose, sideways and straight up (m/s²), the boost's factor, and the top speed without it. */
4916
+ ACC: 24,
4917
+ STRAFE: 14,
4918
+ LIFT: 16,
4919
+ BOOST: 1.7,
4920
+ VMAX: 48,
4921
+ /** Drag with nobody at the stick (1/s), and the skids' friction on a floor. */
4922
+ DRIFT: .25,
4923
+ /** The dampers (1/s) with no key on an axis: the slide on the level stops, and so does the climb with no thrust. */
4924
+ HOLD: 1.5,
4925
+ HOVER: 3,
4926
+ SKID: 3,
4927
+ /** The nose turns toward the look: gain, the rates' caps (yaw, pitch) and how fast a rate follows. */
4928
+ TURN: 4,
4929
+ YRATE: 1.9,
4930
+ PRATE: 1.5,
4931
+ RESP: 8,
4932
+ /** The highest pitch, up or down, and the bank: per rad/s of yaw, per unit of slide, its cap and its response. */
4933
+ PMAX: 1.25,
4934
+ BANK: .4,
4935
+ SLIDE: .3,
4936
+ RMAX: .8,
4937
+ RRESP: 5,
4938
+ /** The ceiling's height (y), the crater's bound shrunk to EDGE, and the depth over which the warning grows. */
4939
+ CEIL: 120,
4940
+ EDGE: .88,
4941
+ WARN: 20,
4942
+ /** Past a limit: the push back (m/s² per metre past it) and the brake on the speed out (1/s). */
4943
+ PUSH: 3,
4944
+ BRAKE: 4,
4945
+ /** The hard stop past the limit, metres. */
4946
+ OVER: 12,
4947
+ /** A player this close to the centre (on the floor plane) and within this height gets in. */
4948
+ ENTER_R: 6,
4949
+ ENTER_H: 4,
4950
+ /** Armour, and the ticks a destroyed ship is gone before it is back on its pad. */
4951
+ HP: 60,
4952
+ WRECK: 600,
4953
+ /** The lasers: ticks between two salvos, the bolts' reach, and where the beams cross ahead along the look. */
4954
+ GUN_COOL: 6,
4955
+ GUN_RANGE: 160,
4956
+ GUN_AIM: 80,
4957
+ /** Missiles: how many a ship carries, the ticks between two, the ticks to load one more, and their speed (m/s, 63 at most on the wire). */
4958
+ MISSILES: 4,
4959
+ MISSILE_COOL: 30,
4960
+ RELOAD: 300,
4961
+ MISSILE_SPEED: 60,
4962
+ /** A missile's burst: the armour it takes at the hull, falling off to nothing this far from it. */
4963
+ BLAST_HP: 14,
4964
+ BLAST_R: 7,
4965
+ /** The armour a laser bolt or a rifle round takes, and a plasma ball per point of its power. */
4966
+ BOLT_HP: 1,
4967
+ BALL_HP: 2
4968
+ };
4969
+ /** The lasers' muzzles at the wing roots, the missiles' pods under the wings: right of the centre, above it, ahead of it. */
4970
+ var SHIP_GUNS = [[
4971
+ -2.6,
4972
+ -.2,
4973
+ 2.2
4974
+ ], [
4975
+ 2.6,
4976
+ -.2,
4977
+ 2.2
4978
+ ]];
4979
+ var PODS = [[
4980
+ -3.4,
4981
+ -.7,
4982
+ .5
4983
+ ], [
4984
+ 3.4,
4985
+ -.7,
4986
+ .5
4987
+ ]];
4988
+ /** The pilot's seat in the cockpit: right of the centre, above it (the feet), ahead of it. */
4989
+ var COCKPIT = [
4990
+ 0,
4991
+ -.55,
4992
+ 2.4
4993
+ ];
4994
+ /** Where who gets out stands, beside the cockpit: clear of the hull, ahead of the wings. */
4995
+ var OUT$1 = SHIP.R + .9;
4996
+ var DT$1 = 1 / 60;
4997
+ var f32$1 = Math.fround;
4998
+ var { sin: sin$1, cos: cos$1, min: min$1, max: max$1, abs: abs$1, sqrt: sqrt$1 } = Math;
4999
+ var clamp$1 = (v, lo, hi) => min$1(max$1(v, lo), hi);
5000
+ var FLOATS$1 = "x y z vx vy vz yaw pitch roll wy wp wr steer".split(" ");
5001
+ /** The ship's axes in the world: right, up and the nose, pitched and banked (mesh.ts's basis()). */
5002
+ var axes = (r) => {
5003
+ const [sy, cy, sp, cp, sr, cr] = [
5004
+ r.yaw,
5005
+ r.pitch,
5006
+ r.roll
5007
+ ].flatMap((a) => [sin$1(a), cos$1(a)]);
5008
+ const R = [
5009
+ cy,
5010
+ 0,
5011
+ -sy
5012
+ ];
5013
+ const U = [
5014
+ sy * sp,
5015
+ cp,
5016
+ cy * sp
5017
+ ];
5018
+ return [
5019
+ [
5020
+ R[0] * cr - U[0] * sr,
5021
+ R[1] * cr - U[1] * sr,
5022
+ R[2] * cr - U[2] * sr
5023
+ ],
5024
+ [
5025
+ U[0] * cr + R[0] * sr,
5026
+ U[1] * cr + R[1] * sr,
5027
+ U[2] * cr + R[2] * sr
5028
+ ],
5029
+ [
5030
+ -sy * cp,
5031
+ sp,
5032
+ -cy * cp
5033
+ ]
5034
+ ];
5035
+ };
5036
+ /** A point of the ship, `b` m right of the centre, `u` m above it and `a` m ahead of it. */
5037
+ var point = (r, b, u, a) => {
5038
+ const [R, U, F] = axes(r);
5039
+ return [
5040
+ r.x + R[0] * b + U[0] * u + F[0] * a,
5041
+ r.y + R[1] * b + U[1] * u + F[1] * a,
5042
+ r.z + R[2] * b + U[2] * u + F[2] * a
5043
+ ];
5044
+ };
5045
+ /** The map's ships at rest on their pads: full armour and missiles, nobody aboard. */
5046
+ var dock = (ships = []) => ships.map(([x, y, z, yaw]) => ({
5047
+ x: f32$1(x),
5048
+ y: f32$1(y + SHIP.DROP),
5049
+ z: f32$1(z),
5050
+ vx: 0,
5051
+ vy: 0,
5052
+ vz: 0,
5053
+ yaw: f32$1(norm(yaw)),
5054
+ pitch: 0,
5055
+ roll: 0,
5056
+ wy: 0,
5057
+ wp: 0,
5058
+ wr: 0,
5059
+ steer: 0,
5060
+ driver: 255,
5061
+ rider: 255,
5062
+ ship: true,
5063
+ hp: SHIP.HP,
5064
+ wreck: 0,
5065
+ nades: SHIP.MISSILES
5066
+ }));
5067
+ /** A body that meets nothing: a ship that is gone. */
5068
+ var NONE = {
5069
+ a: [
5070
+ 0,
5071
+ -1e4,
5072
+ 0
5073
+ ],
5074
+ b: [
5075
+ 0,
5076
+ -1e4,
5077
+ 0
5078
+ ],
5079
+ r: 0,
5080
+ h: 0
5081
+ };
5082
+ /**
5083
+ * The hull as the players on foot and the rovers meet it: the stadium from the tail to the nose
5084
+ * along the floor plane, R wide, from the skids up H. A player walks into it and stands on it.
5085
+ */
5086
+ var shipHull = (r) => {
5087
+ if (r.wreck) return NONE;
5088
+ const [a, b] = [SHIP.BODY[0], SHIP.BODY[2]].map((k) => point(r, 0, -SHIP.DROP, k));
5089
+ return {
5090
+ a,
5091
+ b,
5092
+ r: SHIP.R,
5093
+ h: SHIP.H
5094
+ };
5095
+ };
5096
+ /**
5097
+ * The ship against the crater's edge: its distance from the bound's centre and the edge's along the
5098
+ * same line, and the unit way out on the floor plane. Undefined on a map without a relief.
5099
+ */
5100
+ var edge = (r, w) => {
5101
+ if (!w.relief) return;
5102
+ const [cx, cz, a, b] = w.relief.bound;
5103
+ const [dx, dz] = [r.x - cx, r.z - cz];
5104
+ const d = sqrt$1(dx * dx + dz * dz);
5105
+ if (!d) return [
5106
+ 0,
5107
+ SHIP.EDGE * min$1(a, b),
5108
+ 1,
5109
+ 0
5110
+ ];
5111
+ const [ux, uz] = [dx / d, dz / d];
5112
+ return [
5113
+ d,
5114
+ SHIP.EDGE / sqrt$1(ux * ux / (a * a) + uz * uz / (b * b)),
5115
+ ux,
5116
+ uz
5117
+ ];
5118
+ };
5119
+ /** The lowest bottom of a brush over the circle round (x, z) between y0 and y1, or y1. */
5120
+ var roof = (w, x, z, y0, y1) => {
5121
+ let top = y1;
5122
+ for (const i of near(w, x, z, SHIP.R)) {
5123
+ const { min: lo, max: hi } = w.def.brushes[i];
5124
+ if (x > lo[0] - SHIP.R && x < hi[0] + SHIP.R && z > lo[2] - SHIP.R && z < hi[2] + SHIP.R && lo[1] > y0 && lo[1] < top) top = lo[1];
5125
+ }
5126
+ return top;
5127
+ };
5128
+ /**
5129
+ * One step of 1 / TICK_HZ s, in place. `i` is the pilot's input as the wire rounds it, or
5130
+ * undefined with nobody at the stick: the engines are off and it falls under the map's gravity to
5131
+ * a floor. A ship that is gone (`wreck`) does not move. Returns whether it fell under the kill
5132
+ * floor: the caller docks it again.
5133
+ *
5134
+ * The nose turns toward the look as fast as the rates allow and banks into the turn; the thrust
5135
+ * is along the nose, sideways and straight up, against a drag that sets the top speed. Piloted,
5136
+ * the engines hold it against gravity: it hovers with no key held. On a floor it rests on its
5137
+ * skids, level.
5138
+ */
5139
+ var pilot = (r, i, w) => {
5140
+ if (r.wreck) return false;
5141
+ const keys = i ? i.keys : 0;
5142
+ const on = (k) => keys & k ? 1 : 0;
5143
+ const thr = on(KEY.FORWARD) - on(KEY.BACK);
5144
+ const side = on(KEY.RIGHT) - on(KEY.LEFT);
5145
+ const lift = on(KEY.JUMP) - on(KEY.CROUCH);
5146
+ const boost = on(KEY.SPRINT) && thr > 0 ? SHIP.BOOST : 1;
5147
+ const landed = r.steer < 0;
5148
+ if (i) {
5149
+ const ey = norm(i.yaw - r.yaw + Math.PI) - Math.PI;
5150
+ const tp = clamp$1(i.pitch, landed ? 0 : -SHIP.PMAX, SHIP.PMAX);
5151
+ const k = min$1(1, SHIP.RESP * DT$1);
5152
+ r.wy += (clamp$1(SHIP.TURN * ey, -SHIP.YRATE, SHIP.YRATE) - r.wy) * k;
5153
+ r.wp += (clamp$1(SHIP.TURN * (tp - r.pitch), -SHIP.PRATE, SHIP.PRATE) - r.wp) * k;
5154
+ } else {
5155
+ r.wy *= 1 - min$1(1, SHIP.RESP * DT$1);
5156
+ r.wp = landed ? -SHIP.TURN * r.pitch : r.wp * (1 - min$1(1, SHIP.RESP * DT$1));
5157
+ }
5158
+ r.wr = ((landed ? 0 : clamp$1(-SHIP.BANK * r.wy + SHIP.SLIDE * side, -SHIP.RMAX, SHIP.RMAX)) - r.roll) * SHIP.RRESP;
5159
+ const [sy, cy, sp, cp] = [
5160
+ sin$1(r.yaw),
5161
+ cos$1(r.yaw),
5162
+ sin$1(r.pitch),
5163
+ cos$1(r.pitch)
5164
+ ];
5165
+ const a = i ? [
5166
+ -sy * cp * thr * SHIP.ACC * boost + cy * side * SHIP.STRAFE,
5167
+ sp * thr * SHIP.ACC * boost + lift * SHIP.LIFT,
5168
+ -cy * cp * thr * SHIP.ACC * boost - sy * side * SHIP.STRAFE
5169
+ ] : [
5170
+ 0,
5171
+ -gravity(w),
5172
+ 0
5173
+ ];
5174
+ const over = r.y - SHIP.CEIL;
5175
+ if (a[1] > 0) a[1] *= clamp$1(-over / SHIP.WARN, 0, 1);
5176
+ if (over > 0) {
5177
+ a[1] -= SHIP.PUSH * over;
5178
+ if (r.vy > 0) r.vy *= 1 - min$1(1, SHIP.BRAKE * DT$1);
5179
+ }
5180
+ const e = edge(r, w);
5181
+ if (e) {
5182
+ const [d, at, nx, nz] = e;
5183
+ const out = a[0] * nx + a[2] * nz;
5184
+ const past = d - at;
5185
+ if (out > 0) {
5186
+ const k = 1 - clamp$1(-past / SHIP.WARN, 0, 1);
5187
+ a[0] -= out * nx * k;
5188
+ a[2] -= out * nz * k;
5189
+ }
5190
+ if (past > 0) {
5191
+ a[0] -= SHIP.PUSH * past * nx;
5192
+ a[2] -= SHIP.PUSH * past * nz;
5193
+ const v = r.vx * nx + r.vz * nz;
5194
+ if (v > 0) {
5195
+ const k = v * min$1(1, SHIP.BRAKE * DT$1);
5196
+ r.vx -= k * nx;
5197
+ r.vz -= k * nz;
5198
+ }
5199
+ }
5200
+ }
5201
+ const drag = i ? SHIP.ACC / SHIP.VMAX : SHIP.DRIFT;
5202
+ const level = drag + (i && !thr && !side ? SHIP.HOLD : 0);
5203
+ const climb = drag + (i && !thr && !lift ? SHIP.HOVER : 0);
5204
+ r.vx += (a[0] - r.vx * level) * DT$1;
5205
+ r.vy += (a[1] - r.vy * climb) * DT$1;
5206
+ r.vz += (a[2] - r.vz * level) * DT$1;
5207
+ if (landed) {
5208
+ const k = 1 - min$1(1, SHIP.SKID * DT$1);
5209
+ r.vx *= thr || side ? 1 : k;
5210
+ r.vz *= thr || side ? 1 : k;
5211
+ }
5212
+ r.x += r.vx * DT$1;
5213
+ r.y += r.vy * DT$1;
5214
+ r.z += r.vz * DT$1;
5215
+ r.yaw = norm(r.yaw + r.wy * DT$1);
5216
+ r.pitch = clamp$1(r.pitch + r.wp * DT$1, -SHIP.PMAX, SHIP.PMAX);
5217
+ r.roll += r.wr * DT$1;
5218
+ r.y = min$1(r.y, SHIP.CEIL + SHIP.OVER);
5219
+ if (e) {
5220
+ const [d, at, nx, nz] = edge(r, w);
5221
+ if (d > at + SHIP.OVER) {
5222
+ r.x -= nx * (d - at - SHIP.OVER);
5223
+ r.z -= nz * (d - at - SHIP.OVER);
5224
+ }
5225
+ }
5226
+ let lifted = 0;
5227
+ for (const k of SHIP.BODY) {
5228
+ const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5229
+ lifted = max$1(lifted, floorAt(w, x, z, y + .6) - y);
5230
+ }
5231
+ r.steer = 0;
5232
+ if (lifted > 0) {
5233
+ r.y += lifted;
5234
+ r.vy = max$1(r.vy, 0);
5235
+ r.steer = r.vy > .5 ? 0 : -1;
5236
+ }
5237
+ for (const k of SHIP.BODY) {
5238
+ const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5239
+ const top = roof(w, x, z, y + .6, y + SHIP.H);
5240
+ if (top < y + SHIP.H) {
5241
+ r.y -= y + SHIP.H - top;
5242
+ r.vy = min$1(r.vy, 0);
5243
+ }
5244
+ }
5245
+ for (const k of SHIP.BODY) {
5246
+ const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5247
+ const [px, pz] = shove({
5248
+ x,
5249
+ y: y + .6,
5250
+ z
5251
+ }, w, SHIP.H - .6, SHIP.R);
5252
+ const d = px * px + pz * pz;
5253
+ if (d) {
5254
+ r.x += px;
5255
+ r.z += pz;
5256
+ const v = min$1(0, r.vx * px + r.vz * pz) / d;
5257
+ r.vx -= v * px;
5258
+ r.vz -= v * pz;
5259
+ }
5260
+ }
5261
+ bound(r, w);
5262
+ if (abs$1(r.roll) < 1e-6) r.roll = 0;
5263
+ for (const k of FLOATS$1) r[k] = f32$1(r[k]);
5264
+ return r.y < w.def.floor;
5265
+ };
5266
+ /**
5267
+ * Where a shot from `o` along the unit `d` meets the hull within `m` metres: the distance, or
5268
+ * Infinity. The hull is the HITS spheres; a ship that is gone has none.
5269
+ */
5270
+ var struck = (r, o, d, m) => {
5271
+ if (r.wreck) return Infinity;
5272
+ let best = Infinity;
5273
+ for (const k of SHIP.HITS) {
5274
+ const c = point(r, 0, 0, k);
5275
+ const [px, py, pz] = [
5276
+ o[0] - c[0],
5277
+ o[1] - c[1],
5278
+ o[2] - c[2]
5279
+ ];
5280
+ const b = px * d[0] + py * d[1] + pz * d[2];
5281
+ const q = px * px + py * py + pz * pz - SHIP.HIT * SHIP.HIT;
5282
+ const disc = b * b - q;
5283
+ if (disc < 0) continue;
5284
+ const t = max$1(0, -b - sqrt$1(disc));
5285
+ if (t <= m && t < best) best = t;
5286
+ }
5287
+ return best;
5288
+ };
5289
+ /** The distance from `c` to the nearest point of the hull's spheres, 0 inside. */
5290
+ var reach = (r, c) => min$1(...SHIP.HITS.map((k) => {
5291
+ const [x, y, z] = point(r, 0, 0, k).map((v, n) => c[n] - v);
5292
+ return max$1(0, sqrt$1(x * x + y * y + z * z) - SHIP.HIT);
5293
+ }));
4907
5294
  // src/shared/rover.ts
4908
5295
  /** The rover's sizes and its handling (docs/MOON.md). Lengths in metres, per wheel rates for a body of mass 1. */
4909
5296
  var ROVER = {
@@ -5050,6 +5437,7 @@ var footprint = (r) => ROVER.BODY.map((a) => at(r, a, 0, -DROP));
5050
5437
  * rear circles of footprint(), RB wide and BODY_H tall. A player walks into it and stands on it.
5051
5438
  */
5052
5439
  var hull = (r) => {
5440
+ if (r.ship) return shipHull(r);
5053
5441
  const [a, , b] = footprint(r);
5054
5442
  return {
5055
5443
  a,
@@ -5058,8 +5446,12 @@ var hull = (r) => {
5058
5446
  h: ROVER.BODY_H
5059
5447
  };
5060
5448
  };
5061
- /** The map's rovers at rest on their spawns, nobody aboard. */
5062
- var park = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5449
+ /**
5450
+ * The map's rovers at rest on their spawns, nobody aboard, then its ships on their pads (ship.ts):
5451
+ * the order of the snapshot's.
5452
+ */
5453
+ var park = (w) => [...cars(w), ...dock(w.def.ships)];
5454
+ var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5063
5455
  x: f32(x),
5064
5456
  y: f32(y + DROP),
5065
5457
  z: f32(z),
@@ -5090,6 +5482,7 @@ var park = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5090
5482
  * speed follows it. The rest drifts.
5091
5483
  */
5092
5484
  var drive = (r, i, w, fleet = []) => {
5485
+ if (r.ship) return pilot(r, i, w);
5093
5486
  const { A, B, CMAX, K, D, KP2, KR2, HC, MU, MUL, TILT } = ROVER;
5094
5487
  const g = gravity(w);
5095
5488
  const keys = i ? i.keys : 0;
@@ -5210,8 +5603,8 @@ var drive = (r, i, w, fleet = []) => {
5210
5603
  * speed. The seat leans with the body: on a slope he is not left in the air.
5211
5604
  */
5212
5605
  var seat = (p, r, s) => {
5213
- const [side, up, ahead] = SEATS$1[s];
5214
- [p.x, p.y, p.z] = at(r, ahead, side, up).map(f32);
5606
+ const [side, up, ahead] = r.ship ? COCKPIT : SEATS$1[s];
5607
+ [p.x, p.y, p.z] = (r.ship ? point(r, side, up, ahead) : at(r, ahead, side, up)).map(f32);
5215
5608
  p.vx = r.vx;
5216
5609
  p.vy = r.vy;
5217
5610
  p.vz = r.vz;
@@ -5247,13 +5640,15 @@ var leave = (p, r, s, w) => {
5247
5640
  r.vy,
5248
5641
  r.vz
5249
5642
  ];
5250
- const side = s ? OUT : -OUT;
5643
+ const side = r.ship ? -OUT$1 : s ? OUT : -OUT;
5644
+ const [drop, top] = r.ship ? [SHIP.DROP, SHIP.H] : [DROP, ROVER.BODY_H];
5251
5645
  for (const [b, u] of [
5252
- [side, -DROP],
5253
- [-side, -DROP],
5254
- [0, ROVER.BODY_H - DROP]
5646
+ [side, -drop],
5647
+ [-side, -drop],
5648
+ [0, top - drop]
5255
5649
  ]) {
5256
- const [x, y, z] = at(r, SEATS$1[s][2], b, u);
5650
+ const ahead = r.ship ? COCKPIT[2] : SEATS$1[s][2];
5651
+ const [x, y, z] = r.ship ? point(r, b, u, ahead) : at(r, ahead, b, u);
5257
5652
  Object.assign(p, {
5258
5653
  x,
5259
5654
  y,
@@ -5290,7 +5685,24 @@ var ride = (p, r, i, w, team, fleet = []) => {
5290
5685
  }
5291
5686
  return fell;
5292
5687
  };
5293
- /** Where the rover's lasers cross: GUN_AIM metres from its centre along the driver's look. */
5688
+ /** The squared distance on the floor plane from the vehicle's centre to the player. */
5689
+ var gap2 = (r, p) => (r.x - p.x) ** 2 + (r.z - p.z) ** 2;
5690
+ /**
5691
+ * A player on foot near enough to get in: on the floor plane within ENTER_R of the centre, and
5692
+ * within the reach in height (a ship's ENTER_H). A ship that is gone has no seat.
5693
+ */
5694
+ var nearby = (r, p) => {
5695
+ const [k, h] = r.ship ? [SHIP.ENTER_R, SHIP.ENTER_H] : [ROVER.ENTER_R, ROVER.ENTER_R];
5696
+ return !r.wreck && Math.abs(r.y - p.y) <= h && gap2(r, p) <= k * k;
5697
+ };
5698
+ /**
5699
+ * The seat a player gets: 0 at the wheel (never a flag's carrier), 1 beside it, -1 none. A ship
5700
+ * has its pilot's seat only.
5701
+ */
5702
+ var free = (r, carrier) => r.driver === 255 && !carrier ? 0 : r.rider === 255 && !r.ship ? 1 : -1;
5703
+ /** Metres from the centre to where the lasers cross along the look: a ship's or a rover's. */
5704
+ var aimRange = (r) => r.ship ? SHIP.GUN_AIM : ROVER.GUN_AIM;
5705
+ /** Where the lasers cross: aimRange() metres from the centre along the driver's look. */
5294
5706
  var aimOf = (r, yaw, pitch) => {
5295
5707
  const [sy, cy, sp, cp] = [
5296
5708
  Math.sin(yaw),
@@ -5298,28 +5710,39 @@ var aimOf = (r, yaw, pitch) => {
5298
5710
  Math.sin(pitch),
5299
5711
  Math.cos(pitch)
5300
5712
  ];
5713
+ const k = aimRange(r);
5714
+ return [
5715
+ r.x - sy * cp * k,
5716
+ r.y + sp * k,
5717
+ r.z - cy * cp * k
5718
+ ];
5719
+ };
5720
+ /** A muzzle of the vehicle in the world: `m` is right of the centre, above it, ahead of it. */
5721
+ var muzzle = (r, [side, up, ahead]) => {
5722
+ if (r.ship) return point(r, side, up, ahead);
5723
+ const [fx, fz] = forward(r.yaw);
5301
5724
  return [
5302
- r.x - sy * cp * ROVER.GUN_AIM,
5303
- r.y + sp * ROVER.GUN_AIM,
5304
- r.z - cy * cp * ROVER.GUN_AIM
5725
+ r.x + fx * ahead - fz * side,
5726
+ r.y + up,
5727
+ r.z + fz * ahead + fx * side
5305
5728
  ];
5306
5729
  };
5730
+ /** From `o` toward the aim, unit. */
5731
+ var toward = (o, aim) => {
5732
+ const d = aim.map((v, a) => v - o[a]);
5733
+ const l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
5734
+ return d.map((v) => v / l);
5735
+ };
5307
5736
  /**
5308
5737
  * The two bolts of one salvo of the rover's lasers, left then right: each from its muzzle toward
5309
5738
  * the point GUN_AIM metres along the driver's look (the yaw and pitch of his input) from the rover's
5310
5739
  * centre, so the beams cross there, chest high on level ground with a level look. `id` names the first, `id + 1` the second.
5311
5740
  */
5312
5741
  var bolts = (r, by, team, yaw, pitch, id) => {
5313
- const [fx, fz] = forward(r.yaw);
5314
5742
  const aim = aimOf(r, yaw, pitch);
5315
- return GUNS.map(([side, up, ahead], k) => {
5316
- const o = [
5317
- r.x + fx * ahead - fz * side,
5318
- r.y + up,
5319
- r.z + fz * ahead + fx * side
5320
- ];
5321
- const d = aim.map((v, a) => v - o[a]);
5322
- const l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
5743
+ return (r.ship ? SHIP_GUNS : GUNS).map((m, k) => {
5744
+ const o = muzzle(r, m);
5745
+ const d = toward(o, aim);
5323
5746
  return {
5324
5747
  id: id + k & 255,
5325
5748
  by,
@@ -5327,15 +5750,40 @@ var bolts = (r, by, team, yaw, pitch, id) => {
5327
5750
  x: o[0],
5328
5751
  y: o[1],
5329
5752
  z: o[2],
5330
- dx: d[0] / l,
5331
- dy: d[1] / l,
5332
- dz: d[2] / l,
5333
- left: ROVER.GUN_RANGE,
5753
+ dx: d[0],
5754
+ dy: d[1],
5755
+ dz: d[2],
5756
+ left: r.ship ? SHIP.GUN_RANGE : ROVER.GUN_RANGE,
5334
5757
  burst: false,
5335
5758
  power: 6
5336
5759
  };
5337
5760
  });
5338
5761
  };
5762
+ /**
5763
+ * A ship's missile from its pod `k` (0 left, 1 right) toward where its lasers cross: a grenade
5764
+ * (plasma.ts's toss() flies it, blast() is its burst) launched at MISSILE_SPEED plus the ship's own
5765
+ * speed along the way, 63 m/s at most (the wire's six bits).
5766
+ */
5767
+ var missile = (r, by, team, yaw, pitch, id, k) => {
5768
+ const o = muzzle(r, PODS[k]);
5769
+ const d = toward(o, aimOf(r, yaw, pitch));
5770
+ const own = r.vx * d[0] + r.vy * d[1] + r.vz * d[2];
5771
+ return {
5772
+ id: id & 255,
5773
+ by,
5774
+ team,
5775
+ x: o[0],
5776
+ y: o[1],
5777
+ z: o[2],
5778
+ dx: d[0],
5779
+ dy: d[1],
5780
+ dz: d[2],
5781
+ left: 2 * SHIP.GUN_RANGE,
5782
+ burst: false,
5783
+ power: 7,
5784
+ v: Math.min(63, SHIP.MISSILE_SPEED + Math.max(0, own))
5785
+ };
5786
+ };
5339
5787
  // src/shared/tackle.ts
5340
5788
  /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
5341
5789
  var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
@@ -5429,8 +5877,10 @@ var Room = class {
5429
5877
  gone;
5430
5878
  /** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
5431
5879
  balls = [];
5432
- /** The map's rovers, in the order of WorldDef.rovers. */
5880
+ /** The map's rovers, in the order of WorldDef.rovers, then its ships (ship.ts). */
5433
5881
  rovers;
5882
+ /** Ticks toward each ship's next missile, by index in `rovers`. */
5883
+ rearm = [];
5434
5884
  /** The key of the map being played, which the roster tells the clients. */
5435
5885
  mapName;
5436
5886
  /** The map the host picked for the next match, when it is another one. */
@@ -5512,7 +5962,8 @@ var Room = class {
5512
5962
  if (fell) this.sink(r);
5513
5963
  else {
5514
5964
  this.carry(r);
5515
- this.splat(p, r, input.view);
5965
+ if (r.ship) this.launch(p, r, input);
5966
+ else this.splat(p, r, input.view);
5516
5967
  this.lase(p, r, input);
5517
5968
  }
5518
5969
  } else {
@@ -5593,6 +6044,7 @@ var Room = class {
5593
6044
  this.restart(players);
5594
6045
  }
5595
6046
  this.seats();
6047
+ this.rovers.forEach((r, k) => this.dock(r, k));
5596
6048
  for (const r of this.rovers) if (r.driver !== 255) this.carry(r);
5597
6049
  else if (drive(r, void 0, this.world, this.rovers)) this.sink(r);
5598
6050
  else this.carry(r);
@@ -5775,8 +6227,23 @@ var Room = class {
5775
6227
  fly(b, m) {
5776
6228
  const peers = this.players();
5777
6229
  const foes = peers.filter((q) => q.info.team !== b.team && !q.state.down);
6230
+ const by = peers.find((q) => q.info.id === b.by);
6231
+ const o = [
6232
+ b.x,
6233
+ b.y,
6234
+ b.z
6235
+ ];
5778
6236
  if (b.power === 7) {
5779
6237
  toss(this.world, b, foes.map((f) => f.state));
6238
+ this.ram(b, o);
6239
+ for (const r of b.burst ? this.targets(b.team) : []) {
6240
+ const d = reach(r, [
6241
+ b.x,
6242
+ b.y,
6243
+ b.z
6244
+ ]);
6245
+ if (d < SHIP.BLAST_R) this.hurt(r, Math.ceil(SHIP.BLAST_HP * (1 - d / SHIP.BLAST_R)), by);
6246
+ }
5780
6247
  let hit = false;
5781
6248
  for (const q of b.burst ? peers : []) {
5782
6249
  const own = q.info.id === b.by;
@@ -5790,14 +6257,17 @@ var Room = class {
5790
6257
  hit ||= !own;
5791
6258
  }
5792
6259
  }
5793
- const by = peers.find((q) => q.info.id === b.by);
5794
6260
  if (hit && by) by.state.hits = by.state.hits + 1 & 255;
5795
6261
  return;
5796
6262
  }
5797
6263
  const hit = fly(this.world, b, m, foes.map((f) => f.state));
6264
+ const ship = this.ram(b, o);
6265
+ if (ship) {
6266
+ this.hurt(ship, b.power === 0 || b.power === 6 ? SHIP.BOLT_HP : SHIP.BALL_HP * (b.power ?? 1), by);
6267
+ return;
6268
+ }
5798
6269
  const foe = foes.find((q) => q.state === hit);
5799
6270
  if (!foe) return;
5800
- const by = peers.find((q) => q.info.id === b.by);
5801
6271
  if (by) by.state.hits = by.state.hits + 1 & 255;
5802
6272
  if (b.power === 0 || b.power === 6) {
5803
6273
  foe.graze = ((foe.graze ?? 0) + 1) % 2;
@@ -6019,6 +6489,39 @@ var Room = class {
6019
6489
  * rides holds a seat. So a leaver's seat is free before his id is given again, and one put down,
6020
6490
  * respawned or stumbled out is off the rover.
6021
6491
  */
6492
+ /**
6493
+ * The first enemy ship on the way the ball `b` flew this tick, from `o` to where it is now: the
6494
+ * ball bursts on its hull, short of a body or a wall further on.
6495
+ */
6496
+ ram(b, o) {
6497
+ const d = [
6498
+ b.x - o[0],
6499
+ b.y - o[1],
6500
+ b.z - o[2]
6501
+ ];
6502
+ const m = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
6503
+ if (!m) return;
6504
+ const u = [
6505
+ d[0] / m,
6506
+ d[1] / m,
6507
+ d[2] / m
6508
+ ];
6509
+ let [t, hit] = [m, void 0];
6510
+ for (const r of this.targets(b.team)) {
6511
+ const s = struck(r, o, u, t);
6512
+ if (s < t) [t, hit] = [s, r];
6513
+ }
6514
+ if (hit) {
6515
+ b.left += m - t;
6516
+ [b.x, b.y, b.z] = [
6517
+ o[0] + u[0] * t,
6518
+ o[1] + u[1] * t,
6519
+ o[2] + u[2] * t
6520
+ ];
6521
+ b.burst = true;
6522
+ }
6523
+ return hit;
6524
+ }
6022
6525
  seats() {
6023
6526
  const players = this.players();
6024
6527
  for (const r of this.rovers) for (const k of SEATS) if (!players.some((p) => p.info.id === r[k] && p.state.mode === MODE.RIDE)) r[k] = 255;
@@ -6032,10 +6535,8 @@ var Room = class {
6032
6535
  const q = p.state;
6033
6536
  if (q.down || q.stun || q.lock || q.mode === MODE.RIDE) return;
6034
6537
  const carrier = this.ctf.carrying(p.info.id) >= 0;
6035
- const d2 = (r) => Math.abs(r.y - q.y) > ROVER.ENTER_R ? Infinity : (r.x - q.x) ** 2 + (r.z - q.z) ** 2;
6036
- const free = (r) => r.driver === 255 && !carrier ? 0 : r.rider === 255 ? 1 : -1;
6037
- const r = this.rovers.filter((r) => d2(r) <= ROVER.ENTER_R ** 2 && free(r) >= 0).sort((a, b) => d2(a) - d2(b))[0];
6038
- if (r) board(q, r, free(r));
6538
+ const r = this.rovers.filter((r) => nearby(r, q) && free(r, carrier) >= 0).sort((a, b) => gap2(a, q) - gap2(b, q))[0];
6539
+ if (r) board(q, r, free(r, carrier));
6039
6540
  }
6040
6541
  /**
6041
6542
  * The rider follows the rover on his seat. Over a floor, that is his last ground: where a flag he
@@ -6074,10 +6575,64 @@ var Room = class {
6074
6575
  lase(p, r, i) {
6075
6576
  p.gun = Math.max(0, (p.gun ?? 0) - 1);
6076
6577
  if (!(i.keys & KEY.FIRE) || p.gun || this.ctf.over || p.state.mode !== MODE.RIDE) return;
6077
- p.gun = ROVER.GUN_COOL;
6578
+ p.gun = r.ship ? SHIP.GUN_COOL : ROVER.GUN_COOL;
6078
6579
  p.bolt = (p.bolt ?? 0) + 2 & 255;
6079
6580
  for (const b of bolts(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt)) this.shoot(p, i.view, b);
6080
6581
  }
6582
+ /**
6583
+ * A ship's missiles: while its pilot holds SPECIAL (G), one each SHIP.MISSILE_COOL of his inputs
6584
+ * while it has any, from the left pod then the right, toward where its lasers cross.
6585
+ */
6586
+ launch(p, r, i) {
6587
+ p.pod = Math.max(0, (p.pod ?? 0) - 1);
6588
+ if (!(i.keys & KEY.SPECIAL) || p.pod || !r.nades || this.ctf.over) return;
6589
+ if (p.state.mode !== MODE.RIDE) return;
6590
+ p.pod = SHIP.MISSILE_COOL;
6591
+ p.side = (p.side ?? 0) ^ 1;
6592
+ r.nades--;
6593
+ p.bolt = (p.bolt ?? 0) + 1 & 255;
6594
+ this.shoot(p, i.view, missile(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt, p.side));
6595
+ }
6596
+ /**
6597
+ * A ship's clock outside its pilot's inputs: one that is gone comes back on its pad, new, after
6598
+ * SHIP.WRECK ticks; one short of missiles loads one each SHIP.RELOAD ticks.
6599
+ */
6600
+ dock(r, k) {
6601
+ if (!r.ship) return;
6602
+ if (r.wreck) {
6603
+ if (!--r.wreck) {
6604
+ Object.assign(r, park(this.world)[k]);
6605
+ this.rearm[k] = 0;
6606
+ }
6607
+ return;
6608
+ }
6609
+ this.rearm[k] = (r.nades ?? 0) < SHIP.MISSILES ? (this.rearm[k] ?? 0) + 1 : 0;
6610
+ if (this.rearm[k] >= SHIP.RELOAD) {
6611
+ r.nades = (r.nades ?? 0) + 1;
6612
+ this.rearm[k] = 0;
6613
+ }
6614
+ }
6615
+ /** The ships an enemy of `team` pilots and that are there to hit. */
6616
+ targets(team) {
6617
+ const by = new Map(this.players().map((p) => [p.info.id, p.info.team]));
6618
+ return this.rovers.filter((r) => r.ship && !r.wreck && r.driver !== 255 && by.get(r.driver) !== team);
6619
+ }
6620
+ /**
6621
+ * The ship `r` loses `hp` of armour to the shot of `by`; at 0 it blows up where it is: its pilot
6622
+ * goes down with it, and it is gone SHIP.WRECK ticks.
6623
+ */
6624
+ hurt(r, hp, by) {
6625
+ if (by) by.state.hits = by.state.hits + 1 & 255;
6626
+ r.hp = Math.max(0, (r.hp ?? 0) - hp);
6627
+ if (r.hp) return;
6628
+ for (const q of this.players()) if (this.seatOf(q)[0] === r) this.harm(q, q.state.hp);
6629
+ Object.assign(r, {
6630
+ wreck: SHIP.WRECK,
6631
+ driver: 255,
6632
+ rider: 255,
6633
+ nades: 0
6634
+ });
6635
+ }
6081
6636
  splat(p, r, view) {
6082
6637
  if (len(r.vx, r.vz) < ROVER.SPLAT_MIN) return;
6083
6638
  const body = footprint(r);