@korial29/tiny-fps 0.118.2 → 0.120.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
@@ -7,6 +7,8 @@ var PLAYER_H = 1.8;
7
7
  var EYE = 1.6;
8
8
  /** Pitch is clamped to ±MAX_PITCH radians, just short of straight up or down. */
9
9
  var MAX_PITCH = 1.55;
10
+ /** A floor at most this much higher is walked onto; a higher one needs a jump. */
11
+ var STEP_H = .5;
10
12
  /** Height of the cylinder when sliding or crouching, and the eye in it. */
11
13
  var LOW_H = .9;
12
14
  var LOW_EYE = .7;
@@ -616,7 +618,7 @@ var hidden = (w, a, b) => {
616
618
  ], len) < len - 1e-4;
617
619
  };
618
620
  // src/shared/physics.ts
619
- var DT$1 = 1 / 60;
621
+ var DT$2 = 1 / 60;
620
622
  var TAU = Math.PI * 2;
621
623
  /** Overlaps smaller than this are rounding noise, not contact. */
622
624
  var EPS = 1e-6;
@@ -635,11 +637,11 @@ var TOUCH = .001;
635
637
  var norm = (a) => (a % TAU + TAU) % TAU;
636
638
  /** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
637
639
  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);
640
+ var f32$2 = Math.fround;
641
+ var sqrt$2 = Math.sqrt;
642
+ var clamp$2 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
641
643
  /** The length of (x, z). */
642
- var len$1 = (x, z) => sqrt$1(x * x + z * z);
644
+ var len$1 = (x, z) => sqrt$2(x * x + z * z);
643
645
  /** The unit vector from a player toward a wall or a ledge on each SIDE. */
