@korial29/tiny-fps 0.97.0 → 0.99.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
@@ -455,12 +455,12 @@ var OFF = 1024;
455
455
  /** The key of the cell with integer coordinates (cx, cz). */
456
456
  var key = (cx, cz) => (cx + OFF) * (2 * OFF) + cz + OFF;
457
457
  /** Integer cell coordinate of a metre value, clamped to the keyed range. */
458
- var at$1 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
458
+ var at$2 = (v, cell) => Math.min(Math.max(Math.floor(v / cell), -1024), 1023);
459
459
  /** Builds the grid: each brush is listed in every cell its footprint covers. */
460
460
  var build = (def, cell = CELL) => {
461
461
  const grid = /* @__PURE__ */ new Map();
462
462
  def.brushes.forEach(({ min, max }, i) => {
463
- for (let cx = at$1(min[0], cell); cx <= at$1(max[0], cell); cx++) for (let cz = at$1(min[2], cell); cz <= at$1(max[2], cell); cz++) {
463
+ for (let cx = at$2(min[0], cell); cx <= at$2(max[0], cell); cx++) for (let cz = at$2(min[2], cell); cz <= at$2(max[2], cell); cz++) {
464
464
  const k = key(cx, cz);
465
465
  const list = grid.get(k);
466
466
  if (list) list.push(i);
@@ -484,7 +484,7 @@ var build = (def, cell = CELL) => {
484
484
  */
485
485
  var near = (w, x, z, r) => {
486
486
  const out = [];
487
- for (let cx = at$1(x - r, w.cell); cx <= at$1(x + r, w.cell); cx++) for (let cz = at$1(z - r, w.cell); cz <= at$1(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
487
+ for (let cx = at$2(x - r, w.cell); cx <= at$2(x + r, w.cell); cx++) for (let cz = at$2(z - r, w.cell); cz <= at$2(z + r, w.cell); cz++) for (const i of w.grid.get(key(cx, cz)) ?? []) if (!out.includes(i)) out.push(i);
488
488
  return out;
489
489
  };
490
490
  /**
@@ -507,8 +507,8 @@ var ray = (w, o, d, max, grow = 0) => {
507
507
  var faces = (w, o, d, max, grow) => {
508
508
  const { cell, def } = w;
509
509
  let best = max;
510
- let cx = at$1(o[0], cell);
511
- let cz = at$1(o[2], cell);
510
+ let cx = at$2(o[0], cell);
511
+ let cz = at$2(o[2], cell);
512
512
  const sx = Math.sign(d[0]);
513
513
  const sz = Math.sign(d[2]);
514
514
  const nx = sx ? ((cx + (sx > 0 ? 1 : 0)) * cell - o[0]) / d[0] : Infinity;
@@ -558,7 +558,7 @@ var hidden = (w, a, b) => {
558
558
  ], len) < len - 1e-4;
559
559
  };
560
560
  // src/shared/physics.ts
561
- var DT = 1 / 60;
561
+ var DT$1 = 1 / 60;
562
562
  var TAU = Math.PI * 2;
563
563
  /** Overlaps smaller than this are rounding noise, not contact. */
564
564
  var EPS = 1e-6;
@@ -577,11 +577,11 @@ var TOUCH = .001;
577
577
  var norm = (a) => (a % TAU + TAU) % TAU;
578
578
  /** Unit vector the player faces at yaw, on the floor plane: yaw 0 looks toward -z. */
579
579
  var forward = (yaw) => [-Math.sin(yaw), -Math.cos(yaw)];
580
- var f32 = Math.fround;
581
- var sqrt = Math.sqrt;
582
- var clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
580
+ var f32$1 = Math.fround;
581
+ var sqrt$1 = Math.sqrt;
582
+ var clamp$1 = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
583
583
  /** The length of (x, z). */
584
- var len = (x, z) => sqrt(x * x + z * z);
584
+ var len$1 = (x, z) => sqrt$1(x * x + z * z);
585
585
  /** The unit vector from a player toward a wall or a ledge on each SIDE. */
586
586
  var TOWARD = [
587
587
  [0, 0],
@@ -641,9 +641,9 @@ var spawn = (id, w, n, team = 0) => {
641
641
  const [x, y, z, yaw] = spawns[(n % spawns.length + spawns.length) % spawns.length];
642
642
  return {
643
643
  id,
644
- x: f32(x),
645
- y: f32(y),
646
- z: f32(z),
644
+ x: f32$1(x),
645
+ y: f32$1(y),
646
+ z: f32$1(z),
647
647
  vy: 0,
648
648
  yaw: norm(yaw),
649
649
  pitch: 0,
@@ -672,11 +672,11 @@ var heightOf = (p) => p.mode === MODE.SLIDE || p.mode === MODE.CROUCH ? LOW_H :
672
672
  /** The camera height above the feet in this mode. */
673
673
  var eyeHeight = (p) => p.mode === MODE.SLIDE || p.mode === MODE.CROUCH ? LOW_EYE : EYE;
674
674
  /** Horizontal speed, m/s. */
675
- var speedOf = (p) => len(p.vx, p.vz);
675
+ var speedOf = (p) => len$1(p.vx, p.vz);
676
676
  /** Whether the brush stops a body of height h whose feet are at y when it walks sideways into it. */
677
677
  var blocks = (b, y, h) => b.max[1] > y + .5 + SKIN && b.min[1] < y + h - SKIN;
678
678
  /** The closest point of the brush footprint to (x, z), as the offset from it to (x, z). */
679
- var gap = (b, x, z) => [x - clamp(x, b.min[0], b.max[0]), z - clamp(z, b.min[2], b.max[2])];
679
+ 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])];
680
680
  /**
681
681
  * Pushes the player out of every brush that blocks it and that the circle overlaps, deepest first
682
682
  * (up to 4 passes: two walls in a corner settle in two). The push is along the vector from the
@@ -710,7 +710,7 @@ var shove = (p, w, h, r) => {
710
710
  const d2 = dx * dx + dz * dz;
711
711
  if (d2 >= reach) continue;
712
712
  if (d2) {
713
- const d = sqrt(d2);
713
+ const d = sqrt$1(d2);
714
714
  if (r - d > best) {
715
715
  best = r - d;
716
716
  px = dx / d * best;
@@ -775,6 +775,18 @@ var span = (p, w, h) => {
775
775
  }
776
776
  return [floor, ceil];
777
777
  };
778
+ /**
779
+ * The highest floor under the point (x, z) at most as high as y: the ground of the relief, or the
780
+ * top of a brush the point is over. For a rover's wheel.
781
+ */
782
+ var floorAt = (w, x, z, y) => {
783
+ let floor = ground(w, x, z);
784
+ for (const i of near(w, x, z, 0)) {
785
+ const { min, max } = w.def.brushes[i];
786
+ if (x >= min[0] && x <= max[0] && z >= min[2] && z <= max[2] && max[1] <= y) floor = Math.max(floor, max[1]);
787
+ }
788
+ return floor;
789
+ };
778
790
  /** Whether a standing body fits where the player is: no ceiling or box within PLAYER_H. */
779
791
  var canStand = (p, w) => {
780
792
  const reach = (PLAYER_R - EPS) ** 2;
@@ -869,7 +881,7 @@ var over = (p, w) => {
869
881
  return near(w, p.x, p.z, 0).some((i) => {
870
882
  const b = w.def.brushes[i];
871
883
  const depth = sign > 0 ? c - b.min[a] : b.max[a] - c;
872
- return f32(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
884
+ return f32$1(b.max[1]) === p.edge && co >= b.min[o] && co <= b.max[o] && depth >= .2;
873
885
  });
874
886
  };
875
887
  /** The world's gravity: GRAVITY times the map's share (the moon's half gravity, the user, 2026-11-09). */
@@ -878,7 +890,7 @@ var gravity = (w) => 20 * (w.def.gravity ?? 1);
878
890
  var landingSoon = (p, w) => {
879
891
  if (p.vy >= 0) return false;
880
892
  const [floor] = span(p, w, PLAYER_H);
881
- const t = 6 * DT;
893
+ const t = 6 * DT$1;
882
894
  return p.y - floor <= -p.vy * t + .5 * gravity(w) * t * t;
883
895
  };
884
896
  /** Changes the mode, and starts counting the time in it. */
@@ -896,8 +908,8 @@ var floored = (p) => !!p.zap && p.stun > 24;
896
908
  */
897
909
  var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
898
910
  p.stun = ticks;
899
- p.vx = f32(dx * knock);
900
- p.vz = f32(dz * knock);
911
+ p.vx = f32$1(dx * knock);
912
+ p.vz = f32$1(dz * knock);
901
913
  p.dash = Math.min(p.dash, 50);
902
914
  p.coyote = 0;
903
915
  p.buffer = 0;
@@ -909,7 +921,7 @@ var stumble = (p, dx, dz, ticks = 48, knock = 6) => {
909
921
  };
910
922
  /** Scales the horizontal speed to at most max. */
911
923
  var cap = (p, max) => {
912
- const s = len(p.vx, p.vz);
924
+ const s = len$1(p.vx, p.vz);
913
925
  if (s > max) {
914
926
  p.vx *= max / s;
915
927
  p.vz *= max / s;
@@ -926,7 +938,7 @@ var unwalled = (p, w, c, h) => {
926
938
  for (const i of near(w, p.x, p.z, PLAYER_R + TOUCH)) {
927
939
  const b = w.def.brushes[i];
928
940
  const [dx, dz] = gap(b, p.x, p.z);
929
- const d = len(dx, dz);
941
+ const d = len$1(dx, dz);
930
942
  if (d > 0 && d <= .4 + TOUCH && blocks(b, p.y, h)) {
931
943
  const into = (-x * dx - z * dz) / d;
932
944
  if (into > 0) {
@@ -942,10 +954,10 @@ var unwalled = (p, w, c, h) => {
942
954
  * its length; friction with none.
943
955
  */
944
956
  var steer = (p, wish, top) => {
945
- const m = len(wish[0], wish[1]);
957
+ const m = len$1(wish[0], wish[1]);
946
958
  if (m < EPS) {
947
- const s = len(p.vx, p.vz);
948
- const k = s ? Math.max(0, s - 45 * DT) / s : 0;
959
+ const s = len$1(p.vx, p.vz);
960
+ const k = s ? Math.max(0, s - 45 * DT$1) / s : 0;
949
961
  p.vx *= k;
950
962
  p.vz *= k;
951
963
  return;
@@ -953,13 +965,13 @@ var steer = (p, wish, top) => {
953
965
  const [wx, wz] = [wish[0] / m, wish[1] / m];
954
966
  let par = p.vx * wx + p.vz * wz;
955
967
  let [px, pz] = [p.vx - par * wx, p.vz - par * wz];
956
- const across = len(px, pz);
968
+ const across = len$1(px, pz);
957
969
  if (across) {
958
- const k = Math.max(0, across - 45 * DT) / across;
970
+ const k = Math.max(0, across - 45 * DT$1) / across;
959
971
  [px, pz] = [px * k, pz * k];
960
972
  }
961
973
  top *= m;
962
- par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT) : Math.max(top, par - 12 * DT);
974
+ par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$1) : Math.max(top, par - 12 * DT$1);
963
975
  p.vx = px + par * wx;
964
976
  p.vz = pz + par * wz;
965
977
  };
@@ -971,10 +983,10 @@ var steer = (p, wish, top) => {
971
983
  */
972
984
  var fly$1 = (p, w, h, g, snap) => {
973
985
  const y0 = p.y;
974
- p.x += p.vx * DT;
975
- p.z += p.vz * DT;
986
+ p.x += p.vx * DT$1;
987
+ p.z += p.vz * DT$1;
976
988
  const [cx, cz] = push(p, w, h);
977
- const d = len(cx, cz);
989
+ const d = len$1(cx, cz);
978
990
  if (d) {
979
991
  const into = (p.vx * cx + p.vz * cz) / d;
980
992
  if (into < 0) {
@@ -984,8 +996,8 @@ var fly$1 = (p, w, h, g, snap) => {
984
996
  }
985
997
  bound(p, w);
986
998
  const [floor, ceil] = span(p, w, h);
987
- const vy = p.vy - g * gravity(w) * DT;
988
- p.y += (p.vy + vy) / 2 * DT;
999
+ const vy = p.vy - g * gravity(w) * DT$1;
1000
+ p.y += (p.vy + vy) / 2 * DT$1;
989
1001
  p.vy = vy;
990
1002
  if (p.y + h > ceil) {
991
1003
  p.y = ceil - h;
@@ -1033,16 +1045,16 @@ var hang = (p, w, c) => {
1033
1045
  p.coyote = 0;
1034
1046
  } else {
1035
1047
  const target = Math.max(p.edge - 2, span(p, w, PLAYER_H)[0]);
1036
- p.y += clamp(target - p.y, -8 * DT, 8 * DT);
1048
+ p.y += clamp$1(target - p.y, -8 * DT$1, 8 * DT$1);
1037
1049
  }
1038
1050
  };
1039
1051
  /** Climbing: up to the top, then in from the edge, then standing on it. */
1040
1052
  var climb = (p, w) => {
1041
1053
  const [nx, nz] = TOWARD[p.wall];
1042
- if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT);
1054
+ if (p.y < p.edge) p.y = Math.min(p.edge, p.y + 8 * DT$1);
1043
1055
  else {
1044
- p.x += nx * CLIMB_FWD_SPEED * DT;
1045
- p.z += nz * CLIMB_FWD_SPEED * DT;
1056
+ p.x += nx * CLIMB_FWD_SPEED * DT$1;
1057
+ p.z += nz * CLIMB_FWD_SPEED * DT$1;
1046
1058
  }
1047
1059
  if (p.y >= p.edge && over(p, w)) {
1048
1060
  enter(p, MODE.GROUND);
@@ -1064,7 +1076,7 @@ var run = (p, w, c) => {
1064
1076
  const [nx, nz] = TOWARD[p.wall];
1065
1077
  const into = p.vx * nx + p.vz * nz;
1066
1078
  const [tx, tz] = [p.vx - into * nx, p.vz - into * nz];
1067
- const s = len(tx, tz);
1079
+ const s = len$1(tx, tz);
1068
1080
  if (c.jump) {
1069
1081
  enter(p, MODE.AIR);
1070
1082
  p.vx = tx - nx * 5;
@@ -1080,10 +1092,10 @@ var run = (p, w, c) => {
1080
1092
  p.ev |= EV.WALLRUN_END;
1081
1093
  return;
1082
1094
  }
1083
- const k = Math.max(0, s - WALLRUN_DRAG * DT) / s;
1095
+ const k = Math.max(0, s - WALLRUN_DRAG * DT$1) / s;
1084
1096
  p.vx = tx * k;
1085
1097
  p.vz = tz * k;
1086
- const pull = Math.min(gap, 4 * DT);
1098
+ const pull = Math.min(gap, 4 * DT$1);
1087
1099
  p.x += nx * pull;
1088
1100
  p.z += nz * pull;
1089
1101
  }
@@ -1096,19 +1108,19 @@ var run = (p, w, c) => {
1096
1108
  */
1097
1109
  var startRun = (p, w, c) => {
1098
1110
  if (!c.fwd) return;
1099
- const s = len(p.vx, p.vz);
1111
+ const s = len$1(p.vx, p.vz);
1100
1112
  if (s < 4.5) return;
1101
1113
  for (let side = 1; side <= 4; side++) {
1102
1114
  const [nx, nz] = TOWARD[side];
1103
1115
  const into = p.vx * nx + p.vz * nz;
1104
1116
  const [tx, tz] = [p.vx - into * nx, p.vz - into * nz];
1105
1117
  if (side !== p.wall && into <= .75 * s && into >= -.2 * s && wallGap(p, w, side) !== void 0) {
1106
- const t = len(tx, tz);
1118
+ const t = len$1(tx, tz);
1107
1119
  const k = Math.max(t, WALL_TURN_KEEP * s) / t;
1108
1120
  enter(p, MODE.WALLRUN);
1109
1121
  p.wall = side;
1110
1122
  [p.vx, p.vz] = [tx * k, tz * k];
1111
- p.vy = clamp(p.vy, 2, 3);
1123
+ p.vy = clamp$1(p.vy, 2, 3);
1112
1124
  p.jumps = 1;
1113
1125
  p.dashes = 1;
1114
1126
  p.coyote = 0;
@@ -1121,7 +1133,7 @@ var startRun = (p, w, c) => {
1121
1133
  var grab = (p, l) => {
1122
1134
  enter(p, MODE.HANG);
1123
1135
  p.wall = l.side;
1124
- p.edge = f32(l.top);
1136
+ p.edge = f32$1(l.top);
1125
1137
  if (l.side <= SIDE.WEST) p.x = l.hang;
1126
1138
  else p.z = l.hang;
1127
1139
  p.vx = p.vy = p.vz = 0;
@@ -1164,7 +1176,7 @@ var free = (p, w, c) => {
1164
1176
  p.dashes = 1;
1165
1177
  p.wall = SIDE.NONE;
1166
1178
  if (c.keys & KEY.CROUCH) {
1167
- const slide = len(p.vx, p.vz) >= SLIDE_MIN_SPEED;
1179
+ const slide = len$1(p.vx, p.vz) >= SLIDE_MIN_SPEED;
1168
1180
  enter(p, slide ? MODE.SLIDE : MODE.CROUCH);
1169
1181
  p.ev |= slide ? EV.SLIDE_START : 0;
1170
1182
  } else enter(p, MODE.GROUND);
@@ -1189,7 +1201,7 @@ var onGround = (p, w, c, burst) => {
1189
1201
  leap(p, 7);
1190
1202
  return;
1191
1203
  }
1192
- const speed = len(p.vx, p.vz);
1204
+ const speed = len$1(p.vx, p.vz);
1193
1205
  if (p.mode === MODE.GROUND && low) {
1194
1206
  const slide = speed >= SLIDE_MIN_SPEED;
1195
1207
  enter(p, slide ? MODE.SLIDE : MODE.CROUCH);
@@ -1204,12 +1216,12 @@ var onGround = (p, w, c, burst) => {
1204
1216
  if (burst) return;
1205
1217
  if (c.stumble) {
1206
1218
  if (speed > 2.5) {
1207
- const k = Math.max(STUMBLE_SPEED, speed - 12 * DT) / speed;
1219
+ const k = Math.max(STUMBLE_SPEED, speed - 12 * DT$1) / speed;
1208
1220
  p.vx *= k;
1209
1221
  p.vz *= k;
1210
1222
  } else steer(p, unwalled(p, w, c, heightOf(p)), STUMBLE_SPEED);
1211
1223
  } else if (p.mode === MODE.SLIDE) {
1212
- const k = Math.max(0, speed - 4 * DT) / speed;
1224
+ const k = Math.max(0, speed - 4 * DT$1) / speed;
1213
1225
  p.vx *= k;
1214
1226
  p.vz *= k;
1215
1227
  } else if (p.mode === MODE.CROUCH) steer(p, unwalled(p, w, c, LOW_H), 3);
@@ -1229,9 +1241,9 @@ var air = (p, w, c, burst) => {
1229
1241
  }
1230
1242
  }
1231
1243
  if (burst || !c.wx && !c.wz) return;
1232
- const before = len(p.vx, p.vz);
1233
- p.vx += c.wx * 14 * DT;
1234
- p.vz += c.wz * 14 * DT;
1244
+ const before = len$1(p.vx, p.vz);
1245
+ p.vx += c.wx * 14 * DT$1;
1246
+ p.vz += c.wz * 14 * DT$1;
1235
1247
  cap(p, Math.max(before, 6));
1236
1248
  };
1237
1249
  /**
@@ -1244,7 +1256,7 @@ var move = (p, i, w, team = 0) => {
1244
1256
  p.pitch = Math.max(-MAX_PITCH, Math.min(MAX_PITCH, i.pitch));
1245
1257
  const f = (i.keys & KEY.FORWARD ? 1 : 0) - (i.keys & KEY.BACK ? 1 : 0);
1246
1258
  const s = (i.keys & KEY.RIGHT ? 1 : 0) - (i.keys & KEY.LEFT ? 1 : 0);
1247
- const n = floored(p) ? Infinity : len(f, s) || 1;
1259
+ const n = floored(p) ? Infinity : len$1(f, s) || 1;
1248
1260
  const [fx, fz] = forward(p.yaw);
1249
1261
  const pressed = (bit) => (i.keys & bit) !== 0 && (p.held & bit) === 0;
1250
1262
  const stumbling = p.stun > 0;
@@ -1282,13 +1294,13 @@ var move = (p, i, w, team = 0) => {
1282
1294
  if (p.mode === MODE.AIR && before === MODE.AIR) p.coyote = Math.max(0, p.coyote - 1);
1283
1295
  p.held = i.keys & (KEY.JUMP | KEY.DASH | KEY.USE);
1284
1296
  p.ground = onFloor(p.mode);
1285
- p.x = f32(p.x);
1286
- p.y = f32(p.y);
1287
- p.z = f32(p.z);
1288
- p.vx = f32(p.vx);
1289
- p.vy = f32(p.vy);
1290
- p.vz = f32(p.vz);
1291
- p.edge = f32(p.edge);
1297
+ p.x = f32$1(p.x);
1298
+ p.y = f32$1(p.y);
1299
+ p.z = f32$1(p.z);
1300
+ p.vx = f32$1(p.vx);
1301
+ p.vy = f32$1(p.vy);
1302
+ p.vz = f32$1(p.vz);
1303
+ p.edge = f32$1(p.edge);
1292
1304
  };
1293
1305
  // src/shared/blade.ts
1294
1306
  /** Where on the body the blade is, as a share of its height: the chest, which a brush must not cover. */
@@ -3228,7 +3240,7 @@ var WRECK = [BOWLS[0][0], 140];
3228
3240
  * is 20 m high on it and, past it where nobody goes, climbs to a ragged crest of 60 to 95 m and
3229
3241
  * falls to the plain at 1.65 of the bound.
3230
3242
  */
3231
- var at = (x, z) => {
3243
+ var at$1 = (x, z) => {
3232
3244
  z = Math.abs(z - 140);
3233
3245
  const k = far((x - 80) / 300, z / 360);
3234
3246
  const t = Math.max((k - .78) / .22, 0);
@@ -3251,7 +3263,7 @@ var at = (x, z) => {
3251
3263
  };
3252
3264
  /** The ghost under a drawn rock or mast: a box of half side s from under the ground to h above it. */
3253
3265
  var lump = (x, z, s, h) => ({
3254
- ...box(x - s, at(x, z) - 6, z - s, x + s, at(x, z) + h, z + s, STONE),
3266
+ ...box(x - s, at$1(x, z) - 6, z - s, x + s, at$1(x, z) + h, z + s, STONE),
3255
3267
  ghost: true
3256
3268
  });
3257
3269
  [...FIELD, ...FIELD.map(([x, z, r]) => [
@@ -3518,7 +3530,7 @@ var MAPS = {
3518
3530
  360
3519
3531
  ],
3520
3532
  cell: 4,
3521
- at
3533
+ at: at$1
3522
3534
  },
3523
3535
  sun: {
3524
3536
  dir: [
@@ -3542,6 +3554,32 @@ var MAPS = {
3542
3554
  .035
3543
3555
  ]],
3544
3556
  gravity: .5,
3557
+ rovers: [
3558
+ [
3559
+ 100,
3560
+ 0,
3561
+ 178,
3562
+ 0
3563
+ ],
3564
+ [
3565
+ 30,
3566
+ 0,
3567
+ 255,
3568
+ 0
3569
+ ],
3570
+ [
3571
+ 100,
3572
+ 0,
3573
+ 102,
3574
+ Math.PI
3575
+ ],
3576
+ [
3577
+ 30,
3578
+ 0,
3579
+ 25,
3580
+ Math.PI
3581
+ ]
3582
+ ],
3545
3583
  scenery: "moon",
3546
3584
  helmets: true
3547
3585
  }
@@ -3599,7 +3637,7 @@ var wave = (p, team = 0) => ({
3599
3637
  arc: p.cut
3600
3638
  });
3601
3639
  /** Metres the flight `b` goes in a tick. */
3602
- var stepOf = (b) => b.arc ? ARC_STEP : PLASMA_STEP;
3640
+ var stepOf = (b) => b.arc ? ARC_STEP : b.power === 6 ? 2 : PLASMA_STEP;
3603
3641
  /**
3604
3642
  * Distance at which the ray from `o` along the unit `d` enters the upright cylinder of radius `r`
3605
3643
  * on `c`'s feet, `h` tall; Infinity on a miss.
@@ -3651,6 +3689,23 @@ var fly = (w, b, m, foes) => {
3651
3689
  ];
3652
3690
  return hit;
3653
3691
  };
3692
+ /** A rover's floats, in wire order. */
3693
+ var ROVER_F = [...[
3694
+ "x",
3695
+ "y",
3696
+ "z",
3697
+ "vx",
3698
+ "vy",
3699
+ "vz",
3700
+ "yaw"
3701
+ ], ...[
3702
+ "pitch",
3703
+ "roll",
3704
+ "wy",
3705
+ "wp",
3706
+ "wr",
3707
+ "steer"
3708
+ ]];
3654
3709
  /** The no-gun value of the ammo's 7 bits. */
3655
3710
  var NO_GUN = 127;
3656
3711
  /** A flag's resting place on the wire: 1/16 m in an i16, so ±2 km. A ball's: 1/32 m, ±1 km. */
@@ -3683,13 +3738,15 @@ var decodeInput = (buf) => {
3683
3738
  /** Bytes of a flag on the wire, by its state. */
3684
3739
  var flagBytes = (state) => state === FLAG.CARRIED ? 2 : state === FLAG.DROPPED ? 8 : 1;
3685
3740
  var encodeSnapshot = (s) => {
3686
- const end = 4 + 61 * s.players.length;
3741
+ const rovers = (s.rovers ?? []).slice(0, 7);
3742
+ const mid = 4 + 61 * s.players.length;
3743
+ const end = mid + 54 * rovers.length;
3687
3744
  const balls = s.balls ?? [];
3688
3745
  const tail = end + 10 + s.flags.reduce((n, f) => n + flagBytes(f.state), 0);
3689
3746
  const v = new DataView(new ArrayBuffer(tail + (balls.length && 1 + 11 * balls.length)));
3690
3747
  v.setUint8(0, 2);
3691
3748
  v.setUint16(1, s.tick & 65535);
3692
- v.setUint8(3, s.players.length);
3749
+ v.setUint8(3, s.players.length | rovers.length << 5);
3693
3750
  s.players.forEach((p, i) => {
3694
3751
  const o = 4 + i * 61;
3695
3752
  v.setUint8(o, p.id);
@@ -3721,7 +3778,7 @@ var encodeSnapshot = (s) => {
3721
3778
  v.setUint8(o + 50, p.pushes ?? 0);
3722
3779
  v.setUint8(o + 51, p.away ?? 0);
3723
3780
  v.setUint8(o + 52, (p.rail ?? -1) + 1);
3724
- v.setUint8(o + 53, +!!p.railed | +!!p.inRail << 1 | +!!p.zapping << 2 | +!!p.rifled << 3 | +!!p.inRifle << 4 | +!!p.hot << 5);
3781
+ v.setUint8(o + 53, +!!p.railed | +!!p.inRail << 1 | +!!p.zapping << 2 | +!!p.rifled << 3 | +!!p.inRifle << 4 | +!!p.hot << 5 | (p.held & KEY.USE ? 64 : 0));
3725
3782
  v.setUint8(o + 54, p.slow ?? 0);
3726
3783
  v.setUint8(o + 55, p.mag ?? 0);
3727
3784
  v.setUint8(o + 56, p.cap ?? 0);
@@ -3730,6 +3787,12 @@ var encodeSnapshot = (s) => {
3730
3787
  v.setUint8(o + 59, p.clip ?? 0);
3731
3788
  v.setUint8(o + 60, p.heat ?? 0);
3732
3789
  });
3790
+ rovers.forEach((r, i) => {
3791
+ const o = mid + i * 54;
3792
+ ROVER_F.forEach((k, j) => v.setFloat32(o + 4 * j, r[k]));
3793
+ v.setUint8(o + 52, r.driver);
3794
+ v.setUint8(o + 53, r.rider);
3795
+ });
3733
3796
  v.setUint8(end, s.score[0]);
3734
3797
  v.setUint8(end + 1, s.score[1]);
3735
3798
  v.setUint16(end + 2, s.clock & 32767 | (s.over ? 32768 : 0));
@@ -3805,6 +3868,399 @@ var beam = (w, p, foes = [], range = 30, [dy, dp] = [0, 0]) => {
3805
3868
  hit
3806
3869
  };
3807
3870
  };
3871
+ // src/shared/rover.ts
3872
+ /** The rover's sizes and its handling (docs/MOON.md). Lengths in metres, per wheel rates for a body of mass 1. */
3873
+ var ROVER = {
3874
+ /** Half the wheelbase, half the track, the wheel's radius. */
3875
+ A: 1.25,
3876
+ B: 1,
3877
+ WR: .5,
3878
+ /** The spring's length at rest from the body's centre down to the hub, and its travel. */
3879
+ L0: .6,
3880
+ CMAX: .5,
3881
+ /** Stiffness (1/s²) and damping (1/s) of a spring. */
3882
+ K: 30,
3883
+ D: 2,
3884
+ /** Squared radii of gyration in pitch and roll, and the height of the centre the tyre forces lever on. */
3885
+ KP2: 1.2,
3886
+ KR2: .7,
3887
+ HC: .7,
3888
+ /** Engine and brake (m/s²), the top speed forward and in reverse, rolling drag and the handbrake's. */
3889
+ ENGINE: 12,
3890
+ VMAX: 23.2,
3891
+ VREV: 8,
3892
+ BRAKE: 14,
3893
+ ROLL: .6,
3894
+ HB: 6,
3895
+ /** Grip sideways and in traction, as shares of the load; under the handbrake, the share left sideways and how much faster the nose comes round. */
3896
+ MU: 1.1,
3897
+ MUL: 1.2,
3898
+ HBG: .35,
3899
+ HBY: 1.5,
3900
+ /** Steering toward the driver's look: gain, the speed that halves it, the lock, its rate, and the yaw rate's cap and response. */
3901
+ SK: 2.5,
3902
+ SV: 10,
3903
+ SMAX: .55,
3904
+ SRATE: 3.5,
3905
+ YMAX: 2.4,
3906
+ YRESP: 10,
3907
+ /** In the air: the pull back to level, its damping, the rates' decay, and the tilt nothing passes. */
3908
+ AK: 5,
3909
+ AC: 3,
3910
+ AD: .5,
3911
+ TILT: .9,
3912
+ /**
3913
+ * The body against the brushes: circles of radius RB at BODY along the nose, BODY_H tall. A wheel
3914
+ * takes for its floor what is at most WHEEL_STEP above its hub with the spring out; the body
3915
+ * passes over a brush no more than STEP_H above the wheels' floor, like a player.
3916
+ */
3917
+ RB: 1.05,
3918
+ BODY: [
3919
+ 1.15,
3920
+ 0,
3921
+ -1.15
3922
+ ],
3923
+ BODY_H: 1.5,
3924
+ WHEEL_STEP: .6,
3925
+ /** A player this close to a rover's centre gets in; a rover this fast hurts an enemy, and this fast puts him down. */
3926
+ ENTER_R: 3,
3927
+ SPLAT_MIN: 6,
3928
+ SPLAT_KILL: 12,
3929
+ /** The two lasers, one each side: ticks between two salvos, the bolts' reach, and where the beams cross ahead of the driver's look. */
3930
+ GUN_COOL: 8,
3931
+ GUN_RANGE: 90,
3932
+ GUN_AIM: 50
3933
+ };
3934
+ /** The lasers' muzzles: right of the centre, above it, ahead of it. */
3935
+ var GUNS = [[
3936
+ -1.05,
3937
+ .18,
3938
+ .6
3939
+ ], [
3940
+ 1.05,
3941
+ .18,
3942
+ .6
3943
+ ]];
3944
+ /** The seats, driver then rider: right of the centre, above it (the feet), ahead of it. */
3945
+ var SEATS$1 = [[
3946
+ -.45,
3947
+ -.35,
3948
+ .1
3949
+ ], [
3950
+ .45,
3951
+ -.35,
3952
+ .1
3953
+ ]];
3954
+ /** The wheels, front left, front right, rear left, rear right: ahead of the centre and to its right. */
3955
+ var AI = [
3956
+ 1,
3957
+ 1,
3958
+ -1,
3959
+ -1
3960
+ ].map((s) => s * ROVER.A);
3961
+ var BI = [
3962
+ -1,
3963
+ 1,
3964
+ -1,
3965
+ 1
3966
+ ].map((s) => s * ROVER.B);
3967
+ /** From the centre down to the bottom of a wheel on a spring at rest. */
3968
+ var DROP = ROVER.L0 + ROVER.WR;
3969
+ /** Where who gets out stands, from the centre to the side: clear of the body. And the drop he does not get out over. */
3970
+ var OUT = ROVER.RB + PLAYER_R + .15;
3971
+ var LEDGE = 1;
3972
+ /** The numbers of the state: float32 after every step, and on the wire. */
3973
+ var FLOATS = "x y z vx vy vz yaw pitch roll wy wp wr steer".split(" ");
3974
+ var DT = 1 / 60;
3975
+ var f32 = Math.fround;
3976
+ var { sin, cos, min, max, abs, sqrt } = Math;
3977
+ var clamp = (v, lo, hi) => min(max(v, lo), hi);
3978
+ /**
3979
+ * A point of the body, `a` m ahead of the centre, `b` m to its right and `u` m above: it leans with
3980
+ * the pitch (nose up) and the roll (right side down).
3981
+ */
3982
+ var at = (r, a, b, u = 0) => {
3983
+ const [fx, fz] = forward(r.yaw);
3984
+ const [ca, cb] = [a * cos(r.pitch), b * cos(r.roll)];
3985
+ return [
3986
+ r.x + fx * ca - fz * cb,
3987
+ r.y + u + a * sin(r.pitch) - b * sin(r.roll),
3988
+ r.z + fz * ca + fx * cb
3989
+ ];
3990
+ };
3991
+ /**
3992
+ * Each wheel's corner of the body, and how far the floor under it squeezes the spring: below 0 the
3993
+ * wheel hangs. Its floor is at most WHEEL_STEP above the hub of the spring at rest: what is higher
3994
+ * is over it, or a wall for the body.
3995
+ */
3996
+ var corners = (r, w) => AI.map((a, k) => {
3997
+ const [x, y, z] = at(r, a, BI[k]);
3998
+ return [
3999
+ x,
4000
+ y,
4001
+ z,
4002
+ DROP + floorAt(w, x, z, y - ROVER.L0 + ROVER.WHEEL_STEP) - y
4003
+ ];
4004
+ });
4005
+ /**
4006
+ * The body as the brushes and a run-over meet it: the centres of three circles of radius RB along
4007
+ * the nose, front first, each at the height of its bottom, BODY_H under its top.
4008
+ */
4009
+ var footprint = (r) => ROVER.BODY.map((a) => at(r, a, 0, -DROP));
4010
+ /** The map's rovers at rest on their spawns, nobody aboard. */
4011
+ var park = (w) => (w.def.rovers ?? []).map(([x, y, z, yaw]) => ({
4012
+ x: f32(x),
4013
+ y: f32(y + DROP),
4014
+ z: f32(z),
4015
+ vx: 0,
4016
+ vy: 0,
4017
+ vz: 0,
4018
+ yaw: f32(norm(yaw)),
4019
+ pitch: 0,
4020
+ roll: 0,
4021
+ wy: 0,
4022
+ wp: 0,
4023
+ wr: 0,
4024
+ steer: 0,
4025
+ driver: 255,
4026
+ rider: 255
4027
+ }));
4028
+ /**
4029
+ * One step of 1 / TICK_HZ s, in place. `i` is the driver's input as the wire rounds it (FORWARD and
4030
+ * BACK the throttle, JUMP the handbrake, its yaw where the nose is steered to), or undefined with
4031
+ * nobody at the wheel: the brake is on. Reads only the rover, the input and the world. Returns
4032
+ * whether it fell under the world's kill floor: the caller parks it again.
4033
+ *
4034
+ * The body is a point with a pitch and a roll on four springs. Each wheel reads the floor under
4035
+ * its hub; the four heights give the ground's slope, the springs push along its normal, and the
4036
+ * tyres work on the speed along the nose and across it. Yaw is steered, not simulated: the nose
4037
+ * turns toward the look as fast as the speed allows, and the tyres' grip decides how much of the
4038
+ * speed follows it. The rest drifts.
4039
+ */
4040
+ var drive = (r, i, w) => {
4041
+ const { A, B, CMAX, K, D, KP2, KR2, HC, MU, MUL, TILT } = ROVER;
4042
+ const g = gravity(w);
4043
+ const keys = i ? i.keys : 0;
4044
+ const thr = (keys & KEY.FORWARD ? 1 : 0) - (keys & KEY.BACK ? 1 : 0);
4045
+ const hb = keys & KEY.JUMP;
4046
+ const [fx, fz] = forward(r.yaw);
4047
+ const [cp, cr] = [cos(r.pitch), cos(r.roll)];
4048
+ const c = corners(r, w);
4049
+ const [g0, g1, g2, g3] = c.map(([, y, , k]) => k + y - DROP);
4050
+ const flat = c.some((k) => k[3] < -CMAX);
4051
+ const sf = flat ? 0 : (g0 + g1 - g2 - g3) / (4 * A * cp);
4052
+ const sr = flat ? 0 : (g1 + g3 - g0 - g2) / (4 * B * cr);
4053
+ const ny = 1 / sqrt(sf * sf + sr * sr + 1);
4054
+ const nx = -(sf * fx - sr * fz) * ny;
4055
+ const nz = -(sf * fz + sr * fx) * ny;
4056
+ const along = () => r.vx * nx + r.vy * ny + r.vz * nz;
4057
+ const pen = max(0, ...c.map((k) => k[3] - CMAX));
4058
+ if (pen) {
4059
+ r.y += pen;
4060
+ const v = min(0, along());
4061
+ r.vx -= v * nx;
4062
+ r.vy -= v * ny;
4063
+ r.vz -= v * nz;
4064
+ }
4065
+ const vn = along();
4066
+ let [s, tp, tr] = [
4067
+ 0,
4068
+ 0,
4069
+ 0
4070
+ ];
4071
+ c.forEach(([, , , k], n) => {
4072
+ if (k > pen) {
4073
+ const f = max(0, K * (k - pen) - D * (vn + (AI[n] * cp * r.wp - BI[n] * cr * r.wr) * ny));
4074
+ s += f;
4075
+ tp += f * AI[n];
4076
+ tr += f * BI[n];
4077
+ }
4078
+ });
4079
+ r.vx += s * nx * DT;
4080
+ r.vy += (s * ny - g) * DT;
4081
+ r.vz += s * nz * DT;
4082
+ r.wp += tp / KP2 * DT;
4083
+ r.wr -= tr / KR2 * DT;
4084
+ const load = min(s / g, 2);
4085
+ if (load > 0) {
4086
+ const vl = r.vx * fx + r.vz * fz;
4087
+ const vs = r.vz * fx - r.vx * fz;
4088
+ const err = i ? norm(i.yaw - r.yaw + Math.PI) - Math.PI : 0;
4089
+ const lock = clamp(ROVER.SK * err / (1 + abs(vl) / ROVER.SV), -ROVER.SMAX, ROVER.SMAX);
4090
+ const turn = ROVER.SRATE * DT;
4091
+ r.steer += clamp((vl + thr < 0 ? -lock : lock) - r.steer, -turn, turn);
4092
+ const spin = clamp(vl * r.steer / (2 * A), -ROVER.YMAX, ROVER.YMAX) * (hb ? ROVER.HBY : 1);
4093
+ r.wy += (spin - r.wy) * ROVER.YRESP * DT * min(1, load);
4094
+ const grip = g * load * DT;
4095
+ let dl = clamp((thr * vl < 0 ? thr * ROVER.BRAKE : thr * ROVER.ENGINE * max(0, 1 - abs(vl) / (thr > 0 ? ROVER.VMAX : ROVER.VREV))) * DT, -MUL * grip, MUL * grip);
4096
+ const drag = (ROVER.ROLL + (hb || !i ? ROVER.HB : 0)) * load * DT;
4097
+ dl -= clamp(vl + dl, -drag, drag);
4098
+ const side = MU * grip * (hb ? ROVER.HBG : 1);
4099
+ const ds = -clamp(vs, -side, side);
4100
+ r.vx += dl * fx - ds * fz;
4101
+ r.vz += dl * fz + ds * fx;
4102
+ r.wp += dl * HC / KP2;
4103
+ r.wr -= ds * HC / KR2;
4104
+ } else {
4105
+ r.wp -= (ROVER.AK * r.pitch + ROVER.AC * r.wp) * DT;
4106
+ r.wr -= (ROVER.AK * r.roll + ROVER.AC * r.wr) * DT;
4107
+ }
4108
+ r.wp *= 1 - ROVER.AD * DT;
4109
+ r.wr *= 1 - ROVER.AD * DT;
4110
+ r.x += r.vx * DT;
4111
+ r.y += r.vy * DT;
4112
+ r.z += r.vz * DT;
4113
+ r.yaw = norm(r.yaw + r.wy * DT);
4114
+ r.pitch = clamp(r.pitch + r.wp * DT, -TILT, TILT);
4115
+ r.roll = clamp(r.roll + r.wr * DT, -TILT, TILT);
4116
+ if (abs(r.pitch) === TILT && r.pitch * r.wp > 0) r.wp = 0;
4117
+ if (abs(r.roll) === TILT && r.roll * r.wr > 0) r.wr = 0;
4118
+ for (const a of ROVER.BODY) {
4119
+ const [x, y, z] = at(r, a, 0, -DROP);
4120
+ const [px, pz] = shove({
4121
+ x,
4122
+ y: max(y, g0, g1, g2, g3),
4123
+ z
4124
+ }, w, ROVER.BODY_H, ROVER.RB);
4125
+ const d = px * px + pz * pz;
4126
+ if (d) {
4127
+ r.x += px;
4128
+ r.z += pz;
4129
+ const v = min(0, r.vx * px + r.vz * pz) / d;
4130
+ r.vx -= v * px;
4131
+ r.vz -= v * pz;
4132
+ }
4133
+ }
4134
+ bound(r, w);
4135
+ for (const k of FLOATS) r[k] = f32(r[k]);
4136
+ return r.y < w.def.floor;
4137
+ };
4138
+ /**
4139
+ * Puts the body of a player on seat `s` (0 the driver's, 1 the rider's) of the rover, with its
4140
+ * speed. The seat leans with the body: on a slope he is not left in the air.
4141
+ */
4142
+ var seat = (p, r, s) => {
4143
+ const [side, up, ahead] = SEATS$1[s];
4144
+ [p.x, p.y, p.z] = at(r, ahead, side, up).map(f32);
4145
+ p.vx = r.vx;
4146
+ p.vy = r.vy;
4147
+ p.vz = r.vz;
4148
+ };
4149
+ /**
4150
+ * The player takes seat `s`: he rides (MODE.RIDE) from the next step on. What a seated body is not
4151
+ * doing ends: a dash's burst (as in stumble()), a hang or a climb, a jump press kept for a landing.
4152
+ */
4153
+ var board = (p, r, s) => {
4154
+ r[s ? "rider" : "driver"] = p.id;
4155
+ p.mode = MODE.RIDE;
4156
+ p.t = 0;
4157
+ p.edge = 0;
4158
+ p.ground = false;
4159
+ p.dash = min(p.dash, 50);
4160
+ p.coyote = 0;
4161
+ p.buffer = 0;
4162
+ seat(p, r, s);
4163
+ };
4164
+ /**
4165
+ * The player gets out of seat `s`: in the air, with the rover's speed. Beside it on the side of his
4166
+ * seat when a standing body fits there on a floor, else on the other side, else on top of it: over
4167
+ * a drop, between two walls, in flight. Never in a brush or under the ground. Reads only the two
4168
+ * and the world.
4169
+ */
4170
+ var leave = (p, r, s, w) => {
4171
+ r[s ? "rider" : "driver"] = 255;
4172
+ p.mode = MODE.AIR;
4173
+ p.t = 0;
4174
+ p.coyote = 0;
4175
+ [p.vx, p.vy, p.vz] = [
4176
+ r.vx,
4177
+ r.vy,
4178
+ r.vz
4179
+ ];
4180
+ const side = s ? OUT : -OUT;
4181
+ for (const [b, u] of [
4182
+ [side, -DROP],
4183
+ [-side, -DROP],
4184
+ [0, ROVER.BODY_H - DROP]
4185
+ ]) {
4186
+ const [x, y, z] = at(r, SEATS$1[s][2], b, u);
4187
+ Object.assign(p, {
4188
+ x,
4189
+ y,
4190
+ z
4191
+ });
4192
+ bound(p, w);
4193
+ const floor = floorAt(w, p.x, p.z, r.y);
4194
+ p.y = max(y, floor);
4195
+ const [px, pz] = shove(p, w, PLAYER_H, PLAYER_R);
4196
+ if (!b || floor > y - LEDGE && !px && !pz) break;
4197
+ }
4198
+ [p.x, p.y, p.z, p.vx, p.vz] = [
4199
+ p.x,
4200
+ p.y,
4201
+ p.z,
4202
+ p.vx,
4203
+ p.vz
4204
+ ].map(f32);
4205
+ };
4206
+ /**
4207
+ * The driver's whole step, on the host and in the predictor alike: the rover is driven by his
4208
+ * input, he follows on his seat, and a press of USE gets him out. Returns drive()'s answer. A step
4209
+ * that takes him off his seat (move() puts a body under the kill floor back at a spawn) frees it.
4210
+ */
4211
+ var ride = (p, r, i, w, team) => {
4212
+ const out = (i.keys & KEY.USE) !== 0 && (p.held & KEY.USE) === 0;
4213
+ const fell = drive(r, i, w);
4214
+ step(p, i, w, team, false);
4215
+ if (p.mode !== MODE.RIDE) r.driver = 255;
4216
+ else {
4217
+ seat(p, r, 0);
4218
+ if (out) leave(p, r, 0, w);
4219
+ }
4220
+ return fell;
4221
+ };
4222
+ /**
4223
+ * The two bolts of one salvo of the rover's lasers, left then right: each from its muzzle toward
4224
+ * the point GUN_AIM metres along the driver's look (the yaw and pitch of his input) from the rover's
4225
+ * centre, so the beams cross there, chest high on level ground with a level look. `id` names the first, `id + 1` the second.
4226
+ */
4227
+ var bolts = (r, by, team, yaw, pitch, id) => {
4228
+ const [fx, fz] = forward(r.yaw);
4229
+ const [sy, cy, sp, cp] = [
4230
+ Math.sin(yaw),
4231
+ Math.cos(yaw),
4232
+ Math.sin(pitch),
4233
+ Math.cos(pitch)
4234
+ ];
4235
+ const aim = [
4236
+ r.x - sy * cp * ROVER.GUN_AIM,
4237
+ r.y + sp * ROVER.GUN_AIM,
4238
+ r.z - cy * cp * ROVER.GUN_AIM
4239
+ ];
4240
+ return GUNS.map(([side, up, ahead], k) => {
4241
+ const o = [
4242
+ r.x + fx * ahead - fz * side,
4243
+ r.y + up,
4244
+ r.z + fz * ahead + fx * side
4245
+ ];
4246
+ const d = aim.map((v, a) => v - o[a]);
4247
+ const l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
4248
+ return {
4249
+ id: id + k & 255,
4250
+ by,
4251
+ team,
4252
+ x: o[0],
4253
+ y: o[1],
4254
+ z: o[2],
4255
+ dx: d[0] / l,
4256
+ dy: d[1] / l,
4257
+ dz: d[2] / l,
4258
+ left: ROVER.GUN_RANGE,
4259
+ burst: false,
4260
+ power: 6
4261
+ };
4262
+ });
4263
+ };
3808
4264
  // src/shared/tackle.ts
3809
4265
  /** Whether the player's body is a weapon: in a slide, or in the burst of a dash. */
3810
4266
  var tackling = (p) => p.mode === MODE.SLIDE || p.dash > 50;
@@ -3818,6 +4274,10 @@ var reaches = (a, b) => Math.hypot(a.x - b.x, a.z - b.z) < 1.1 && a.y < b.y + he
3818
4274
  var MAX_CATCH_UP = 20;
3819
4275
  /** A new player does not spawn within this many metres of another one. */
3820
4276
  var SPAWN_CLEAR = 2;
4277
+ /** Ticks before a rover can run the same player over again. */
4278
+ var SPLAT_COOLDOWN = 30;
4279
+ /** The two seats of a rover, the driver's first. */
4280
+ var SEATS = ["driver", "rider"];
3821
4281
  /** First n characters (code points) of s, trimmed. */
3822
4282
  var cut = (s, n) => Array.from(s).slice(0, n).join("").trim();
3823
4283
  var cleanName = (raw) => cut((typeof raw === "string" ? raw : "").replace(/\s+/g, " ").replace(/\p{Cc}/gu, "").trim(), 16);
@@ -3827,6 +4287,7 @@ var unique = (name, taken) => {
3827
4287
  for (let n = 2; taken.includes(out); n++) out = `${cut(name, 15 - `${n}`.length)} ${n}`;
3828
4288
  return out;
3829
4289
  };
4290
+ var len = (x, z) => Math.sqrt(x * x + z * z);
3830
4291
  var setEvery = (cb, ms) => {
3831
4292
  const id = setInterval(cb, ms);
3832
4293
  return () => clearInterval(id);
@@ -3850,6 +4311,9 @@ var setEvery = (cb, ms) => {
3850
4311
  * - The host is the player in the room the longest; when he leaves, the next oldest. Only his
3851
4312
  * { t: 'map', map } counts: the map (a MAPS key) is played from the next match on, or from the
3852
4313
  * next join once the room is empty. The roster tells everyone the host and the map picked.
4314
+ * - The map's rovers (rover.ts) are in every snapshot. A press of USE near one seats a player; a
4315
+ * driven rover is stepped by its driver's inputs alone (ride()), a driverless one by the tick.
4316
+ * seats() keeps the seats and the players' MODE.RIDE in step.
3853
4317
  */
3854
4318
  /** A player out of any saber lock. */
3855
4319
  var FREE = {
@@ -3866,6 +4330,12 @@ var pick = ({ x, y, z, yaw }) => ({
3866
4330
  z,
3867
4331
  yaw
3868
4332
  });
4333
+ /** Where a player stands. */
4334
+ var spot = ({ x, y, z }) => ({
4335
+ x,
4336
+ y,
4337
+ z
4338
+ });
3869
4339
  var Room = class {
3870
4340
  /** Every connected peer; null until it joins. */
3871
4341
  peers = /* @__PURE__ */ new Map();
@@ -3882,6 +4352,8 @@ var Room = class {
3882
4352
  gone;
3883
4353
  /** The plasma balls in flight, and the ones that burst since the last snapshot, which sends them once more. */
3884
4354
  balls = [];
4355
+ /** The map's rovers, in the order of WorldDef.rovers. */
4356
+ rovers;
3885
4357
  /** The key of the map being played, which the roster tells the clients. */
3886
4358
  mapName;
3887
4359
  /** The map the host picked for the next match, when it is another one. */
@@ -3898,6 +4370,7 @@ var Room = class {
3898
4370
  this.world = build(def ?? mapOf(this.mapName));
3899
4371
  this.ctf = new Ctf(this.world, this.rules);
3900
4372
  this.gone = this.spots();
4373
+ this.rovers = park(this.world);
3901
4374
  }
3902
4375
  /** The health, ammo and cell packs of the map, all there (0 ticks before each is back). */
3903
4376
  spots() {
@@ -3920,6 +4393,7 @@ var Room = class {
3920
4393
  this.world = build(mapOf(this.mapName));
3921
4394
  this.ctf = new Ctf(this.world, this.rules);
3922
4395
  this.gone = this.spots();
4396
+ this.rovers = park(this.world);
3923
4397
  this.history = [];
3924
4398
  this.balls = [];
3925
4399
  for (const p of this.players()) this.ctf.join(p.info.id, p.info.team, p.state);
@@ -3949,17 +4423,37 @@ var Room = class {
3949
4423
  if (input && p.bank > 0) {
3950
4424
  p.bank--;
3951
4425
  const slow = p.state.slow ?? 0;
3952
- const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over);
3953
- this.ctf.moved(p.state);
3954
- this.tackle(p, input.view);
3955
- if (struck === STRIKE.SHOT) this.shoot(p, input.view);
3956
- else if (struck === STRIKE.CUT) this.cut(p, input.view);
3957
- else if (struck === STRIKE.RAIL) this.rail(p, input.view);
3958
- else if (struck === STRIKE.LASER) this.shoot(p, input.view);
4426
+ const use = (input.keys & KEY.USE) !== 0 && (p.state.held & KEY.USE) === 0;
4427
+ const [r, s] = this.seatOf(p);
4428
+ if (r && !s) {
4429
+ const fell = ride(p.state, r, input, this.world, p.info.team);
4430
+ this.ctf.moved(p.state);
4431
+ if (fell) this.sink(r);
4432
+ else {
4433
+ this.carry(r);
4434
+ this.splat(p, r, input.view);
4435
+ this.lase(p, r, input);
4436
+ }
4437
+ } else {
4438
+ const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over);
4439
+ this.ctf.moved(p.state);
4440
+ this.tackle(p, input.view);
4441
+ const here = spot(p.state);
4442
+ const seen = r && struck ? this.past(input.view).find((q) => q.id === p.info.id) : void 0;
4443
+ Object.assign(p.state, seen && spot(seen));
4444
+ if (struck === STRIKE.SHOT) this.shoot(p, input.view);
4445
+ else if (struck === STRIKE.CUT) this.cut(p, input.view);
4446
+ else if (struck === STRIKE.RAIL) this.rail(p, input.view);
4447
+ else if (struck === STRIKE.LASER) this.shoot(p, input.view);
4448
+ Object.assign(p.state, here);
4449
+ if (use && r && p.state.mode === MODE.RIDE) leave(p.state, r, 1, this.world);
4450
+ else if (use) this.enter(p);
4451
+ }
3959
4452
  p.burn = slow ? (p.burn ?? 0) + 1 : 0;
3960
4453
  if (slow && !(p.burn % 60)) this.fry(p);
3961
4454
  this.duel(p);
3962
4455
  p.ack = input.seq;
4456
+ this.seats();
3963
4457
  }
3964
4458
  }
3965
4459
  /** A peer left: its player goes, the roster goes out again. */
@@ -3971,8 +4465,10 @@ var Room = class {
3971
4465
  if (!this.size) {
3972
4466
  this.ctf.reset();
3973
4467
  this.gone.fill(0);
4468
+ this.rovers = park(this.world);
3974
4469
  this.load();
3975
4470
  }
4471
+ this.seats();
3976
4472
  this.roster();
3977
4473
  }
3978
4474
  }
@@ -3995,7 +4491,7 @@ var Room = class {
3995
4491
  for (const p of players) p.bank = Math.min(10, p.bank + 1);
3996
4492
  for (const b of this.balls) if (!b.burst && b.left > 0) this.fly(b, stepOf(b));
3997
4493
  this.heal(players);
3998
- const turn = this.ctf.tick(players.filter((p) => !p.state.down).map((p) => ({
4494
+ const turn = this.ctf.tick(players.filter((p) => !p.state.down && !this.rovers.some((r) => r.driver === p.info.id)).map((p) => ({
3999
4495
  id: p.info.id,
4000
4496
  team: p.info.team,
4001
4497
  state: p.state
@@ -4005,6 +4501,11 @@ var Room = class {
4005
4501
  this.load();
4006
4502
  this.restart(players);
4007
4503
  }
4504
+ this.seats();
4505
+ for (const r of this.rovers) if (r.driver !== 255) this.carry(r);
4506
+ else if (drive(r, void 0, this.world)) this.sink(r);
4507
+ else this.carry(r);
4508
+ this.seats();
4008
4509
  if (now % 2 === 0) {
4009
4510
  this.history.push({
4010
4511
  tick: now,
@@ -4020,7 +4521,8 @@ var Room = class {
4020
4521
  })),
4021
4522
  ...this.ctf.wire(),
4022
4523
  packs: this.gone.reduce((m, t, k) => t ? m : m + 2 ** k, 0),
4023
- balls: this.balls
4524
+ balls: this.balls,
4525
+ rovers: this.rovers
4024
4526
  });
4025
4527
  players.forEach((p) => p.conn.send(snap));
4026
4528
  this.balls = this.balls.filter((b) => !b.burst && b.left > 0);
@@ -4060,7 +4562,11 @@ var Room = class {
4060
4562
  * One the history does not hold stands where it is.
4061
4563
  */
4062
4564
  rewind(id, view = 0) {
4063
- const now = this.players().filter((p) => p.info.id !== id).map((p) => p.state);
4565
+ return this.past(view).filter((p) => p.id !== id);
4566
+ }
4567
+ /** Every player as the snapshots around the view tick `view` showed him: rewind(), the asker included. */
4568
+ past(view = 0) {
4569
+ const now = this.players().map((p) => p.state);
4064
4570
  const [first, last] = [this.history[0], this.history.at(-1)];
4065
4571
  if (!first || !last) return now;
4066
4572
  const back = ((this.ticks - view + 32768) % 65536 + 65536) % 65536 - 32768;
@@ -4120,6 +4626,7 @@ var Room = class {
4120
4626
  harm(foe, hp) {
4121
4627
  if ((foe.state.hp -= hp) > 0) return false;
4122
4628
  foe.graze = 0;
4629
+ if (foe.state.mode === MODE.RIDE) this.unseat(foe);
4123
4630
  Object.assign(foe.state, {
4124
4631
  hp: 0,
4125
4632
  down: 120,
@@ -4169,7 +4676,7 @@ var Room = class {
4169
4676
  if (!foe) return;
4170
4677
  const by = peers.find((q) => q.info.id === b.by);
4171
4678
  if (by) by.state.hits = by.state.hits + 1 & 255;
4172
- if (b.power === 0) {
4679
+ if (b.power === 0 || b.power === 6) {
4173
4680
  foe.graze = ((foe.graze ?? 0) + 1) % 2;
4174
4681
  if (!foe.graze) this.harm(foe, 1);
4175
4682
  } else if (!b.arc) this.harm(foe, b.power ?? 1);
@@ -4336,6 +4843,108 @@ var Room = class {
4336
4843
  }
4337
4844
  });
4338
4845
  }
4846
+ /** The rover `p` is seated in and his seat (0 the driver's), or nothing on foot. */
4847
+ seatOf(p) {
4848
+ if (p.state.mode === MODE.RIDE) for (const r of this.rovers) {
4849
+ const s = SEATS.findIndex((k) => r[k] === p.info.id);
4850
+ if (s >= 0) return [r, s];
4851
+ }
4852
+ return [];
4853
+ }
4854
+ /** Takes `p` off his seat: in the air where he sat. */
4855
+ unseat(p) {
4856
+ for (const r of this.rovers) SEATS.forEach((k) => r[k] = r[k] === p.info.id ? 255 : r[k]);
4857
+ Object.assign(p.state, {
4858
+ mode: MODE.AIR,
4859
+ t: 0,
4860
+ coyote: 0
4861
+ });
4862
+ }
4863
+ /**
4864
+ * The one place seats are kept true: a seat is held by a player who is there and rides, and who
4865
+ * rides holds a seat. So a leaver's seat is free before his id is given again, and one put down,
4866
+ * respawned or stumbled out is off the rover.
4867
+ */
4868
+ seats() {
4869
+ const players = this.players();
4870
+ 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;
4871
+ for (const p of players) if (p.state.mode === MODE.RIDE && !this.seatOf(p).length) this.unseat(p);
4872
+ }
4873
+ /**
4874
+ * A press of USE on foot: the nearest rover within ROVER.ENTER_R on the floor plane with a seat
4875
+ * for him, the wheel first; a flag carrier only rides. Not while down, stumbling or in a lock.
4876
+ */
4877
+ enter(p) {
4878
+ const q = p.state;
4879
+ if (q.down || q.stun || q.lock || q.mode === MODE.RIDE) return;
4880
+ const carrier = this.ctf.carrying(p.info.id) >= 0;
4881
+ const d2 = (r) => Math.abs(r.y - q.y) > ROVER.ENTER_R ? Infinity : (r.x - q.x) ** 2 + (r.z - q.z) ** 2;
4882
+ const free = (r) => r.driver === 255 && !carrier ? 0 : r.rider === 255 ? 1 : -1;
4883
+ const r = this.rovers.filter((r) => d2(r) <= ROVER.ENTER_R ** 2 && free(r) >= 0).sort((a, b) => d2(a) - d2(b))[0];
4884
+ if (r) board(q, r, free(r));
4885
+ }
4886
+ /**
4887
+ * The rider follows the rover on his seat. Over a floor, that is his last ground: where a flag he
4888
+ * carries lies if he is put down or falls with the rover.
4889
+ */
4890
+ carry(r) {
4891
+ const p = this.players().find((q) => q.info.id === r.rider);
4892
+ if (p?.state.mode === MODE.RIDE) {
4893
+ seat(p.state, r, 1);
4894
+ const y = floorAt(this.world, r.x, r.z, r.y);
4895
+ if (y > this.world.def.floor) this.ctf.place(p.info.id, {
4896
+ ...p.state,
4897
+ y
4898
+ });
4899
+ }
4900
+ }
4901
+ /** The rover fell under the kill floor: who was aboard is back at a spawn, it is parked again. */
4902
+ sink(r) {
4903
+ for (const p of this.players()) if (this.seatOf(p)[0] === r) {
4904
+ respawn(p.state, this.world, p.info.team);
4905
+ this.ctf.moved(p.state);
4906
+ }
4907
+ const k = this.rovers.indexOf(r);
4908
+ Object.assign(r, park(this.world)[k]);
4909
+ }
4910
+ /**
4911
+ * After a step of the driver `p` at the view tick `view`: the rover's body (footprint()) over an
4912
+ * enemy on foot, as `p` drew him, runs him over. Closing on him at ROVER.SPLAT_KILL or more puts
4913
+ * him down; from ROVER.SPLAT_MIN it takes 1 hp and throws him the rover's way in a stumble. Once
4914
+ * per SPLAT_COOLDOWN ticks a victim; a hit counts for the driver. The rover is never changed.
4915
+ */
4916
+ /**
4917
+ * The rover's lasers: while its driver holds FIRE, a salvo of two bolts each ROVER.GUN_COOL of his
4918
+ * inputs, toward where he looks. Not once the match is over. The rover is not changed.
4919
+ */
4920
+ lase(p, r, i) {
4921
+ p.gun = Math.max(0, (p.gun ?? 0) - 1);
4922
+ if (!(i.keys & KEY.FIRE) || p.gun || this.ctf.over || p.state.mode !== MODE.RIDE) return;
4923
+ p.gun = ROVER.GUN_COOL;
4924
+ p.bolt = (p.bolt ?? 0) + 2 & 255;
4925
+ for (const b of bolts(r, p.info.id, p.info.team, i.yaw, i.pitch, p.bolt)) this.shoot(p, i.view, b);
4926
+ }
4927
+ splat(p, r, view) {
4928
+ if (len(r.vx, r.vz) < ROVER.SPLAT_MIN) return;
4929
+ const body = footprint(r);
4930
+ for (const seen of this.enemies(p, view)) {
4931
+ const foe = this.players().find((q) => q.info.id === seen.id);
4932
+ if (!foe || foe.state.mode === MODE.RIDE || this.ticks - foe.run < SPLAT_COOLDOWN) continue;
4933
+ if (!body.find(([x, y, z]) => len(seen.x - x, seen.z - z) < ROVER.RB + .4 && seen.y < y + ROVER.BODY_H && seen.y + heightOf(seen) > y)) continue;
4934
+ const [dx, dz] = [seen.x - r.x, seen.z - r.z];
4935
+ const d = len(dx, dz) || 1;
4936
+ const closing = ((r.vx - seen.vx) * dx + (r.vz - seen.vz) * dz) / d;
4937
+ if (closing < ROVER.SPLAT_MIN) continue;
4938
+ foe.run = this.ticks;
4939
+ p.state.hits = p.state.hits + 1 & 255;
4940
+ if (!this.harm(foe, closing < ROVER.SPLAT_KILL ? 1 : foe.state.hp)) {
4941
+ const v = len(r.vx, r.vz);
4942
+ stumble(foe.state, r.vx / v, r.vz / v);
4943
+ foe.state.zap = false;
4944
+ foe.by = p.info.id;
4945
+ }
4946
+ }
4947
+ }
4339
4948
  /** The first spawn point of the team with none of `others` within SPAWN_CLEAR, else the next one round-robin. */
4340
4949
  place(id, team, others) {
4341
4950
  const n = this.world.def.teams[team].spawns.findIndex((_, k) => {
@@ -4366,6 +4975,7 @@ var Room = class {
4366
4975
  const put = [];
4367
4976
  this.rr = [0, 0];
4368
4977
  this.gone.fill(0);
4978
+ this.rovers = park(this.world);
4369
4979
  for (const p of players) {
4370
4980
  const { shots, hits } = p.state;
4371
4981
  p.state = {
@@ -4403,7 +5013,8 @@ var Room = class {
4403
5013
  bank: 10,
4404
5014
  ack: 65535,
4405
5015
  by: 0,
4406
- tackled: -30
5016
+ tackled: -30,
5017
+ run: -SPLAT_COOLDOWN
4407
5018
  };
4408
5019
  this.peers.set(conn, player);
4409
5020
  this.ctf.join(id, team, player.state);