644
646
  var TOWARD = [
645
647
  [0, 0],
@@ -701,9 +703,9 @@ var spawn = (id, w, n, team = 0) => {
701
703
  const [x, y, z, yaw] = spawns[(n % spawns.length + spawns.length) % spawns.length];
702
704
  return {
703
705
  id,
704
- x: f32$1(x),
705
- y: f32$1(y),
706
- z: f32$1(z),
706
+ x: f32$2(x),
707
+ y: f32$2(y),
708
+ z: f32$2(z),
707
709
  vy: 0,
708
710
  yaw: norm(yaw),
709
711
  pitch: 0,
@@ -736,7 +738,7 @@ var speedOf = (p) => len$1(p.vx, p.vz);
736
738
  /** Whether the brush stops a body of height h whose feet are at y when it walks sideways into it. */
737
739
  var blocks = (b, y, h) => b.max[1] > y + .5 + SKIN && b.min[1] < y + h - SKIN;
738
740
  /** 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])];
741
+ 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
742
  /**
741
743
  * Pushes the player out of every brush that blocks it and that the circle overlaps, deepest first
742
744
  * (up to 4 passes: two walls in a corner settle in two). The push is along the vector from the
@@ -770,7 +772,7 @@ var shove = (p, w, h, r) => {
770
772
  const d2 = dx * dx + dz * dz;
771
773
  if (d2 >= reach) continue;
772
774
  if (d2) {
773
- const d = sqrt$1(d2);
775
+ const d = sqrt$2(d2);
774
776
  if (r - d > best) {
775
777
  best = r - d;
776
778
  px = dx / d * best;
@@ -818,7 +820,7 @@ var gapTo = (o, x, z) => {
818
820
  const [[ax, ay, az], [bx, by, bz]] = [o.a, o.b];
819
821
  const [ux, uz] = [bx - ax, bz - az];
820
822
  const l2 = ux * ux + uz * uz;
821
- const t = l2 ? clamp$1(((x - ax) * ux + (z - az) * uz) / l2, 0, 1) : 0;
823
+ const t = l2 ? clamp$2(((x - ax) * ux + (z - az) * uz) / l2, 0, 1) : 0;
822
824
  return [
823
825
  x - ax - t * ux,
824
826
  z - az - t * uz,
@@ -837,7 +839,7 @@ var jostle = (p, bodies, h) => {
837
839
  const r = o.r + PLAYER_R;
838
840
  const d2 = dx * dx + dz * dz;
839
841
  if (d2 >= (r - EPS) ** 2 || y + o.h <= p.y + .5 + SKIN || y >= p.y + h - SKIN) continue;
840
- const d = sqrt$1(d2);
842
+ const d = sqrt$2(d2);
841
843
  const [ux, uz] = [o.b[0] - o.a[0], o.b[2] - o.a[2]];
842
844
  const l = len$1(ux, uz);
843
845
  const [nx, nz] = d ? [dx / d, dz / d] : l ? [uz / l, -ux / l] : [1, 0];
@@ -983,7 +985,7 @@ var over = (p, w) => {
983
985
  return near(w, p.x, p.z, 0).some((i) => {
984
986
  const b = w.def.brushes[i];
985
987
  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;
988
+ return f32$2(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
987
989
  });
988
990
  };
989
991
  /** The world's gravity: GRAVITY times the map's share (the moon's half gravity, the user, 2026-11-09). */
@@ -992,7 +994,7 @@ var gravity = (w) => 20 * (w.def.gravity ?? 1);
992
994
  var landingSoon = (p, w) => {
993
995
  if (p.vy >= 0) return false;
994
996
  const [floor] = span(p, w, PLAYER_H);
995
- const t = 6 * DT$1;
997
+ const t = 6 * DT$2;
996
998
  return p.y - floor <= -p.vy * t + .5 * gravity(w) * t * t;
997
999
  };
998
1000
  /** Changes the mode, and starts counting the time in it. */
@@ -1010,8 +1012,8 @@ var floored = (p) => !!p.zap && p.stun > 24;
1010
1012
  */
1011
1013
  var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
1012
1014
  p.stun = ticks;
1013
- p.vx = f32$1(dx * knock);
1014
- p.vz = f32$1(dz * knock);
1015
+ p.vx = f32$2(dx * knock);
1016
+ p.vz = f32$2(dz * knock);
1015
1017
  p.dash = Math.min(p.dash, 50);
1016
1018
  p.coyote = 0;
1017
1019
  p.buffer = 0;
@@ -1059,7 +1061,7 @@ var steer = (p, wish, top) => {
1059
1061
  const m = len$1(wish[0], wish[1]);
1060
1062
  if (m < EPS) {
1061
1063
  const s = len$1(p.vx, p.vz);
1062
- const k = s ? Math.max(0, s - 45 * DT$1) / s : 0;
1064
+ const k = s ? Math.max(0, s - 45 * DT$2) / s : 0;
1063
1065
  p.vx *= k;
1064
1066
  p.vz *= k;
1065
1067
  return;
@@ -1069,11 +1071,11 @@ var steer = (p, wish, top) => {
1069
1071
  let [px, pz] = [p.vx - par * wx, p.vz - par * wz];
1070
1072
  const across = len$1(px, pz);
1071
1073
  if (across) {
1072
- const k = Math.max(0, across - 45 * DT$1) / across;
1074
+ const k = Math.max(0, across - 45 * DT$2) / across;
1073
1075
  [px, pz] = [px * k, pz * k];
1074
1076
  }
1075
1077
  top *= m;
1076
- par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$1) : Math.max(top, par - 12 * DT$1);
1078
+ par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$2) : Math.max(top, par - 12 * DT$2);
1077
1079
  p.vx = px + par * wx;
1078
1080
  p.vz = pz + par * wz;
1079
1081
  };
@@ -1086,8 +1088,8 @@ var steer = (p, wish, top) => {
1086
1088
  */
1087
1089
  var fly$1 = (p, w, h, g, snap, bodies) => {
1088
1090
  const y0 = p.y;
1089
- p.x += p.vx * DT$1;
1090
- p.z += p.vz * DT$1;
1091
+ p.x += p.vx * DT$2;
1092
+ p.z += p.vz * DT$2;
1091
1093
  let [cx, cz] = push(p, w, h);
1092
1094
  const [jx, jz] = jostle(p, bodies, h);
1093
1095
  if (jx || jz) {
@@ -1105,8 +1107,8 @@ var fly$1 = (p, w, h, g, snap, bodies) => {
1105
1107
  }
1106
1108
  bound(p, w);
1107
1109
  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;
1110
+ const vy = p.vy - g * gravity(w) * DT$2;
1111
+ p.y += (p.vy + vy) / 2 * DT$2;
1110
1112
  p.vy = vy;
1111
1113
  if (p.y + h > ceil) {
1112
1114
  p.y = ceil - h;
@@ -1154,16 +1156,16 @@ var hang = (p, w, c) => {
1154
1156
  p.coyote = 0;
1155
1157
  } else {
1156
1158
  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);
1159
+ p.y += clamp$2(target - p.y, -8 * DT$2, 8 * DT$2);
1158
1160
  }
1159
1161
  };
1160
1162
  /** Climbing: up to the top, then in from the edge, then standing on it. */
1161
1163
  var climb = (p, w) => {
1162
1164
  const [nx, nz] = TOWARD[p.wall];
1163
- if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT$1);
1165
+ if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT$2);
1164
1166
  else {
1165
- p.x += nx * CLIMB_FWD_SPEED * DT$1;
1166
- p.z += nz * CLIMB_FWD_SPEED * DT$1;
1167
+ p.x += nx * CLIMB_FWD_SPEED * DT$2;
1168
+ p.z += nz * CLIMB_FWD_SPEED * DT$2;
1167
1169
  }
1168
1170
  if (p.y >= p.edge && over(p, w)) {
1169
1171
  enter(p, MODE.GROUND);
@@ -1201,10 +1203,10 @@ var run = (p, w, c) => {
1201
1203
  p.ev |= EV.WALLRUN_END;
1202
1204
  return;
1203
1205
  }
1204
- const k = Math.max(0, s - WALLRUN_DRAG * DT$1) / s;
1206
+ const k = Math.max(0, s - WALLRUN_DRAG * DT$2) / s;
1205
1207
  p.vx = tx * k;
1206
1208
  p.vz = tz * k;
1207
- const pull = Math.min(gap, 4 * DT$1);
1209
+ const pull = Math.min(gap, 4 * DT$2);
1208
1210
  p.x += nx * pull;
1209
1211
  p.z += nz * pull;
1210
1212
  }
@@ -1229,7 +1231,7 @@ var startRun = (p, w, c) => {
1229
1231
  enter(p, MODE.WALLRUN);
1230
1232
  p.wall = side;
1231
1233
  [p.vx, p.vz] = [tx * k, tz * k];
1232
- p.vy = clamp$1(p.vy, 2, 3);
1234
+ p.vy = clamp$2(p.vy, 2, 3);
1233
1235
  p.jumps = 1;
1234
1236
  p.dashes = 1;
1235
1237
  p.coyote = 0;
@@ -1242,7 +1244,7 @@ var startRun = (p, w, c) => {
1242
1244
  var grab = (p, l) => {
1243
1245
  enter(p, MODE.HANG);
1244
1246
  p.wall = l.side;
1245
- p.edge = f32$1(l.top);
1247
+ p.edge = f32$2(l.top);
1246
1248
  if (l.side <= SIDE.WEST) p.x = l.hang;
1247
1249
  else p.z = l.hang;
1248
1250
  p.vx = p.vy = p.vz = 0;
@@ -1253,7 +1255,7 @@ var grab = (p, l) => {
1253
1255
  p.ev |= EV.GRAB;
1254
1256
  };
1255
1257
  /** The modes that move freely: everything but the hang and the climb. */
1256
- var free = (p, w, c) => {
1258
+ var free$1 = (p, w, c) => {
1257
1259
  const ground = p.mode === MODE.GROUND;
1258
1260
  if (c.dash && p.dash === 0 && (ground || (p.mode === MODE.AIR || p.mode === MODE.WALLRUN) && p.dashes > 0)) {
1259
1261
  const [dx, dz] = c.wx || c.wz ? [c.wx, c.wz] : [c.fx, c.fz];
@@ -1325,12 +1327,12 @@ var onGround = (p, w, c, burst) => {
1325
1327
  if (burst) return;
1326
1328
  if (c.stumble) {
1327
1329
  if (speed > 2.5) {
1328
- const k = Math.max(STUMBLE_SPEED, speed - 12 * DT$1) / speed;
1330
+ const k = Math.max(STUMBLE_SPEED, speed - 12 * DT$2) / speed;
1329
1331
  p.vx *= k;
1330
1332
  p.vz *= k;
1331
1333
  } else steer(p, unwalled(p, w, c, heightOf(p)), STUMBLE_SPEED);
1332
1334
  } else if (p.mode === MODE.SLIDE) {
1333
- const k = Math.max(0, speed - 4 * DT$1) / speed;
1335
+ const k = Math.max(0, speed - 4 * DT$2) / speed;
1334
1336
  p.vx *= k;
1335
1337
  p.vz *= k;
1336
1338
  } else if (p.mode === MODE.CROUCH) steer(p, unwalled(p, w, c, LOW_H), 3);
@@ -1351,8 +1353,8 @@ var air = (p, w, c, burst) => {
1351
1353
  }
1352
1354
  if (burst || !c.wx && !c.wz) return;
1353
1355
  const before = len$1(p.vx, p.vz);
1354
- p.vx += c.wx * 14 * DT$1;
1355
- p.vz += c.wz * 14 * DT$1;
1356
+ p.vx += c.wx * 14 * DT$2;
1357
+ p.vz += c.wz * 14 * DT$2;
1356
1358
  cap(p, Math.max(before, 6));
1357
1359
  };
1358
1360
  /**
@@ -1394,7 +1396,7 @@ var move = (p, i, w, team = 0, bodies = []) => {
1394
1396
  }
1395
1397
  if (p.mode === MODE.HANG) hang(p, w, c);
1396
1398
  if (p.mode === MODE.CLIMB) climb(p, w);
1397
- else if (p.mode !== MODE.HANG && !riding) free(p, w, c);
1399
+ else if (p.mode !== MODE.HANG && !riding) free$1(p, w, c);
1398
1400
  if (p.slow) {
1399
1401
  p.slow--;
1400
1402
  cap(p, 3);
@@ -1405,13 +1407,13 @@ var move = (p, i, w, team = 0, bodies = []) => {
1405
1407
  if (p.mode === MODE.AIR && before === MODE.AIR) p.coyote = Math.max(0, p.coyote - 1);
1406
1408
  p.held = i.keys & (KEY.JUMP | KEY.DASH | KEY.USE);
1407
1409
  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);
1410
+ p.x = f32$2(p.x);
1411
+ p.y = f32$2(p.y);
1412
+ p.z = f32$2(p.z);
1413
+ p.vx = f32$2(p.vx);
1414
+ p.vy = f32$2(p.vy);
1415
+ p.vz = f32$2(p.vz);
1416
+ p.edge = f32$2(p.edge);
1415
1417
  };
1416
1418
  // src/shared/blade.ts
1417
1419
  /** Where on the body the blade is, as a share of its height: the chest, which a brush must not cover. */
@@ -2011,7 +2013,7 @@ var powerOf = (ticks) => ticks < 10 ? 1 : 1 + Math.floor(4 * (ticks - 10) / 50);
2011
2013
  /** The bottom of every building: far below the kill floor, so nothing shows beneath a roof. */
2012
2014
  var BASE$1 = -30;
2013
2015
  /** 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) => ({
2016
+ var roof$1 = (x0, z0, x1, z1, top, side = TEX.CONCRETE) => ({
2015
2017
  min: [
2016
2018
  x0,
2017
2019
  BASE$1,
@@ -2059,12 +2061,12 @@ var stair = (z, y) => [
2059
2061
  z - k + 1
2060
2062
  ], TEX.CONCRETE));
2061
2063
  [
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),
2064
+ roof$1(4, 57.7, 24, 76, 10),
2065
+ roof$1(4, 36, 24, 53.5, 10, TEX.GLASS),
2066
+ roof$1(4, 20, 24, 36, 12.4),
2067
+ roof$1(4, -5, 24, 7, 12.4, TEX.GLASS),
2068
+ roof$1(27, 20, 47, 50, 8),
2069
+ roof$1(27, 60, 47, 76, 8, TEX.BRICK),
2068
2070
  box$1([
2069
2071
  9,
2070
2072
  12.2,
@@ -2251,7 +2253,7 @@ var ladder = (x, z, dx, dz, d, low, tops) => tops.map((top, k) => box$1([
2251
2253
  ], TEX.STEEL, TEX.CONCRETE));
2252
2254
  /** Red's half: z from 120 to 240, then flipped. */
2253
2255
  var half$1 = [
2254
- roof(12, 212, 52, 240, 26, TEX.GLASS),
2256
+ roof$1(12, 212, 52, 240, 26, TEX.GLASS),
2255
2257
  pad(12, 26, 212, 52, 26.12, 212.5, RED$1),
2256
2258
  pad(12, 26, 239.5, 52, 26.12, 240, RED$1),
2257
2259
  pad(12, 26, 212.5, 12.5, 26.12, 239.5, RED$1),
@@ -2294,10 +2296,10 @@ var half$1 = [
2294
2296
  27.5,
2295
2297
  219
2296
2298
  ], 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),
2299
+ roof$1(6, 164, 26, 201, 26, TEX.GLASS),
2300
+ roof$1(6, 134, 26, 147, 26, TEX.GLASS),
2301
+ roof$1(6, 201, 26, 212, 19),
2302
+ roof$1(15, 147, 26, 164, 19),
2301
2303
  box$1([
2302
2304
  14,
2303
2305
  26,
@@ -2397,7 +2399,7 @@ var half$1 = [
2397
2399
  27.3,
2398
2400
  143
2399
2401
  ], TEX.STEEL),
2400
- roof(32, 186, 76, 209, 19),
2402
+ roof$1(32, 186, 76, 209, 19),
2401
2403
  pad(32, 19, 207.5, 76, 19.1, 209, RED$1),
2402
2404
  ...ladder(33, 209, 7, 0, 3, 19, [
2403
2405
  21.2,
@@ -2435,8 +2437,8 @@ var half$1 = [
2435
2437
  top,
2436
2438
  z1
2437
2439
  ], TEX.STEEL, TEX.CONCRETE)),
2438
- roof(32, 166, 64, 182, 21.2, TEX.GLASS),
2439
- roof(32, 140, 64, 161, 19),
2440
+ roof$1(32, 166, 64, 182, 21.2, TEX.GLASS),
2441
+ roof$1(32, 140, 64, 161, 19),
2440
2442
  box$1([
2441
2443
  40,
2442
2444
  21.2,
@@ -2516,10 +2518,10 @@ var half$1 = [
2516
2518
  21.6,
2517
2519
  23.8
2518
2520
  ]),
2519
- roof(76, 213, 100, 240, 14.5, TEX.STEEL),
2521
+ roof$1(76, 213, 100, 240, 14.5, TEX.STEEL),
2520
2522
  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),
2523
+ roof$1(76, 185, 100, 209, 14.5),
2524
+ roof$1(76, 138, 100, 181, 14.5, TEX.GLASS),
2523
2525
  box$1([
2524
2526
  80,
2525
2527
  15.7,
@@ -2588,8 +2590,8 @@ var half$1 = [
2588
2590
  ];
2589
2591
  /** What stands on the centre line, symmetric as written: the plaza, its dais and canopy, the beam. */
2590
2592
  var centre$1 = [
2591
- roof(6, 106, 62, 134, 15),
2592
- roof(62, 106, 100, 134, 14.5),
2593
+ roof$1(6, 106, 62, 134, 15),
2594
+ roof$1(62, 106, 100, 134, 14.5),
2593
2595
  box$1([
2594
2596
  34,
2595
2597
  15,
@@ -3009,12 +3011,6 @@ var box = (x0, y0, z0, x1, y1, z1, top, side = top, tint) => ({
3009
3011
  side,
3010
3012
  tint
3011
3013
  });
3012
- var fromBx = ({ min, max }, top, side = top) => ({
3013
- min,
3014
- max,
3015
- top,
3016
- side
3017
- });
3018
3014
  var bx = (x0, y0, z0, x1, y1, z1) => ({
3019
3015
  min: [
3020
3016
  x0,
@@ -3121,7 +3117,7 @@ var stairs = (axis, a, b, w0, w1, y, top) => {
3121
3117
  * The mezzanine 3.5 m up along the walls (not over the door), the stairs up to it facing the door,
3122
3118
  * a console and two parapets on it, three crates on the floor clear of the flag's dais (moon.ts).
3123
3119
  */
3124
- var FIT = [
3120
+ var FIT$1 = [
3125
3121
  ...turns([[
3126
3122
  12,
3127
3123
  -D1,
@@ -3369,7 +3365,7 @@ var BASE = [
3369
3365
  TZ0 - DOME[1]
3370
3366
  ]
3371
3367
  ].map((p) => ghost(p, 0, BANDS[1])),
3372
- ...FIT,
3368
+ ...FIT$1,
3373
3369
  ...KIT.map(([, x0, z0, x1, z1, y0, y1]) => ({
3374
3370
  ...box(x0, y0, z0, x1, y1, z1, STEEL$1),
3375
3371
  ghost: true
@@ -3393,13 +3389,12 @@ var [RED, BLUE] = TEAM_TINT;
3393
3389
  var { STONE, CONCRETE, METAL, STEEL, PAINT } = TEX;
3394
3390
  /** The twin of a box across the centre line. */
3395
3391
  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. */
3392
+ /** 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
3393
  var PAD = [
3398
3394
  40,
3399
3395
  220,
3400
3396
  13
3401
3397
  ];
3402
- var SHUTTLE = bx(33, .25, 218, 47, 3.25, 222);
3403
3398
  var MASTS = [
3404
3399
  [27.3, 207.3],
3405
3400
  [52.7, 207.3],
@@ -3877,22 +3872,15 @@ var at$1 = (x, z) => {
3877
3872
  if (k > 1) w = (w + (k - 1) * 60 * (Math.abs(2 * noise(x / 45, z / 45, 5) - 1) - .5)) * (1 + (k - 1) * (1.2 * noise(x / 90, z / 90, 7) - .6)) * (1 - sm((k - 1.25) / .4));
3878
3873
  return Math.max(h, -14.5) + w;
3879
3874
  };
3880
- /** Five bearings a fifth of a turn apart, as unit vectors: no Math.cos in what the host and the clients must agree on. */
3881
- var FIFTHS = [
3882
- [1, 0],
3883
- [.309, .951],
3884
- [-.809, .588],
3885
- [-.809, -.588],
3886
- [.309, -.951]
3887
- ];
3875
+ /** How high a rock's middle is over the ground: three tenths of its height, and 0.6 m or half its height if less. Its widest is there, its flank steep down to the ground: a body is stopped at its foot. */
3876
+ var rockMid = (H) => Math.max(.3 * H, Math.min(.5 * H, .8));
3888
3877
  /**
3889
3878
  * The form of a boulder of radius R and height H from a seed: how far it reaches from its middle
3890
- * (a quarter of its height over the ground) along a unit vector. One to three lobes, each a block
3891
- * cut by five leaning planes round it and a nearly level one on top, its corners rounded by an
3892
- * ellipsoid: a main mass, a shoulder beside it half as high from 1.3 m of radius, a low one from
3893
- * 3.2 m. One plane cuts under a side (an overhang), and the whole swells and shrinks by 6 % with
3894
- * the bearing. Only + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
3895
- * `tops` are the lobes' middles (x, z) and the height of their top over the rock's middle.
3879
+ * (rockMid() over the ground) along a unit vector. A rounded solid, no plane in it:
3880
+ * an ellipsoid stretched unevenly on its three axes and turned by the seed, upright under its
3881
+ * middle (it stands in the regolith, as wide at the ground as at its middle) and a dome over it, swollen and shrunk by two low octaves
3882
+ * of noise with the bearing (large soft lobes), with one gentle hollow and one flatter side. Only
3883
+ * + - * /, Math.sqrt and the hash: the boxes below come from it on every side.
3896
3884
  */
3897
3885
  var rockOf = (s, R, H) => {
3898
3886
  const h = (k) => hash(s, k, 131);
@@ -3901,168 +3889,219 @@ var rockOf = (s, R, H) => {
3901
3889
  const l = Math.sqrt(a * a + b * b) || 1;
3902
3890
  return [a / l, b / l];
3903
3891
  };
3904
- const lobes = [
3892
+ const [cx, sx] = flat(1);
3893
+ const [a, b] = [R * (.9 + .25 * h(3)), R * (.68 + .22 * h(4))];
3894
+ const lean = .3 * h(9) - .15;
3895
+ const [hx, hz] = flat(5);
3896
+ const [fx, fz] = flat(7);
3897
+ const swell = (u) => {
3898
+ const n = .8 + .28 * noise(1.1 * u[0] + s, 1.1 * u[2] + .9 * u[1], s) + .1 * noise(2.3 * u[0] - s, 2.3 * u[2] + 1.7 * u[1], s + 1);
3899
+ const hollow = c1((.8 * (u[0] * hx + u[2] * hz) + .6 * u[1] - .55) / .45);
3900
+ const side = c1((.954 * (u[0] * fx + u[2] * fz) + .3 * u[1] - .4) / .6);
3901
+ return n * (1 - .14 * hollow * hollow) * (1 - .16 * side * side);
3902
+ };
3903
+ const cu = (H - rockMid(H)) / swell([
3905
3904
  0,
3906
3905
  1,
3907
- 2
3908
- ].slice(0, R < 1.3 ? 1 : R < 3.2 ? 2 : 3).map((k) => {
3909
- const [fx, fz] = flat(20 * k + 1);
3910
- const [off, rad] = [[
3911
- .1,
3912
- .45,
3913
- .42
3914
- ][k] * R, [
3915
- .8,
3916
- .75,
3917
- .65
3918
- ][k] * R];
3919
- const o = [fx * off, fz * off];
3920
- const top = [
3921
- H,
3922
- (.5 + .15 * h(20 * k + 3)) * H,
3923
- .34 * H
3924
- ][k] - .25 * H;
3925
- const tilt = Math.min(.06, .06 / rad);
3926
- const [tx, tz] = [(2 * h(20 * k + 4) - 1) * tilt, (2 * h(20 * k + 5) - 1) * tilt];
3927
- const tl = Math.sqrt(tx * tx + 1 + tz * tz);
3928
- return {
3929
- o,
3930
- rad,
3931
- top,
3932
- planes: [[
3933
- tx / tl,
3934
- 1 / tl,
3935
- tz / tl,
3936
- (tx * o[0] + top + tz * o[1]) / tl
3937
- ], ...FIFTHS.map(([px, pz], j) => {
3938
- const [ax, az] = [px + h(20 * k + 6 + j) - .5, pz + h(20 * k + 11 + j) - .5];
3939
- const l = Math.sqrt(ax * ax + az * az);
3940
- const y = -.15 + .5 * h(20 * k + 16 + j);
3941
- const c = Math.sqrt(1 - y * y);
3942
- const [nx, nz] = [c * ax / l, c * az / l];
3943
- return [
3944
- nx,
3945
- y,
3946
- nz,
3947
- nx * o[0] + nz * o[1] + rad * (.72 + .22 * h(20 * k + 21 + j))
3948
- ];
3949
- })]
3950
- };
3951
- });
3952
- const [ux, uz] = flat(91);
3953
- const under = [
3954
- .866 * ux,
3955
- -.5,
3956
- .866 * uz,
3957
- .72 * R
3958
- ];
3906
+ 0
3907
+ ]);
3908
+ const deep = rockMid(H) + .7 * H;
3959
3909
  const reach = (u) => {
3960
- let far = 0;
3961
- for (const { o, rad, planes } of lobes) {
3962
- const [a, c] = [1.2 * rad, 1.15 * H];
3963
- const A = (u[0] * u[0] + u[2] * u[2]) / (a * a) + u[1] * u[1] / (c * c);
3964
- const B = -2 * (u[0] * o[0] + u[2] * o[1]) / (a * a);
3965
- const C = (o[0] * o[0] + o[1] * o[1]) / (a * a) - 1;
3966
- let t = (-B + Math.sqrt(B * B - 4 * A * C)) / (2 * A);
3967
- for (const [nx, ny, nz, d] of [...planes, under]) {
3968
- const k = u[0] * nx + u[1] * ny + u[2] * nz;
3969
- t = k > 1e-9 ? Math.min(t, d / k) : t;
3970
- }
3971
- far = Math.max(far, t);
3910
+ if (u[1] < 0) {
3911
+ const l = Math.sqrt(u[0] * u[0] + u[2] * u[2]);
3912
+ return l < 1e-6 ? deep : Math.min(reach([
3913
+ u[0] / l,
3914
+ 0,
3915
+ u[2] / l
3916
+ ]) / l, deep / -u[1]);
3972
3917
  }
3973
- return far * (.94 + .12 * noise(1.5 * u[0] + s, 1.5 * u[2] + 2 * u[1], s));
3974
- };
3975
- return {
3976
- reach,
3977
- tops: lobes.map(({ o, top }) => [
3978
- o[0],
3979
- o[1],
3980
- top
3981
- ])
3918
+ const x = (u[0] * cx + u[2] * sx - lean * u[1]) / a;
3919
+ const z = (u[2] * cx - u[0] * sx - (.15 - lean) * u[1]) / b;
3920
+ const q = u[1] * u[1] / (cu * cu);
3921
+ const [D, E] = [x * x + z * z + .65 * q, .35 * q * q];
3922
+ const T = E < 1e-12 ? 1 / D : (Math.sqrt(D * D + 4 * E) - D) / (2 * E);
3923
+ return Math.sqrt(T) * swell(u);
3982
3924
  };
3925
+ return { reach };
3983
3926
  };
3984
3927
  /**
3985
- * The boxes inside a boulder, one for each lobe, each x0, y0, z0, x1, y1, z1 round its middle
3986
- * (y from the middle's height): the widest box under the lobe's top, standing from `foot` under
3987
- * the middle, whose corners and the middles of its sides are all in the rock at its foot, half
3988
- * way up and on top. A body is stopped a little inside what is drawn, never outside it.
3928
+ * The boxes a boulder collides with, x0, y0, z0, x1, y1, z1 round its middle: what stops a body is
3929
+ * where the rock is drawn. From `lo` (the ground round it) to its top it is cut in layers: up to
3930
+ * `band` (a body's height over the ground) a layer ends where the rock has moved in or out by
3931
+ * FIT[0] on a bearing, or at 0.9 m; over it by FIT[1], or at 1.5 m; none thinner than 0.25 m. In
3932
+ * each a grid of points says where the rock is at the layer's foot and top (a box may stand 7 cm
3933
+ * out of it), and boxes are picked on it one after the other: the largest first, then the one
3934
+ * that brings the most of the outline within FIT[2] (FIT[3] over the band) of a box, overlapping
3935
+ * one already there, until the whole outline is. No crack between them.
3989
3936
  */
3990
- var inside = ({ reach, tops }, R, foot) => {
3991
- const holds = (x, y, z, slack = .09) => {
3992
- const l = Math.sqrt(x * x + y * y + z * z);
3993
- return l < 1e-6 || l <= reach([
3994
- x / l,
3995
- y / l,
3996
- z / l
3997
- ]) + slack;
3998
- };
3999
- const grid = [
4000
- -1,
4001
- 0,
4002
- 1
4003
- ];
4004
- /** A box of half sides p and q round (cx, cz) from the foot up to t: in the rock at its foot, half way up and on top, and with no rock 0.2 m over its top (what stands on it is not in the rock). */
4005
- const fits = (cx, cz, p, q, t) => [
4006
- foot + .05,
4007
- (foot + t) / 2,
4008
- t
4009
- ].every((y) => grid.every((i) => grid.every((j) => holds(cx + i * p, y, cz + j * q)))) && grid.every((i) => grid.every((j) => !holds(cx + i * p, t + .2, cz + j * q, 0)));
4010
- return tops.flatMap(([ox, oz, top], k) => {
4011
- let best = [
4012
- 0,
4013
- 0,
4014
- 0,
3937
+ /** How far over the ground a rock's first layer of boxes goes: more than a body steps up, from ground a little higher. */
3938
+ var WALL = STEP_H + .2;
3939
+ var FIT = [
3940
+ .16,
3941
+ .3,
3942
+ .16,
3943
+ .3
3944
+ ];
3945
+ var fitted = ({ reach }, R, lo, band, foot) => {
3946
+ /**
3947
+ * The rock's outline at a height: how far it goes from its axis on 8 m bearings, m to each side
3948
+ * of a square round it (no Math.cos), 7 cm out of it; then whether a point is in that outline.
3949
+ */
3950
+ const outline = (y, m) => {
3951
+ const o = new Float64Array(8 * m);
3952
+ const u = [
4015
3953
  0,
4016
3954
  0,
4017
3955
  0
4018
3956
  ];
4019
- const l = Math.sqrt(ox * ox + oz * oz) || 1;
4020
- for (const a of k ? [
4021
- .1,
4022
- .3,
4023
- .5
4024
- ] : [
4025
- -.15,
4026
- 0,
4027
- .15
4028
- ]) for (const b of [
4029
- -.15,
4030
- 0,
4031
- .15
4032
- ]) {
4033
- const [cx, cz] = k ? [ox + (a * ox - b * oz) * (R / l), oz + (a * oz + b * ox) * (R / l)] : [ox + a * R, oz + b * R];
4034
- let t = 0;
4035
- for (let y = top + .1; !t && y > foot + .3; y -= .1) t = fits(cx, cz, .08 * R, .08 * R, y) ? y : 0;
4036
- let [p, q] = [.08 * R, .08 * R];
4037
- for (const [fa, fb] of t ? [
4038
- [1, 1],
4039
- [1, 0],
4040
- [0, 1]
4041
- ] : []) for (let step = .5 * R; step > .03; step /= 2) [p, q] = fits(cx, cz, p + fa * step, q + fb * step, t) ? [p + fa * step, q + fb * step] : [p, q];
4042
- if (t && p * q * (t - foot) > best[0]) best = [
4043
- p * q * (t - foot),
4044
- cx,
4045
- cz,
4046
- p,
4047
- q,
4048
- t
3957
+ for (let k = 0; k < 8 * m; k++) {
3958
+ const t = (k % (2 * m) + .5) / m - 1;
3959
+ const side = Math.floor(k / (2 * m));
3960
+ const l = Math.sqrt(1 + t * t) * (side > 1 ? -1 : 1);
3961
+ const dx = (side % 2 ? -t : 1) / l;
3962
+ const dz = (side % 2 ? 1 : t) / l;
3963
+ let p = 0;
3964
+ let q = 1.6 * R;
3965
+ for (let it = 0; it < 8; it++) {
3966
+ const r = (p + q) / 2;
3967
+ const d = Math.sqrt(r * r + y * y);
3968
+ u[0] = r * dx / d;
3969
+ u[1] = y / d;
3970
+ u[2] = r * dz / d;
3971
+ if (d <= reach(u) + .07) p = r;
3972
+ else q = r;
3973
+ }
3974
+ o[k] = p;
3975
+ }
3976
+ return o;
3977
+ };
3978
+ const within = (o, x, z) => {
3979
+ const m = o.length / 8;
3980
+ const wide = Math.abs(x) >= Math.abs(z);
3981
+ if (Math.abs(x) + Math.abs(z) < 1e-9) return true;
3982
+ const side = wide ? x > 0 ? 0 : 2 : z > 0 ? 1 : 3;
3983
+ const f = ((wide ? z / x : -x / z) + 1) * m - .5 + side * 2 * m;
3984
+ const k = Math.floor(f);
3985
+ const r = o[(k + 8 * m) % (8 * m)] * (1 - (f - k)) + o[(k + 1) % (8 * m)] * (f - k);
3986
+ return x * x + z * z <= r * r;
3987
+ };
3988
+ const top = reach([
3989
+ 0,
3990
+ 1,
3991
+ 0
3992
+ ]) - .1;
3993
+ const c = Math.max(.07, Math.min(.12, R / 12));
3994
+ const out = [];
3995
+ const wall = band - PLAYER_H + WALL;
3996
+ const cuts = [lo];
3997
+ for (let a = lo; a < top - 1e-9;) {
3998
+ const shift = a < band - 1e-9 ? FIT[0] : FIT[1];
3999
+ const base = outline(a + .03, 2);
4000
+ let b = Math.min(a === lo && wall < top - .3 ? wall : a + .25, top);
4001
+ while (b < top && b - a < .9 && outline(Math.min(b + .1, top), 2).every((r, k) => Math.abs(r - base[k]) <= shift)) b = Math.min(b + .1, top);
4002
+ a = top - b < .15 ? top : b;
4003
+ cuts.push(a);
4004
+ }
4005
+ const lines = cuts.map((y, k) => outline(k ? y : y + .03, 8));
4006
+ for (let l = 0; l + 1 < cuts.length; l++) {
4007
+ const [a, b] = [cuts[l], cuts[l + 1]];
4008
+ const near = a < band - 1e-9 ? FIT[2] : FIT[3];
4009
+ const n = Math.ceil(Math.min(Math.max(...lines[l]), Math.max(...lines[l + 1])) / c) + 1;
4010
+ const N = 2 * n + 1;
4011
+ const inl = new Uint8Array(N * N);
4012
+ for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) {
4013
+ const [x, z] = [(i - n) * c, (j - n) * c];
4014
+ inl[i + j * N] = within(lines[l], x, z) && within(lines[l + 1], x, z) ? 1 : 0;
4015
+ }
4016
+ const NEAR = Math.max(1, Math.round(near / c));
4017
+ const on = (i, j) => i >= 0 && i < N && j >= 0 && j < N && inl[i + j * N] > 0;
4018
+ const edge = new Uint8Array(N * N);
4019
+ for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) edge[i + j * N] = on(i, j) && !(on(i - 1, j) && on(i + 1, j) && on(i, j - 1) && on(i, j + 1)) ? 1 : 0;
4020
+ const rects = [];
4021
+ const all = new Uint8Array(N);
4022
+ const hop = N > 48 ? 2 : 1;
4023
+ for (let i0 = 0; i0 < N; i0 += hop) {
4024
+ all.fill(1);
4025
+ for (let i1 = i0; i1 < N; i1++) {
4026
+ let any = false;
4027
+ for (let j = 0, from = 0; j <= N; j++) {
4028
+ all[j] = j < N && all[j] && inl[i1 + j * N] ? 1 : 0;
4029
+ if (!all[j]) {
4030
+ if (j - 1 - from >= 2 && i1 - i0 >= 2 && (i1 - i0) % hop === 0) rects.push([
4031
+ i0,
4032
+ from,
4033
+ i1,
4034
+ j - 1
4035
+ ]);
4036
+ any ||= j - 1 > from;
4037
+ from = j + 1;
4038
+ }
4039
+ }
4040
+ if (!any) break;
4041
+ }
4042
+ }
4043
+ const sum = new Int32Array((N + 1) * (N + 1));
4044
+ const count = (i0, j0, i1, j1) => {
4045
+ const [a0, b0, a1, b1] = [
4046
+ Math.max(i0, 0),
4047
+ Math.max(j0, 0),
4048
+ Math.min(i1, N - 1) + 1,
4049
+ Math.min(j1, N - 1) + 1
4049
4050
  ];
4051
+ return sum[a1 + b1 * (N + 1)] - sum[a0 + b1 * (N + 1)] - sum[a1 + b0 * (N + 1)] + sum[a0 + b0 * (N + 1)];
4052
+ };
4053
+ const picked = [];
4054
+ for (let k = 0; k < 40 && rects.length; k++) {
4055
+ for (let j = 0; j < N; j++) for (let i = 0; i < N; i++) sum[i + 1 + (j + 1) * (N + 1)] = edge[i + j * N] + sum[i + (j + 1) * (N + 1)] + sum[i + 1 + j * (N + 1)] - sum[i + j * (N + 1)];
4056
+ let [best, score] = [-1, 0];
4057
+ for (let m = 0; m < rects.length; m++) {
4058
+ const q = rects[m];
4059
+ if (k && !picked.some((p) => q[0] < p[2] && p[0] < q[2] && q[1] < p[3] && p[1] < q[3])) continue;
4060
+ const area = (q[2] - q[0]) * (q[3] - q[1]);
4061
+ const gain = k ? count(q[0] - NEAR, q[1] - NEAR, q[2] + NEAR, q[3] + NEAR) : 2;
4062
+ const v = k ? gain * 1e6 + area : area;
4063
+ if (gain >= 2 && v > score) [best, score] = [m, v];
4064
+ }
4065
+ if (best < 0) break;
4066
+ const [i0, j0, i1, j1] = rects[best];
4067
+ picked.push(rects[best]);
4068
+ for (let i = Math.max(i0 - NEAR, 0); i <= Math.min(i1 + NEAR, N - 1); i++) for (let j = Math.max(j0 - NEAR, 0); j <= Math.min(j1 + NEAR, N - 1); j++) edge[i + j * N] = 0;
4069
+ out.push([
4070
+ (i0 - n) * c,
4071
+ l ? a : foot,
4072
+ (j0 - n) * c,
4073
+ (i1 - n) * c,
4074
+ b,
4075
+ (j1 - n) * c
4076
+ ]);
4050
4077
  }
4051
- const [, cx, cz, p, q, t] = best;
4052
- return Math.min(p, q) < (k ? .25 : 0) ? [] : [[
4053
- cx - p,
4054
- foot,
4055
- cz - q,
4056
- cx + p,
4057
- t,
4058
- cz + q
4059
- ]];
4060
- });
4078
+ }
4079
+ return out;
4080
+ };
4081
+ /** The ground as it is walked on: at()'s 4 m lattice, each square two triangles, as ground() in relief.ts reads it. */
4082
+ var walked = (x, z) => {
4083
+ const [i, j] = [Math.floor(x / 4), Math.floor(z / 4)];
4084
+ const [fu, fv] = [x / 4 - i, z / 4 - j];
4085
+ const h = (u, v) => at$1(4 * (i + u), 4 * (j + v));
4086
+ const [a, d] = [h(0, 0), h(1, 1)];
4087
+ return fu >= fv ? a + (h(1, 0) - a) * fu + (d - h(1, 0)) * fv : a + (h(0, 1) - a) * fv + (d - h(0, 1)) * fu;
4061
4088
  };
4062
4089
  /** A rock of the map: where its middle is over the ground (x, the ground's height, z), its radius, height and seed, and the boxes it collides with (x0, y0, z0, x1, y1, z1), inside what rockOf() draws. */
4063
- var crag = (x, z, R, H, s, deep = 0) => {
4064
- const g = at$1(x, z);
4065
- const y = g + .25 * H;
4090
+ var crag = (x, z, R, H, s) => {
4091
+ const g = walked(x, z);
4092
+ const y = g + rockMid(H);
4093
+ const span = [
4094
+ -3,
4095
+ -2,
4096
+ -1,
4097
+ 0,
4098
+ 1,
4099
+ 2,
4100
+ 3
4101
+ ].map((k) => .4 * R * k);
4102
+ const round = span.map((u) => span.map((v) => walked(x + u, z + v)));
4103
+ const lo = Math.max(Math.min(...round.flat()), g - .55 * H);
4104
+ const band = Math.max(...round.flat()) + PLAYER_H;
4066
4105
  return {
4067
4106
  at: [
4068
4107
  x,
@@ -4072,12 +4111,9 @@ var crag = (x, z, R, H, s, deep = 0) => {
4072
4111
  R,
4073
4112
  H,
4074
4113
  s,
4075
- parts: inside(rockOf(s, R, H), R, -.25 * H).filter((b, k, l) => {
4076
- const gap = Math.max(b[0] - l[0][3], l[0][0] - b[3], b[2] - l[0][5], l[0][2] - b[5]);
4077
- return !k || gap <= 0 || gap > 1.2;
4078
- }).map(([x0, , z0, x1, y1, z1]) => [
4114
+ parts: fitted(rockOf(s, R, H), R, lo - y, band - y, lo - .5 - y).map(([x0, y0, z0, x1, y1, z1]) => [
4079
4115
  x + x0,
4080
- deep,
4116
+ y + y0,
4081
4117
  z + z0,
4082
4118
  x + x1,
4083
4119
  y + y1,
@@ -4088,7 +4124,7 @@ var crag = (x, z, R, H, s, deep = 0) => {
4088
4124
  /** Red's rocks: in the arena the field's stones (as wide as their old box was long, a fifth higher) and the boulders along the walls, then the boulder field's. */
4089
4125
  var CRAGS = {
4090
4126
  arena: [...STONES.map(([x, z, w, d, h], i) => crag(x + w / 2, z + d / 2, .31 * (w + d), 1.15 * h, i + 61)), ...BOULDERS.map(([x, z, r], i) => crag(x, z, r, .8 * r, i))],
4091
- field: FIELD.map(([x, z, r], i) => crag(x, z, r, .75 * r, i + 100, at$1(x, z) - 6))
4127
+ field: FIELD.map(([x, z, r], i) => crag(x, z, r, .75 * r, i + 100))
4092
4128
  };
4093
4129
  var ghosts = (l) => l.flatMap((c) => c.parts).map(([x0, y0, z0, x1, y1, z1]) => ({
4094
4130
  ...box(x0, y0, z0, x1, y1, z1, STONE),
@@ -4203,7 +4239,6 @@ var LAYOUT = {
4203
4239
  280 - PAD[1],
4204
4240
  PAD[2]
4205
4241
  ]],
4206
- shuttles: [SHUTTLE, mirror(SHUTTLE)],
4207
4242
  modules: [...MODULES, ...MODULES.map(mirror)],
4208
4243
  tubes: [...TUBES, ...TUBES.map(mirror)],
4209
4244
  masts: [...MASTS, ...MASTS.map(([x, z]) => [x, 280 - z])]
@@ -4274,26 +4309,6 @@ var half = [
4274
4309
  },
4275
4310
  box(60, 0, 259, 70, 1.5, 265, STEEL, PAINT, RED),
4276
4311
  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
4312
  ...MASTS.map(([x, z]) => box(x - .2, x < 60 ? .25 : 0, z - .2, x + .2, x < 60 ? 10.25 : 10, z + .2, STEEL)),
4298
4313
  box(12, -30, 148 - 2.5 / 2, 24, 0, 148, PAINT, STONE, [
4299
4314
  1,
@@ -4538,6 +4553,17 @@ var MAPS = {
4538
4553
  Math.PI
4539
4554
  ]
4540
4555
  ],
4556
+ ships: [[
4557
+ PAD[0],
4558
+ .25,
4559
+ PAD[1],
4560
+ 0
4561
+ ], [
4562
+ PAD[0],
4563
+ .25,
4564
+ 280 - PAD[1],
4565
+ Math.PI
4566
+ ]],
4541
4567
  doors: [...DOORS, ...DOORS.map(mirror)],
4542
4568
  scenery: "moon",
4543
4569
  helmets: true,
@@ -4766,7 +4792,7 @@ var flagBytes = (state) => state === FLAG$1.CARRIED ? 2 : state === FLAG$1.DROPP
4766
4792
  var encodeSnapshot = (s) => {
4767
4793
  const rovers = (s.rovers ?? []).slice(0, 7);
4768
4794
  const mid = 4 + 62 * s.players.length;
4769
- const end = mid + 54 * rovers.length;
4795
+ const end = mid + 57 * rovers.length;
4770
4796
  const balls = s.balls ?? [];
4771
4797
  const tail = end + 10 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
4772
4798
  const doors = s.doors ?? [];
@@ -4817,10 +4843,15 @@ var encodeSnapshot = (s) => {
4817
4843
  v.setUint8(o + 61, (p.nades ?? 0) << 6 | (p.lob ?? 0));
4818
4844
  });
4819
4845
  rovers.forEach((r, i) => {
4820
- const o = mid + i * 54;
4846
+ const o = mid + i * 57;
4821
4847
  ROVER_F.forEach((k, j) => v.setFloat32(o + 4 * j, r[k]));
4822
4848
  v.setUint8(o + 52, r.driver);
4823
4849
  v.setUint8(o + 53, r.rider);
4850
+ if (r.ship) {
4851
+ v.setUint8(o + 54, 128 | Math.max(0, Math.min(127, r.hp ?? 0)));
4852
+ v.setUint8(o + 55, Math.min(255, Math.ceil((r.wreck ?? 0) / 4)));
4853
+ v.setUint8(o + 56, r.nades ?? 0);
4854
+ }
4824
4855
  });
4825
4856
  v.setUint8(end, s.score[0]);
4826
4857
  v.setUint8(end + 1, s.score[1]);
@@ -4904,6 +4935,405 @@ var beam = (w, p, foes = [], range = 30, [dy, dp] = [0, 0]) => {
4904
4935
  hit
4905
4936
  };
4906
4937
  };
4938
+ // src/shared/ship.ts
4939
+ /** The ship's sizes and its handling. Lengths in metres, rates per second. */
4940
+ var SHIP = {
4941
+ /** From the centre down to the skids' bottom, the hull's height from there, and the hull's half width. */
4942
+ DROP: 1.3,
4943
+ H: 2.6,
4944
+ R: 1.6,
4945
+ /** The hull against the brushes: circles of radius R this far along the nose. */
4946
+ BODY: [
4947
+ 4.8,
4948
+ 0,
4949
+ -4.8
4950
+ ],
4951
+ /** The hull as the shots meet it: spheres of radius HIT this far along the nose. */
4952
+ HITS: [
4953
+ 4.5,
4954
+ 0,
4955
+ -4.5
4956
+ ],
4957
+ HIT: 2.6,
4958
+ /** Thrust along the nose, sideways and straight up (m/s²), the boost's factor, and the top speed without it. */
4959
+ ACC: 24,
4960
+ STRAFE: 14,
4961
+ LIFT: 16,
4962
+ BOOST: 1.7,
4963
+ VMAX: 48,
4964
+ /** Drag with nobody at the stick (1/s), and the skids' friction on a floor. */
4965
+ DRIFT: .25,
4966
+ /** The dampers (1/s) with no key on an axis: the slide on the level stops, and so does the climb with no thrust. */
4967
+ HOLD: 1.5,
4968
+ HOVER: 3,
4969
+ SKID: 3,
4970
+ /** The nose turns toward the look: gain, the rates' caps (yaw, pitch) and how fast a rate follows. */
4971
+ TURN: 4,
4972
+ YRATE: 1.9,
4973
+ PRATE: 1.5,
4974
+ RESP: 8,
4975
+ /** The highest pitch, up or down, and the bank: per rad/s of yaw, per unit of slide, its cap and its response. */
4976
+ PMAX: 1.25,
4977
+ BANK: .4,
4978
+ SLIDE: .3,
4979
+ RMAX: .8,
4980
+ RRESP: 5,
4981
+ /** The ceiling's height (y), the crater's bound shrunk to EDGE, and the depth over which the warning grows. */
4982
+ CEIL: 120,
4983
+ EDGE: .88,
4984
+ WARN: 20,
4985
+ /** Past a limit: the push back (m/s² per metre past it) and the brake on the speed out (1/s). */
4986
+ PUSH: 3,
4987
+ BRAKE: 4,
4988
+ /** The hard stop past the limit, metres. */
4989
+ OVER: 12,
4990
+ /** A player this close to the centre (on the floor plane) and within this height gets in. */
4991
+ ENTER_R: 6,
4992
+ ENTER_H: 4,
4993
+ /** Armour, and the ticks a destroyed ship is gone before it is back on its pad. */
4994
+ HP: 60,
4995
+ WRECK: 600,
4996
+ /** The lasers: ticks between two salvos, the bolts' reach, and where the beams cross ahead along the look. */
4997
+ GUN_COOL: 6,
4998
+ GUN_RANGE: 160,
4999
+ GUN_AIM: 80,
5000
+ /** 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). */
5001
+ MISSILES: 4,
5002
+ MISSILE_COOL: 30,
5003
+ RELOAD: 300,
5004
+ MISSILE_SPEED: 60,
5005
+ /** A missile's burst: the armour it takes at the hull, falling off to nothing this far from it. */
5006
+ BLAST_HP: 14,
5007
+ BLAST_R: 7,
5008
+ /** The armour a laser bolt or a rifle round takes, and a plasma ball per point of its power. */
5009
+ BOLT_HP: 1,
5010
+ BALL_HP: 2
5011
+ };
5012
+ /** The lasers' muzzles at the wing roots, the missiles' pods under the wings: right of the centre, above it, ahead of it. */
5013
+ var SHIP_GUNS = [[
5014
+ -2.6,
5015
+ -.2,
5016
+ 2.2
5017
+ ], [
5018
+ 2.6,
5019
+ -.2,
5020
+ 2.2
5021
+ ]];
5022
+ var PODS = [[
5023
+ -3.4,
5024
+ -.7,
5025
+ .5
5026
+ ], [
5027
+ 3.4,
5028
+ -.7,
5029
+ .5
5030
+ ]];
5031
+ /** The pilot's seat in the cockpit: right of the centre, above it (the feet), ahead of it. */
5032
+ var COCKPIT = [
5033
+ 0,
5034
+ -.55,
5035
+ 2.4
5036
+ ];
5037
+ /** Where who gets out stands, beside the cockpit: clear of the hull, ahead of the wings. */
5038
+ var OUT$1 = SHIP.R + .9;
5039
+ var DT$1 = 1 / 60;
5040
+ var f32$1 = Math.fround;
5041
+ var { sin: sin$1, cos: cos$1, min: min$1, max: max$1, abs: abs$1, sqrt: sqrt$1 } = Math;
5042
+ var clamp$1 = (v, lo, hi) => min$1(max$1(v, lo), hi);
5043
+ var FLOATS$1 = "x y z vx vy vz yaw pitch roll wy wp wr steer".split(" ");
5044
+ /** The ship's axes in the world: right, up and the nose, pitched and banked (mesh.ts's basis()). */
5045
+ var axes = (r) => {
5046
+ const [sy, cy, sp, cp, sr, cr] = [
5047
+ r.yaw,
5048
+ r.pitch,
5049
+ r.roll
5050
+ ].flatMap((a) => [sin$1(a), cos$1(a)]);
5051
+ const R = [
5052
+ cy,
5053
+ 0,
5054
+ -sy
5055
+ ];
5056
+ const U = [
5057
+ sy * sp,
5058
+ cp,
5059
+ cy * sp
5060
+ ];
5061
+ return [
5062
+ [
5063
+ R[0] * cr - U[0] * sr,
5064
+ R[1] * cr - U[1] * sr,
5065
+ R[2] * cr - U[2] * sr
5066
+ ],
5067
+ [
5068
+ U[0] * cr + R[0] * sr,
5069
+ U[1] * cr + R[1] * sr,
5070
+ U[2] * cr + R[2] * sr
5071
+ ],
5072
+ [
5073
+ -sy * cp,
5074
+ sp,
5075
+ -cy * cp
5076
+ ]
5077
+ ];
5078
+ };
5079
+ /** A point of the ship, `b` m right of the centre, `u` m above it and `a` m ahead of it. */
5080
+ var point = (r, b, u, a) => {
5081
+ const [R, U, F] = axes(r);
5082
+ return [
5083
+ r.x + R[0] * b + U[0] * u + F[0] * a,
5084
+ r.y + R[1] * b + U[1] * u + F[1] * a,
5085
+ r.z + R[2] * b + U[2] * u + F[2] * a
5086
+ ];
5087
+ };
5088
+ /** The map's ships at rest on their pads: full armour and missiles, nobody aboard. */
5089
+ var dock = (ships = []) => ships.map(([x, y, z, yaw]) => ({
5090
+ x: f32$1(x),
5091
+ y: f32$1(y + SHIP.DROP),
5092
+ z: f32$1(z),
5093
+ vx: 0,
5094
+ vy: 0,
5095
+ vz: 0,
5096
+ yaw: f32$1(norm(yaw)),
5097
+ pitch: 0,
5098
+ roll: 0,
5099
+ wy: 0,
5100
+ wp: 0,
5101
+ wr: 0,
5102
+ steer: 0,
5103
+ driver: 255,
5104
+ rider: 255,
5105
+ ship: true,
5106
+ hp: SHIP.HP,
5107
+ wreck: 0,
5108
+ nades: SHIP.MISSILES
5109
+ }));
5110
+ /** A body that meets nothing: a ship that is gone. */
5111
+ var NONE = {
5112
+ a: [
5113
+ 0,
5114
+ -1e4,
5115
+ 0
5116
+ ],
5117
+ b: [
5118
+ 0,
5119
+ -1e4,
5120
+ 0
5121
+ ],
5122
+ r: 0,
5123
+ h: 0
5124
+ };
5125
+ /**
5126
+ * The hull as the players on foot and the rovers meet it: the stadium from the tail to the nose
5127
+ * along the floor plane, R wide, from the skids up H. A player walks into it and stands on it.
5128
+ */
5129
+ var shipHull = (r) => {
5130
+ if (r.wreck) return NONE;
5131
+ const [a, b] = [SHIP.BODY[0], SHIP.BODY[2]].map((k) => point(r, 0, -SHIP.DROP, k));
5132
+ return {
5133
+ a,
5134
+ b,
5135
+ r: SHIP.R,
5136
+ h: SHIP.H
5137
+ };
5138
+ };
5139
+ /**
5140
+ * The ship against the crater's edge: its distance from the bound's centre and the edge's along the
5141
+ * same line, and the unit way out on the floor plane. Undefined on a map without a relief.
5142
+ */
5143
+ var edge = (r, w) => {
5144
+ if (!w.relief) return;
5145
+ const [cx, cz, a, b] = w.relief.bound;
5146
+ const [dx, dz] = [r.x - cx, r.z - cz];
5147
+ const d = sqrt$1(dx * dx + dz * dz);
5148
+ if (!d) return [
5149
+ 0,
5150
+ SHIP.EDGE * min$1(a, b),
5151
+ 1,
5152
+ 0
5153
+ ];
5154
+ const [ux, uz] = [dx / d, dz / d];
5155
+ return [
5156
+ d,
5157
+ SHIP.EDGE / sqrt$1(ux * ux / (a * a) + uz * uz / (b * b)),
5158
+ ux,
5159
+ uz
5160
+ ];
5161
+ };
5162
+ /** The lowest bottom of a brush over the circle round (x, z) between y0 and y1, or y1. */
5163
+ var roof = (w, x, z, y0, y1) => {
5164
+ let top = y1;
5165
+ for (const i of near(w, x, z, SHIP.R)) {
5166
+ const { min: lo, max: hi } = w.def.brushes[i];
5167
+ 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];
5168
+ }
5169
+ return top;
5170
+ };
5171
+ /**
5172
+ * One step of 1 / TICK_HZ s, in place. `i` is the pilot's input as the wire rounds it, or
5173
+ * undefined with nobody at the stick: the engines are off and it falls under the map's gravity to
5174
+ * a floor. A ship that is gone (`wreck`) does not move. Returns whether it fell under the kill
5175
+ * floor: the caller docks it again.
5176
+ *
5177
+ * The nose turns toward the look as fast as the rates allow and banks into the turn; the thrust
5178
+ * is along the nose, sideways and straight up, against a drag that sets the top speed. Piloted,
5179
+ * the engines hold it against gravity: it hovers with no key held. On a floor it rests on its
5180
+ * skids, level.
5181
+ */
5182
+ var pilot = (r, i, w) => {
5183
+ if (r.wreck) return false;
5184
+ const keys = i ? i.keys : 0;
5185
+ const on = (k) => keys & k ? 1 : 0;
5186
+ const thr = on(KEY.FORWARD) - on(KEY.BACK);
5187
+ const side = on(KEY.RIGHT) - on(KEY.LEFT);
5188
+ const lift = on(KEY.JUMP) - on(KEY.CROUCH);
5189
+ const boost = on(KEY.SPRINT) && thr > 0 ? SHIP.BOOST : 1;
5190
+ const landed = r.steer < 0;
5191
+ if (i) {
5192
+ const ey = norm(i.yaw - r.yaw + Math.PI) - Math.PI;
5193
+ const tp = clamp$1(i.pitch, landed ? 0 : -SHIP.PMAX, SHIP.PMAX);
5194
+ const k = min$1(1, SHIP.RESP * DT$1);
5195
+ r.wy += (clamp$1(SHIP.TURN * ey, -SHIP.YRATE, SHIP.YRATE) - r.wy) * k;
5196
+ r.wp += (clamp$1(SHIP.TURN * (tp - r.pitch), -SHIP.PRATE, SHIP.PRATE) - r.wp) * k;
5197
+ } else {
5198
+ r.wy *= 1 - min$1(1, SHIP.RESP * DT$1);
5199
+ r.wp = landed ? -SHIP.TURN * r.pitch : r.wp * (1 - min$1(1, SHIP.RESP * DT$1));
5200
+ }
5201
+ r.wr = ((landed ? 0 : clamp$1(-SHIP.BANK * r.wy + SHIP.SLIDE * side, -SHIP.RMAX, SHIP.RMAX)) - r.roll) * SHIP.RRESP;
5202
+ const [sy, cy, sp, cp] = [
5203
+ sin$1(r.yaw),
5204
+ cos$1(r.yaw),
5205
+ sin$1(r.pitch),
5206
+ cos$1(r.pitch)
5207
+ ];
5208
+ const a = i ? [
5209
+ -sy * cp * thr * SHIP.ACC * boost + cy * side * SHIP.STRAFE,
5210
+ sp * thr * SHIP.ACC * boost + lift * SHIP.LIFT,
5211
+ -cy * cp * thr * SHIP.ACC * boost - sy * side * SHIP.STRAFE
5212
+ ] : [
5213
+ 0,
5214
+ -gravity(w),
5215
+ 0
5216
+ ];
5217
+ const over = r.y - SHIP.CEIL;
5218
+ if (a[1] > 0) a[1] *= clamp$1(-over / SHIP.WARN, 0, 1);
5219
+ if (over > 0) {
5220
+ a[1] -= SHIP.PUSH * over;
5221
+ if (r.vy > 0) r.vy *= 1 - min$1(1, SHIP.BRAKE * DT$1);
5222
+ }
5223
+ const e = edge(r, w);
5224
+ if (e) {
5225
+ const [d, at, nx, nz] = e;
5226
+ const out = a[0] * nx + a[2] * nz;
5227
+ const past = d - at;
5228
+ if (out > 0) {
5229
+ const k = 1 - clamp$1(-past / SHIP.WARN, 0, 1);
5230
+ a[0] -= out * nx * k;
5231
+ a[2] -= out * nz * k;
5232
+ }
5233
+ if (past > 0) {
5234
+ a[0] -= SHIP.PUSH * past * nx;
5235
+ a[2] -= SHIP.PUSH * past * nz;
5236
+ const v = r.vx * nx + r.vz * nz;
5237
+ if (v > 0) {
5238
+ const k = v * min$1(1, SHIP.BRAKE * DT$1);
5239
+ r.vx -= k * nx;
5240
+ r.vz -= k * nz;
5241
+ }
5242
+ }
5243
+ }
5244
+ const drag = i ? SHIP.ACC / SHIP.VMAX : SHIP.DRIFT;
5245
+ const level = drag + (i && !thr && !side ? SHIP.HOLD : 0);
5246
+ const climb = drag + (i && !thr && !lift ? SHIP.HOVER : 0);
5247
+ r.vx += (a[0] - r.vx * level) * DT$1;
5248
+ r.vy += (a[1] - r.vy * climb) * DT$1;
5249
+ r.vz += (a[2] - r.vz * level) * DT$1;
5250
+ if (landed) {
5251
+ const k = 1 - min$1(1, SHIP.SKID * DT$1);
5252
+ r.vx *= thr || side ? 1 : k;
5253
+ r.vz *= thr || side ? 1 : k;
5254
+ }
5255
+ r.x += r.vx * DT$1;
5256
+ r.y += r.vy * DT$1;
5257
+ r.z += r.vz * DT$1;
5258
+ r.yaw = norm(r.yaw + r.wy * DT$1);
5259
+ r.pitch = clamp$1(r.pitch + r.wp * DT$1, -SHIP.PMAX, SHIP.PMAX);
5260
+ r.roll += r.wr * DT$1;
5261
+ r.y = min$1(r.y, SHIP.CEIL + SHIP.OVER);
5262
+ if (e) {
5263
+ const [d, at, nx, nz] = edge(r, w);
5264
+ if (d > at + SHIP.OVER) {
5265
+ r.x -= nx * (d - at - SHIP.OVER);
5266
+ r.z -= nz * (d - at - SHIP.OVER);
5267
+ }
5268
+ }
5269
+ let lifted = 0;
5270
+ for (const k of SHIP.BODY) {
5271
+ const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5272
+ lifted = max$1(lifted, floorAt(w, x, z, y + .6) - y);
5273
+ }
5274
+ r.steer = 0;
5275
+ if (lifted > 0) {
5276
+ r.y += lifted;
5277
+ r.vy = max$1(r.vy, 0);
5278
+ r.steer = r.vy > .5 ? 0 : -1;
5279
+ }
5280
+ for (const k of SHIP.BODY) {
5281
+ const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5282
+ const top = roof(w, x, z, y + .6, y + SHIP.H);
5283
+ if (top < y + SHIP.H) {
5284
+ r.y -= y + SHIP.H - top;
5285
+ r.vy = min$1(r.vy, 0);
5286
+ }
5287
+ }
5288
+ for (const k of SHIP.BODY) {
5289
+ const [x, y, z] = point(r, 0, -SHIP.DROP, k);
5290
+ const [px, pz] = shove({
5291
+ x,
5292
+ y: y + .6,
5293
+ z
5294
+ }, w, SHIP.H - .6, SHIP.R);
5295
+ const d = px * px + pz * pz;
5296
+ if (d) {
5297
+ r.x += px;
5298
+ r.z += pz;
5299
+ const v = min$1(0, r.vx * px + r.vz * pz) / d;
5300
+ r.vx -= v * px;
5301
+ r.vz -= v * pz;
5302
+ }
5303
+ }
5304
+ bound(r, w);
5305
+ if (abs$1(r.roll) < 1e-6) r.roll = 0;
5306
+ for (const k of FLOATS$1) r[k] = f32$1(r[k]);
5307
+ return r.y < w.def.floor;
5308
+ };
5309
+ /**
5310
+ * Where a shot from `o` along the unit `d` meets the hull within `m` metres: the distance, or
5311
+ * Infinity. The hull is the HITS spheres; a ship that is gone has none.
5312
+ */
5313
+ var struck = (r, o, d, m) => {
5314
+ if (r.wreck) return Infinity;
5315
+ let best = Infinity;
5316
+ for (const k of SHIP.HITS) {
5317
+ const c = point(r, 0, 0, k);
5318
+ const [px, py, pz] = [
5319
+ o[0] - c[0],
5320
+ o[1] - c[1],
5321
+ o[2] - c[2]
5322
+ ];
5323
+ const b = px * d[0] + py * d[1] + pz * d[2];
5324
+ const q = px * px + py * py + pz * pz - SHIP.HIT * SHIP.HIT;
5325
+ const disc = b * b - q;
5326
+ if (disc < 0) continue;
5327
+ const t = max$1(0, -b - sqrt$1(disc));
5328
+ if (t <= m && t < best) best = t;
5329
+ }
5330
+ return best;
5331
+ };
5332
+ /** The distance from `c` to the nearest point of the hull's spheres, 0 inside. */
5333
+ var reach = (r, c) => min$1(...SHIP.HITS.map((k) => {
5334
+ const [x, y, z] = point(r, 0, 0, k).map((v, n) => c[n] - v);
5335
+ return max$1(0, sqrt$1(x * x + y * y + z * z) - SHIP.HIT);
5336
+ }));
4907
5337
  // src/shared/rover.ts
4908
5338
  /** The rover's sizes and its handling (docs/MOON.md). Lengths in metres, per wheel rates for a body of mass 1. */
4909
5339
  var ROVER = {
@@ -5050,6 +5480,7 @@ var footprint = (r) => ROVER.BODY.map((a) => at(r, a, 0, -DROP));
5050
5480
  * rear circles of footprint(), RB wide and BODY_H tall. A player walks into it and stands on it.
5051
5481
  */
5052
5482
  var hull = (r) => {
5483
+ if (r.ship) return shipHull(r);
5053
5484
  const [a, , b] = footprint(r);
5054
5485
  return {
5055
5486
  a,
@@ -5058,8 +5489,12 @@ var hull = (r) => {
5058
5489
  h: ROVER.BODY_H
5059
5490
  };
5060
5491
  };
5061
- /** The map's rovers at rest on their spawns, nobody aboard. */
5062
- var park = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5492
+ /**
5493
+ * The map's rovers at rest on their spawns, nobody aboard, then its ships on their pads (ship.ts):
5494
+ * the order of the snapshot's.
5495
+ */
5496
+ var park = (w) => [...cars(w), ...dock(w.def.ships)];
5497
+ var cars = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5063
5498
  x: f32(x),
5064
5499
  y: f32(y + DROP),
5065
5500
  z: f32(z),
@@ -5090,6 +5525,7 @@ var park = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
5090
5525
  * speed follows it. The rest drifts.
5091
5526
  */
5092
5527
  var drive = (r, i, w, fleet = []) => {
5528
+ if (r.ship) return pilot(r, i, w);
5093
5529
  const { A, B, CMAX, K, D, KP2, KR2, HC, MU, MUL, TILT } = ROVER;
5094
5530
  const g = gravity(w);
5095
5531
  const keys = i ? i.keys : 0;
@@ -5210,8 +5646,8 @@ var drive = (r, i, w, fleet = []) => {
5210
5646
  * speed. The seat leans with the body: on a slope he is not left in the air.
5211
5647
  */
5212
5648
  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);
5649
+ const [side, up, ahead] = r.ship ? COCKPIT : SEATS$1[s];
5650
+ [p.x, p.y, p.z] = (r.ship ? point(r, side, up, ahead) : at(r, ahead, side, up)).map(f32);
5215
5651
  p.vx = r.vx;
5216
5652
  p.vy = r.vy;
5217
5653
  p.vz = r.vz;
@@ -5247,13 +5683,15 @@ var leave = (p, r, s, w) => {
5247
5683
  r.vy,
5248
5684
  r.vz
5249
5685
  ];
5250
- const side = s ? OUT : -OUT;
5686
+ const side = r.ship ? -OUT$1 : s ? OUT : -OUT;
5687
+ const [drop, top] = r.ship ? [SHIP.DROP, SHIP.H] : [DROP, ROVER.BODY_H];
5251
5688
  for (const [b, u] of [
5252
- [side, -DROP],
5253
- [-side, -DROP],
5254
- [0, ROVER.BODY_H - DROP]
5689
+ [side, -drop],
5690
+ [-side, -drop],
5691
+ [0, top - drop]
5255
5692
  ]) {
5256
- const [x, y, z] = at(r, SEATS$1[s][2], b, u);
5693
+ const ahead = r.ship ? COCKPIT[2] : SEATS$1[s][2];
5694
+ const [x, y, z] = r.ship ? point(r, b, u, ahead) : at(r, ahead, b, u);
5257
5695
  Object.assign(p, {
5258
5696
  x,
5259
5697
  y,
@@ -5290,7 +5728,24 @@ var ride = (p, r, i, w, team, fleet = []) => {
5290
5728
  }
5291
5729
  return fell;
5292
5730
  };
5293
- /** Where the rover's lasers cross: GUN_AIM metres from its centre along the driver's look. */
5731
+ /** The squared distance on the floor plane from the vehicle's centre to the player. */
5732
+ var gap2 = (r, p) => (r.x - p.x) ** 2 + (r.z - p.z) ** 2;
5733
+ /**
5734
+ * A player on foot near enough to get in: on the floor plane within ENTER_R of the centre, and
5735
+ * within the reach in height (a ship's ENTER_H). A ship that is gone has no seat.
5736
+ */
5737
+ var nearby = (r, p) => {
5738
+ const [k, h] = r.ship ? [SHIP.ENTER_R, SHIP.ENTER_H] : [ROVER.ENTER_R, ROVER.ENTER_R];
5739
+ return !r.wreck && Math.abs(r.y - p.y) <= h && gap2(r, p) <= k * k;
5740
+ };
5741
+ /**
5742
+ * The seat a player gets: 0 at the wheel (never a flag's carrier), 1 beside it, -1 none. A ship
5743
+ * has its pilot's seat only.
5744
+ */
5745
+ var free = (r, carrier) => r.driver === 255 && !carrier ? 0 : r.rider === 255 && !r.ship ? 1 : -1;
5746
+ /** Metres from the centre to where the lasers cross along the look: a ship's or a rover's. */
5747
+ var aimRange = (r) => r.ship ? SHIP.GUN_AIM : ROVER.GUN_AIM;
5748
+ /** Where the lasers cross: aimRange() metres from the centre along the driver's look. */
5294
5749
  var aimOf = (r, yaw, pitch) => {
5295
5750
  const [sy, cy, sp, cp] = [
5296
5751
  Math.sin(yaw),
@@ -5298,28 +5753,39 @@ var aimOf = (r, yaw, pitch) => {
5298
5753
  Math.sin(pitch),
5299
5754
  Math.cos(pitch)
5300
5755
  ];
5756
+ const k = aimRange(r);
5757
+ return [
5758
+ r.x - sy * cp * k,
5759
+ r.y + sp * k,
5760
+ r.z - cy * cp * k
5761
+ ];
5762
+ };
5763
+ /** A muzzle of the vehicle in the world: `m` is right of the centre, above it, ahead of it. */
5764
+ var muzzle = (r, [side, up, ahead]) => {
5765
+ if (r.ship) return point(r, side, up, ahead);
5766
+ const [fx, fz] = forward(r.yaw);
5301
5767
  return [
5302
- r.x - sy * cp * ROVER.GUN_AIM,
5303
- r.y + sp * ROVER.GUN_AIM,
5304
- r.z - cy * cp * ROVER.GUN_AIM
5768
+ r.x + fx * ahead - fz * side,
5769
+ r.y + up,
5770
+ r.z + fz * ahead + fx * side
5305
5771
  ];
5306
5772
  };
5773
+ /** From `o` toward the aim, unit. */
5774
+ var toward = (o, aim) => {
5775
+ const d = aim.map((v, a) => v - o[a]);
5776
+ const l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
5777
+ return d.map((v) => v / l);
5778
+ };
5307
5779
  /**
5308
5780
  * The two bolts of one salvo of the rover's lasers, left then right: each from its muzzle toward
5309
5781
  * the point GUN_AIM metres along the driver's look (the yaw and pitch of his input) from the rover's
5310
5782
  * centre, so the beams cross there, chest high on level ground with a level look. `id` names the first, `id + 1` the second.
5311
5783
  */
5312
5784
  var bolts = (r, by, team, yaw, pitch, id) => {
5313
- const [fx, fz] = forward(r.yaw);
5314
5785
  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]);
5786
+ return (r.ship ? SHIP_GUNS : GUNS).map((m, k) => {
5787
+ const o = muzzle(r, m);
5788
+ const d = toward(o, aim);
5323
5789
  return {
5324
5790
  id: id + k & 255,
5325
5791
  by,
@@ -5327,15 +5793,40 @@ var bolts = (r, by, team, yaw, pitch, id) => {
5327
5793
  x: o[0],
5328
5794
  y: o[1],
5329
5795
  z: o[2],
5330
- dx: d[0] / l,
5331
- dy: d[1] / l,
5332
- dz: d[2] / l,
5333
- left: ROVER.GUN_RANGE,
5796
+ dx: d[0],
5797
+ dy: d[1],
5798
+ dz: d[2],
5799
+ left: r.ship ? SHIP.GUN_RANGE : ROVER.GUN_RANGE,
5334
5800
  burst: false,
5335
5801
  power: 6
5336
5802
  };
5337
5803
  });
5338
5804
  };
5805
+ /**
5806
+ * A ship's missile from its pod `k` (0 left, 1 right) toward where its lasers cross: a grenade
5807
+ * (plasma.ts's toss() flies it, blast() is its burst) launched at MISSILE_SPEED plus the ship's own
5808
+ * speed along the way, 63 m/s at most (the wire's six bits).
5809
+ */
5810
+ var missile = (r, by, team, yaw, pitch, id, k) => {
5811
+ const o = muzzle(r, PODS[k]);
5812
+ const d = toward(o, aimOf(r, yaw, pitch));
5813
+ const own = r.vx * d[0] + r.vy * d[1] + r.vz * d[2];
5814
+ return {
5815
+ id: id & 255,
5816
+ by,
5817
+ team,
5818
+ x: o[0],
5819
+ y: o[1],
5820
+ z: o[2],
5821
+ dx: d[0],
5822
+ dy: d[1],
5823
+ dz: d[2],
5824
+ left: 2 * SHIP.GUN_RANGE,
5825
+ burst: false,
5826
+ power: 7,
5827
+ v: Math.min(63, SHIP.MISSILE_SPEED + Math.max(0, own))
5828
+ };
5829
+ };
5339
5830
  // src/shared/tackle.ts
5340
5831
  /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
5341
5832
  var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
@@ -5429,8 +5920,10 @@ var Room = class {
5429
5920
  gone;
5430
5921
  /** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
5431
5922
  balls = [];
5432
- /** The map's rovers, in the order of WorldDef.rovers. */
5923
+ /** The map's rovers, in the order of WorldDef.rovers, then its ships (ship.ts). */
5433
5924
  rovers;
5925
+ /** Ticks toward each ship's next missile, by index in `rovers`. */
5926
+ rearm = [];
5434
5927
  /** The key of the map being played, which the roster tells the clients. */
5435
5928
  mapName;
5436
5929
  /** The map the host picked for the next match, when it is another one. */
@@ -5512,7 +6005,8 @@ var Room = class {
5512
6005
  if (fell) this.sink(r);
5513
6006
  else {
5514
6007
  this.carry(r);
5515
- this.splat(p, r, input.view);
6008
+ if (r.ship) this.launch(p, r, input);
6009
+ else this.splat(p, r, input.view);
5516
6010
  this.lase(p, r, input);
5517
6011
  }
5518
6012
  } else {
@@ -5593,6 +6087,7 @@ var Room = class {
5593
6087
  this.restart(players);
5594
6088
  }
5595
6089
  this.seats();
6090
+ this.rovers.forEach((r, k) => this.dock(r, k));
5596
6091
  for (const r of this.rovers) if (r.driver !== 255) this.carry(r);
5597
6092
  else if (drive(r, void 0, this.world, this.rovers)) this.sink(r);
5598
6093
  else this.carry(r);
@@ -5775,8 +6270,23 @@ var Room = class {
5775
6270
  fly(b, m) {
5776
6271
  const peers = this.players();
5777
6272
  const foes = peers.filter((q) => q.info.team !== b.team && !q.state.down);
6273
+ const by = peers.find((q) => q.info.id === b.by);
6274
+ const o = [
6275
+ b.x,
6276
+ b.y,
6277
+ b.z
6278
+ ];
5778
6279
  if (b.power === 7) {
5779
6280
  toss(this.world, b, foes.map((f) => f.state));
6281
+ this.ram(b, o);
6282
+ for (const r of b.burst ? this.targets(b.team) : []) {
6283
+ const d = reach(r, [
6284
+ b.x,
6285
+ b.y,
6286
+ b.z
6287
+ ]);
6288
+ if (d < SHIP.BLAST_R) this.hurt(r, Math.ceil(SHIP.BLAST_HP * (1 - d / SHIP.BLAST_R)), by);
6289
+ }
5780
6290
  let hit = false;
5781
6291
  for (const q of b.burst ? peers : []) {
5782
6292
  const own = q.info.id === b.by;
@@ -5790,14 +6300,17 @@ var Room = class {
5790
6300
  hit ||= !own;
5791
6301
  }
5792
6302
  }
5793
- const by = peers.find((q) => q.info.id === b.by);
5794
6303
  if (hit && by) by.state.hits = by.state.hits + 1 & 255;
5795
6304
  return;
5796
6305
  }
5797
6306
  const hit = fly(this.world, b, m, foes.map((f) => f.state));
6307
+ const ship = this.ram(b, o);
6308
+ if (ship) {
6309
+ this.hurt(ship, b.power === 0 || b.power === 6 ? SHIP.BOLT_HP : SHIP.BALL_HP * (b.power ?? 1), by);
6310
+ return;
6311
+ }
5798
6312
  const foe = foes.find((q) => q.state === hit);
5799
6313
  if (!foe) return;
5800
- const by = peers.find((q) => q.info.id === b.by);
5801
6314
  if (by) by.state.hits = by.state.hits + 1 & 255;
5802
6315
  if (b.power === 0 || b.power === 6) {
5803
6316
  foe.graze = ((foe.graze ?? 0) + 1) % 2;
@@ -6019,6 +6532,39 @@ var Room = class {
6019
6532
  * rides holds a seat. So a leaver's seat is free before his id is given again, and one put down,
6020
6533
  * respawned or stumbled out is off the rover.
6021
6534
  */
6535
+ /**
6536
+ * The first enemy ship on the way the ball `b` flew this tick, from `o` to where it is now: the
6537
+ * ball bursts on its hull, short of a body or a wall further on.
6538
+ */
6539
+ ram(b, o) {
6540
+ const d = [
6541
+ b.x - o[0],
6542
+ b.y - o[1],
6543
+ b.z - o[2]
6544
+ ];
6545
+ const m = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
6546
+ if (!m) return;
6547
+ const u = [
6548
+ d[0] / m,
6549
+ d[1] / m,
6550
+ d[2] / m
6551
+ ];
6552
+ let [t, hit] = [m, void 0];
6553
+ for (const r of this.targets(b.team)) {
6554
+ const s = struck(r, o, u, t);
6555
+ if (s < t) [t, hit] = [s, r];
6556
+ }
6557
+ if (hit) {
6558
+ b.left += m - t;
6559
+ [b.x, b.y, b.z] = [
6560
+ o[0] + u[0] * t,
6561
+ o[1] + u[1] * t,
6562
+ o[2] + u[2] * t
6563
+ ];
6564
+ b.burst = true;
6565
+ }
6566
+ return hit;
6567
+ }
6022
6568
  seats() {
6023
6569
  const players = this.players();
6024
6570
  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 +6578,8 @@ var Room = class {
6032
6578
  const q = p.state;
6033
6579
  if (q.down || q.stun || q.lock || q.mode === MODE.RIDE) return;
6034
6580
  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));
6581
+ const r = this.rovers.filter((r) => nearby(r, q) && free(r, carrier) >= 0).sort((a, b) => gap2(a, q) - gap2(b, q))[0];
6582
+ if (r) board(q, r, free(r, carrier));
6039
6583
  }
6040
6584
  /**
6041
6585
  * The rider follows the rover on his seat. Over a floor, that is his last ground: where a flag he
@@ -6074,10 +6618,64 @@ var Room = class {
6074
6618
  lase(p, r, i) {
6075
6619
  p.gun = Math.max(0, (p.gun ?? 0) - 1);
6076
6620
  if (!(i.keys & KEY.FIRE) || p.gun || this.ctf.over || p.state.mode !== MODE.RIDE) return;
6077
- p.gun = ROVER.GUN_COOL;
6621
+ p.gun = r.ship ? SHIP.GUN_COOL : ROVER.GUN_COOL;
6078
6622
  p.bolt = (p.bolt ?? 0) + 2 & 255;
6079
6623
  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
6624
  }
6625
+ /**
6626
+ * A ship's missiles: while its pilot holds SPECIAL (G), one each SHIP.MISSILE_COOL of his inputs
6627
+ * while it has any, from the left pod then the right, toward where its lasers cross.
6628
+ */
6629
+ launch(p, r, i) {
6630
+ p.pod = Math.max(0, (p.pod ?? 0) - 1);
6631
+ if (!(i.keys & KEY.SPECIAL) || p.pod || !r.nades || this.ctf.over) return;
6632
+ if (p.state.mode !== MODE.RIDE) return;
6633
+ p.pod = SHIP.MISSILE_COOL;
6634
+ p.side = (p.side ?? 0) ^ 1;
6635
+ r.nades--;
6636
+ p.bolt = (p.bolt ?? 0) + 1 & 255;
6637
+ this.shoot(p, i.view, missile(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt, p.side));
6638
+ }
6639
+ /**
6640
+ * A ship's clock outside its pilot's inputs: one that is gone comes back on its pad, new, after
6641
+ * SHIP.WRECK ticks; one short of missiles loads one each SHIP.RELOAD ticks.
6642
+ */
6643
+ dock(r, k) {
6644
+ if (!r.ship) return;
6645
+ if (r.wreck) {
6646
+ if (!--r.wreck) {
6647
+ Object.assign(r, park(this.world)[k]);
6648
+ this.rearm[k] = 0;
6649
+ }
6650
+ return;
6651
+ }
6652
+ this.rearm[k] = (r.nades ?? 0) < SHIP.MISSILES ? (this.rearm[k] ?? 0) + 1 : 0;
6653
+ if (this.rearm[k] >= SHIP.RELOAD) {
6654
+ r.nades = (r.nades ?? 0) + 1;
6655
+ this.rearm[k] = 0;
6656
+ }
6657
+ }
6658
+ /** The ships an enemy of `team` pilots and that are there to hit. */
6659
+ targets(team) {
6660
+ const by = new Map(this.players().map((p) => [p.info.id, p.info.team]));
6661
+ return this.rovers.filter((r) => r.ship && !r.wreck && r.driver !== 255 && by.get(r.driver) !== team);
6662
+ }
6663
+ /**
6664
+ * The ship `r` loses `hp` of armour to the shot of `by`; at 0 it blows up where it is: its pilot
6665
+ * goes down with it, and it is gone SHIP.WRECK ticks.
6666
+ */
6667
+ hurt(r, hp, by) {
6668
+ if (by) by.state.hits = by.state.hits + 1 & 255;
6669
+ r.hp = Math.max(0, (r.hp ?? 0) - hp);
6670
+ if (r.hp) return;
6671
+ for (const q of this.players()) if (this.seatOf(q)[0] === r) this.harm(q, q.state.hp);
6672
+ Object.assign(r, {
6673
+ wreck: SHIP.WRECK,
6674
+ driver: 255,
6675
+ rider: 255,
6676
+ nades: 0
6677
+ });
6678
+ }
6081
6679
  splat(p, r, view) {
6082
6680
  if (len(r.vx, r.vz) < ROVER.SPLAT_MIN) return;
6083
6681
  const body = footprint(r);